> Note for AI agents: For other pages, see [llms.txt](https://supabase.com/docs/llms.txt).

# Member access rules

Choose which Postgres roles each team member can assume with database token access and limit each role by expiry, allowed network, and preview branch.

A member access rule lets a team member connect to your project database as a [Postgres role](https://supabase.com/docs/guides/database/postgres/roles) with their own [access token](https://supabase.com/docs/guides/platform/personal-access-tokens) instead of the database password. You can limit each role by expiry, network, and branch and remove one person's access without changing the database password. For how it works and how to connect, see [Database token access](https://supabase.com/docs/guides/platform/database-token-access).

A rule doesn't create a role or user in the database. It lets the team member assume roles that already exist. Because those roles keep their own passwords, service connections that use them don't change. Rules live on your main project and apply to its [read replicas](https://supabase.com/docs/guides/platform/read-replicas) and [preview branches](https://supabase.com/docs/guides/deployment/branching).

## Prerequisites

- [Turn on database token access](https://supabase.com/docs/guides/platform/database-token-access#manage-database-token-access-via-the-dashboard) for the project.
- Confirm that the team member has access to the project.

## Choose a role

A rule can map any Postgres role that can log in. Even with a valid token, Postgres refuses any role without the `LOGIN` attribute. To give someone less access than `postgres`, create a narrower role with `LOGIN` first. See [Postgres roles](https://supabase.com/docs/guides/database/postgres/roles).

You can't map the roles Supabase manages for its own services. These are `service_role`, `authenticator`, `pgbouncer`, `supabase_admin`, and every other `supabase_*_admin` role. You can map `supabase_read_only_user` for read-only access. The dashboard lists only the roles you can map.

## Authorize a team member

After you create a rule, the team member connects as a mapped role with their access token as the password. For connection strings, see [Connect with database token access](https://supabase.com/docs/guides/platform/database-token-access#connect-with-database-token-access).

### In the dashboard

1. Go to [Database Settings](https://supabase.com/dashboard/project/_/database/settings) > **Database access** and click **Add member** in the **Members** list.
2. Select the team member.
3. Under **Roles and settings**, select each role the team member can assume. To limit a role, set the fields described in [Restrict a team member's access](#restrict-a-team-members-access).
4. Click **Create rule**.

To change a rule, open its **More actions** menu in the **Members** list and click **Edit**.

### With the Management API

Create a personal access token in the [Supabase Dashboard](https://supabase.com/dashboard/account/tokens) to call the Management API. If you scope the token, give it **Organization members** with **Read only** access and **Database token access** with **Read and write** access. Send every request to the main project's ref because the Management API rejects rule requests sent to a branch.

1. Set your access token, project ref, and organization slug:

   ```bash
   export SUPABASE_MANAGEMENT_API_TOKEN="YOUR_ACCESS_TOKEN"
   export PROJECT_REF="YOUR_PROJECT_REF"
   export ORG_SLUG="YOUR_ORG_SLUG"
   ```

   The organization slug is the part of your organization's URL in the Supabase Dashboard that follows `/org/`.

2. List the organization's members and copy the `user_id` of the team member you want to authorize:

   ```bash
   curl "https://api.supabase.com/v1/organizations/$ORG_SLUG/members" \
     -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN"
   ```

3. Map the team member to the roles they can assume. Each request replaces the team member's rule. List every role they need. Replace `YOUR_MEMBER_USER_ID` with the `user_id` you copied. To restrict access from the start, add the fields from [Restrict a team member's access](#restrict-a-team-members-access) to this request:

   ```bash
   export MEMBER_USER_ID="YOUR_MEMBER_USER_ID"

   curl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/database/jit" \
     -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN" \
     -H "Content-Type: application/json" \
     -d @- <<EOF
   {
     "user_id": "$MEMBER_USER_ID",
     "roles": [{ "role": "postgres" }]
   }
   EOF
   ```

## Restrict a team member's access

Each role in a rule takes three optional restrictions. The dashboard field is in parentheses:

- `expires_at` (**Expires in**): a future Unix timestamp in seconds. After it passes, the database rejects new connections even if the access token is still valid. Connections that are already open stay open. Without it, the role doesn't expire. In the dashboard, **Expires in** defaults to **1 hour** and also offers **1 day**, **7 days**, **30 days**, **Never**, and **Custom** for a date up to one year away.
- `allowed_networks` (**Restricted IP addresses**): the CIDR ranges the team member can connect from. In the API, put IPv4 ranges in `allowed_cidrs` and IPv6 ranges in `allowed_cidrs_v6`.
- `branches_only` (**Applies to** set to **Preview branches only**): the team member can assume the role on preview branches but not on the main project.

This API example uses the variables from [With the Management API](#with-the-management-api). It limits the `postgres` role to one IPv4 address for seven days. Replace `203.0.113.10/32` with the address or range the team member connects from:

```bash
export EXPIRES_AT=$(( $(date +%s) + 7 * 24 * 60 * 60 ))

curl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/database/jit" \
  -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "user_id": "$MEMBER_USER_ID",
  "roles": [
    {
      "role": "postgres",
      "expires_at": $EXPIRES_AT,
      "allowed_networks": {
        "allowed_cidrs": [{ "cidr": "203.0.113.10/32" }]
      }
    }
  ]
}
EOF
```

## Remove a team member's access

In the dashboard, open the rule's **More actions** menu in the **Members** list, click **Delete**, and confirm with **Delete rule**.

With the Management API, send a delete request:

```bash
curl -X DELETE "https://api.supabase.com/v1/projects/$PROJECT_REF/database/jit/$MEMBER_USER_ID" \
  -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN"
```

Removing a rule blocks new connections but doesn't close the ones the team member already has open. To close those, see [End access that's already in use](https://supabase.com/docs/guides/platform/database-token-access#end-access-thats-already-in-use). A team member who knows the role's password can still connect with it. To end that access, change the role's password. For the `postgres` role, see [Changing your project password](https://supabase.com/docs/guides/database/postgres/roles#changing-your-project-password).

## Check your own access

A team member can see their own rule with the Management API. Use a [personal access token](https://supabase.com/docs/guides/platform/personal-access-tokens). A scoped token needs **Database token access** with **Read only** access:

```bash
curl "https://api.supabase.com/v1/projects/$PROJECT_REF/database/jit" \
  -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN"
```

The response lists each role you can assume along with its expiry, allowed networks, and branch setting. A `406` response means you don't have a rule on the project. For the full response, see [Get your member access rule](https://supabase.com/docs/reference/api/v1-get-jit-access).

## Next steps

After you add or change a rule, refer to these docs:

- [Connect with database token access](https://supabase.com/docs/guides/platform/database-token-access#connect-with-database-token-access): build the connection string with the token as the password, directly or through the shared pooler.
- [Troubleshooting](https://supabase.com/docs/guides/platform/database-token-access#troubleshooting): fix a token connection the database rejects.
- [End access that's already in use](https://supabase.com/docs/guides/platform/database-token-access#end-access-thats-already-in-use): close open connections after you remove or restrict a rule.
