-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keycloak modules retry request on authentication error, support refresh token parameter #9494
base: main
Are you sure you want to change the base?
Conversation
…not yet working [8857]
…ith retry logic [8857]
… credentials [8857]
…n, valid refresh token [8857]
…without username/pass [8857]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @armkeh thanks for your contribution!
Couple of comments on the PR.
required_together=([['auth_realm', 'auth_username', 'auth_password']]), | ||
required_by={ | ||
'refresh_token': 'auth_realm', | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a pain, but being helpful to those coming after us:
required_together=([['auth_realm', 'auth_username', 'auth_password']]), | |
required_by={ | |
'refresh_token': 'auth_realm', | |
}) | |
required_together=([['auth_realm', 'auth_username', 'auth_password']]), | |
required_by={'refresh_token': 'auth_realm'}, | |
) |
We get leaner PRs with this, like one for plugins/modules/keycloak_clientscope_type.py below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! Please add a changelog fragment. Thanks.
|
||
return self.get_client_role_scope_from_realm(clientid, realm) | ||
|
||
def fail_open_url(self, e, msg, **kwargs): | ||
def fail_request(self, e, msg, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method fail_open_url
must be kept (simply add a wrapper that calls fail_request
) for backwards compatibility. The module utils is part of the public API of the collection.
token = _get_token_using_credentials(self.module.params) | ||
self.restheaders['Authorization'] = 'Bearer ' + token | ||
|
||
return make_request_ignoring_401() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the last request be made without ignoring 401?
SUMMARY
Fixes #8857.
Wraps all requests to Keycloak in the Keycloak modules (
keycloak_authentication
,keycloak_authz_authorization_scope
,keycloak_authz_custom_policy
, etc.) with retry logic to make use of a newrefresh_token
module parameter.This improves the user experience when using Keycloak modules with the
auth_token
parameter; previously if that token expired during playbook execution, subsequent tasks would fail. Now they "fall back" to using therefresh_token
, or, if it is not provided or is expired itself, to using theauth_username
andauth_password
.ISSUE TYPE
COMPONENT NAME
keycloak