Skip to content

Member access rules

A member access rule lets a team member connect to your project database as a Postgres role with their own access token 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.

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 and preview branches.

Prerequisites

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.

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.

In the dashboard

  1. Go to 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.
  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 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:

    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:

    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 to this request:

    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. 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:

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:

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. 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.

Check your own access

A team member can see their own rule with the Management API. Use a personal access token. A scoped token needs Database token access with Read only access:

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.

Next steps

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