db4b2cb577
## Backport This PR is auto-generated from #18062 to be assessed for backporting due to the inclusion of the label backport/1.16. The below text is copied from the body of the original PR. --- ### Description <!-- Please describe why you're making this change, in plain English. --> - Currently the jwt-auth filter doesn't take into account the service identity when validating jwt-auth, it only takes into account the path and jwt provider during validation. This causes issues when multiple source intentions restrict access to an endpoint with different JWT providers. - To fix these issues, rather than use the JWT auth filter for validation, we use it in metadata mode and allow it to forward the successful validated JWT token payload to the RBAC filter which will make the decisions. This PR ensures requests with and without JWT tokens successfully go through the jwt-authn filter. The filter however only forwards the data for successful/valid tokens. On the RBAC filter level, we check the payload for claims and token issuer + existing rbac rules. ### Testing & Reproduction steps <!-- * In the case of bugs, describe how to replicate * If any manual tests were done, document the steps and the conditions to replicate * Call out any important/ relevant unit tests, e2e tests or integration tests you have added or are adding --> - This test covers a multi level jwt requirements (requirements at top level and permissions level). It also assumes you have envoy running, you have a redis and a sidecar proxy service registered, and have a way to generate jwks with jwt. I mostly use: https://www.scottbrady91.com/tools/jwt for this. - first write your proxy defaults ``` Kind = "proxy-defaults" name = "global" config { protocol = "http" } ``` - Create two providers ``` Kind = "jwt-provider" Name = "auth0" Issuer = "https://ronald.local" JSONWebKeySet = { Local = { JWKS = "eyJrZXlzIjog....." } } ``` ``` Kind = "jwt-provider" Name = "okta" Issuer = "https://ronald.local" JSONWebKeySet = { Local = { JWKS = "eyJrZXlzIjogW3...." } } ``` - add a service intention ``` Kind = "service-intentions" Name = "redis" JWT = { Providers = [ { Name = "okta" }, ] } Sources = [ { Name = "*" Permissions = [{ Action = "allow" HTTP = { PathPrefix = "/workspace" } JWT = { Providers = [ { Name = "okta" VerifyClaims = [ { Path = ["aud"] Value = "my_client_app" }, { Path = ["sub"] Value = "5be86359073c434bad2da3932222dabe" } ] }, ] } }, { Action = "allow" HTTP = { PathPrefix = "/" } JWT = { Providers = [ { Name = "auth0" }, ] } }] } ] ``` - generate 3 jwt tokens: 1 from auth0 jwks, 1 from okta jwks with different claims than `/workspace` expects and 1 with correct claims - connect to your envoy (change service and address as needed) to view logs and potential errors. You can add: `-- --log-level debug` to see what data is being forwarded ``` consul connect envoy -sidecar-for redis1 -grpc-addr 127.0.0.1:8502 ``` - Make the following requests: ``` curl -s -H "Authorization: Bearer $Auth0_TOKEN" --insecure --cert leaf.cert --key leaf.key --cacert connect-ca.pem https://localhost:20000/workspace -v RBAC filter denied curl -s -H "Authorization: Bearer $Okta_TOKEN_with_wrong_claims" --insecure --cert leaf.cert --key leaf.key --cacert connect-ca.pem https://localhost:20000/workspace -v RBAC filter denied curl -s -H "Authorization: Bearer $Okta_TOKEN_with_correct_claims" --insecure --cert leaf.cert --key leaf.key --cacert connect-ca.pem https://localhost:20000/workspace -v Successful request ``` ### TODO * [x] Update test coverage * [ ] update integration tests (follow-up PR) * [x] appropriate backport labels added --- <details> <summary> Overview of commits </summary> - 70536f5a38507d7468f62d00dd93a6968a3d9cf3 </details> Co-authored-by: Ronald Ekambi <ronekambi@gmail.com> |
||
---|---|---|
.. | ||
default-allow-deny-all-and-path-allow--httpfilter.golden | ||
default-allow-deny-all-and-path-allow.golden | ||
default-allow-deny-all-and-path-deny--httpfilter.golden | ||
default-allow-deny-all-and-path-deny.golden | ||
default-allow-kitchen-sink--httpfilter.golden | ||
default-allow-kitchen-sink.golden | ||
default-allow-one-deny--httpfilter.golden | ||
default-allow-one-deny.golden | ||
default-allow-path-allow--httpfilter.golden | ||
default-allow-path-allow.golden | ||
default-allow-path-deny--httpfilter.golden | ||
default-allow-path-deny.golden | ||
default-allow-service-wildcard-deny--httpfilter.golden | ||
default-allow-service-wildcard-deny.golden | ||
default-allow-single-intention-with-kitchen-sink-perms--httpfilter.golden | ||
default-allow-single-intention-with-kitchen-sink-perms.golden | ||
default-allow-two-path-deny-and-path-allow--httpfilter.golden | ||
default-allow-two-path-deny-and-path-allow.golden | ||
default-deny-allow-deny--httpfilter.golden | ||
default-deny-allow-deny.golden | ||
default-deny-deny-all-and-path-allow--httpfilter.golden | ||
default-deny-deny-all-and-path-allow.golden | ||
default-deny-deny-all-and-path-deny--httpfilter.golden | ||
default-deny-deny-all-and-path-deny.golden | ||
default-deny-kitchen-sink--httpfilter.golden | ||
default-deny-kitchen-sink.golden | ||
default-deny-mixed-precedence--httpfilter.golden | ||
default-deny-mixed-precedence.golden | ||
default-deny-one-allow--httpfilter.golden | ||
default-deny-one-allow.golden | ||
default-deny-path-allow--httpfilter.golden | ||
default-deny-path-allow.golden | ||
default-deny-path-deny--httpfilter.golden | ||
default-deny-path-deny.golden | ||
default-deny-peered-kitchen-sink--httpfilter.golden | ||
default-deny-peered-kitchen-sink.golden | ||
default-deny-service-wildcard-allow--httpfilter.golden | ||
default-deny-service-wildcard-allow.golden | ||
default-deny-single-intention-with-kitchen-sink-perms--httpfilter.golden | ||
default-deny-single-intention-with-kitchen-sink-perms.golden | ||
default-deny-two-path-deny-and-path-allow--httpfilter.golden | ||
default-deny-two-path-deny-and-path-allow.golden | ||
empty-top-level-jwt-with-one-permission--httpfilter.golden | ||
empty-top-level-jwt-with-one-permission.golden | ||
top-level-jwt-no-permissions--httpfilter.golden | ||
top-level-jwt-no-permissions.golden | ||
top-level-jwt-with-multiple-permissions--httpfilter.golden | ||
top-level-jwt-with-multiple-permissions.golden | ||
top-level-jwt-with-one-permission--httpfilter.golden | ||
top-level-jwt-with-one-permission.golden |