feat: SSO support for Argo Workflows CLI #14471
Open
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.
Support authentication in Argo Workflows CLI via SSO and store / reuse the token in further CLI calls.
The PR also adds support for file-based configuration via
Viper
.New command is as follows:
You can also optionally pass
--sso-port
variable for a custom local server port.Help for the cmd:
A new global CLI option
--config
is added to load config from a custom file location. If omited - we use$HOME/.argo/config.yaml
as the default config file location.Motivation
In our company we have hundreds of users of Argo Workflows.
From time to time users use
argo
cli to test / update / trigger workflows simply because that's it's handier than UI and because you can script it however you need with predefined params.The only downside to the approach is that users had to copy
ARGO_TOKEN
from workflows UI, manually store it somewhere then periodically update etc..If we compare the workflow to ArgoCD CLI - we can clearly see advantages of using SSO within that CLI and automatically storing tokens.
This PR attempts to bring this functionality on par with
argocd
cli.ArgoCD and Argo Workflows use slightly different mechanics underneath when it comes to SSO:
CLI Flow
Modifications
In order to support CLI SSO Flow, I customized the
state
cookie within oauth flow to include besides redirect url some additional information:cli
flag to indicate that this is a CLI flowcli_state
variable to include state from CLI into temporary JWT token (jti
) and validate it during JWT token exchange phase.The above means that we need to encode the data to store it in a cookie.
For the purpose I encoded the data into
json
and then further encoded it intobase64
to encode invalid cookie characters.When we are in the CLI flow within
/oauth2/callback
handler - then instead of storing auth token within CookiesCLI then calls
POST /oauth2/cli/exchange
with the code and cli state in json body to exchange the code (temporary cli jwt) for authentication token (actual long-living jwt).The token is then stored within
$HOME/.argo/config.yaml
file.On server side to split token types I used JWT Audiences.
cli-auth
audience and is not valid for anything besides cli exchange flow (the token is valid for just 10 seconds to minimise any potential security risks).argo-session
audience and is used for normal operations (beforehand audience wasn't set at all).In order to support token preloading from config file I utilised
viper.ReadInConfig()
method.Since you already using viper in your command parsing code it was logic choice.
I also moved viper configuration and flags override into
cobra.OnInitialize()
method since that is the correct way to update flags only after they were fully parsed.And lastly, I allowed
localhost
inredirect
value for/oauth2/redirect
handler as otherwise we can't redirect to a local CLI server.Verification
Changes were successfully tested locally using Dev Containers.
Documentation
Documentation was updated automatically when I ran
make pre-commit -B
I find the generated documentation sufficient.
Users can discover the new feature simply by using
argo --help
orargo auth --help
.