Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 04: Projects and RBAC

Projects scope what an app can use (repos, destinations, resource kinds). RBAC (argocd-rbac-cm) scopes what users can do. Needs lab 01, logged in as admin.

Projects

argocd proj get default
kubectl get appproject default -n argocd -o yaml
  • default allows any repo, any cluster/namespace, any resource. Fine for labs, not for multi-tenancy

Create projects:

argocd proj create dev-team \
  --description "dev team" \
  --dest 'https://kubernetes.default.svc,dev-*' \
  --src 'https://github.com/argoproj/*'
argocd proj create prod-team \
  --description "prod team" \
  --dest 'https://kubernetes.default.svc,prod-*' \
  --src 'https://github.com/argoproj/*'
kubectl create namespace dev-app1
kubectl create namespace prod-app1
  • --dest is server,namespace, --src is a repo glob
  • Cluster-scoped resources are denied by default in a new project, namespaced ones are allowed

Resource filtering:

argocd proj allow-cluster-resource dev-team "" Namespace
argocd proj deny-namespace-resource prod-team "" Secret
argocd proj get dev-team
  • Cluster-scoped kinds: allow-cluster-resource / deny-cluster-resource (whitelist/blacklist)
  • Namespaced kinds: allow-namespace-resource / deny-namespace-resource
  • Args are GROUP KIND, "" is the core group

Project roles

argocd proj role create dev-team developer --description "dev access"
argocd proj role add-policy dev-team developer --action get --permission allow --object '*'
argocd proj role add-policy dev-team developer --action sync --permission allow --object '*'
argocd proj role add-policy dev-team developer --action create --permission allow --object '*'
argocd proj role add-policy dev-team developer --action update --permission allow --object '*'
argocd proj role list dev-team
  • Generates p, proj:dev-team:developer, applications, <action>, dev-team/*, allow
  • --object is the app name inside the project
  • Project roles can have JWT tokens (argocd proj role create-token), good for CI

Global RBAC

Policy format:

p, <subject>, <resource>, <action>, <project>/<object>, <allow|deny>
g, <user or group>, <role>
  • Resources: applications, applicationsets, clusters, projects, repositories, accounts, certificates, gpgkeys, logs, exec
  • Actions: get, create, update, delete, sync, override, action/*
  • Built in roles: role:admin, role:readonly

Edit argocd-rbac-cm (changes are picked up live, no restart):

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-rbac-cm
  namespace: argocd
data:
  policy.default: ""
  policy.csv: |
    p, role:dev-lead, applications, *, dev-team/*, allow
    p, role:dev-lead, projects, get, dev-team, allow
    p, role:dev-lead, logs, get, dev-team/*, allow

    p, role:prod-ops, applications, get, prod-team/*, allow
    p, role:prod-ops, applications, sync, prod-team/*, allow
    p, role:prod-ops, projects, get, prod-team, allow

    g, alice, role:dev-lead
    g, bob, proj:dev-team:developer
    g, charlie, role:prod-ops
    g, diana, role:readonly
  • policy.default is the role for authenticated users with no match. role:readonly here would let everyone read every project, so it is empty for the isolation test
  • Projects need to be readable (projects, get) for the user to see apps in the UI

Local users

Edit argocd-cm:

data:
  accounts.alice: apiKey, login
  accounts.bob: apiKey, login
  accounts.charlie: apiKey, login
  accounts.diana: apiKey, login
  • login = UI/CLI password login, apiKey = can have tokens
  • Disable admin once something else works: accounts.admin.enabled: "false"

Set passwords (as admin, --current-password is the admin’s own password):

argocd account list
argocd account update-password --account alice --current-password '<admin pw>' --new-password '<pw>'
  • Same for bob, charlie, diana

Test

Admin creates the apps:

argocd app create dev-test-app --project dev-team \
  --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook \
  --dest-server https://kubernetes.default.svc --dest-namespace dev-app1
argocd app create prod-test-app --project prod-team \
  --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook \
  --dest-server https://kubernetes.default.svc --dest-namespace prod-app1

Then login as each user (use a separate --config file or a second terminal, argocd login overwrites the context):

argocd login localhost:8080 --username alice --insecure --config ~/.config/argocd/alice
  • Pass the same --config to every later command for that user
argocd account can-i sync applications 'dev-team/dev-test-app'
argocd account can-i sync applications 'prod-team/prod-test-app'
argocd app get prod-test-app
  • alice: full on dev-team, PermissionDenied on prod-team
  • bob: via the project role, get/sync/create/update on dev-team, no delete
  • charlie: get + sync on prod-team, can’t create or delete
  • diana: read only (built in role:readonly: get everything, sync nothing)
  • can-i only answers for the logged in user

Tighten destinations:

spec:
  destinations:
  - namespace: dev-app1
    server: https://kubernetes.default.svc

Tokens

TOKEN=$(argocd account generate-token --account alice --expires-in 1h)
argocd app list --auth-token "$TOKEN"
  • Tokens expire, list/revoke with argocd account get --account alice / delete-token

Auditing

kubectl logs -n argocd deploy/argocd-server --tail=100 | grep -iE "denied|login"
kubectl get applications -n argocd -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.operationState.operation.initiatedBy.username}{"\n"}{end}'
  • Argo CD’s own log is the audit trail for auth/RBAC, initiatedBy on the operation says who synced
  • Real SSO (Dex/OIDC): map groups with g, <group>, role:x and set scopes in policy.csv

Cleanup

argocd app delete dev-test-app prod-test-app --yes
argocd proj delete dev-team prod-team
kubectl delete namespace dev-app1 prod-app1
kubectl edit configmap argocd-cm -n argocd
kubectl edit configmap argocd-rbac-cm -n argocd
  • Remove the accounts.* lines and the policy.* entries (don’t delete argocd-rbac-cm, it is part of the install)
  • Delete apps before projects, a project with apps can’t be deleted