docs/api-keys.md in oak/oak
API keys and tokens
Tokens for scripts, deploy machines and agents, and how the CLI picks its credential.
The CLI, the HTTP API, CI jobs and agents all sign in with a bearer token:
Authorization: Bearer oak_...
There are three kinds of token.
| Token | Comes from | Lifetime | Use it for |
|---|---|---|---|
| Login session | oak login | 90 days | You, at your own terminal. |
| Personal API key | You create it | Until revoked | Scripts and tools acting as you. |
| Agent key | An org admin creates it for one of the organization's agents | Until revoked | Bots, deploy machines, and agents with their own identity. |
Personal API keys
Create one under Settings → API keys on oak.space, or over the API:
curl -X POST https://oak.space/api/api-keys \
-H "Authorization: Bearer $OAK_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "release script", "scope": "read", "repo": "acme/web"}'
| Field | Value |
|---|---|
name | 1–100 characters, for your own reference. |
scope | full (default) or read, which can only make read requests. |
repo | Optional owner/name. The key then works only for that one repo. |
expires_in | Optional lifetime in seconds, from one minute to 366 days. Omitted, the key lasts until you revoke it. |
org, groups | Make it a key for an agent. |
The full key is shown once, when it's created; after that only its first characters are. List your keys with GET /api/api-keys and revoke one with DELETE /api/api-keys/{id}.
A personal key acts as you. A read-only or single-repository key can do less, never more.
Keys for agents
Anything holding a personal key has all your access. A key for an agent gives away less:
curl -X POST https://oak.space/api/api-keys \
-H "Authorization: Bearer $OAK_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "web agent", "org": "acme", "groups": ["web"], "expires_in": 28800}'
Or open For an agent under Settings → API keys.
| Field | Value |
|---|---|
org | The organization the key works in. It can't reach any other, or your account. |
groups | Groups of that organization you are on. Leave it out for no group. An organization owner or admin can name any group. |
Inside a repository, path rules treat the key as a member of those groups and the groups above them, and as nobody else:
- It isn't you. A boundary that lists
@youdoesn't reach it, and it never has an owner's or admin's full access, whoever made it. - It follows your membership. Leave a group and your keys lose it on their next request.
- It does an agent's work: clone, pull, push branches, describe and close them, move the marks its groups own and write their logs. Merging, approving, and anything under settings take your own credential.
- If its groups can't read every directory, it's a restricted reader like any other. It gets a checkout without those directories and doesn't see branches that touch them.
GET /api/whoami with such a key answers with a grant block (org, groups), so an agent can tell what it is.
Two things to know:
- Groups take access away only where a path rule lists readers or writers. A key on
webstill reads every directory that's open to all of the repository's readers. - A key protects you only where the agent can't reach your login.
oak loginstores a session in~/.config/oak/credentials, and a session can make new keys. Give an agent this key in a container, on a remote machine, or in a sandbox without your home directory.
Organization agents
An organization agent is an account an organization owns for a program: a deploy machine, a build machine, a coding agent that runs on its own. Its actions show under its own name in the audit log.
It reaches what its groups reach, like a person, and never borrows the access of whoever created it or issued its keys. A new agent is on no group, so it reaches only public repositories.
Organization owners and admins create agents and issue their keys under the organization's Settings → Agents, or over the API. Whoever manages a group adds agents to it from a repository's Settings → Access. An agent made there (or created with "repo": "<name>") works only in that repository, whatever its groups reach, and is deleted with it.
# Create the agent
curl -X POST https://oak.space/api/orgs/acme/agents \
-H "Authorization: Bearer $OAK_TOKEN" -H "Content-Type: application/json" \
-d '{"name": "nightly-agent", "display_name": "Nightly refactor agent"}'
# Put it on the web group, so it reaches what web reaches
curl -X PUT https://oak.space/api/orgs/acme/groups/web/agents/nightly-agent \
-H "Authorization: Bearer $OAK_TOKEN"
# Give it a key that can push branches
curl -X POST https://oak.space/api/orgs/acme/agents/nightly-agent/keys \
-H "Authorization: Bearer $OAK_TOKEN" -H "Content-Type: application/json" \
-d '{"name": "prod", "scopes": "read,write"}'
| Scope | Allows |
|---|---|
read | Every read request an agent makes: clone, pull, list, view. |
write | Push branches, describe, close, reopen and rename them, move the marks its groups own and write their logs, in repos its groups can write. |
release | Move marks (still only the ones the key's groups own), without write. No other scope implies it. |
Scopes are required. Merging, approving, creating repositories and settings take a person's credential, so an agent's key can't carry merge, review or admin. A key works only inside its organization: the repositories its groups reach (/api/{org}/{repo}/...), /api/repos, /api/whoami and /api/capabilities. A repository its groups weren't given answers 404, and anything else out of reach answers 403 saying why. GET /api/whoami answers with a grant block listing its groups.
Organization agents and their keys can only be managed from a signed-in session, never with an API key, so a key can't mint itself a stronger one.
Disable an agent (PATCH /api/orgs/{slug}/agents/{name} with {"disabled": true}) to stop all its keys at once, or delete it. Revoke one key with DELETE …/agents/{name}/keys/{key_id}. The older /api/orgs/{slug}/service-accounts paths still work.
Using a key with the CLI
export OAK_API_KEY=oak_...
oak clone acme/web
oak auth status # confirms which credential is in use and who it resolves to
The CLI picks its credential in this order:
OAK_API_KEY, if set.- A key stored in the checkout itself (
oak clonesaves one, bound to the server it came from). - Your
oak loginsession for that server, from~/.config/oak/credentials.
If a push or pull says a repository you know exists isn't found, a stale key from step 2 is the usual cause; oak auth status shows which source is in use.
Using a key with the API
curl https://oak.space/api/repos -H "Authorization: Bearer $OAK_API_KEY"
See api.