> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/integrations/resource-integrations/argocd.md).

# Argo CD

Install P0 for your Argo CD instances so people can request just-in-time Argo CD roles, on a whole instance or on one project.

{% hint style="info" %}
The Argo CD integration is in beta. Functionality and configuration may change.
{% endhint %}

Use the Argo CD integration to give people temporary roles in [Argo CD](https://argo-cd.readthedocs.io). A person requests one of two kinds of access:

* **A global role**, such as `role:readonly` or `role:admin`, on a whole Argo CD instance.
* **A project role**, one of the roles an Argo CD project (an AppProject) already defines.

When the request is approved, P0 adds one line to your Argo CD policy that gives the person's SSO user that role. When access ends, P0 removes the line.

To learn more, see:

* [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md)
* [Requesting Argo CD access](https://docs.p0.dev/integrations/resource-integrations/argocd/requesting-access.md)

## How it works

* **The connector runs in your cloud.** You deploy P0's Argo CD connector (see [P0 connectors](https://docs.p0.dev/readme/connectors.md)) on AWS Lambda or Google Cloud Run. P0 invokes the connector, and the connector calls the Argo CD API of your instances over HTTPS. It never calls the Kubernetes API. One connector can serve several Argo CD instances.
* **The connector acts as an Argo CD local account you create.** You add the account `p0-connector` in Git, with a role that can read one Application and update one ConfigMap through it, as in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#step-1-add-the-p0-connector-account).
* **The account's API token stays in your secret manager.** You store it in AWS Secrets Manager or Google Secret Manager, under a name you choose. P0 stores only the secret's name and where it is, and never reads the secret. The connector does.
* **P0 writes grants to a key of its own.** Every grant is a line in the `policy.p0.csv` key of `argocd-rbac-cm`, written through the Application that manages `argocd-rbac-cm`. Your own policy keys stay as you wrote them, and Argo CD's audit log records each change.
* **You decide which email domains can receive access.** The connector's `ALLOWED_EMAIL_DOMAIN_PATTERN` environment variable holds a regular expression for the allowed email domains. The connector refuses everyone else, and P0 can't change the pattern.
* **P0 grants roles to SSO users by email.** The line names the person's P0 email in lowercase, and Argo CD matches it to the email your identity provider sends. P0 never creates or changes Argo CD accounts, projects or roles.

## What P0 changes in Argo CD

| When                  | What P0 does                                                                                                                    |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| A request is approved | Adds `g, <email>, role:<role>` for a global role, or `g, <email>, proj:<project>:<role>` for a project role, to `policy.p0.csv` |
| Access ends           | Removes that line. If the line is already gone, there's nothing to do, and the request ends normally                            |

P0 changes nothing else in Argo CD. It never edits your other policy keys, your AppProjects or your Applications, and never syncs an Application.

P0 refuses a request for a role the person already holds. For the details, see [Requesting Argo CD access](https://docs.p0.dev/integrations/resource-integrations/argocd/requesting-access.md#roles-you-already-hold).

{% hint style="warning" %}
**Keep `policy.p0.csv` out of Git, and never sync `argocd-rbac-cm` with `Replace=true`.** If Git declares the key, the next sync replaces P0's lines with what Git holds. A replace sync deletes the key. Either way, everyone loses the access P0 granted at once, and P0 doesn't put it back. For the setup that keeps the key safe, see [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#step-1-add-the-p0-connector-account).
{% endhint %}

## Access policies

In the [Configuring access policies](https://docs.p0.dev/policy-studio/policy-studio/configure-your-first-access-policy.md#resource) section of an access policy, Argo CD is the service `argocd`. Its access types are `global-role` and `project-role`.

### Available filters

A rule can filter on these properties of a request, each with the key `name`:

| Filter     | What it matches                                                                                                      | Example         |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | --------------- |
| `instance` | The Argo CD instance's ID in P0, whichever way the requestor named it                                                | `prod`          |
| `project`  | The project's name in Argo CD. Applies to `project-role` only                                                        | `payments`      |
| `role`     | For `global-role`, the role's full name, with its `role:` prefix. For `project-role`, the role's name on the project | `role:readonly` |

Patterns are unanchored, case-sensitive regular expressions. Use `^` and `$` to match a whole name.

### Example access policy

{% hint style="warning" %}
**Treat `role:admin` as standing access.** Someone who holds `role:admin`, even for an hour through P0, can change `argocd-rbac-cm` or create API tokens, and so give themselves access that outlasts the grant. Require approval for it, and review [Argo CD's audit log](https://argo-cd.readthedocs.io/en/stable/operator-manual/security/#auditing) for changes made while someone held it.
{% endhint %}

These policies send requests for `role:readonly` on any instance, and for any role on the `payments` project, to your Security Reviewers, and deny `role:admin` on the `prod` instance:

```yaml
- requestor:
    type: any
  resource:
    type: integration
    service: argocd
    accessType: global-role
    filters:
      role:
        effect: keep
        key: name
        pattern: ^role:readonly$
  approval:
    - type: p0
- requestor:
    type: any
  resource:
    type: integration
    service: argocd
    accessType: project-role
    filters:
      project:
        effect: keep
        key: name
        pattern: ^payments$
  approval:
    - type: p0
- requestor:
    type: any
  resource:
    type: integration
    service: argocd
    accessType: global-role
    filters:
      instance:
        effect: keep
        key: name
        pattern: ^prod$
      role:
        effect: keep
        key: name
        pattern: ^role:admin$
  approval:
    - type: deny
```

## Error messages for admins

Requestors and approvers see these messages on a request when it needs an admin's attention. For the messages a requestor can fix themselves, see [Requesting Argo CD access](https://docs.p0.dev/integrations/resource-integrations/argocd/requesting-access.md#troubleshooting). For the messages you see while you add an instance, see [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#what-the-install-checks).

### The install

| Message                                                                                                                   | What to do                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `The Argo CD connector for <instance> can't check email domains. Ask your P0 admin to check its setup.`                   | The connector's `ALLOWED_EMAIL_DOMAIN_PATTERN` is unset, blank, or isn't a regular expression that compiles. Set it as in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#the-email-domain-pattern). The connector's log says what's wrong with it. |
| `The Argo CD instance <instance> uses the connector <connector>, which isn't installed. Ask your P0 admin to install it.` | Install a connector with that ID again, in the same place, as in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#step-3-install-the-connector).                                                                                                     |
| `P0 isn't installed on any Argo CD instance yet. Ask your P0 admin to install one.`                                       | Add an Argo CD instance, as in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#step-4-add-the-argo-cd-instance).                                                                                                                                    |
| A message that starts `P0 is not installed for the instance` and names an instance                                        | The request is for an instance that was removed from P0. See [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#remove-or-replace-an-instance).                                                                                                        |

### The connector and the p0-connector account

| Message                                                                                                                                                                                                                 | What to do                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `P0 couldn't reach the Argo CD connector. Ask your P0 admin to check its deployment.`                                                                                                                                   | Check that the connector's function or service exists where its hosting says, and that the connector's Terraform is applied: it gives P0 `lambda:InvokeFunction` on AWS, or `roles/run.invoker` and `roles/run.viewer` on Google Cloud. Check the connector's logs.                                                                           |
| `The Argo CD connector couldn't read the p0-connector account's API token. Ask your P0 admin to check the Argo CD install.`                                                                                             | Check the secret's name, and its account and region or project, on the instance's page in P0. Check that the secret holds `{"token": "<api token>"}`, and that the instance's Terraform is applied. The connector's log records why the read failed.                                                                                          |
| A message that starts `Argo CD at <host> didn't accept the connector's API token`                                                                                                                                       | The token was deleted, or the `p0-connector` account was disabled, removed or lost its `apiKey` capability. Check the account with `argocd account get --account p0-connector`, and if you need a new token, follow [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#rotate-the-api-token). |
| A message that starts `Argo CD at <host> refused the connector's call to`                                                                                                                                               | The `p0-connector` account lost one of its policy lines, or the managing Application was renamed or deleted. Check the account's lines in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#step-1-add-the-p0-connector-account) against `argocd-rbac-cm`.                                   |
| A message that says an Application `doesn't manage ConfigMap <namespace>/argocd-rbac-cm`                                                                                                                                | `argocd-rbac-cm` is no longer deployed by the Application the instance names. See [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#remove-or-replace-an-instance) to point P0 at the Application that deploys it now.                                                                       |
| `Argo CD is temporarily unavailable. Try again in a few minutes.`                                                                                                                                                       | The connector couldn't reach Argo CD, or Argo CD answered with an error or limited its calls. Check that Argo CD is up and that the connector's network can reach it. The connector's log says what happened. Then retry.                                                                                                                     |
| `The Argo CD connector's account on <instance> may do more than P0 allows, such as sync any application, so P0 grants nothing there until its privileges are cut back. Ask your P0 admin to check the Argo CD install.` | Someone widened the `p0-connector` account's role. Remove what it shouldn't have, as in [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#permissions-not-to-grant-the-account).                                                                                                             |

### Argo CD's policy

| Message                                                                                                                                                                                                             | What to do                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `argocd-rbac-cm on the Argo CD instance <instance> has a line Argo CD refuses, so Argo CD keeps enforcing the policy it had and a new grant wouldn't take effect. Ask an Argo CD admin to fix or remove that line.` | A line in one of your policy keys doesn't parse, so Argo CD ignores the whole change and keeps its earlier policy. Fix the line in Git, starting with the most recent change to a policy key. |
| A message that starts `Argo CD at <host> accepted the change to policy.p0.csv in argocd-rbac-cm, but reading it back`                                                                                               | Something changed `policy.p0.csv` right after P0 wrote it, such as a sync. Check that Git doesn't declare the key, then retry.                                                                |

When P0 can't revoke a role, the request shows as errored, and the line stays in `policy.p0.csv`. Fix the cause, then click **Retry revoke** on the request's page.

## Limitations

* P0 grants roles to SSO users only, by email. It can't grant a role to an Argo CD local account, and it doesn't check that a user exists in your identity provider.
* Your identity provider must send emails in lowercase. Argo CD compares a policy line's email with the email the identity provider sends, capitalization included, and P0 writes the email in lowercase. If your identity provider sends `Alice@Example.com`, a grant to `alice@example.com` gives Alice nothing.
* An Application must manage `argocd-rbac-cm`. P0 writes through that Application, so an instance whose `argocd-rbac-cm` no Application deploys isn't supported.
* Argo CD must be version 3.0 or later, and served at the root of its address. An Argo CD served under a path (`server.rootpath`) isn't supported.
* P0 never creates or edits AppProject roles. A project role must already be defined on the project, and P0 offers every role a project defines. See [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#project-roles).
* P0 doesn't put back a line that someone else removes. If a sync or a person removes P0's line, the person loses the access before it ends, and the request still ends normally.
* A person can have one open request for each role at a time. See [Requesting Argo CD access](https://docs.p0.dev/integrations/resource-integrations/argocd/requesting-access.md#one-request-per-role).
* Removing an instance from P0 leaves the lines P0 wrote in `policy.p0.csv`, and P0 can't revoke them while the instance isn't installed. See [Installing Argo CD](https://docs.p0.dev/integrations/resource-integrations/argocd/installation.md#remove-or-replace-an-instance).
* The instance must be reachable over the public internet at an `https` address, with a certificate from a public certificate authority.
* The connector runs on AWS Lambda or Google Cloud Run, and reads the API token's secret from the secret manager of the same cloud.
