All jobs

Add AppProjects to Restrict Each Team's Argo CD Applications

Yes. An agent writes one AppProject per team with the repos, namespaces and source namespaces each may use, proves the invalid app is refused, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how Applications are declared before it writes a Project. In a GitOps repository shaped like argoproj/argocd-example-apps, apps/ is a Helm chart named applications whose single template, apps/templates/applications.yaml, renders one Application per entry in apps/values.yaml with project: {{ .project | default "default" }}, a namespace defaulting to argocd, a destination of https://kubernetes.default.svc, this repository as the source at targetRevision: master, and an automated sync with prune, selfHeal and CreateNamespace=true. Nineteen entries use it. Four of them are the interesting ones: three app-any-ns Applications that live in the team-frontend, team-backend and team-platform namespaces, each naming a project of the same name and deploying lightweight/app-a into a team-<name>-apps namespace, and an app-any-ns-invalid entry placed in the team-platform namespace while claiming the team-backend project.

The ApplicationSets tell the same story. applicationset/appset-any-ns-team-frontend.yaml and its backend and platform twins each declare an ApplicationSet named services in a team namespace, generate api and worker Applications from a list generator under project: team-frontend and so on, and deploy lightweight/app-b into team-frontend-api and team-frontend-worker. applicationset/README.md says these need the ApplicationSet controller's namespaces setting and, in its own words, corresponding AppProjects with sourceNamespaces configured. There is no kind: AppProject anywhere in the repository, so every reference to team-frontend, team-backend and team-platform points at a project that has to exist out of band. That is the gap the agent closes.

It writes three AppProject manifests, one per team, as a new template in the same chart so they ship with the Applications that depend on them, rendered with an argocd.argoproj.io/sync-wave: "-1" annotation so they are applied first. Each project allows this repository alone in sourceRepos, lists the in-cluster server with the namespaces that team's Applications actually target, which the agent reads from the values file and the ApplicationSets rather than guessing: team-frontend-apps, team-frontend-api and team-frontend-worker for the frontend project, and the same pattern for the others. sourceNamespaces names the team's own namespace so an Application declared there is accepted, and namespaceResourceWhitelist is limited to ConfigMap because lightweight/app-a and app-b deploy nothing else. The agent leaves the default project untouched, since the other fifteen Applications and every generator example rely on it.

Then it proves the shape. In the sandbox it starts a kind cluster, installs Argo CD with the ApplicationSet controller's namespaces set to the three team namespaces, renders the chart with helm template apps/, and applies it. It checks that the three app-any-ns Applications and the six generated api and worker Applications reach Synced, and that app-any-ns-invalid, which claims the team-backend project from the team-platform namespace, is refused with the project's source-namespace error, which is exactly what the values comment says the entry is for. If CreateNamespace=true needs a cluster-scoped allowance under the stricter project, the dry run shows it and the agent adds the narrowest clusterResourceWhitelist that makes the sync pass, and says so.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add Argo CD AppProjects to this GitOps repository. Read apps/Chart.yaml, apps/values.yaml, apps/templates/applications.yaml, every file under applicationset/ including its README, and lightweight/app-a and app-b first, and list every project name an Application or ApplicationSet references, the namespace each is declared in, and the destination namespaces each targets. Write one AppProject per team-scoped project that does not exist yet, as a template in the apps chart applied in an earlier sync wave than the Applications: sourceRepos limited to this repository, destinations limited to the in-cluster server and the namespaces that team's Applications and ApplicationSets actually target, sourceNamespaces set to the team's own namespace, and namespaceResourceWhitelist limited to the kinds the lightweight apps deploy. Leave the default project alone. Start a kind cluster in the sandbox, install Argo CD with the ApplicationSet controller allowed in the team namespaces, apply the rendered chart, and confirm the team Applications sync and the intentionally invalid one is refused with a project error. If CreateNamespace needs a cluster resource allowance, add the narrowest one and explain it. Open a pull request that lists each project's rules and quotes the sync and refusal output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds apps/templates/projects.yaml with three AppProjects, an entry per project in apps/values.yaml so the chart stays data-driven, and a short section in applicationset/README.md replacing the sentence that said projects were required with where they now live. No Application changes, because every reference already named the right project.

The description holds a table of the three projects with their source repositories, destination namespaces, source namespaces and resource whitelists, the helm template output for the new manifests, and the sandbox cluster's view: the nine team Applications Synced and the refusal message for app-any-ns-invalid quoted from the Argo CD controller. It states whether a cluster resource allowance was needed for namespace creation and what it was.

Before merging, a reviewer compares each project's destination list against the namespaces in production rather than the example cluster, decides whether the ConfigMap-only whitelist is right for apps that will grow, and checks that the sync-wave annotation puts projects before Applications in a fresh install. Widening a project for a new service is a follow-up on the same session.

Run it on every team onboarding to the cluster

A platform team starts one run when a new team gets a namespace, from the console or with a POST /o/{org}/sessions naming the repository in resources. Everyone in the org can open the run and read the transcript as the kind cluster comes up; its starter or an org admin sends a follow-up when the first draft of the whitelist is too narrow, so the project's rules are settled against a live cluster rather than in review comments.

Give the API key a webhook_url and Rush posts run.completed or run.failed with the session_url when the turn ends. Parked sandboxes keep their disk for 7 idle days, so the kind cluster's configuration is still there when a teammate asks the next morning to add a second destination namespace.

The use case this job follows, with its automation and trigger: Steer a run as a team.

Why run it on Rush?

An AppProject is a permission boundary, and the only way to know it is right is to apply it next to the Applications it governs and watch what the controller accepts and refuses. On a laptop that means a local cluster, an Argo CD install and a long afternoon. In the sandbox the agent does all of it in one pass, including the negative case the repository already carries, and the pull request arrives with the controller's own messages rather than an argument about what the spec should mean.

The record is what makes this a team change rather than one person's. The transcript shows every namespace the agent read out of the values file and the ApplicationSets, the exact manifests applied, and the sync status of each Application, so a reviewer who wants team-platform to reach one more namespace can say so in a follow-up and watch the cluster accept it before the branch moves.

Frequently asked questions

Why put the projects in the apps chart instead of a separate directory?

Because the Applications that name those projects are rendered by that chart, and a project has to exist before its Applications are accepted. Rendering both from one chart with a lower sync wave on the projects keeps the order right on a fresh install; a separate directory would need its own Application and a manual ordering rule.

Will the default project change?

No. Fifteen Applications and every generator example under applicationset/ use the default project, and tightening it would break the demo. Only the three team projects that are referenced but missing are added.

What does sourceNamespaces do here?

It lets an Application or ApplicationSet declared in a team namespace, rather than in argocd, use the project. The three app-any-ns Applications and the three services ApplicationSets are declared that way, and without sourceNamespaces the controller refuses them, which is what the invalid example demonstrates on purpose.

Is a ConfigMap-only whitelist too strict?

For the lightweight apps it is exact, since app-a and app-b each deploy one ConfigMap. The pull request says so and points at the one line to widen when a team's service adds a Deployment or a Service, so the restriction is a deliberate starting point rather than an accident.

Does the agent need access to my real cluster?

No. It proves the projects on a kind cluster inside its sandbox with a fresh Argo CD install, and the pull request carries the controller output from that cluster. Applying it to production is your sync, after review.

More Argo CD jobs

More jobs like this: Steer a run as a team

Keep reading