Back to Infisical

Supabase API Key

docs/documentation/platform/secret-rotation/supabase-api-key.mdx

0.159.265.0 KB
Original Source
<Note> **Rotation Type: Dual-Phase**

This rotation maintains two active credential sets with overlapping validity, ensuring zero-downtime during rotation cycles. </Note>

Prerequisites

  • Create a Supabase Connection. That connection is used to create and delete API keys on your behalf during rotation.

Create a Supabase API Key Rotation in Infisical

<Tabs> <Tab title="Infisical UI"> 1. Navigate to your Secret Manager Project's Dashboard and select **Add Secret Rotation** from the actions dropdown.
    ![Secret Manager Dashboard](/images/secret-rotations-v2/generic/add-secret-rotation.png)

    2. Select the **Supabase API Key** option.

    ![Select Supabase API Key](/images/secret-rotations-v2/supabase-api-key/select-supabase-api-key.png)

    3. Configure the rotation behavior, then click **Next**.

    - **Supabase Connection** – The connection that will create and delete API keys during rotation.
    - **Rotation Interval** – The interval, in days, after which a rotation is triggered.
    - **Rotate At** – The local time of day when rotation runs once the interval has elapsed.
    - **Auto-Rotation Enabled** – Whether to rotate automatically on the interval. Turn off to rotate only manually or pause rotation.

    ![Rotation Configuration](/images/secret-rotations-v2/supabase-api-key/configuration.png)

    4. Set the Supabase API key parameters, then click **Next**.

    - **Project** – The Supabase project to rotate the API key for.
    - **Key Type** – The type of the API key to rotate:
        - `publishable` – The public `anon` key, safe to expose in client-side code. It is used with Row Level Security (RLS) policies to control per-user access.
        - `secret` – The `service_role` key, which bypasses RLS entirely and has full access to your project's data. Must be kept server-side only.

    ![Rotation Parameters](/images/secret-rotations-v2/supabase-api-key/parameters.png)

    5. Specify the secret name that the rotated API key will be mapped to. Then click **Next**.

    - **API Key** – The name of the secret in Infisical where the rotated API key value will be stored.

    ![Rotation Secrets Mapping](/images/secret-rotations-v2/supabase-api-key/secrets-mapping.png)

    6. Give your rotation a name and description (optional). Then click **Next**.

    - **Name** – A slug-friendly name for this rotation configuration.
    - **Description** (optional) – Notes about this rotation.

    ![Rotation Details](/images/secret-rotations-v2/supabase-api-key/details.png)

    7. Review your configuration, then click **Create Secret Rotation**.

    ![Rotation Review](/images/secret-rotations-v2/supabase-api-key/review.png)

    8. Your **Supabase API Key** rotation is created. The current API key is available as a secret at the mapped path. Rotations will create a new key, switch the active secret to it, then revoke the previous key for zero-downtime rotation.

    ![Rotation Created](/images/secret-rotations-v2/supabase-api-key/created.png)
</Tab>
<Tab title="API">
    To create a Supabase API Key rotation, call the [Create Supabase API Key Rotation](/api-reference/endpoints/secret-rotations/supabase-api-key/create) API endpoint.

    ### Sample request

    ```bash Request
    curl --request POST \
      --url https://us.infisical.com/api/v2/secret-rotations/supabase-api-key \
      --header 'Content-Type: application/json' \
      --data '{
        "name": "my-supabase-rotation",
        "projectId": "<project-id>",
        "description": "Supabase API key rotation",
        "connectionId": "<supabase-connection-id>",
        "environment": "dev",
        "secretPath": "/",
        "isAutoRotationEnabled": true,
        "rotationInterval": 30,
        "rotateAtUtc": {
          "hours": 0,
          "minutes": 0
        },
        "parameters": {
          "projectRef": "<supabase-project-ref>",
          "keyType": "secret"
        },
        "secretsMapping": {
          "apiKey": "SUPABASE_API_KEY"
        }
      }'
    ```

    ### Sample response

    ```bash Response
    {
      "secretRotation": {
        "id": "<rotation-id>",
        "name": "my-supabase-rotation",
        "description": "Supabase API key rotation",
        "secretsMapping": {
          "apiKey": "SUPABASE_API_KEY"
        },
        "isAutoRotationEnabled": true,
        "activeIndex": 0,
        "connectionId": "<supabase-connection-id>",
        "rotationInterval": 30,
        "rotateAtUtc": { "hours": 0, "minutes": 0 },
        "type": "supabase-api-key",
        "parameters": {
          "projectRef": "<supabase-project-ref>",
          "keyType": "secret"
        }
      }
    }
    ```
</Tab>
</Tabs>