Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt_authn: Allow to extract keys from jwt struct claims #30377

Merged
merged 5 commits into from
Oct 24, 2023

Conversation

Reflejo
Copy link
Contributor

@Reflejo Reflejo commented Oct 23, 2023

Commit Message: Allow to extract object from jwt struct claims
Additional Description:

Serialize non-primitive custom claim objects from JWT tokens. The JWT filter will now serialize these claim as JSON and encode it to Base64.

Risk Level: Low
Testing: unit test
Docs Changes: Updated docs/root/configuration/http/http_filters/jwt_authn_filter.rst
Release Notes: Updated changelogs/current.yaml

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #30377 was opened by Reflejo.

see: more, trace.

Added a new field `list_claim_keys` on
:ref:`claim_to_headers <envoy_v3_api_field_extensions.filters.http.jwt_authn.v3.JwtProvider.claim_to_headers>`
to extract keys from JWT token claims. This field enables the retrieval of keys
from custom JWT token claims, such as `{"tenants": {"bitdrift": {}}` (in this
case a claim_name of `tenants would extract the key "bitdrift").

Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
@mattklein123 mattklein123 self-assigned this Oct 23, 2023
@Reflejo Reflejo changed the title Allow to extract keys from jwt struct claims jwt_authn: Allow to extract keys from jwt struct claims Oct 23, 2023
@htuch
Copy link
Member

htuch commented Oct 23, 2023

CC @kyessenov

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

At a high level this seems like a useful feature, however I'm wondering if it would be more future proof to have an option to pack the entire struct into the header, vs. being specific about a list.

For example, you could take the struct and base64 encode the JSON. Or pack it in a proto stuct and base64 that.

Thoughts @lizan @kyessenov ?

@lizan
Copy link
Member

lizan commented Oct 23, 2023

@Reflejo can you elaborate your exact use case for this?

I would like the API to be more generic / future proof and not specific about a list. But would like to know where this implementation is coming from.

/wait:any

@Reflejo
Copy link
Contributor Author

Reflejo commented Oct 23, 2023

@lizan The use-case is many authentication providers nowadays send custom claims on JWT tokens that are formatted as per my example:

"tenants": {"a": {}, "b": {}}

Basically they do this as a way of sending lists. Our specific use-case is, we need to extract the tenants from the jwt and forward them to the service as a header.

I wouldn't mind changing my PR to define a bool serialize_struct instead and send the JSON string in base64. Would that be better?

@kyessenov
Copy link
Contributor

Unless there's a common RFC that requires this encoding, I think I mostly agree with Matt's proposal - either encoding the whole JWT sub-struct as a header, or a separate extension that computes the header from dynamic metadata would be better.

Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
@Reflejo
Copy link
Contributor Author

Reflejo commented Oct 24, 2023

@kyessenov @lizan @mattklein123 updated the PR implementing the proposed solution (serializing objects). The reason I added the flag allow_serialize_object (instead of just serializing non-primitive types) is to not make this a breaking change (ie anyone relying on the fact that we ignore keys with object types right now).

@kyessenov
Copy link
Contributor

The last change looks good to me. I'm not sure it deserves an API flag since it's a new feature with a reasonable default (don't expect this header to blow up since it's always a subset of JWT).

@kyessenov
Copy link
Contributor

Related: #30072

@mattklein123
Copy link
Member

The last change looks good to me. I'm not sure it deserves an API flag since it's a new feature with a reasonable default (don't expect this header to blow up since it's always a subset of JWT).

I had mentioned to @Reflejo offline that I could probably lose the API change as well, but I don't feel strongly either way. This is certainly safer. I suppose if we wanted to limit the API change we could runtime guard instead. I'm fine either way. This LGTM. @lizan?

Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
@Reflejo
Copy link
Contributor Author

Reflejo commented Oct 24, 2023

ok removed the flag, this should be ready to go

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 enabled auto-merge (squash) October 24, 2023 16:41
@mattklein123 mattklein123 merged commit 42934fb into envoyproxy:main Oct 24, 2023
102 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants