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

# PlanetScale Vitess dynamic secrets

> Learn how to issue short-lived passwords for PlanetScale Vitess databases on demand.

The PlanetScale Vitess dynamic secret creates a new password for a [PlanetScale](https://planetscale.com/) database branch each time someone creates a [lease](https://infisical.com/docs/documentation/platform/dynamic-secrets/overview), and deletes the password when the lease ends. Use it to give an application or a CI job its own short-lived MySQL credentials instead of sharing one long-lived password.

PlanetScale Vitess databases don't support MySQL users and grants, so the [MySQL dynamic secret](https://infisical.com/docs/documentation/platform/dynamic-secrets/mysql.md) can't create users on them. PlanetScale databases that run PostgreSQL use roles instead of passwords, so this dynamic secret doesn't support them.

## Prerequisites

* A PlanetScale [service token](https://planetscale.com/docs/api/reference/service-tokens) with these permissions on the database:
  * `connect_branch` and `delete_branch_password` for a development branch
  * `connect_production_branch` and `delete_production_branch_password` for a production branch
* A [role](https://infisical.com/docs/documentation/platform/access-controls/role-based-access-controls.md) in the Infisical project that lets you create dynamic secrets

## Step 1: Create the dynamic secret

**Step 1**

In your project, go to the environment and folder where you want the dynamic secret, then select **Add New** > **Add Dynamic Secret**.

**Step 2**

Select **PlanetScale Vitess**.

**Step 3**

Fill in the form:

**Secret Name** `string` *required*

The name you use to refer to the dynamic secret.

**Default TTL** `string` *required*

How long a lease lasts if the person creating it doesn't choose a TTL (for example, `1h`).

**Max TTL** `string`

The longest TTL anyone can request for a lease (for example, `24h`).

**Service Token ID** `string` *required*

The ID of your PlanetScale service token.

**Service Token** `string` *required*

The value of your PlanetScale service token. When you edit the dynamic secret, leave this blank to keep the current token.

**Organization** `string` *required*

The name of your PlanetScale organization.

**Database** `string` *required*

The name of the PlanetScale database.

**Branch** `string` *required* (default: main)

The database branch that each password gives access to.

**Role** `string` (default: Read-only)

The [role](https://planetscale.com/docs/vitess/security/password-roles) that each password gets: **Read-only**, **Write-only**, **Read/write**, or **Admin**.

**Password Name Template** `string` (default: \{\{randomUsername}})

The name each password gets in PlanetScale, under **Advanced**. The default gives each password a random name. PlanetScale names must be unique on the branch and can only contain up to 63 lowercase letters, numbers, and dashes. Infisical lowercases the name, turns other characters into dashes, shortens it if needed, and adds a random suffix. You can use `{{dynamicSecret.name}}`, `{{identity.name}}`, `{{unixTimestamp}}`, and `{{randomUsername}}` to make the passwords easier to find in PlanetScale.

> [!NOTE]
>
> You can't change the organization, database, or branch while the dynamic secret has active leases. Revoke the leases first.

**Step 4**

Select **Submit**.

Before Infisical saves the dynamic secret, it checks that the service token can access the branch. If PlanetScale rejects the token, PlanetScale can't find the branch, or the database doesn't run Vitess, Infisical shows the error and doesn't save the dynamic secret.

## Step 2: Create a lease

**Step 1**

In the row for the dynamic secret, select **Generate Lease**.

**Step 2**

Enter a **Default TTL** for the lease, then select **Provision Lease**.

**Step 3**

Copy the values Infisical shows:

* `DB_HOST`: the PlanetScale host to connect to
* `DB_USERNAME`: the MySQL username
* `DB_PASSWORD`: the MySQL password

> [!WARNING]
>
> Infisical shows the password only once. Copy it before you close the dialog.

## Revoke a lease

Select the dynamic secret to see its leases, then select **Revoke lease** next to a lease to delete its password in PlanetScale before the lease expires.

When a lease expires, Infisical deletes its password. PlanetScale also stops accepting the password when the lease expires, even if Infisical can't delete it. You can't renew a PlanetScale lease. To keep access, create a new lease before the current one expires.

> [!NOTE]
>
> If the service token can't delete passwords on the branch, revoking a lease fails and the password keeps working until the lease expires. Grant the token `delete_branch_password` (`delete_production_branch_password` for a production branch), then revoke the lease again.


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