Skip to the page

Learn · Agent access

Agent access & grants

An agent calls Napalm with a service key, a person’s consent or its own grants, and never runs as a database superuser.

Agent credentials#

Every agent authenticates with one of three credentials, and the compiled access rules in dbschema/default.gel govern every row that credential can read or mutate.

The agent holdsYour schema seesAllowed access
A service key (ndb_…)No global caller. The branch’s serviceGlobals plus any globals the key carries.Allowed accessReads and writes rows permitted by your service rules. A --read-only key cannot write. A key made with --allow-query calls only the deployed queries listed. A key made with --call-budget makes at most that many calls in each hour or day.
A person’s consentglobal caller is the person. global ext::napalm::ClientTokenAgentGrant is the person’s grant. The branch’s userGlobals plus any globals the person set at consent.Allowed accessActs within the person’s access until the grant expires, or reads only when the person chose read-only. Calls only the deployed queries the person chose, and only as often as the call budget the person chose, where your consent page offers each choice. Schema rules can read the grant to narrow access further.
A sign-in for the agentglobal caller is the agent’s own ext::auth::Identity.Allowed accessReaches nothing until a row grants that identity permission.

Use a read-only service key for your own coding or reporting agent. Use a person’s consent when one of your users connects an outside assistant such as Claude or ChatGPT. Give an agent a separate sign-in when a user delegates a specific subset of records to an unattended agent.

Grants as rows in your schema#

Access rules walk links across your types, so agent delegation is just one more object type in your schema. In the example below, an AgentGrant opens selected notes to an agent’s identity until an exact deadline.

