Token VaultDocs
Policies and Activity

Policies

Write ABAC rules (time window, rate limit, lifetime cap, IP, country, channel), attach them to credentials, labels, agents, keys or MCP servers, and read the denials.

A policy is a named list of rules. Token Vault runs every rule of every attached policy before it hands out a credential ticket or forwards an MCP tool call. If one rule fails, the request is refused and the refusal shows up in Activity.

Policies decide when, where and how often. They never grant access. Access comes from grants.

Loading diagram...

AND semantics

Rules inside a policy are AND-ed. Policies attached to the same entity are AND-ed. A request that touches several entities (agent + credential + label) must pass the policies of all of them. A label carried by both sides is evaluated once.

Rules

Open Policies > New policy (/policies/new). The wizard has four steps: Basics (name), Rules, Attach to (optional, you can attach later) and Review. Account cap: 20 policies.

Rule in the UItypeWhat it checks
Who can readaccess_channelWhich channel is asking: web app, tvault CLI, agents, API keys, MCP tools
Time windowtime_windowDays of week and hours in a timezone
Rate limitrate_limitN requests per window (denies with 429)
Lifetime capmax_usageTotal requests, ever
IP allowlistip_allowlistCaller IP inside one of the CIDRs
Countriesgeo_restrictCaller country allowed or blocked

Each rule is stored as { "type": ..., "config": {...} }.

Templates

The wizard has a Start from a template menu.

TemplateRules
Business Hours OnlyMon to Fri, 09:00 to 17:00 UTC
CI/CD Pipeline GuardGitHub Actions IP ranges, 100 requests per hour
Agent Leash - Strict10 per minute, 1000 lifetime, US/GB/DE only
Zero Trust - Geo + IPUS/GB, two CIDRs, Mon to Fri 08:00 to 20:00 New York
Weekend LockoutMon to Fri only, 200 per hour
Block CLI Readsaccess_channel deny cli
Agents Onlyaccess_channel allow agents and MCP tools
No Browser Revealaccess_channel deny web
Human-in-the-LoopListed but disabled: "Needs a push channel - manual approval denies every request"

Attach a policy

A policy does nothing until it is attached. Attach in the wizard, on the policy page (Attached tab), or from the CLI.

Attach toentityTypeentityIdEffect
Credentialtokencredential nameEvery read and tool call on it
Labellabelthe labelEvery credential, agent and key carrying it, now and later. See Labels
Agentagentagent idEverything that agent does
API keyapi_keykey idEverything that key does
MCP servermcp_server{service}:{server}Tool calls to that one MCP server

Pre-existing proxy and token_group attachments still display and still apply. You cannot create new ones. Convert copies each proxy attachment to the new MCP server (Old MCP connection URLs).

tvault policy attach 3f9c2a71e0b84d5f9a6c1d2e7b8f40a1 --credential github
tvault policy attach 3f9c2a71e0b84d5f9a6c1d2e7b8f40a1 --label ai --agent ci-bot --key deploy
tvault policy detach 3f9c2a71e0b84d5f9a6c1d2e7b8f40a1 --label ai      # needs policies:write

policy attach takes --label, --credential, --agent and --key (repeatable). There is no --server flag (for an MCP server) and no CLI command to create a policy: use the console or POST /api/policies. Requires tvault 0.14.0 or later.

The policy page (/policies/[id]) has three tabs: Rules, Attached (n) and Denials (recent refusals from this policy).

Worked example: rate-limit one MCP server

Goal: the linear MCP server on your linear credential may be called at most 5 times per 5 minutes, whoever calls it.

Create the policy with one rule:

{
  "name": "linear-5-per-5min",
  "rules": [
    { "type": "rate_limit", "config": { "maxRequests": 5, "windowSeconds": 300 } }
  ]
}

Attach it to the MCP server (entity id is {service}:{server}):

curl -X POST https://api.tokenvault.uk/api/policies/$POLICY_ID/attach \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"attachments":[{"entityType":"mcp_server","entityId":"linear:linear"}]}'

The sixth call inside five minutes gets:

HTTP/1.1 429 Too Many Requests
Retry-After: 212
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "id": 7,
  "error": {
    "code": -32029,
    "message": "Rate limit exceeded by policy.",
    "data": { "code": "POLICY_DENIED", "retryAfter": 212 }
  }
}

On this path a rate_limit denial is a JSON-RPC error (-32029, HTTP 429). Every other rule type on an MCP server call returns the plain 403 body below.

What a denial looks like

REST value fetch (GET /api/agents/credentials), time window, agent caller:

HTTP/1.1 403 Forbidden

{
  "error": "Access denied by policy",
  "policy": "office-hours",
  "rule": "time_window",
  "reason": "Access denied: current time 22:15 Europe/London is outside allowed window 08:00–19:00",
  "code": "POLICY_DENIED",
  "retryAfter": 35100
}

The same denial for a human caller (web session, or your own tvault login) adds an explanation. Agents and keys never get these fields, because they could route around the policy.

{
  "policyId": "3f9c2a71e0b84d5f9a6c1d2e7b8f40a1",
  "appliedVia": { "type": "label", "id": "ai", "carriedBy": ["agent"] },
  "ruleSettings": {
    "days": [1, 2, 3, 4, 5], "start": "08:00", "end": "19:00", "timezone": "Europe/London"
  }
}

ruleSettings per rule: rate_limit {limit, windowSeconds}, max_usage {max, used}, geo_restrict {mode, countryCodes}, ip_allowlist {cidrCount}, access_channel {mode, channels}.

The web app and Activity drawer turn this into plain words ("Outside allowed hours: Mon to Fri 08:00 to 19:00 Europe/London (policy office-hours, on label ai)") with a fix button. The CLI prints denied: and hint: lines. See Activity and Troubleshooting.

Policy refusals are not the only refusals. A missing grant, an expired grant or an MCP-only grant is refused earlier, with its own code (NO_GRANT, GRANT_EXPIRED, GRANT_TOOLS_ONLY). Those are not policy denials.

On this page