mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The database access preview still uses “Temporary access” across its settings and member rules. ## Solution Use “Database token access” for the feature and “Member access” for member rules. Update the preview, settings, dialogs, feedback, member status messages and docs together. Move the guide to `/guides/platform/token-access`, permanently redirect the old URL, and preserve existing section anchors. ## Review instructions 1. Open [the Studio preview](https://studio-staging-git-dnywh-database-token-access-naming-supabase.vercel.app), then Feature previews and find **Database token access**. Enable the preview for a supported project, then open [Database Settings](https://studio-staging-git-dnywh-database-token-access-naming-supabase.vercel.app/project/_/database/settings). 2. Check the **Database token access** heading, **Allow token access** switch and **Member access** table. Open **Add rule** and an existing rule to check the sheet titles. Open a rule’s delete confirmation and cancel it. 3. With an assigned role, check the access status above the member table. As a member without management permission, check the access notice uses the same feature name. 4. Open the [database token access guide in the docs preview](https://docs-git-dnywh-database-token-access-naming-supabase.vercel.app/docs/guides/platform/token-access). Check the guide and navigation use the new name, the dashboard instructions match Studio, and the existing section links from the member guide still work. Open `/docs/guides/platform/temporary-access` and its `.md` variant to check they permanently redirect to the new URLs. | Before | After | | --- | --- | | <img width="726" height="367" alt="CleanShot 2026-11-30 at 16 06 00" src="https://github.com/user-attachments/assets/be351f0c-d578-4289-8785-5c4e69a254a7" /> | <img width="729" height="374" alt="CleanShot 2026-11-30 at 16 05 38" src="https://github.com/user-attachments/assets/f02b470d-ef1a-4b6c-bdbb-20fe10b847c6" /> |
107 lines
5.0 KiB
Plaintext
107 lines
5.0 KiB
Plaintext
---
|
|
id: 'team-database-access'
|
|
title: 'Map team members to Postgres roles'
|
|
description: 'Give team members database access through their own access tokens instead of a shared password.'
|
|
---
|
|
|
|
Let a team member connect to your project database as a [Postgres role](/docs/guides/database/postgres/roles), using their own [access token](/docs/guides/platform/personal-access-tokens) instead of a shared password. This follows security best practices, allowing each person to only access what they need for as long as they need it.
|
|
|
|
A member access rule maps a team member to one or more Postgres roles they can assume. It creates no new role or user in the database, and the assumed role's permissions apply. The role's own password keeps working, so long-lived service connections don't change. A team member who knows the role's password can connect with it after you remove their mapping. To end that access, change the role's password. For the `postgres` role, see [Changing your project password](/docs/guides/database/postgres/roles#changing-your-project-password).
|
|
|
|
Use this guide when:
|
|
|
|
- Your team shares the `postgres` password, and you want each person to connect with their own credentials.
|
|
- Someone needs database access that [ends on a date you set](#restrict-a-team-members-access).
|
|
- You want to [remove one person's access](#remove-a-team-members-access) without changing a password everyone else uses.
|
|
|
|
For details on how database token access works, see [Database token access](/docs/guides/platform/token-access).
|
|
|
|
## Prerequisites
|
|
|
|
Before you authorize a team member, set up the following:
|
|
|
|
- [Enable database token access](/docs/guides/platform/token-access#manage-temporary-access-via-the-management-api) on the project.
|
|
- Create a personal access token in the [Supabase Dashboard](/dashboard/account/tokens) to call the Management API. If you scope the token, give it **Organization members** with **Read only** access and **Database JIT** with **Read and write** access.
|
|
- Confirm that the team member has access to the project.
|
|
|
|
## Authorize a team member
|
|
|
|
To authorize a team member:
|
|
|
|
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 mappings, so list every role they need. 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="the-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
|
|
```
|
|
|
|
This example maps the `postgres` role, which has broad privileges on your database. If the team member needs less, map a narrower role.
|
|
|
|
The team member can now connect as the `postgres` role, with their access token as the password. For connection strings, see [Connect with database token access](/docs/guides/platform/token-access#using-temporary-access).
|
|
|
|
## Restrict a team member's access
|
|
|
|
Each role in the mapping takes two optional restrictions:
|
|
|
|
- `expires_at`: a Unix timestamp in seconds. After it passes, the database rejects the connection, even if the access token is still valid.
|
|
- `allowed_networks`: the CIDR ranges the team member can connect from. Put IPv4 ranges in `allowed_cidrs` and IPv6 ranges in `allowed_cidrs_v6`.
|
|
|
|
This example uses the variables from [Authorize a team member](#authorize-a-team-member). 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
|
|
|
|
To remove all of a team member's role mappings, 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"
|
|
```
|