Skip to content

LG-6948: Store key name in AttemptEvent redis key#6811

Merged
n1zyy merged 8 commits intomainfrom
mattw/LG_6948_jwe_key_name
Aug 26, 2022
Merged

LG-6948: Store key name in AttemptEvent redis key#6811
n1zyy merged 8 commits intomainfrom
mattw/LG_6948_jwe_key_name

Conversation

@n1zyy
Copy link
Contributor

@n1zyy n1zyy commented Aug 22, 2022

Why: To allow for eventual support for key rotation, where we'd want to indicate which key was used to encrypt a particular event.

Commentary

I don't completely love this, but I think we should go with this unless someone has a better idea.

The schema describes us as returning something like this:

{
  "sets": {
    "4cf27640-5b92-4b10-9c96-40e4e3f1f183": {
        "KEYID": "ENCRYPTED_VALUE"
    },
    "8ae5ed6b-5efd-423d-8afa-cbd82a9cf439": {
        "KEYID2": "ENCRYPTED_VALUE"
    }
  }
}

Where KEYID or KEYID2 would be the key ID used to encrypt the event.

Redis seems to only support string hash values, so I ended up encoding this in Redis as key_id:jti for the key and a simple jwe as the value. We then swap it out to the format indicated in the schema when reading it from Redis.

The goal of this story is only to get the returned data supporting this, not to actually support multiple keys. That will probably some changes to how keys are stored in addition to the code changes.

event_data = parsed_event['events'].values.first
AttemptEvent.new(
jti: parsed_event['jti'],
jti: parsed_event['jti'].split(':').last,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to extract out the key_id as a property on the event now too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story is dragging on (my fault), but having just implemented this, I don't like it and think I want to change the model a bit.

tl;dr, it doesn't make sense to me to set key id but not be able to set the key itself. It's logical enough in from_jwe that we'd capture that information, but if you were to then call key_id you'd get a key id that might not match what event_data_encryption_key returns.

Right now it's implemented in the yaml like so:

  irs_attempt_api_public_key: change-me-pls
  irs_attempt_api_public_key_id: key1

This seems easy enough for currently only supporting one key. If we're going to keep this, I think we should not extract the key_id parameter as proposed in this comment.

But I feel like what we actually want is something like:

  irs_attempt_api_public_keys:
    key1: change-me-pls

Then, setting key_id in code would cause the correct public key to be looked up.

What do you think, @zachmargolis et al.? Should I go ahead with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly, I'm not sure I follow anymore so I trust your call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'm going to propose leaving this as-is for now and not explicitly capturing key_id as an attribute inside AttemptEvent.

What I proposed with application.yml.default changes turns out to not be quite how IdentityConfig works, and feels a little too close to implementing actual multi-key support. (Jack also pointed out that it would probably make more sense to implement storage of that in the database when the time comes.)

@n1zyy n1zyy marked this pull request as ready for review August 25, 2022 15:06
key_id, jit = k.split(':')
sets[jit] = { key_id => v }
end
sets
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not thrilled with this living in the controller, but we're getting a hash out of Redis and it's just doing some light data munging. 😐

@n1zyy n1zyy requested review from a team and mitchellhenke August 25, 2022 20:49
Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one typo?

Otherwise looks good!

@n1zyy n1zyy merged commit bf91847 into main Aug 26, 2022
@n1zyy n1zyy deleted the mattw/LG_6948_jwe_key_name branch August 26, 2022 20:18
@aduth aduth mentioned this pull request Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants