Add rule requirement feature to jwt_authn filter#4101
Add rule requirement feature to jwt_authn filter#4101mattklein123 merged 23 commits intoenvoyproxy:masterfrom
Conversation
There was a problem hiding this comment.
matchers_ should be created per filter config, not per request. Here Authenticator is created per-request.
You can move them here https://github.com/envoyproxy/envoy/blob/master/source/extensions/filters/http/jwt_authn/filter_config.h#L59
There was a problem hiding this comment.
You can just ommit the parameter name.
There was a problem hiding this comment.
also, make the parameter const reference?
There was a problem hiding this comment.
from the comment, you don't need a pair, just return a JwtMatcherConstPtr is enough
There was a problem hiding this comment.
Ideally, we only need to extract the tokens for required providers. So Extractor should take a list of required_issuers.
There was a problem hiding this comment.
Current approach will be very difficult to extend to support multiple tokens. Especially with such requirements as
- require A and B, or 2) require A or B.
Ideally, for 1), if A fail, not need to verify B. for 2) if A success, not need to verify B
But single token is the most common use case. We can worry about supporting multiple tokens later.
Please add // TODO
There was a problem hiding this comment.
can we move Matcher into a set of .h, and .cc file, and add some unit-test for them.
Same for Verifier.
There was a problem hiding this comment.
I think we need two functions:
requiredIssuers() to return required issuers. This one is need for Extractor to only extract required tokens.
staus verify(vector<pair<issuer, status>> issuer_status); // after required token are verified, passed their issuers and verified_status to verify if they satisfy the requirement.
There was a problem hiding this comment.
- To do this we need to move jwt parser to extractor?
- OK I'll do that.
|
@potatop thanks for helping out this feature. Here are some high level ideas how it should be done:
|
There was a problem hiding this comment.
Not need to list verifier.h here again since this lib depends on verifier_lib which already listed it.
There was a problem hiding this comment.
per google style guide: https://google.github.io/styleguide/cppguide.html
please add comment for each function in the header file.
There was a problem hiding this comment.
you could implement it here. move line 42- 47 here
There was a problem hiding this comment.
for is_allow_missing_or_failed, try to see if we don't need to make this as a special case.
There was a problem hiding this comment.
can we have one static function to create a matcher? hide of the logic of creating different matcher inside the function.
There was a problem hiding this comment.
This checking will not eliminate anything.
What I means is: when each request come, find its matched requirement, and required provider, only extract token for that provider or providers.
There was a problem hiding this comment.
Yeah, I realized that later, so I already changed that. However, I'll probably back out all this With extract only returning tokens with expected issuers, this is probably not needed.
|
@potatop please try to restructure the data flow to following: a) find the requirement for a request, if no found, just pass the request. |
|
I'm working to add more tests. |
62754b9 to
df53323
Compare
|
@qiwzhang I updated the code like you asked. Please take another look. Thanks |
There was a problem hiding this comment.
Can we pass in a reference, not to make a copy
There was a problem hiding this comment.
please move these implementation inside the class, e.g. to line 49. It will be easier to read
There was a problem hiding this comment.
Ideally, not to check all headers or parameters. only check these headers and parameters specified by the required providers
There was a problem hiding this comment.
In general, I don't like this implementation. It put all logic inside this class. The code is fairly complicated.
Please take a look rbac implementation in Envoy. https://github.com/envoyproxy/envoy/tree/master/source/extensions/filters/common/rbac
Please try to see if we can implement the matcher like that.
d105bd8 to
7b3c54c
Compare
|
@qiwzhang What about this? Matchers are created at start up based on the rules configuration. |
7b3c54c to
d09300f
Compare
| if (state_ == Responded) { | ||
| return; | ||
| } | ||
| if (context_) { |
There was a problem hiding this comment.
This should be done by the Verifier.
The correct way is: in BaseVerifierImpl::completeWithStatus() function, before calling the context->callback, call context->cancel()
| FilterConfigSharedPtr filter_config_; | ||
| MockJwksFetcher* fetcher_; | ||
| JwksFetcherPtr fetcherPtr_; | ||
| JwksFetcherPtr fetcher_ptr_; |
There was a problem hiding this comment.
how about this one is called fetcher_. the one above it is called raw_fetcher_
| auth_->verify(headers, std::move(tokens), std::move(on_complete_cb)); | ||
| } | ||
|
|
||
| // This test verifies that when invalid Jwks is fetched, JwksFetchFail status is returned. |
There was a problem hiding this comment.
comment doesn't match the test
Signed-off-by: Kai Yang <kai.yang@intradiem.com>
9505c79 to
c083bbd
Compare
|
LGTM |
|
@lizan Can this be merged now? |
8af3414 to
05ce051
Compare
Signed-off-by: Kai Yang <kai.yang@intradiem.com>
05ce051 to
0ce1d0b
Compare
|
Sorry I was on vacation last Friday, LGTM and I will take another pass tomorrow since this is huge. |
|
Ok. Thanks. |
Signed-off-by: Kai Yang <kai.yang@intradiem.com>
|
@potatop thanks, waiting one of senior maintainers to take a final pass and merge. |
mattklein123
left a comment
There was a problem hiding this comment.
Did a high level skim / sanity check and LGTM.
Title: Add rule requirement feature to jwt_authn filter
Description: Add rule requirement feature based on config proto and discussions in #3381.
Requires type provider_and_audiences, requires_any, and requires_all is not implemented.
Risk Level: Medium
Testing: unit test and manual