Skip to content
NordBaseDocs

Search the docs

Find a page or a section of the NordBase docs

Access

Credentials

How a Credential connects software to one Database, and how presets, Grants, row filters, expiry, IP and Region limits and rotation keep it to least privilege.

NordBase has two kinds of secret. Keep them apart: each one can do only its own job.

CredentialAccess token
What it doesConnects software to one DatabaseManages your Account through the API or the MCP server
Used byYour app, a migration tool, a scriptYou, your CI, an AI agent
Lives inNORDBASE_URL or a key fileAn Authorization: Bearer header
What it may doIts Permission setIts scopes
Secret prefixnbs_nbt_
Id prefixcr_at_
Can connect to a DatabaseYesNever

Both secrets are 40 letters and digits after the prefix, so secret scanners can spot a leaked one. Both are shown once, when you create them.

This page is about Credentials. For Access tokens and their scopes, see the API reference.

What a Credential is

A Credential is a PostgreSQL role with a login, created for one Database. Its id, such as cr_4k2m8p0d9a, is the username in the Connection URL, and its secret, nbs_…, is the password.

NordBase stores only a SCRAM-SHA-256 verifier of the secret, never the secret itself. That is why the secret is shown once and cannot be shown again. If it is lost, rotate the Credential.

No Credential is ever a PostgreSQL superuser.

Permission sets

A Permission set is a preset plus, optionally, a list of Grants.

Document Databases are simpler for now: a Document Credential is either read_only or read_write (which can also create and drop collections and indexes), and takes no Grants. Finer Document permissions arrive when the engine supports them.

PresetWhat it allows
read_onlyRead every table or collection
read_writeRead and change rows or documents
schemaread_write, plus create, alter and drop tables, indexes and collections. Migrations have to own the tables they change, so this preset can also change any table's permissions and row-level security: treat it like owner and give it only to the migration runner
ownerThe Database's owner: every schema and table, their permissions and row-level security. For people, not for apps

Permissions are enforced by PostgreSQL itself: NordBase turns your Permission set into GRANT and REVOKE statements, and row filters into row-level security, inside the Database. No statement shape can get around them, because PostgreSQL checks every object a statement touches.

Grants

A Grant is one allow or deny rule on one object:

FieldValues
effectallow or deny
objectSQL: a schema, and optionally a table. Document: a namespace, and optionally a collection
actionsAny of read, insert, update, delete
row_filterSQL Databases, allow Grants only: a row-level security condition

Grants are applied after the preset, in order. A deny always beats an allow, whatever the order. A Permission set can hold up to 500 Grants.

An app Credential that can change orders but never touch payouts:

json
{
  "preset": "read_write",
  "grants": [
    { "effect": "deny", "object": { "schema": "public", "table": "payouts" }, "actions": ["read", "insert", "update", "delete"] }
  ]
}

A Document Credential that can add and change orders but never delete them:

json
{
  "preset": "read_write",
  "grants": [
    { "effect": "deny", "object": { "namespace": "shop", "collection": "orders" }, "actions": ["delete"] }
  ]
}

Because a deny always wins, a deny on a whole schema or Namespace cannot be narrowed by an allow on one table or collection inside it. Deny the specific objects instead.

Row filters

On SQL Databases an allow Grant can carry a row filter, a condition PostgreSQL applies to every row through row-level security:

json
{
  "effect": "allow",
  "object": { "schema": "public", "table": "invoices" },
  "actions": ["read"],
  "row_filter": "tenant_id = 7"
}

A row filter limits the rows that Grant allows. It is validated by PostgreSQL and never concatenated into other SQL. It can be up to 2,000 characters.

Expiry, IPs and Regions

Some limits PostgreSQL cannot check; the Router checks them before a connection reaches your Database:

SettingWhat it does
expires_atAfter this time, the Credential stops working. null means it does not expire
allowed_regionsRegion codes whose Endpoints this Credential may use, such as ["fi-hel"]

Changes to a Credential's name, Permission set, expiry or Regions take effect within 5 seconds.

Allowing a Credential only from some IP addresses is not available yet: the Router cannot check a client's address per Credential today, and NordBase does not offer a control it cannot enforce. Keep the secret in your servers' environment and rotate it when someone leaves.

Creating a Credential

In the console: open the Database, go to Credentials, choose New credential. Through the API:

bash
curl -X POST "https://api.nordbase.<base>/v1/databases/db-k7q2x9m4p1/credentials" \
  -H "Authorization: Bearer $NORDBASE_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 4c7d1a9e-2b6f-4e83-9a05-6d1b8c3f7e24" \
  -d '{
    "name": "web-app",
    "permissions": {
      "preset": "read_write",
      "grants": [
        { "effect": "deny", "object": { "schema": "public", "table": "payouts" }, "actions": ["read", "insert", "update", "delete"] }
      ]
    },
    "allowed_regions": ["fi-hel", "de-fsn"]
  }'

The answer holds the secret, the Connection URL and the key file, once. It is sent with Cache-Control: no-store. Put the URL straight into your secret store or .env.

Rotation

Rotating issues a new secret while the old one keeps working for an overlap, so you can deploy the new secret without downtime:

bash
curl -X POST "https://api.nordbase.<base>/v1/databases/db-k7q2x9m4p1/credentials/cr_4k2m8p0d9a/rotate" \
  -H "Authorization: Bearer $NORDBASE_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "overlap_minutes": 60 }'
  1. Rotate. The answer holds the new secret and Connection URL, once.
  2. Deploy the new NORDBASE_URL everywhere.
  3. When the overlap ends, the old secret stops working.

The overlap is 60 minutes by default and can be 0 to 10,080 minutes (7 days). The Credential id stays the same, so its Permission set and settings carry over.

Revoking

Revoking a Credential takes effect immediately: new connections are refused and open connections using it are closed.

bash
curl -X DELETE "https://api.nordbase.<base>/v1/databases/db-k7q2x9m4p1/credentials/cr_4k2m8p0d9a" \
  -H "Authorization: Bearer $NORDBASE_ACCESS_TOKEN"

Which Credential am I using

Every SQL Database has a nordbase.whoami() function that any Credential can call. It returns the Credential id, its preset and its expiry:

ts
const [me] = await db.sql`select nordbase.whoami() as me`

Least privilege

  • One Credential per app and environment. web-app in production, another for staging. Revoking one never breaks the other.
  • Apps get read_write, with denies on tables they never need.
  • Migrations get schema, used only by your deploy step, never by the running app.
  • Reporting and analytics get read_only.
  • owner only for people, never for an app.
  • Temporary access expires. A Credential for a contractor, a one-off import or an AI agent gets an expires_at.
  • AI agents get the least of all. A read_only Credential with an expiry, and an Access token without sql:write. See MCP server.
  • Never log the Connection URL. The NordBase libraries print the secret as nbs_****; do the same in your own logs.