Skip to content

jwt_authn: Add header_to_metadata#18140

Merged
mattklein123 merged 12 commits intoenvoyproxy:mainfrom
dio:jwt-auth-18138
Sep 21, 2021
Merged

jwt_authn: Add header_to_metadata#18140
mattklein123 merged 12 commits intoenvoyproxy:mainfrom
dio:jwt-auth-18138

Conversation

@dio
Copy link
Copy Markdown
Member

@dio dio commented Sep 16, 2021

Commit Message:

This patch adds the header_to_metadata field to the JwtProvider config to allow setting the extracted header of a successfully verified JWT to dynamic metadata.

Additional Description:
Risk Level: Low, a new feature
Testing: Added
Docs Changes: Added
Release Notes: Added
Platform-Specific Features: N/A
Fixes #18138

dio added 2 commits September 16, 2021 01:43
This patch adds header_to_metadata field to JwtProvider config to allow
setting the extracted header of a successfully verified JWT to dynamic
metadata.

Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #18140 was opened by dio.

see: more, trace.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #18140 was opened by dio.

see: more, trace.

Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@lizfeed
Copy link
Copy Markdown

lizfeed commented Sep 16, 2021

Thanks for the quick response! I've verified I can log this new metadata field in this release. I use envoy_data_plane, so I can also verify that the protobufs are generated correctly at least for python.

Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio dio marked this pull request as ready for review September 16, 2021 20:52
@dio dio requested a review from lizan as a code owner September 16, 2021 20:52
Comment thread source/extensions/filters/http/jwt_authn/verifier.cc Outdated
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Comment thread api/envoy/extensions/filters/http/jwt_authn/v3/config.proto Outdated
// kid: EF71iSaosbC5C4tC6Syq1Gm647M
// alg: PS256
//
string header_in_metadata = 14;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if payload_in_metadata is the same as header_in_metadata? Is it allowed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it should not be allowed, please add comment on this restriction.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a warning section. Please let me know if we want to validate this when checking the config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, the current comment says ... is not allowed ... which I would expect the validation is going to reject the config, or you can just update the comment to be more accurate (it's not suggested due to potential override but can still be used (won't be rejected in validation) if the user is sure it won't have any override for their use case).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@yangminzhu I updated as you suggested.

dio added 4 commits September 16, 2021 16:19
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio dio requested review from qiwzhang and yangminzhu September 16, 2021 23:52
// kid: EF71iSaosbC5C4tC6Syq1Gm647M
// alg: PS256
//
string header_in_metadata = 14;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, the current comment says ... is not allowed ... which I would expect the validation is going to reject the config, or you can just update the comment to be more accurate (it's not suggested due to potential override but can still be used (won't be rejected in validation) if the user is sure it won't have any override for their use case).

// The active span for the request
Tracing::Span* parent_span_{&Tracing::NullSpan::instance()};
// the callback function to set payload
// The callback function called to set the extracted payload and header from a verified JWT.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

set_payload_cb_ should have a more generic name as it now sets both payload and header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated.

qiwzhang
qiwzhang previously approved these changes Sep 17, 2021
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio
Copy link
Copy Markdown
Member Author

dio commented Sep 17, 2021

@qiwzhang @yangminzhu I have a question, re:

/**
* Successfully verified JWT payload are stored in the struct with its
* *fields* containing **issuer** as keys and **payload** as string values
* This function is called before onComplete() function.
* It will not be called if no payload to write.
*/
. Do you think this is still correct? I'm not sure I understand there is a use-case when we do this (storing the payload as a string).

dio added 2 commits September 16, 2021 22:12
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio dio requested review from qiwzhang and yangminzhu September 17, 2021 23:54
@mattklein123
Copy link
Copy Markdown
Member

Will wait for review/approve from @yangminzhu or @qiwzhang before looking, thanks.

/wait-any

@yangminzhu
Copy link
Copy Markdown
Contributor

@qiwzhang @yangminzhu I have a question, re:

/**
* Successfully verified JWT payload are stored in the struct with its
* *fields* containing **issuer** as keys and **payload** as string values
* This function is called before onComplete() function.
* It will not be called if no payload to write.
*/

. Do you think this is still correct? I'm not sure I understand there is a use-case when we do this (storing the payload as a string).

storing the payload as a string is to pass the payload to backend application without the signature so that the backend can not reuse the JWT token.

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.

No way to retrieve JWT kid as metadata

5 participants