> ## Documentation Index
> Fetch the complete documentation index at: https://www.unkey.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Unkey is two separate products. Compute builds, deploys, and runs apps behind a gateway. API Management issues API keys, enforces rate limits, manages identities and permissions, and reports usage. Say which product a page belongs to; a reader can use either without the other.
> Every Unkey API endpoint is an HTTP POST to https://api.unkey.com/v2/{service}.{procedure} with a root key in the Authorization: Bearer header. Root keys are workspace scoped.
> Error codes have the form err:{system}:{category}:{specific} and each has a page at /errors/{system}/{category}/{specific}.
> The word environment means production or preview in Compute. Rate limiting has four meanings on this site; the glossary lists them.

# Credentials and security

> What each PlanetScale credential can do, when Unkey deletes it, and how Unkey stores your secrets.

## What a credential can do

Read-write credentials can read and write data. Read-only credentials can only read. Deployment credentials can't create or change tables. For schema changes, see [Migrations](https://www.unkey.com/docs/compute/integrations/planetscale/migrations.md). Unkey never gives a deployment credential an admin role:

| Engine | Read-write credential | Read-only replica credential |
| - | - | - |
| Postgres, Neki | A role that inherits `pg_read_all_data` and `pg_write_all_data` | A role that inherits `pg_read_all_data` |
| Vitess | A password with the `readwriter` role | A replica password with the `reader` role |

No deployment credential inherits the `postgres` admin role or gets the Vitess `admin` role.

## Lifecycle

Every deployment gets its own credential for each connection of its environment, so deleting one never breaks another deployment.

| Event | What happens |
| - | - |
| A deployment is created | Before the build, Unkey creates its credentials and writes the connection URLs into its snapshot. The URLs are available at build time and at run time. |
| A deployment fails, or is cancelled or superseded before it goes live | Unkey deletes its credentials right away. |
| A deployment stops | Unkey deletes its credentials at least 5 minutes later, so running requests can drain first. |
| A stopped deployment wakes | Unkey creates new credentials if the old ones were deleted. |
| An environment is disconnected | Unkey deletes that database's credentials for every deployment of the environment, including running ones. On Vitess and Neki, their open connections close within seconds. On Postgres, open connections stay open until you stop or redeploy those deployments, but no new ones can be made. |
| A delete fails after a stop | Unkey marks the credential and tries again later, with longer waits each time. For a disconnect, see [Disconnect and remove](https://www.unkey.com/docs/compute/integrations/planetscale/connect.md#disconnect-and-remove). |

> [!WARNING]
>
> Disconnecting an environment deletes the credentials of its running deployments right away. Deploy a version of your app that doesn't need the database before you disconnect. Older deployments you might roll back to lose their credentials too.

## Pull requests from forks

Deployments built from a fork, or from a pull request opened from a fork, get no database credentials, because their code isn't trusted with your database.

## What Unkey stores

| What | Where | How |
| - | - | - |
| PlanetScale OAuth refresh and access tokens | Unkey's database | Encrypted with [Vault](#how-secrets-are-encrypted), with a key scoped to your workspace |
| Connection URLs of a deployment, including the password | The deployment's environment variable snapshot | Encrypted with Vault, with a key scoped to the environment |
| Credential name and PlanetScale ID | Unkey's database | Plaintext, so Unkey can find and delete the credential later. Never the password |

### How secrets are encrypted

Unkey encrypts every secret before it's written, with the same Vault service that protects [environment variables](https://www.unkey.com/docs/compute/configure/environment-variables.md). OAuth tokens use a key per workspace. Connection URLs use a key per environment, the same key the runtime uses to decrypt the environment variables of your instances.

Connection URLs are not in your environment variables list, and the dashboard and the API never return them. Your app reads them at run time, and your build can read them like any other variable, through [build-time secrets](https://www.unkey.com/docs/compute/build/build-secrets.md).

### Who can see what

* Unkey writes a new credential's password straight into that deployment's encrypted snapshot, and nowhere else.
* Deployment credentials are named `unkey-`, then the deployment ID in lowercase with `_` replaced by `-`, then a random suffix. For example, deployment `d_4Kx9…` gets a credential named like `unkey-d-4kx9…-1a2b3c4d5e6f`. This way you can find them in the PlanetScale console.
* Unkey records every PlanetScale change in your workspace [audit log](https://www.unkey.com/docs/platform/workspace/audit-logs/event-types.md#planetscale-databases), including each deployment credential it creates or deletes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.