Owner-bounded delegation
An owner can delegate only records that owner is already permitted to read.
Named records and deadline
Each grant links specific records and an expiration timestamp enforced on every read.
Revoked on delete
Deleting the grant row cuts off the next statement and evicts open live subscriptions.
dbschema/default.gel
using extension auth;using extension napalm;using future simple_scoping; module default {  global caller := global ext::auth::ClientTokenIdentity;   # A statement sent to the API can't name ext::auth's types, so the schema looks an identity up for it.  function identity_by_id(target: uuid) -> optional ext::auth::Identity    using (select ext::auth::Identity filter .id = target);   type Person {    required identity: ext::auth::Identity {      constraint exclusive;    };    required name: str;     access policy self_has_full_access      allow all      using (.identity ?= global caller);  }   type AgentGrant {    required person: Person;    required agent: ext::auth::Identity;    multi notes: Note;    required expires: datetime;     access policy person_has_full_access      allow all      using (.person.identity ?= global caller);    access policy agent_can_see_its_own      allow select      using (.agent ?= global caller);  }   type Note {    required title: str;    required author: Person;     access policy author_has_full_access      allow all      using (.author.identity ?= global caller);    access policy granted_agent_can_read      allow select      using (exists (        select .<notes[is AgentGrant]        filter .agent ?= global caller          and .expires > datetime_of_statement()      ));  }}
give.edgeql
insert AgentGrant {  person := (select Person filter .identity = global caller),  agent := identity_by_id(<uuid>$agent),  notes := (select Note filter .id in array_unpack(<array<uuid>>$notes)),  expires := datetime_of_statement() + <duration>'168 hours',}

Narrow grants#

Grant rows and OAuth consent tokens let you constrain an agent across records, operations, time and callable tools without relying on prompt instructions.

Multi-axis grant narrowing

ext::napalm::ClientTokenAgentGrant and custom AgentGrant rows bound access by linked records, datetime_of_statement() expiry, is_read_only mode and allowed_queries tool allowlists.

Which records
The grant’s notes link lists the delegated records, so the agent never sees the owner’s other notes.
Which operations
The rule above allows select only. To let an agent edit, add a can_edit field to the grant and a separate allow update rule that reads that field.
Until when
The rule compares expires against datetime_of_statement(), so an expired grant stops matching immediately without a cleanup job.
Reading only
Napalm refuses every write from a --read-only key or a read-only consent before the statement runs.
Which tools
Your consent page can read the available agent queries from GET /sign-in/agents/request using the user’s session (excluding queries hidden from agents) and pass the user’s selection as allowedQueries to POST /sign-in/agents/allow. The grant stores the list in allowed_queries and exposes only those tools. Calling any other deployed query returns 403 forbidden, ad-hoc statements return 403 deployed_query_required and no route can widen a grant after consent.
Requested scope
An agent can request narrower permissions up front via the authorize request’s OAuth scope, such as database:read for read-only access or query:listNotes for a single deployed query. Approving users can only narrow those requested scopes: the resulting grant never includes an unrequested query or write access when the agent asked for read-only, and the token response’s scope reports the granted permissions. OAuth scopes never set schema globals, so only the user on your consent page can pick a tenant.
How often
Your consent page can pass callBudget (such as {"calls": 1000, "period": "hour"}) to cap the agent’s calls per UTC hour or day, stored on the grant as call_budget and call_budget_period. Calls past the budget fail with JSON-RPC error -32029 (call_budget_reached) and report when the next period starts. Both the console’s Agent grants section and napalm grants ls show current usage against the budget. See Limits.
Reading only in the schema
To enforce read-only in your rules as well, add deny insert, update, delete using ((global ext::napalm::ClientTokenAgentGrant).is_read_only ?= true).

Grants held to one tenant#

When a user belongs to several organizations in your app, setting a grant global at consent scopes the agent to a single tenant. The grant stores that global for its lifetime and overlays the branch’s userGlobals while running each call as the user. Service-key globals pin a backend key to one tenant the same way. See Service keys for one organization’s servers.

  1. Add a deny rule that reads the global

    The allow rule admits members of the ticket’s organization as usual. When a grant sets current_org, the deny rule blocks tickets from every other organization. Without current_org, the deny rule does nothing and the user sees tickets across all of their organizations. Naming an organization the user does not belong to returns zero tickets because the allow rule never matched.

    dbschema/default.gel
    # The person's pick at consent: one organization for the agentglobal current_org: str; type Ticket {  required org: Organization;  required title: str;   # A member reads the organization's tickets.  access policy member_can_read    allow select    using ((global caller in .org.members.identity) ?? false);   # An agent whose grant holds current_org is kept to that organization.  access policy chosen_org    deny all    using ((<str>.org.id != global current_org) ?? false);}
  2. Let a person set the global

    Allowlist each global a user may set at consent with --grant-global on napalm endpoint or under Grant globals in the console’s Application access settings. Grants accept no globals until allowlisted, and removing a global from the allowlist disables existing grants carrying it until re-authorized.

    Terminal
    # Let a person set current_org when the person lets an agent innapalm endpoint notes --grant-global default::current_org
  3. Send the global from your consent page

    Read the allowlisted grantGlobals from GET /sign-in/agents/request using the user’s session, let the user pick one of their organizations and pass globals in your POST /sign-in/agents/allow payload. Unlisted global names fail with 400 invalid_request, and agents cannot request globals via OAuth scope.

    Consent page
    // On your consent page: the person picked one of the person's organizations.const answer = await fetch('https://notes.napalmdata.com/sign-in/agents/allow', {  method: 'POST',  headers: { Authorization: `Bearer ${session}`, 'Content-Type': 'application/json' },  body: JSON.stringify({    request,    isReadOnly: true,    days: 30,    globals: { 'default::current_org': organization.id },  }),})location.href = (await answer.json()).redirectTo
  4. Count what the global alone opens

    Because a service key has no global caller, running napalm keys reach --new with current_org verifies that the global alone opens zero tickets. In napalm test, assert the same invariant using { key: { globals: { default::current_org: <organization id> } } } with reach: Ticket and expect: { count: 0 }. Test an agent’s grant covers testing the combined user and grant rule.

    Run napalm grants reach to count a stored grant’s live reach as its approving user with the grant’s globals and read-only mode applied, confirming that a grant scoped to Acme sees only Acme’s tickets.

    Terminal
    # A key holds the global and no person: the count is 0 ticketsnapalm keys reach notes --new --read-only --global default::current_org=<organization id> # A person's grant that holds the global: that organization's tickets alonenapalm grants reach notes <grant id>

Prompt injection#

An agent connected over MCP or A2A reaches your project’s data. The schema stays hidden unless you enable --share-schema, and on connection the server instructs the client that database rows are data rather than instructions.

Compiled rules against prompt injection

Even when a readable document contains adversarial instructions telling an agent to fetch another tenant’s records, compiled PostgreSQL access policies block unauthorized rows.

Compiled access policies enforce the real boundary. A row containing “fetch everyone’s notes” never widens global caller or the rows that caller may read. Set --passthrough none to reject ad-hoc statements and restrict the agent strictly to deployed queries and actions. See Tools for agents.

Audit log and change log#

Declare a schema trigger to write an immutable audit entry inside the same transaction as every mutation, so no write from any caller commits without a provenance row.

Transactional provenance and instant revocation

Schema triggers log global caller inside each write commit while napalm changes stamps http, mcp and a2a sources, and deleting ext::napalm::AgentGrant or running napalm keys revoke severs access immediately.

dbschema/default.gel
using extension auth;using extension napalm;using future simple_scoping; module default {  global caller := global ext::auth::ClientTokenIdentity;   type Note {    required title: str;    owner: ext::auth::Identity;     access policy owner_has_full_access      allow all      using (.owner ?= global caller);     trigger record_change after insert, update for each do (      insert Change {        note := __new__,        changed_by := global caller,        title := __new__.title,      }    );  }   type Change {    required note: Note;    changed_by: ext::auth::Identity;    required title: str;    required at: datetime {      default := datetime_of_statement();    };     access policy note_owner_can_read      allow select      using (.note.owner ?= global caller);    access policy callers_record_as_themselves      allow insert      using (.changed_by ?= global caller);  }}

The branch’s change log also records each commit’s caller kind and protocol source (http, mcp or a2a). Inspect recent commits with napalm changes. Watching and stopping an agent covers live inspection and kill switches.

Revocation#

Deleting a grant cuts off the agent’s access by its very next statement and evicts restricted rows from open live streams. Deleting either a custom grant row or a built-in ext::napalm::AgentGrant row from OAuth consent takes effect immediately.

revoke.edgeql
delete AgentGrantfilter .agent.id = <uuid>$agent

Because API statements cannot reference ext::napalm::AgentGrant directly unless enabled, expose a schema alias when users manage OAuth grants inside your app, as Watching and stopping an agent shows. Revoke a service key with napalm keys revoke, or halt all external traffic immediately with napalm endpoint --disable.

Project managers can inspect and revoke grants across every branch in the console’s project overview (under Agent grants), via napalm grants ls and napalm grants revoke, or at GET /projects/{id}/agent-grants and POST /projects/{id}/agent-grants/{grant}/revoke. Each entry shows the agent, approving user, write mode, allowed queries, globals, expiry and last call. Once revoked, the agent’s next call fails with 401 invalid_token until the user re-approves access on your consent page. Managers can also audit a live grant’s exact row reach with Reach in the console, napalm grants reach or GET /projects/{id}/agent-grants/{grant}/reach.

Type a word or two to search every docs page.