THREESCALE-11887 Add configurable whitelist_deny_unmatched policy option - #1605
borisurbanik wants to merge 4 commits into
Conversation
df726c7 to
1c1afcc
Compare
|
The current PR shape is unnecessary complicated and confused. For example, if I have type set to Typically, you would only want the policy react on what is being configured, the Arguably, a better assumption might be that if an admin didn't configure a path, there is no explicit rules for the path. With no explicit rules, the policy should ignore paths not matching any scope. So, for this PR, I suggest to add a simple boolean value to the |
1c1afcc to
7b3e856
Compare
Yes, that's a good simplification, the blacklist path is the confusing one. I've updated the policy to use a whitelist specific boolean and ignore it in the blacklist path. |
7b3e856 to
923e5f9
Compare
923e5f9 to
e67a96e
Compare
tkan145
left a comment
There was a problem hiding this comment.
No spec or .t test covers "missing JWT + whitelist_deny_unmatched: false + a request path that matches a configured scope."
|
|
||
| if not context.jwt then | ||
| return false | ||
| return nil |
There was a problem hiding this comment.
Why are we doing this? This is authentication bypass
There was a problem hiding this comment.
Thank you for the review! To answer your question - this PR intentionally preserves the existing functionality when type is blacklist. The nil return was introduced to implement the whitelist_deny_unmatched flag where it needs to distinguish between no path matched and path matched but roles failed. You can verify that both nil and false result produce the same outcome in the blacklist branch compared to master in all configurations except when whitelist path is unmatched.
I agree that the blacklist implementation is very permissive, but it works in tandem with jwt_parser. Enforcing this in the keycloak policy would be inconsistent with jwt_parser.required: false. Note that if a service is using oauth, JWT will always be present. This code path is only possible if customers are explicitly injecting JWT with jwt_parser to requests authenticated with api key.
Please open a separate JIRA if the policy should deny blacklist when no JWT is in the context.
a7f18c0 to
46699cf
Compare
Thanks for the review, I've added missing JWT tests to specs for whitelist for combinations of matched/unmatched paths and whitelist_deny_unmatched configurations. |
Fixes:
Verification:
Deploy 3Scale and Keycloak using the operators.
The default 3Scale configuration comes with API Product and Developer account that has an echo backend mapped to /echo path.
Configure 3Scale OIDC integration for the API Product following the documentation:
https://docs.redhat.com/en/documentation/red_hat_3scale_api_management/2.16/html/administering_the_api_gateway/integrating-threescale-with-an-openid-connect-identity-provider#integrating-threescale-with-rhsso-as-the-openid-connect-identity-provider_oidc
Add new application under Developer account, set client id and client password environment variables:
Verify that the integration is setup correctly:
To test authorized user, add another application and assign a role "my-role" to the corresponding client (this will work with configuration below).
Scenarios tested
Policy created with original version:
{ "name": "keycloak_role_check", "version": "builtin", "configuration": { "scopes": [ { "realm_roles": [], "resource": "/echo/protected", "methods": [ "ANY" ], "client_roles": [ { "client": "{{ jwt.azp }}", "name": "my-role", "name_type": "plain", "client_type": "liquid" } ], "resource_type": "plain" } ], "type": "whitelist" } }With authorized application: 200 response for /echo/protected, 403 for /echo
With not-authorized application: 403 for both
With authorized application: 200 response for both
With not-authorized application: 403 for /echo/protected, 200 response for /echo