Skip to the page

Learn · Schema & access

Access & sign-in

Sign-in and keys identify the caller. The access policies in your schema decide which rows that caller can read or write.

Caller identity#

Every data-plane request carries either a user session token (from your project’s /sign-in routes) or a project service key (ndb_…). Before running any query, Napalm verifies the token and binds the caller’s identity to ext::auth::ClientTokenIdentity.

dbschema/default.gel
global caller := global ext::auth::ClientTokenIdentity;

For a signed-in person, global caller resolves to that person’s ext::auth::Identity record. For a service key, global caller resolves to the empty set ({}). Callers can never supply or override ClientTokenIdentity or any other global in a request body. All globals come from the verified credential and your project’s endpoint settings. See Sessions and keys.

Signed-in person

Verified /sign-in sessions bind the caller’s ext::auth::Identity record directly to global caller.

Backend service key

Branch-scoped ndb_… keys evaluate with global caller := {} and inject configured serviceGlobals.

Delegated AI agent

OAuth 2.1 consent tokens bind the granting user’s Identity alongside ClientTokenAgentGrant limits.

Default-deny access policies#

Any stored object type without an access policy is closed over the Project API. Adding allow policies opens access to matching rows, and multiple allow rules combine by OR. Any matching deny rule overrides every allow rule, and removing a type’s last policy closes the type immediately.

Closed-by-default policy lock

Stored object types without an access policy stay sealed over the Project API until an explicit allow rule matches.

Allow and deny evaluation

Multiple allow rules combine by OR while any matching deny rule overrides every allow, filtering reads or aborting disallowed writes.

Statement kindWhen an access policy denies access
select (queries, search, live streams, CDC)Unreadable rows are silently omitted from the result set
update or delete target selectionOnly rows permitted by update read or delete policies are targeted
insert or update writing disallowed stateThe transaction aborts with 400 query_failed (AccessPolicyError)

Access rule syntax#

Access policies walk the object graph in the same EdgeQL language as queries. Policies can traverse links and backlinks, read globals, check datetime_of_statement() and call non-volatile schema functions. In the notes schema, each note’s author gets full read and write control while collaborators listed in shared_with get read access.

dbschema/default.gel
type Note {  required title: str;  body: str;  pinned: bool;  required author: Person;  multi shared_with: Person;   access policy author_has_full_access    allow all    using (.author.identity ?= global caller);  access policy shared_can_read    allow select    using ((global caller in .shared_with.identity) ?? false);}
Declared on the type
Policies sit right beside properties and links in your schema.
Enforced across links
Traversing a link automatically applies the target type’s policies.
Filtered in SQL
PostgreSQL excludes unreadable rows during the query.
allow select
Controls which rows the caller can read and sets the visibility baseline for updates and deletes.
allow insert
Checks each newly inserted row before commit. A false result aborts the transaction.
allow update read
Controls which existing rows an update statement may target.
allow update write
Checks the post-update row. The transaction aborts if the new field values violate the rule.
allow delete
Controls which rows a delete statement may remove.
allow all
Grants select, insert, update read, update write and delete at once.

For deny rules, when preconditions and custom errmessage strings, see the access policies reference.

Policies read your links inside the transaction. Sharing or revoking access is an ordinary database write and needs no separate permission cache.

share.edgeql
update Notefilter .id = <uuid>$noteset { shared_with += (select Person filter .id = <uuid>$person) }
unshare.edgeql
update Notefilter .id = <uuid>$noteset { shared_with -= (select Person filter .id = <uuid>$person) }

Application queries need no per-endpoint WHERE filters. Every user runs the same query and receives only permitted rows.

my-notes.edgeql
select Note {  title,  author: { name },  shared := exists .shared_with,}order by .title

Built-in user sign-in#

Every project hosts a built-in authentication service at /sign-in. Enable the sign-in methods your app needs in the console or Control API without integrating an external auth vendor.

Built-in /sign-in and PKCE S256 exchange

Passwords, magic-link codes, WebAuthn passkeys and OAuth/OIDC redirects verify at /sign-in and mint sessions bound to ext::auth::Identity.

Email and password
Password sign-up and sign-in, optional email verification and password resets.
Magic links
A six-digit code or a link sent through your configured SMTP server or email webhook.
WebAuthn passkeys
Hardware and platform passkey registration and sign-in scoped to your allowed browser origins.
OAuth providers
Google, GitHub, Microsoft, Discord and Slack using your own OAuth client ID and secret.
OpenID Connect
Any OpenID Connect issuer configured through a discovery URL and client credentials.

A user stays signed in from 1 hour up to 365 days (14 days by default). The client renews the session’s hour-long token, and signing out ends the session at the project. The engine checks the session and the caller’s ext::auth::Identity on every request, so deleting an identity ends every session for that user immediately.

Configure your app’s display name, light and dark logos and accent color once in sign-in settings. Auth emails, OAuth consent screens and your generated project CLI apply those brand settings automatically, and your frontend can read them from GET /sign-in.

PKCE exchange flow#

Clients start sign-in with an OAuth 2.0 PKCE S256 challenge, complete the user’s factor or OAuth redirect and exchange the authorization code at GET /sign-in/token for a session. A session is an hour-long bearer token plus a refresh token. Upstream provider tokens stay inside the database and never reach the browser. See Sign-in for full route details.

Session and service-key globals#

To distinguish backend service keys from end-user sessions inside your schema, configure forced globals on your project endpoint (userGlobals for user sessions and serviceGlobals for service keys). Napalm injects the configured globals automatically on every request.

dbschema/default.gel
using extension napalm;using future simple_scoping; module default {  global role: str;   type AuditEntry {    required message: str;     access policy service_can_record      allow insert, select      using (global role ?= 'service');  }}

Setting default::role to "service" in serviceGlobals ensures only backend service keys can insert or read AuditEntry records. Built-in system modules (ext, sys, cfg and schema) cannot be overridden via endpoint globals.

Read-only enforcement#

Individual service keys (--read-only), OAuth 2.1 agent grants or an entire project endpoint can be marked read-only. When a request is read-only, Napalm rejects any statement containing insert, update, delete or write-capable actions before execution.

Access audits and explanations#

Reach and policy commands verify which rows a service key or signed-up user can access without ever exposing field values.

Value-blind policy traces with explain-access

napalm explain-access evaluates every allow and deny rule on an object UUID and pinpoints the first empty link hop without exposing field values.

Key reach
Counts the rows per type a service key can select, update and delete, and reports whether inserts are allowed plus total readable ext::files::File bytes. Run napalm keys reach <project> <key> (or --new before creating a key), click Reach in the console or invoke the MCP describe_reach tool. Reach checks sample huge tables so responses return quickly.
User reach
Counts reachable rows per type as a specific user’s session through napalm people reach <project> <email-or-id> or the console’s People tab. Requires manage scope and writes an immutable entry to organization activity.
Explain access
Evaluates every access policy on one object UUID as a service key, a specific user or the default service context. Reports matched rules, failed rules and the first empty link step without exposing field values. Run napalm explain-access <project> <object-id> [--as <user>]. Add --new to test access for a service key before creating it (--new accepts --read-only and --branch, matching napalm keys reach --new).
Dry-run mutations
Runs a write under the caller’s policies, returns the exact before and after states and rolls back cleanly. Pass "is_dry_run": true to POST /query (or --dry-run in the CLI).

For step-by-step diagnosis of unexpected [] results, update write policy errors and index profiling, see Troubleshooting and auditing.

Type a word or two to search every docs page.