mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
docs: Add keycloak PKCE and argo-cd cli method documentation (#20698)
* Add keycloak PKCE and argo-cd cli method Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> * add company Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> * Oups Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> * Docaposte in a separated pr Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> * Fix typo and improve doc Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> * A good idea :) Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr> --------- Signed-off-by: Grégoire Bellon-Gervais <gregoire.bellon-gervais@docaposte.fr>
This commit is contained in:
committed by
GitHub
parent
2fe9a220dd
commit
f2e4739178
BIN
docs/assets/keycloak-add-client-pkce_2.png
Normal file
BIN
docs/assets/keycloak-add-client-pkce_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
BIN
docs/assets/keycloak-authentication-successful.png
Normal file
BIN
docs/assets/keycloak-authentication-successful.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
docs/assets/keycloak-configure-client-pkce.png
Normal file
BIN
docs/assets/keycloak-configure-client-pkce.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
BIN
docs/assets/keycloak-configure-client-pkce_2.png
Normal file
BIN
docs/assets/keycloak-configure-client-pkce_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 83 KiB |
@@ -1,14 +1,23 @@
|
||||
# Keycloak
|
||||
Keycloak and ArgoCD integration can be configured in two ways with Client authentication and with PKCE.
|
||||
|
||||
# Integrating Keycloak and ArgoCD
|
||||
If you need to authenticate with __argo-cd command line__, you must choose PKCE way.
|
||||
|
||||
* [Keycloak and ArgoCD with Client authentication](#keycloak-and-argocd-with-client-authentication)
|
||||
* [Keycloak and ArgoCD with PKCE](#keycloak-and-argocd-with-pkce)
|
||||
|
||||
## Keycloak and ArgoCD with Client authentication
|
||||
|
||||
These instructions will take you through the entire process of getting your ArgoCD application authenticating with Keycloak.
|
||||
|
||||
These instructions will take you through the entire process of getting your ArgoCD application authenticating with Keycloak.
|
||||
You will create a client within Keycloak and configure ArgoCD to use Keycloak for authentication, using groups set in Keycloak
|
||||
to determine privileges in Argo.
|
||||
|
||||
## Creating a new client in Keycloak
|
||||
### Creating a new client in Keycloak
|
||||
|
||||
First we need to setup a new client. Start by logging into your keycloak server, select the realm you want to use (`master` by default)
|
||||
First we need to setup a new client.
|
||||
|
||||
Start by logging into your keycloak server, select the realm you want to use (`master` by default)
|
||||
and then go to __Clients__ and click the __Create client__ button at the top.
|
||||
|
||||

|
||||
@@ -19,60 +28,26 @@ Enable the __Client authentication__.
|
||||
|
||||
Configure the client by setting the __Root URL__, __Web origins__, __Admin URL__ to the hostname (https://{hostname}).
|
||||
|
||||
Also you can set __Home URL__ to your _/applications_ path and __Valid Post logout redirect URIs__ to "+".
|
||||
Also you can set __Home URL__ to _/applications_ path and __Valid Post logout redirect URIs__ to "https://{hostname}/applications".
|
||||
|
||||
The Valid Redirect URIs should be set to https://{hostname}/auth/callback (you can also set the less secure https://{hostname}/* for testing/development purposes,
|
||||
but it's not recommended in production).
|
||||
|
||||

|
||||
|
||||
Make sure to click __Save__. There should be a tab called __Credentials__. You can copy the Secret that we'll use in our ArgoCD
|
||||
configuration.
|
||||
Make sure to click __Save__.
|
||||
|
||||
There should be a tab called __Credentials__. You can copy the Client Secret that we'll use in our ArgoCD configuration.
|
||||
|
||||

|
||||
|
||||
## Configuring the groups claim
|
||||
|
||||
In order for ArgoCD to provide the groups the user is in we need to configure a groups claim that can be included in the authentication token.
|
||||
To do this we'll start by creating a new __Client Scope__ called _groups_.
|
||||
|
||||

|
||||
|
||||
Once you've created the client scope you can now add a Token Mapper which will add the groups claim to the token when the client requests
|
||||
the groups scope. In the Tab "Mappers", click on "Configure a new mapper" and choose __Group Membership__.
|
||||
Make sure to set the __Name__ as well as the __Token Claim Name__ to _groups_. Also disable the "Full group path".
|
||||
|
||||

|
||||
|
||||
We can now configure the client to provide the _groups_ scope. Go back to the client we've created earlier and go to the Tab "Client Scopes".
|
||||
Click on "Add client scope", choose the _groups_ scope and add it either to the __Default__ or to the __Optional__ Client Scope. If you put it in the Optional
|
||||
category you will need to make sure that ArgoCD requests the scope in its OIDC configuration. Since we will always want group information, I recommend
|
||||
using the Default category.
|
||||
|
||||

|
||||
|
||||
Create a group called _ArgoCDAdmins_ and have your current user join the group.
|
||||
|
||||

|
||||
|
||||
## Configuring ArgoCD OIDC
|
||||
### Configuring ArgoCD OIDC
|
||||
|
||||
Let's start by storing the client secret you generated earlier in the argocd secret _argocd-secret_.
|
||||
|
||||
1. First you'll need to encode the client secret in base64: `$ echo -n '83083958-8ec6-47b0-a411-a8c55381fbd2' | base64`
|
||||
2. Then you can edit the secret and add the base64 value to a new key called _oidc.keycloak.clientSecret_ using `$ kubectl edit secret argocd-secret`.
|
||||
|
||||
Your Secret should look something like this:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: argocd-secret
|
||||
data:
|
||||
...
|
||||
oidc.keycloak.clientSecret: ODMwODM5NTgtOGVjNi00N2IwLWE0MTEtYThjNTUzODFmYmQy
|
||||
...
|
||||
You can patch it with value copied previously:
|
||||
```bash
|
||||
kubectl -n argo-cd patch secret argocd-secret --patch='{"stringData": { "oidc.keycloak.clientSecret": "<REPLACE_WITH_CLIENT_SECRET>" }}'
|
||||
```
|
||||
|
||||
Now we can configure the config map and add the oidc configuration to enable our keycloak authentication.
|
||||
@@ -103,7 +78,110 @@ Make sure that:
|
||||
- __clientSecret__ points to the right key you created in the _argocd-secret_ Secret
|
||||
- __requestedScopes__ contains the _groups_ claim if you didn't add it to the Default scopes
|
||||
|
||||
## Configuring ArgoCD Policy
|
||||
## Keycloak and ArgoCD with PKCE
|
||||
|
||||
These instructions will take you through the entire process of getting your ArgoCD application authenticating with Keycloak.
|
||||
|
||||
You will create a client within Keycloak and configure ArgoCD to use Keycloak for authentication, using groups set in Keycloak
|
||||
to determine privileges in Argo.
|
||||
|
||||
You will also be able to authenticate using argo-cd command line.
|
||||
|
||||
### Creating a new client in Keycloak
|
||||
|
||||
First we need to setup a new client.
|
||||
|
||||
Start by logging into your keycloak server, select the realm you want to use (`master` by default)
|
||||
and then go to __Clients__ and click the __Create client__ button at the top.
|
||||
|
||||

|
||||
|
||||
Leave default values.
|
||||
|
||||

|
||||
|
||||
Configure the client by setting the __Root URL__, __Web origins__, __Admin URL__ to the hostname (https://{hostname}).
|
||||
|
||||
Also you can set __Home URL__ to _/applications_ path and __Valid Post logout redirect URIs__ to "https://{hostname}/applications".
|
||||
|
||||
The Valid Redirect URIs should be set to:
|
||||
- http://localhost:8085/auth/callback (needed for argo-cd cli, depends on value from [--sso-port](../../user-guide/commands/argocd_login.md))
|
||||
- https://{hostname}/auth/callback
|
||||
- https://{hostname}/pkce/verify
|
||||
|
||||

|
||||
|
||||
Make sure to click __Save__.
|
||||
|
||||
Now go to a tab called __Advanced__, look for parameter named __Proof Key for Code Exchange Code Challenge Method__ and set it to __S256__
|
||||
|
||||

|
||||
Make sure to click __Save__.
|
||||
|
||||
### Configuring ArgoCD OIDC
|
||||
Now we can configure the config map and add the oidc configuration to enable our keycloak authentication.
|
||||
You can use `$ kubectl edit configmap argocd-cm`.
|
||||
|
||||
Your ConfigMap should look like this:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: argocd-cm
|
||||
data:
|
||||
url: https://argocd.example.com
|
||||
oidc.config: |
|
||||
name: Keycloak
|
||||
issuer: https://keycloak.example.com/realms/master
|
||||
clientID: argocd
|
||||
enablePKCEAuthentication: true
|
||||
requestedScopes: ["openid", "profile", "email", "groups"]
|
||||
```
|
||||
|
||||
Make sure that:
|
||||
|
||||
- __issuer__ ends with the correct realm (in this example _master_)
|
||||
- __issuer__ on Keycloak releases older than version 17 the URL must include /auth (in this example /auth/realms/master)
|
||||
- __clientID__ is set to the Client ID you configured in Keycloak
|
||||
- __enablePKCEAuthentication__ must be set to true to enable correct ArgoCD behaviour with PKCE
|
||||
- __requestedScopes__ contains the _groups_ claim if you didn't add it to the Default scopes
|
||||
|
||||
## Configuring the groups claim
|
||||
|
||||
In order for ArgoCD to provide the groups the user is in we need to configure a groups claim that can be included in the authentication token.
|
||||
|
||||
To do this we'll start by creating a new __Client Scope__ called _groups_.
|
||||
|
||||

|
||||
|
||||
Once you've created the client scope you can now add a Token Mapper which will add the groups claim to the token when the client requests
|
||||
the groups scope.
|
||||
|
||||
In the Tab "Mappers", click on "Configure a new mapper" and choose __Group Membership__.
|
||||
|
||||
Make sure to set the __Name__ as well as the __Token Claim Name__ to _groups_. Also disable the "Full group path".
|
||||
|
||||

|
||||
|
||||
We can now configure the client to provide the _groups_ scope.
|
||||
|
||||
Go back to the client we've created earlier and go to the Tab "Client Scopes".
|
||||
|
||||
Click on "Add client scope", choose the _groups_ scope and add it either to the __Default__ or to the __Optional__ Client Scope.
|
||||
|
||||
If you put it in the Optional
|
||||
category you will need to make sure that ArgoCD requests the scope in its OIDC configuration.
|
||||
Since we will always want group information, I recommend
|
||||
using the Default category.
|
||||
|
||||

|
||||
|
||||
Create a group called _ArgoCDAdmins_ and have your current user join the group.
|
||||
|
||||

|
||||
|
||||
## Configuring ArgoCD Policy
|
||||
|
||||
Now that we have an authentication that provides groups we want to apply a policy to these groups.
|
||||
We can modify the _argocd-rbac-cm_ ConfigMap using `$ kubectl edit configmap argocd-rbac-cm`.
|
||||
@@ -126,8 +204,23 @@ You can now login using our new Keycloak OIDC authentication:
|
||||
|
||||

|
||||
|
||||
If you have used PKCE method, you can also authenticate using command line:
|
||||
```bash
|
||||
argocd login argocd.example.com --sso --grpc-web
|
||||
```
|
||||
|
||||
argocd cli will start to listen on localhost:8085 and open your web browser to allow you to authenticate with Keycloak.
|
||||
|
||||
Once done, you should see
|
||||
|
||||

|
||||
|
||||
## Troubleshoot
|
||||
If ArgoCD auth returns 401 or when the login attempt leads to the loop, then restart the argocd-server pod.
|
||||
```
|
||||
kubectl rollout restart deployment argocd-server -n argocd
|
||||
```
|
||||
|
||||
If you migrate from Client authentification to PKCE, you can have the following error `invalid_request: Missing parameter: code_challenge_method`.
|
||||
|
||||
It could be a redirect issue, try in private browsing or clean browser cookies.
|
||||
|
||||
Reference in New Issue
Block a user