> 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/launchdarkly.md).

# LaunchDarkly

Install P0 for your LaunchDarkly accounts so people can request just-in-time base roles.

{% hint style="info" %}
The LaunchDarkly integration is in preview. Functionality and configuration may change.
{% endhint %}

Use the LaunchDarkly integration to give people temporary access in [LaunchDarkly](https://launchdarkly.com). A person requests a base role in one LaunchDarkly account. When the request is approved, P0 raises the base role of their existing LaunchDarkly member, and when access ends, P0 lowers it again.

To learn more, see:

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

## How it works

* **The connector runs in your cloud.** You deploy P0's LaunchDarkly 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 LaunchDarkly. One connector can serve several LaunchDarkly accounts.
* **The connector uses an access token you create.** It's a LaunchDarkly admin's personal access token, with the Admin role. See [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#step-1-create-the-access-token).
* **The token stays in your secret manager.** You store it in AWS Secrets Manager or Google Secret Manager, one secret per account. P0 stores only the secret's name and where it is, and never reads the secret. The connector does.
* **You decide which email domains can receive access.** The connector's `DOMAIN_ALLOW_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 finds each person by email.** P0 matches the requestor's P0 email to the LaunchDarkly member with the same email, who has verified it and joined the account. P0 never invites members.
* **P0 changes only base roles.** P0 never creates, edits or deletes anything else in LaunchDarkly.

## What P0 changes in LaunchDarkly

| Access type | What the person gets                        | When a request is approved                         | When access ends                                                                                           |
| ----------- | ------------------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `base-role` | A higher base role: Reader, Writer or Admin | Raises the member's base role to the requested one | Lowers it to the highest role the person's other live requests still grant, or to the role they had before |

A grant never lowers a base role, and the end of access never raises one. P0 never grants or changes the Owner role. For the details, see [Requesting LaunchDarkly access](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/requesting-access.md#when-your-access-ends).

{% hint style="warning" %}
**Access added outside P0 can end with a request.** When access ends, P0 removes what the request names, even if someone also added that same access outside P0 while the request was live. If an admin also raises a person's base role while their request is live, P0 still lowers it when the request ends.
{% endhint %}

## Access policies

In access policies (see [Configuring access policies](https://docs.p0.dev/policy-studio/policy-studio/configure-your-first-access-policy.md#resource)), LaunchDarkly is the service `launchdarkly`. Its access type is `base-role`.

### Available filters

A rule can filter on these properties of a request:

| Filter      | Key    | What it matches                                        | Example     |
| ----------- | ------ | ------------------------------------------------------ | ----------- |
| `account`   | `name` | The LaunchDarkly account's name in P0                  | `acme-prod` |
| `base-role` | `name` | The requested base role: `reader`, `writer` or `admin` | `admin`     |

Patterns are unanchored, case-sensitive regular expressions. Use `^` and `$` to match a whole name. The request form lists only the base roles a rule's patterns match.

The request form ignores a rule's `account` filter. P0 applies it when the request is made, so the form can list an option on an account where such a rule then refuses the request or routes it elsewhere.

### Example access policy

These policies send requests for the Admin base role on any account to your Security Reviewers, and deny every base role on the account `acme-prod`:

```yaml
- requestor:
    type: any
  resource:
    type: integration
    service: launchdarkly
    accessType: base-role
    filters:
      base-role:
        effect: keep
        key: name
        pattern: ^admin$
  approval:
    - type: p0
- requestor:
    type: any
  resource:
    type: integration
    service: launchdarkly
    accessType: base-role
    filters:
      account:
        effect: keep
        key: name
        pattern: ^acme-prod$
  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 LaunchDarkly access](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/requesting-access.md#troubleshooting).

### The install

| Message                                                                                                                      | What to do                                                                                                                                                                                                                                                                                                |
| ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `The LaunchDarkly connector for <account> can't check email domains. Ask your P0 admin to check its setup.`                  | The connector's `DOMAIN_ALLOW_PATTERN` is unset, blank, or isn't a regular expression that compiles. Set it as in [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#the-email-domain-pattern). The connector's log says what's wrong with it. |
| `The LaunchDarkly account <account> 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 LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#step-3-install-the-connector).                                                                                             |
| `P0 has no LaunchDarkly account set up yet. Ask your P0 admin to add one.`                                                   | Add a LaunchDarkly account, as in [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#step-4-add-the-launchdarkly-account).                                                                                                                     |
| `P0 hasn't checked the LaunchDarkly account <account> yet. Ask your P0 admin to finish installing it.`                       | Finish adding the account in the installer, so that P0 checks it through the connector.                                                                                                                                                                                                                   |

### The connector and the access token

| Message                                                                                                                                                                    | What to do                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `P0 couldn't reach the LaunchDarkly 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 LaunchDarkly connector couldn't read the account's access token. Ask your P0 admin to check the token's secret and the connector's access to it.`                     | Check the secret's name, and its account and region or project, on the account's page in P0. Check that the secret holds the token alone, and that the account's Terraform is applied. The connector's log records why the read failed.                                                                                                                         |
| A message that contains `didn't accept the connector's access token`                                                                                                       | LaunchDarkly refused the token: it was reset, it expired, or its owner left LaunchDarkly. Store a new token, as in [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#rotate-the-access-token).                                                                                                      |
| A message that contains `with 403`                                                                                                                                         | The token or its owner no longer has the Admin role. Store a new token from an admin, as in [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#rotate-the-access-token).                                                                                                                             |
| `The access token P0 uses for the LaunchDarkly account <account> belongs to another LaunchDarkly account. Ask your P0 admin to put the account's own token in its secret.` | The account's secret holds a token for another LaunchDarkly account, so P0 refuses requests on the account and grants nothing on it. Store the account's own token in the secret, as in [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#rotate-the-access-token). Then the person requests again. |
| A message that starts `The LaunchDarkly connector's access token on <host> belongs to another account`                                                                     | The account's secret holds a token for another LaunchDarkly account. Store the account's own token in the secret, then click **Retry revoke**. P0 takes nothing back until you do.                                                                                                                                                                              |

### A person's member

| Message                                                                                                                                                                                                                                                            | What to do                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `LaunchDarkly at <host> accepted <change> for member <member-id>, but reading the member back 3 times didn't show it, so P0 takes the change back. An identity provider using SSO or SCIM may have undone it. Request access again once the member keeps changes.` | LaunchDarkly accepted the grant, but the change didn't show on the member. If your identity provider manages LaunchDarkly members through SSO or SCIM, it likely undid the grant. See [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#identity-providers-that-manage-launchdarkly). P0 takes back what it applied. |
| `Another P0 request already changed your LaunchDarkly member on <account>, and P0 can't read what it held before. Ask your P0 admin to check your earlier requests, then request again.`                                                                           | Another of the person's base role requests holds its access, but P0 has no record of what the member held before it. Check that request's error, and end it. Then the person requests again.                                                                                                                                                                                     |
| `P0 didn't record your LaunchDarkly member's base role on the LaunchDarkly account <account> before this request, so it won't change it. A LaunchDarkly admin has to set it back by hand.`                                                                         | In LaunchDarkly, set the person's base role to what it should be. **Retry revoke** fails the same way for this message, so contact P0 at <support@p0.dev> to close the request.                                                                                                                                                                                                  |

When P0 can't revoke access, the request shows as errored, and the access stays in place in LaunchDarkly. Except for the last row, fix the cause, then click **Retry revoke** on the request's page.

## Limitations

* P0 grants access only to LaunchDarkly members that already exist, have verified their email and have joined the account. A person who hasn't accepted their invitation can't receive access.
* P0 matches people by email only. A member whose email differs from the person's P0 email can't receive access.
* P0 never gives access to the member whose personal token the connector uses.
* If your identity provider manages members' roles through SSO or SCIM, it can undo a grant. See [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#identity-providers-that-manage-launchdarkly).
* A person can have one live request for each base role on an account at a time, such as one request for Admin.
* P0 manages each LaunchDarkly member for one P0 user at a time. When two P0 users' emails find the same member, a live request from one refuses the other's requests on that account.
* LaunchDarkly ignores the base role of a member who has custom roles assigned directly, so P0 refuses a base role request from such a member. See [Requesting LaunchDarkly access](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/requesting-access.md#base-roles).
* When one of a person's requests ends, P0 keeps only the access their other live requests hold. A request whose revoke failed doesn't count, so the access it shares with the ending request is removed too.
* Removing a LaunchDarkly account from P0 leaves the access P0 granted on it in place in LaunchDarkly, and P0 can't revoke it while the account isn't installed. See [Installing LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md#remove-an-account).
* The connector runs on AWS Lambda or Google Cloud Run, and reads each account's secret from the secret manager of the same cloud.
