jwt_authn: Support extraction of JWT from Cookies in JWT Extension#17721
jwt_authn: Support extraction of JWT from Cookies in JWT Extension#17721lizan merged 9 commits intoenvoyproxy:mainfrom theshubhamp:theshubhamp/envoy-jwt-cookie
Conversation
Added "from_cookies" config directive to jwt_authn that enables JWT extraction from request cookies. Testing: unit tests Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
|
Hi @theshubhamp, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
|
Running LMK if these should be included. |
source/common/http/utility.cc
Outdated
| return EMPTY_STRING; | ||
| } | ||
|
|
||
| std::map<std::string, std::string> Utility::parseCookies(const RequestHeaderMap& headers) { |
There was a problem hiding this comment.
This is very similar to the existing code in source/common/http/utility.cc #L257-L282
Could not use it as-is because that'd scan over cookies multiple times. Any suggestions on merging them together ?
There was a problem hiding this comment.
Perhaps you could introduce something like void forEachCookie(const Http::HeaderMap::GetResult cookie_headers, std::function<bool(...)> fn) where fn is a closure dealing with a cookie and returning false to stop iteration.
There was a problem hiding this comment.
Thanks for the suggestion! Was able to get this working locally 👍
I would prefer to do this change in a follow-up PR. I hope that's okay.
There was a problem hiding this comment.
Yes, a follow-up would be Ok. Just put a TODO note to the function.
There was a problem hiding this comment.
The other places using parseCookieValue would be benefit from this logic if you see how oauth2 filter use it.
I would suggest you to land the refactoring before this PR.
There was a problem hiding this comment.
Cool, I'll do that first
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
rojkov
left a comment
There was a problem hiding this comment.
Thank you! Added a couple of suggestions.
source/common/http/utility.cc
Outdated
| return EMPTY_STRING; | ||
| } | ||
|
|
||
| std::map<std::string, std::string> Utility::parseCookies(const RequestHeaderMap& headers) { |
There was a problem hiding this comment.
Perhaps you could introduce something like void forEachCookie(const Http::HeaderMap::GetResult cookie_headers, std::function<bool(...)> fn) where fn is a closure dealing with a cookie and returning false to stop iteration.
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
qiwzhang
left a comment
There was a problem hiding this comment.
LGTM on jwt_authn extractor code . Thanks.
|
/retest |
|
Retrying Azure Pipelines: |
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
|
Pushed a commit ^ that adds TODO for cookie iterator improvements suggested in the review. |
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
|
/retest |
|
Retrying Azure Pipelines: |
|
/retest |
|
Retrying Azure Pipelines: |
|
cc: @lizan, this PR requires a mandatory review from you. PTAL whenever you can! |
|
|
||
| // JWT is sent in a cookie. `from_cookies` represents the cookie names to extract from. | ||
| // | ||
| // For example, if config is: | ||
| // | ||
| // .. code-block:: yaml | ||
| // | ||
| // from_cookies: | ||
| // - auth-token | ||
| // | ||
| // Then JWT will be extracted from `auth-token` cookie in the request. | ||
| // | ||
| repeated string from_cookies = 13; |
There was a problem hiding this comment.
Move this block after from_params.
This doesn't have to be ordered by field tag.
There was a problem hiding this comment.
Done, thanks for pointing this out
source/common/http/utility.cc
Outdated
| return EMPTY_STRING; | ||
| } | ||
|
|
||
| std::map<std::string, std::string> Utility::parseCookies(const RequestHeaderMap& headers) { |
There was a problem hiding this comment.
The other places using parseCookieValue would be benefit from this logic if you see how oauth2 filter use it.
I would suggest you to land the refactoring before this PR.
| : JwtLocationBase(token, issuer_checker) {} | ||
|
|
||
| void removeJwt(Http::HeaderMap&) const override { | ||
| // TODO(theshubhamp): remove JWT from cookies. |
There was a problem hiding this comment.
Use NOT_IMPLEMENTED_GCOVR_EXCL_LINE
There was a problem hiding this comment.
Added below the comment
Reordered `from_cookies` to be after `from_params` in proto. Added NOT_IMPLEMENTED_GCOVR_EXCL_LINE in JwtCookieLocation::removeJwt(..) Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
|
/retest |
|
Retrying Azure Pipelines: |
|
can you resolve conflicts? |
…-cookie Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
Signed-off-by: Shubham Patil <theshubhamp@gmail.com>
|
Merged in master and resolved conflicts. PTAL! |

Support extraction of JWT from Cookies in JWT Extension
Added "from_cookies" config directive to jwt_authn that enables JWT extraction from request cookies.
Risk Level: low
Testing: unit tests
Docs Changes: Updated
docs/root/configuration/http/http_filters/jwt_authn_filter.rstRelease Notes: Updated
docs/root/version_history/current.rstPlatform Specific Features: None
Fixes #17424
Signed-off-by: Shubham Patil theshubhamp@gmail.com