feat: support keycloak based login #309
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Description
This implements an auth handler that if your lagoon-cli configuration has a keycloak url defined, will hand off the authentication to keycloak and redirect the user back to the cli once a token has been retrieved. To use this feature, you just need to use the
--keycloak-url
when adding a cluster configuration (or edit your cli configuration file manually) and point it to your lagoon provided keycloak bare url (eg.https://keycloak.example.com
).This also uses the oauth token refresh mechanism to automatically refresh the token if it expires. There are some conditions on this though, if the targeted keycloak has low SSO session values, then a user may be prompted to login more frequently as there are limits to the length of time an inactive session can use a refresh token. Lagoon administrators should configure sensible SSO session values in their keycloak configuration to prevent users from being frustrated from having to log in continuously.
It also changes the standard ssh token generation to use the
grant
option instead of the oldertoken
option, the grant option returns a standard oauth token instead of just the raw access token.SSH token generation is still the default option for the cli for the time being so that tools in CI etc can still generate tokens as requried. Eventually SSH token generation will be disabled by default, and users will need to update their configuration files to change the
sshtoken
value fromfalse
totrue
if they wish to use ssh tokens (see theconfig add
documentation for the--ssh-token
flag when adding a cluster configuration, or edit the configuration file manually)Usage example
You will then be prompted to log in normally via a browser


Once logged in, it will redirect you to let you know you've successfully logged in
When you return to the cli, you should see that it has logged in and returned your requested data
The login message and success are printed to stderr, so tools like
jq
can still process the stdout as required.