TExcelTAD
Home › GitOps: Argo CD & Flux › Projects & Access Control

Projects & Access Control

An Argo CD instance usually serves many teams, and its application-controller has cluster-admin-like rights. Without guard rails, any Application could deploy anything from any repo into kube-system. AppProjects are those guard rails: every Application belongs to exactly one project, and the project decides what its applications may deploy, from where, to where.

What a project restricts

yaml
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: linkly
  namespace: argocd
spec:
  description: linkly team
  sourceRepos:                       # where manifests may come from
    - https://github.com/acme/linkly-deploy.git
    - ghcr.io/acme/charts             # OCI Helm charts
  destinations:                      # where they may go
    - server: https://kubernetes.default.svc
      namespace: linkly-*            # wildcards allowed
  clusterResourceWhitelist: []       # no cluster-scoped objects at all (no CRDs, ClusterRoles...)
  namespaceResourceBlacklist:        # namespaced kinds the team may NOT create
    - group: ""
      kind: ResourceQuota
    - group: networking.k8s.io
      kind: NetworkPolicy
  roles:
    - name: deployer
      description: CI may sync, nothing else
      policies:
        - p, proj:linkly:deployer, applications, sync, linkly/*, allow
  syncWindows:
    - kind: deny                     # no automatic syncs to production on Friday evenings
      schedule: "0 17 * * 5"
      duration: 63h
      applications: ["*-production"]

The default project allows everything; real installations restrict or delete it so that every app must pick a deliberate project. Note the namespace: linkly-* destination: with CreateNamespace=true, the team may create any namespace starting with linkly-, but not kube-system.

The check, modelled

When an Application is created or synced, Argo CD checks it against its project. This model implements the core of that check (repo, destination, cluster-scoped kinds) with shell-style wildcards:

python · try it yourself
from fnmatch import fnmatch

project = {
    "sourceRepos": ["https://github.com/acme/linkly-deploy.git", "ghcr.io/acme/charts"],
    "destinations": [("https://kubernetes.default.svc", "linkly-*")],
    "clusterResourceWhitelist": [],                     # nothing cluster-scoped
    "namespaceResourceBlacklist": ["ResourceQuota", "NetworkPolicy"],
}
CLUSTER_SCOPED = {"Namespace", "ClusterRole", "CustomResourceDefinition"}

def check(app, objects):
    errors = []
    if not any(fnmatch(app["repo"], pattern) for pattern in project["sourceRepos"]):
        errors.append(f"repo {app['repo']} is not permitted in project")
    if not any(fnmatch(app["server"], s) and fnmatch(app["namespace"], n) for s, n in project["destinations"]):
        errors.append(f"destination {app['namespace']} is not permitted in project")
    for kind in objects:
        if kind in CLUSTER_SCOPED and kind not in project["clusterResourceWhitelist"]:
            errors.append(f"cluster-scoped {kind} is not permitted in project")
        elif kind in project["namespaceResourceBlacklist"]:
            errors.append(f"{kind} is blacklisted in project")
    return errors or ["OK"]

base = {"repo": "https://github.com/acme/linkly-deploy.git", "server": "https://kubernetes.default.svc"}
cases = [
    ("linkly staging", dict(base, namespace="linkly-staging"), ["Deployment", "Service", "HTTPRoute"]),
    ("wrong namespace", dict(base, namespace="kube-system"), ["Deployment"]),
    ("forked repo", dict(base, repo="https://github.com/mallory/linkly-deploy.git", namespace="linkly-prod"), ["Deployment"]),
    ("sneaky RBAC", dict(base, namespace="linkly-prod"), ["Deployment", "ClusterRole", "NetworkPolicy"]),
]
for name, app, objects in cases:
    print(f"{name:16} " + "; ".join(check(app, objects)))
linkly staging   OK
wrong namespace  destination kube-system is not permitted in project
forked repo      repo https://github.com/mallory/linkly-deploy.git is not permitted in project
sneaky RBAC      cluster-scoped ClusterRole is not permitted in project; NetworkPolicy is blacklisted in project

The real controller reports these as conditions on the Application (InvalidSpecError) or as a failed sync, and nothing is applied.

Validate projects in CI

bash · try it yourself
cat > project.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata: {name: linkly, namespace: argocd}
spec:
  sourceRepos: [https://github.com/acme/linkly-deploy.git, ghcr.io/acme/charts]
  destinations:
    - {server: https://kubernetes.default.svc, namespace: linkly-*}
  clusterResourceWhitelist: []
  namespaceResourceBlacklist:
    - {group: "", kind: ResourceQuota}
    - {group: networking.k8s.io, kind: NetworkPolicy}
  roles:
    - name: deployer
      policies: ["p, proj:linkly:deployer, applications, sync, linkly/*, allow"]
  syncWindows:
    - {kind: deny, schedule: "0 17 * * 5", duration: 63h, applications: ["*-production"]}
EOF
kubeconform -strict -summary project.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0

Who may do what: RBAC

Projects restrict applications; RBAC restricts people and tokens. Policies are Casbin CSV lines in the argocd-rbac-cm ConfigMap:

yaml
apiVersion: v1
kind: ConfigMap
metadata: {name: argocd-rbac-cm, namespace: argocd}
data:
  policy.default: role:readonly
  policy.csv: |
    # p, <subject>, <resource>, <action>, <project>/<object>, <allow|deny>
    p, role:linkly-dev, applications, get,      linkly/*, allow
    p, role:linkly-dev, applications, sync,     linkly/*-staging, allow
    p, role:linkly-dev, applications, update/*, linkly/*-staging, allow
    p, role:linkly-dev, logs,         get,      linkly/*, allow
    # SSO group -> role
    g, acme:linkly-team, role:linkly-dev

The team can see every linkly app and read logs, but can only sync and change staging. Production changes go through Git, where CODEOWNERS decides who approves. Remember the 3.0 changes: update/* (on the app's resources) and logs, get must be granted explicitly. Check a policy without guessing with argocd admin settings rbac can role:linkly-dev sync applications linkly/linkly-production --policy-file policy.csv (prints No).

Project-scoped tokens for CI

The deployer role above can get a JWT for automation (argocd proj role create-token linkly deployer). In GitOps, CI rarely needs one (it commits to Git), but a pipeline that waits for a sync to finish (argocd app wait linkly-staging --health) needs read access, and nothing more.

Test yourself

An Application in project linkly targets namespace kube-system, but the project allows only linkly-*. What happens?

  1. It deploys with a warning
  2. Argo CD refuses: the destination is not permitted in the project
  3. It deploys to linkly-kube-system
  4. The project is updated automatically

What does clusterResourceWhitelist: [] in an AppProject prevent?

  1. Creating any namespaced object
  2. Creating any cluster-scoped object, such as ClusterRoles or CRDs
  3. Using more than one cluster
  4. Syncing on Fridays

What is the difference between an AppProject and argocd-rbac-cm?

  1. None
  2. Projects restrict what applications may deploy; RBAC restricts what users and tokens may do in Argo CD
  3. Projects are for users, RBAC for clusters
  4. RBAC replaces projects in 3.x