Access Control
local graph
Chapter 4 — Access Control
Section titled “Chapter 4 — Access Control”In this chapter, we’re going to discover how to set up a user’s access to Argo CD, what options we have in order to connect with the CLI from a terminal or a CI/CD pipeline, and how role-based access control is performed. We will be checking out the single sign-on (SSO) options, which usually is a feature that you need to pay for, but with Argo CD being completely open source and without a commercial offering, you receive that out of the box.
The main topics we are going to cover are as follows:
- Declarative users
- Service accounts
- Single sign-on
Technical requirements
Section titled “Technical requirements”For this chapter, we assume you already have an installation of Argo CD up and running on your device or on a cloud platform. We don’t need a highly available one; it can be in a local Kubernetes cluster, but we do need one that can manage itself because we are going to make several changes to it. For the single sign-on part, we will need an installation that can be reached by our external provider, so we will need a domain name or a public IP for it.
We are going to write some code (YAML to be more precise), so a code editor will be needed as well. I am using Visual Studio Code (https://code.visualstudio.com). All the changes we will be making can be found at the book’s companion GitHub repository in the ch04 folder.
Declarative users
Section titled “Declarative users”The Open Web Application Security Project (OWASP) – https://owasp.org – is a nonprofit foundation that does a lot of work with regard to web application security. Their most well-known project is the OWASP Top Ten (https://owasp.org/www-project-top-ten/), which is a list of the most important risks to consider when it comes to the security of our web applications. They update this list every few years. Currently, in their latest version, which is from 2021, so brand new, we have in first place Broken Access Control (it was in the fifth position on the previous 2017 list). Since the primary goal of the Top Ten is to bring awareness in the community about the major web security risks, we can understand with Broken Access Control being at the top that it is critical to do a proper setup for our users and the kind of access everyone gets in order to not violate the principle of least privilege. It would be common for our development teams to get write access to development environments and read-only for our production ones, while an SRE would have full rights. Next, we will see how to accomplish that.
Admin and local users
Section titled “Admin and local users”After we install Argo CD in the cluster, all we get is the admin user. Initially, the password for the admin user was the name of the application server Pods (and if there were more, then the first one that started); it looked something like this – argocd-server-bfb77d489-wnzjk. But this was considered a poor choice because the first part (the Pod starts with argocd-server-) was fixed for most installations, while the second part was generated and it was supposed to have random characters, but they weren’t actually random (more details can be found at https://argo-cd.readthedocs.io/en/stable/security_considerations/#cve-2020-8828-insecure-default-administrative-password). Moreover, it was visible to everyone who had cluster access (which didn’t necessarily mean Argo CD admin access). So, ever since version 2.0.0 was released, a new password is generated for the user when the application is installed and it is saved in a Secret called argocd-initial-admin-secret. We can see what the password is after installation with this command:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -dThe command output is your password and it should look something like this (from which you should remove the % character because the shell inserted this CR/LF in order for the prompt to start on a new line):
pOLpcl9ah90dViCD%Now, you can use the password for the UI and CLI to check that it all works. For updating the password, you can use the UI by navigating to the User-Info section, or there is also the possibility of doing it via the CLI with the argocd account update-password command (https://argo-cd.readthedocs.io/en/stable/user-guide/commands/argocd_account_update-password/). If you forget the password, there is a way to reset it and it involves making some changes directly on the Argo CD main Secret resource where the bcrypt hashes are stored – more details can be found at https://argo-cd.readthedocs.io/en/stable/faq/#i-forgot-the-admin-password-how-do-i-reset-it.
The next thing after we have the admin user up and running would be to disable it because it is just too powerful and we want to follow the least privilege principle, which means we should use only the minimal type of access that we need in order to accomplish our work (learn more about it here: https://en.wikipedia.org/wiki/Principle_of_least_privilege). But in order to not lose access to the system, we need to first create a local user with fewer rights that will allow us to perform our day-to-day tasks. We will name it alina and allow it access to both the UI and the CLI. The rule of thumb here is to always have a dedicated user for every one of your colleagues who needs to access Argo CD instead of using it as a group or a team user. This helps if somebody loses access to the system as they are leaving the team because we can always disable or remove their account. To add a new user, the ConfigMap argocd-cm file should look like this:
apiVersion: v1kind: ConfigMapmetadata: name: argocd-cmdata: accounts.alina: apiKey, loginWe should create the commit and push this update to remote so that our configuration change is applied by Argo CD (in order for this ConfigMap to be applied automatically when the push is done, you need to have Argo CD installed and configured as described in Chapter 3, Operating Argo CD). Assuming that the CLI is installed and points to our API server instance (the login being done with the admin user), we can verify that the new user is created by running the following code:
argocd account listThe output should be like this:
NAME ENABLED CAPABILITIESadmin true loginalina true apiKey, loginThis means that we have the user ready, but we still need to set its password. For this, we can use this command, using the admin password as the current password:
argocd account update-password --account alina --current-password pOLpcl9ah90dViCD --new-password k8pL-xzE3WMexWm3cT8tmnFor that, the output is as follows:
Password updatedWhen running this update-password command, it is possible to skip the passing of the --current-password and --new-password parameters; this way, their values will not be saved in the shell history. If they are not passed, you will be asked to introduce them in an interactive way, which is a much safer choice.
To see what happened, we need to take a look at the argocd-secret Secret resource by running this command. We will see new entries there for our user, just like for the admin user:
kubectl get secret argocd-secret -n argocd -o yamlAnd we should get the following (we will remove some of the fields that are of no interest to us):
apiVersion: v1data: accounts.alina.password: JDJhJDEwJHM0MVdJdTE5UEFZak9oUD dWdk9iYS5KVEladjFjLkdReFZ0eVdlN0hYLnlLem01Z3BEelBX accounts.alina.passwordMtime: MjAyMS0xMC0wOVQxMzo1MDoxNVo= accounts.alina.tokens: bnVsbA== admin.password: JDJhJDEwJEd1LzlZVG4uOEVmY2x3bGV6dDV3amVDd2d jQW1FUEk3c21BbGoxQjV0WXIxek9pYUxjL1ZL admin.passwordMtime: MjAyMS0xMC0wOFQwNzo0Mzo1NVo= server.secretkey: WkI3dzBzYkpoT1pnb2Njb2ZZSEh0NmpQUFM3YkRDMTN zc1Z5VWpCNWRKcz0=kind: Secretmetadata: labels: app.kubernetes.io/instance: argocd app.kubernetes.io/name: argocd-secret app.kubernetes.io/part-of: argocd name: argocd-secret namespace: argocdtype: OpaqueIf we look at the tokens created for this user (in the accounts.alina.tokens field), we will see that it is actually null, which means that we don’t have any created for now:
echo "bnVsbA==" | base64 –dThat gives the following output:
null%If you are wondering about what rights this user has, it actually can’t do anything yet. We can log in with it, but if we try to list applications or clusters, we will get empty lists. In order to allow it to do something, we have two options: either we will give specific rights to the user, or we set the default policy that every user will fall back to when authenticated in case nothing specific for it can be found. We are going to set the default policy to read-only now and we will check how to add specific rights when we use the access token. In order to do this, there is a new ConfigMap resource we need to modify, which is where we will set all our Role-Based Access Control (RBAC) rules. Create a new file named argocd-rbac-cm.yaml in the same location where we have the argocd-cm.yaml ConfigMap and add this content:
apiVersion: v1kind: ConfigMapmetadata: name: argocd-rbac-cmdata: policy.default: role:readonlyDon’t forget to add an entry to the kustomization.yaml file. Now, under patchesStrategicMerge, we should have two entries for both the ConfigMaps we modified:
patchesStrategicMerge: - patches/argocd-cm.yaml - patches/argocd-rbac-cm.yamlCreate the commit for both the files and push it to remote so that Argo CD can apply the RBAC default policy. After the change is made, we can use the new user with the CLI. To do this, first we should log in to our API server (in my case, I used port-forwarding from my local installation so the server is on https://localhost:8083):
argocd login localhost:8083 --username alinaYou will probably receive a warning message that the certificate comes from an unknown authority, which is correct because it is self-signed. We can ignore it for now because we are connecting to localhost:
WARNING: server certificate had error: x509: certificate signed by unknown authority. Proceed insecurely (y/n)?Next, enter the password for the alina account and you should be logged in and ready to issue commands. We can try to list the Applications Argo CD has installed to make sure we have the read access:
argocd app listThe output should be as follows (before setting the default policy to read-only, this list would have been empty):
CURRENT NAME SERVER* localhost:8083 localhost:8083Now, we can move on and disable the admin user, for which we can use the admin.enabled field and set it to false in the argocd-cm ConfigMap. It should look like this:
apiVersion: v1kind: ConfigMapmetadata: name: argocd-cmdata: accounts.alina: apiKey, login admin.enabled: "false"Commit the changes and push them to remote, so that the admin user can’t be used anymore. You just moved one step further toward securing your Argo CD instance and getting it ready for production.
We have seen how we can deal with the users in a declarative way, how to create new local ones and disable the admin, and how passwords are handled. Next, we will learn about the users used in automations, the so-called service accounts.
Service accounts
Section titled “Service accounts”Service accounts are the accounts we use for authenticating automations such as CI/CD pipelines to the system. They should not be tied to a user because we don’t want our pipelines to start failing if we disable that user, or if we restrict its rights. Service accounts should have strict access control and should not be allowed to do more than what is required by the pipeline, while a real user will probably need to have access to a larger variety of resources.
There are two ways to create service accounts in Argo CD: one is with local users (for which we only use apiKey and remove the login part) and the other is to use project roles and have tokens assigned for those roles.
Local service accounts
Section titled “Local service accounts”We are now going to create a separate local account that only has the apiKey functionality specified. This way, the user doesn’t have a password for the UI or the CLI and access can be accomplished only after we generate an API key for it (which gives it CLI or direct API access). We will also set specific rights for it; for example, we will allow it to start a sync for specific applications.
We will modify the argocd-cm ConfigMap to add the new service account user, which we will name gitops-ci:
apiVersion: v1kind: ConfigMapmetadata: name: argocd-cmdata: accounts.alina: apiKey, login accounts.gitops-ci: apiKey admin.enabled: "false"Commit and push it to remote so that we have the new account up and running. After we have the new account created, we need to run a command in order to generate an access token. The issue here is that the alina user doesn’t have the rights to do this, and the admin account was disabled. We can re-enable admin, but that’s not a good practice because we could always forget to disable it again, or just leave it enabled for a long time. Normally, we should disable admin only after we finish the setup of all the local users. However, we might need to create new ones at any point because there are either new people joining our teams, or new scenarios to be automated with pipelines.
So, let’s see how we can assign the rights to update accounts to the user alina. To do this, we will modify the argocd-rbac-cm.yaml file to create a new role for user updates named role:user-update and we will assign the role to the user (the lines that are used to define the policies start with p, while the lines to link users or groups to roles start with g):
apiVersion: v1kind: ConfigMapmetadata: name: argocd-rbac-cmdata: policy.default: role:readonly policy.csv: | p, role:user-update, accounts, update, *, allow p, role:user-update, accounts, get, *, allow g, alina, role:user-updateNote – RBAC – policy.csv
If you are wondering where the policy.csv file is coming from, or what is with p and g and all these notations, you can check out the casbin library that Argo CD is using to implement RBAC: https://casbin.org/docs/en/get-started.
Commit, push the changes to remote, and make sure they are applied by Argo CD. Now, we can run the command in order to create the token (we assume that you are logged in with the CLI with the user alina):
argocd account generate-token -a gitops-ciThe output should be similar to this (and it is the account token):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZTc2NWI5Ny04MG YyLTRkODUtYTkzYi1mNGIzMjRkYTc0ODciLCJpYXQiOjE2MzQxNDkyODksImlzc yI6ImFyZ29jZCIsIm5iZiI6MTYzNDE0OTI4OSwic3ViIjoiZ2l0b3BzLWNpOmFw aUtleSJ9.azbvrvckSDevFOG6Tun9nJV0fEMcMpI9Eca9Q5F2QR4One easy way to check whether the newly generated token is working is by running the argocd account get-user-info command. We can run it once with the logged-in user and again with the authentication token. Here, I am putting the example only for the token (for the logged-in user, just don’t pass the --auth-token parameter). The --auth-token flag is a general one, meaning it can be used for any command (and of course you will have another token, so don’t forget to replace it):
argocd account get-user-info --auth-token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZTc2NWI5 Ny04MGYyLTRkODUtYTkzYi1mNGIzMjRkYTc0ODciLCJpYXQiOjE2MzQxNDkyODk sImlzcyI6ImFyZ29jZCIsIm5iZiI6MTYzNDE0OTI4OSwic3ViIjoiZ2l0b3BzLW NpOmFwaUtleSJ9.azbvrvckSDevFOG6Tun9nJV0fEMcMpI9Eca9Q5F2QR4The output should be similar to this:
Logged In: trueUsername: gitops-ciIssuer: argocdGroups:For the newly created service account, since we didn’t specify any permissions, it’ll take the default ones, meaning the read-only access. Of course, creating such a token with just read access doesn’t make a lot of sense. Normally, it should do something like register a new cluster or unregister it (which is usually done in an imperative way – by running a command), create or remove users, create an application, synchronize it, and so on. We are not able to set a local account to be a part of an RBAC group, we can only have roles and assign local users to the roles. We will see how groups work when we talk about SSO users later in this chapter. For a complete list of resources and actions you can use for your local accounts in the RBAC ConfigMap, you can check the official documentation: https://argo-cd.readthedocs.io/en/stable/operator-manual/rbac/#rbac-resources-and-actions.
Project roles and tokens
Section titled “Project roles and tokens”Project roles are the second option we can use for service accounts. An application project is a way for us to apply some constraints on the application definition. We can set the repository from where we take the state, the destination cluster, and the namespaces where we can deploy and even filter the resource types that we can install (for example, we can declare that the applications that use this project can’t deploy Secrets). Besides these, there is also the possibility to create a project role and to specify the kind of actions it is allowed to do, and a role can then have tokens assigned.
When Argo CD is installed, it also comes with a default project, actually called default, that doesn’t set any restrictions to its applications (everything is set to allow: '*'). In order to show how projects are used with their tokens, we will create a new project and use it for our existing argocd application. Once we have it, we will need to create a role for the project, assign permissions to the role, and create a token.
We will create a new file called argocd-proj.yaml and we will store it in the same location as our argo-app.yaml file (the files can also be found in our official repo at the book’s companion GitHub repository in the ch04/kustomize-installation folder). After we create it, we will need to apply it manually (we will see in Chapter 5, Argo CD Bootstrap K8s Cluster, how the app-of-apps pattern can help us create all these Applications and AppProjects automatically). This is the content of the file for now. You can see the restrictions for the destination namespace and cluster and also that we can only load the state from a fixed repo. We also added a new role called read and sync, for which we allowed the get and sync actions for all the applications under the AppProject:
apiVersion: argoproj.io/v1alpha1kind: AppProjectmetadata: name: argocdspec: roles: - name: read-sync description: read and sync privileges policies: - p, proj:argocd:read-sync, applications, get, argocd/*, allow - p, proj:argocd:read-sync, applications, sync, argocd/*, allow clusterResourceWhitelist: - group: '*' kind: '*' description: Project to configure argocd self-manage application destinations: - namespace: argocd server: https://kubernetes.default.svc sourceRepos: - https://github.com/PacktPublishing/ArgoCD-in-Practice.gitWe will apply the AppProject to the cluster with kubectl apply:
kubectl apply -n argocd –f argocd-proj.yamlThe command output should be similar to this:
appproject.argoproj.io/argocd createdThen, we will modify the argocd Application to start using this new AppProject, changing from project: default to project: argocd in the definition. Now, apply the updated file to the cluster with kubectl apply (the complete argocd-app.yaml file can be found at the book’s companion GitHub repository in ch04/kustomize-installation):
kubectl apply -n argocd -f argocd-app.yamlNow, we should be ready to generate our token for the read and sync role we created. This needs to be done in a synchronous way, either with the CLI or from the UI, so we can retrieve the generated token. We can run the CLI command using the user alina, but we will get an error as it doesn’t have the needed permissions:
FATA[0000] rpc error: code = PermissionDenied desc = permission denied: projects, update, argocd, sub: alina, iat: 2021-10-16T10:16:33ZLet’s add the needed permissions by modifying the RBAC ConfigMap. I am pasting just the policy.csv part here and, this time, I will restrict the action only to our exact project, named argocd:
policy.csv: | p, role:user-update, accounts, update, *, allow p, role:user-update, accounts, get, *, allow p, role:user-update, projects, update, argocd, allow
g, alina, role:user-updateDon’t forget to commit and push it to remote so that our change will be picked up by Argo CD and applied to the cluster. After this, we can generate the token using the following command:
argocd proj role create-token argocd read-syncThe response will look something like this:
Create token succeeded for proj:argocd:read-sync. ID: ccdc5906-11fc-483b-8e8d-0511c6f28978 Issued At: 2021-10-16T13:44:19+03:00 Expires At: Never Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjY2RjN TkwNi0xMWZjLTQ4M2ItOGU4ZC0wNTExYzZmMjg5NzgiLCJpYXQiOjE2MzQzODEw NTksImlzcyI6ImFyZ29jZCIsIm5iZiI6MTYzNDM4MTA1OSwic3ViIjoicHJvajp hcmdvY2Q6cmVhZC1zeW5jIn0.R02VHylpb4aPjtpd5qLOXHpELGOVgnelCJr3q8 bGU5YI can now use this token to start a manual sync for all the Applications under the argocd AppProject. We only have one Application and it is named the same as the AppProject, argocd. We can see that if we try to call the sync using the logged-in user alina, we will get a permissions-denied error, as can be seen in the output following this command:
argocd app sync argocdThe error will be as follows:
FATA[0000] rpc error: code = PermissionDenied desc = permission denied: applications, sync, argocd/argocd, sub: alina, iat: 2021-10-16T10:16:33ZUsing the generated token, the command becomes this:
argocd app sync argocd --auth-token eyJhbGciOiJIUzI1NiIsInR5cCI 6IkpXVCJ9.eyJqdGkiOiJjY2RjNTkwNi0xMWZjLTQ4M2ItOGU4ZC0wNTExYzZmM jg5NzgiLCJpYXQiOjE2MzQzODEwNTksImlzcyI6ImFyZ29jZCIsIm5iZiI6MTYz NDM4MTA1OSwic3ViIjoicHJvajphcmdvY2Q6cmVhZC1zeW5jIn0.R02VHylpb4a Pjtpd5qLOXHpELGOVgnelCJr3q8bGU5YThe output is very long because it starts to enumerate all the resources our Argo CD Application has installed along with their status and this means that the sync is working. It can be seen also from the sync status in the UI (go to the argocd Application and on its page, you should have a Sync Status button, which shows details about the last initiated sync):

Figure 4.1 – argocd: Sync initiated by the project role
Every token that we generate is saved into the project role. We can check the amount of time we used it for and whether it is about time to rotate it. We can also set an expiration date for it if we plan to use it for a limited time. Otherwise, putting a hard deadline for when we will need to refresh it will require strong discipline from the engineers managing Argo CD. In my case, I usually have a tendency to postpone the quarterly review of access control by up to a week or two, so having expiration dates might lead to failed pipelines.
Note – Tokens with sync action only
Does it make sense to have tokens (either coming from local accounts or project roles) that only do the sync action as long as we can allow Applications to sync automatically? I think so, and a valid scenario would be to still allow Applications to sync automatically but set a bigger timeout, such as 10-15 minutes (which can reduce the system load and increase its performance). However, after we make a commit to the GitOps repo, we can call the sync from the pipeline as well.
Project roles can only be used for performing actions on Applications’ resources and those Applications need to be under the project for which the role is created, so it is pretty limited in scope. However, it is actually such constraints that transform them into good candidates to use in our pipelines because if they get compromised for any reason, then the attack surface is a reduced one.
Single sign-on
Section titled “Single sign-on”Single Sign-On (SSO – https://en.wikipedia.org/wiki/Single_sign-on) allows us to have a master login, and based on that, we can be authorized into other independent applications (they do keep a connection with the master system even if they are independent). It means that if I want to access argocd.mycompany.com, then argocd.mycompany.com will trust an external provider in order to verify my identity. Furthermore, the type of access I will receive to argocd.mycompany.com can be controlled from the external master system based on the groups I am part of, or sometimes by setting attributes on the account.
I know that there are companies that see SSO as mandatory; they will not adopt a new tool if it doesn’t offer the option. And it does make sense considering it has security benefits, such as not needing passwords for all the applications we use, and ease of onboarding/offboarding colleagues by controlling everything from one dashboard. These factors rank this feature as a must-have one.
Luckily, Argo CD offers the SSO feature with two ways of configuring it. One is by using the Dex OIDC provider (https://github.com/dexidp/dex) that is installed by default, and the second is directly with Argo CD (skipping the Dex installation) when you rely on another OIDC provider. We will look at examples for both these cases.
Argo CD offers SSO logins for the UI and for the CLI. Once you have SSO enabled and if there are no local accounts that can log in and admin is disabled, the user/password form will be automatically removed from the UI and only the log in via SSO button will remain.

Figure 4.2 – No user/password login with SSO on and admin disabled
For the CLI, the log in with SSO command will look like this (replace argocd.mycompany.com with your correct server address):
argocd login --sso argocd.mycompany.comBy using SSO, you significantly reduce the attack surface because only one set of credentials is needed to get access to many applications. And in Argo CD, SSO is well covered and it can be accomplished with the help of Dex, or with Argo CD directly when using an external OIDC provider. Next, we are going to explore both options, starting with Dex.
SSO with Dex
Section titled “SSO with Dex”Dex is an identity system that allows applications to offload authentication. Dex is able to use different authentication schemes such as LDAP or SAML and can connect to well-known identity providers, such as Google, GitHub, and Microsoft. The main advantage is that you connect once with Dex and then get the benefit of all the connectors it supports (for example, you could have authentication to your website with Google, Microsoft, and GitHub – all just by using Dex).
The official documentation of Argo CD covers this topic very well – https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/#sso. There are extensive examples on how to configure Google via SAML (https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/google/#g-suite-saml-app-auth-using-dex), Microsoft Azure Active Directory (https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/microsoft/#azure-ad-saml-enterprise-app-auth-using-dex), or GitHub (https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/#2-configure-argo-cd-for-sso).
Dex SAML Connector – Unmaintained
At the time of finalizing this book (October 2022), the Dex SAML connector is proposed to be deprecated because it is not maintained anymore. Still, this is the main way to connect to providers, so we hope it will get into better shape in the future and that’s why our demo is based on it. For more details, please follow https://github.com/dexidp/dex/discussions/1884.
RBAC groups
Section titled “RBAC groups”When we use SSO, a user can be added automatically to our RBAC groups without any configuration per user on the Argo CD side. Everything will be controlled by the SSO system.
When we use Google SAML, which is pretty popular, we don’t have the option to export the group information that we set in the Google system. However, we do have a way to expose additional user details from Google and that is by using a custom attribute, based on which we can assign the user to an Argo CD RBAC group. The custom attribute needs to be defined initially and then set its value for each user. In order to do all these changes, including the ones from the initial setup, you need administrative access for your GSuite account.
Do follow the official tutorial for the Google SAML setup initially before we continue with the group’s configuration. Now, let’s define the additional schema for the attribute, which we will name ArgoCDSSO, while we name the role ArgoCDRole. Go to https://developers.google.com/admin-sdk/directory/reference/rest/v1/schemas/insert?authuser=1 and use the Try this API form. Set the my_customer value for the customerId field (which means to use the customer ID of the logged-in user) and in Request Body, add the following JSON, which defines our new attribute:
{ "schemaName": "ArgoCDSSO", "displayName": "ArgoCD_SSO_Role", "fields": [ { "fieldType": "STRING", "fieldName": "ArgoCDRole", "displayName": "ArgoCD_Role", "multiValued": true, "readAccessType": "ADMINS_AND_SELF" } ]}After we execute the form, we can go back to the SAML Attribute Mapping page so that we can add the additional attribute. We will use the name role for the mapping, while in the first dropdown, we will be able to select the newly created ArgoCDSSO schema, and in the second dropdown, we will choose the ArgoCDRole attribute.
In the argocd-cm ConfigMap where we added the dex.config section, we will need to make a small change in order to introduce the mapping between the RBAC groups and the role we created in Google SAML. I am pasting only the part with dex.config from the file. What is important is the last line – the value of groupsAttr needs to match the name of the mapping (the complete argocd-cm.yaml file can also be found in the official repository for the book: the book’s companion GitHub repository in ch04/sso-setup):
url: https://argocd.mycompany.comdex.config: | connectors: - type: saml id: argocd-mycompany-saml-id name: google config: ssoURL: https://accounts.google.com/o/saml2/idp?idpid=<id-provided-by-google> caData: | BASE64-ENCODED-CERTIFICATE-DATA entityIssuer: argocd-mycompany-saml-id redirectURI: https://argocd.mycompany.com/api/dex/callback usernameAttr: name emailAttr: email groupsAttr: roleWe saw how RBAC roles work when we created the local account and assigned it update user rights via an update-user role. In the case of local accounts (no matter whether we’re using username/password or an API key), we need to link each of them to a role if we want to give them rights; but for SSO, we will see they are linked automatically to groups.
Based on the tasks engineers perform, we can separate them into developers and site reliability people. This means it would make sense to have at least these two groups defined in your system. There could be more if we want to give fewer permissions for new joiners than for developers – for example, no write access, not even for the development environment applications.
When Argo CD is installed, it comes with two RBAC roles already set up, the admin one, which has full rights, and the readonly one, which, as the name suggests, can do all the read actions and no changes or deletions (if you want to see the permissions of the built-in roles, check out https://github.com/argoproj/argo-cd/blob/master/assets/builtin-policy.csv). The readonly one would be a good role for new joiners, while for developers, besides the read access, we could allow them to sync applications. SREs should be able to perform additional updates to Applications and AppProjects and even delete them. So, let’s see how we can define these groups in Argo CD RBAC ConfigMap and tie them to SSO.
We will use the readonly role and have the new developer one inherit all its permissions by using such an entry – g, role:developer, role:readonly. Then, we will add the additional permissions we want the developer role to have, which in our case is syncing applications. After we finish with the developer role, we set the sre one to inherit all the permissions from developer and continue with adding any new permissions. In the end, it is important to make the mapping between the name of the Argo CD RBAC group and the value of the special attribute we defined in the identity provider. So, in our case, for a user to have the developer permissions, they should have developer set as the value of the ArgoCDRole attribute in their Google dashboard. Here is what the changes will look like in the argocd-rbac-cm.yaml RBAC ConfigMap. Also, this time, we didn’t use the default read-only policy (a reference to this file can be seen in the official repo at the book’s companion GitHub repository in the ch04/sso-setup folder):
apiVersion: v1kind: ConfigMapmetadata: name: argocd-rbac-cmdata: policy.csv: |
g, role:developer, role:readonly p, role:developer, applications, sync, */*, allow
g, role:sre, role:developer
p, role:sre, applications, create, */*, allow p, role:sre, applications, update, */*, allow p, role:sre, applications, override, */*, allow p, role:sre, applications, action/*, */*, allow p, role:sre, projects, create, *, allow p, role:sre, projects, update, *, allow p, role:sre, repositories, create, *, allow p, role:sre, repositories, update, *, allow
g, Sre, role:sre g, Developer, role:developer g, Onboarding, role:readonlyThis would be a good start for defining your access control policy in Argo CD, but do expect that changes will be needed over time. You might need to give more permissions to SRE people in order to solve some strange situations in production, or provide some of the senior developers with more permissions by creating a new role and group.
If you are wondering how to allow more rights for your users based on the environments they are going to modify, there are a few ways it can be done. So, for example, we could allow SREs to have admin rights in development/staging and only some of the permissions in pre-production or production. Probably, the best way would be to have separate Argo CD instances that would take care of development and live environments. Another way is that you can use specific prefixes for Applications and AppProjects, though it might get more complicated for clusters, repositories, or accounts.
SSO with Argo CD directly
Section titled “SSO with Argo CD directly”Also, for the SSO done directly with Argo CD (so, by skipping Dex), we have extensive documentation. There are many tutorials in the official documentation on how to set up external OIDC providers, including these ones:
- OKTA – https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/okta/#oidc-without-dex
- OneLogin – https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/onelogin/
- OpenUnison – https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/openunison/
- Keycloak – https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/keycloak/
The explanations are good, and they have many screenshots on how to do all the preparations on the OIDC provider side and configuration examples for Argo CD, so it is not worth repeating such tutorials in this chapter. One thing to note would be that we can make these SSO configurations more secure as we can extract the sensitive information from the ConfigMap and store it in Secret resources populated with an external operator.
OpenID Connect – OpenID Foundation
OpenID Connect was created in a working group that was part of the OpenID Foundation. The OpenID Foundation is a non-profit organization that takes care of the OpenID technologies: https://openid.net/foundation/.
We will take the example of OneLogin. After everything is created on the OneLogin side, the Argo CD configuration file looks like this:
apiVersion: v1kind: ConfigMapmetadata: name: argocd-cmdata: url: https://argocd.mycompany.com oidc.config: | name: OneLogin issuer: https://mycompany.onelogin.com/oidc/2 clientID: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaa clientSecret: abcdef123456 requestedScopes: ["openid", "profile", "email", "groups"]An improvement for this would be to move the clientSecret entry into a Secret and reference it from the ConfigMap. Referencing a Secret from the ConfigMap is not something supported by Kubernetes, but instead Argo CD will understand the notation and will read the value from the Secret. You can find out more at https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/#sensitive-data-and-sso-client-secrets. We want to use a separate Secret because we don’t want to commit the sensitive values directly to Git. There are some solutions where we can create a custom resource that will know to populate the sensitive information from a different source. We have tools such as ExternalSecrets (https://github.com/external-secrets/external-secrets), aws-secret-operator (https://github.com/mumoshu/aws-secret-operator), or even a plugin for Argo CD (https://github.com/IBM/argocd-vault-plugin) to help us accomplish this. The ExternalSecrets project has some advantages because of the wide range of data stores it supports, such as AWS Parameter Store, Azure Key Vault, Google Cloud Secrets Manager, Hashicorp Vault, and some others, which means it is likely that it will fit your infrastructure. It can be installed via a Helm chart – https://github.com/external-secrets/external-secrets/tree/main/deploy/charts/external-secrets – and here is some very good documentation – https://external-secrets.io/. These are some great sources to read in order to get started.
Removing Dex Deployment
Section titled “Removing Dex Deployment”When we are using OIDC directly with Argo CD, or we’re using no SSO at all, we can remove the Dex installation as it will not be useful for us. One way to do that is to set it to 0 Pods, but it is also possible with a Kustomize patch to remove the Deployment completely, and this is what we will do here. We need to make two changes – one is to add a new file called argocd-dex-server.yaml, put it in the patches folder, and that’s where we will place the delete patch:
apiVersion: apps/v1kind: Deploymentmetadata: name: argocd-dex-server$patch: deleteAnd the second is to add the entry in the kustomization.yaml file for the new files we added (showing here just the patchesStrategicMerge entries):
patchesStrategicMerge: - patches/argocd-cm.yaml - patches/argocd-rbac-cm.yaml - patches/argocd-dex-server-deployment.yamlNext, create the commit and push it to remote so Argo CD can apply it. The Dex deployment will be removed and if we want to bring it back later, we need to remove this Kustomization patch file.
It is important to secure these OIDC connectivities as, most likely, your company will have a rule that all systems you use should have SSO. So, it would be a good practice for all sensitive information on SSO be kept secure, as it is not just about Argo CD anymore. Stopping Dex can also be seen as an improvement as we reduce the attack surface by stopping a service that we will not be using; for example, it will not affect us in any way if it will have any vulnerabilities in the future.
Summary
Section titled “Summary”In this chapter, we went through different options for how we can accomplish user administration and access control. We started with how we can create new local users and assign them rights in order to be able to disable the admin account as it would be too risky to use it for daily operations. Then, we discovered what the options are for service accounts and how to access Argo CD from a pipeline or other types of automations. Local users are great for small companies, but SSO is becoming more relevant because it is more secure and has the power to manage everything from one place Argo CD supports many SSO providers either directly or via Dex; the official documentation has a lot of examples on how to set that up and we saw how we can make them more secure.
In the next chapter, we will dive deep into how to create a Kubernetes cluster and then deploy applications on it with Argo CD following the app-of-apps pattern.
Further reading
Section titled “Further reading”- Another example of how Attribute mapping can be used for Group mapping on Google SAML: https://www.dynatrace.com/support/help/how-to-use-dynatrace/user-management-and-sso/manage-users-and-groups-with-saml/saml-google-workspace#preparing-group-mapping
- Why Argo CD implemented the direct OIDC option and allows you to skip Dex: https://github.com/argoproj/argo-cd/issues/671.
- Benefits of SSO: https://www.onelogin.com/learn/why-sso-important.
- OpenID Connect protocol: https://openid.net/connect/faq/.