# Roles, tokens and dual control

Aegis Core decides who may do what on every route, and asks a second person for the operations that cannot be undone.

## Roles

| Role | May |
| --- | --- |
| `auditor` | Read: status, the catalogue, keys and public keys, the tenant's audit records and access policy; verify signatures |
| `operator` | Everything an auditor may, and use keys: sign, encrypt, decrypt, decapsulate; the stateless tools |
| `admin` | Everything, and manage keys, tokens and the tenant's access policy; in the system's namespace, also unseal, seal, back up, switch algorithms and manage tenants |
| `emergency` | Nothing but `GET /v1/sys/whoami`, until its holder starts a break-glass session |
| `monitor` | Only the metrics and the detailed readiness check, for monitoring systems |

Every route has one row in an authorisation matrix with its operation (`key.sign`, `key.export`…), the lowest role and its reach; a route with no row is refused. Separation of duties is built in: an auditor never uses a key, an operator never changes access. A tenant's access policy can define **custom roles** narrowed by route patterns and operations, never above their base role.

Aegis Cloud has its own organisation roles (`owner`, `admin`, `developer`, `auditor`), and its API keys carry `developer` or `auditor`.

## Tokens: scoped, expiring, bound

Callers authenticate with a bearer token (`agt_…`). Administrators issue tokens with `POST /v1/sys/tokens`, and can make each one as narrow as the job:

| Field | Narrows the token to |
| --- | --- |
| `role` | A built-in or custom role |
| `scope.paths` | Route patterns, such as `/v1/keys/payments-*/**` |
| `scope.operations` | Operations, such as `key.sign` or `key.*` |
| `scope.keys` | Key names or patterns |
| `expires_in` | A lifetime from 60 seconds to a year |
| `bound` | A client certificate's public key: the token then works only over mutual TLS with that key |

The token is shown once; the daemon stores only its hash. `POST /v1/sys/tokens/{name}/revoke` ends it at once and retires the name for good. `GET /v1/sys/whoami` shows what the current token may do.

For an AI agent, issue a token with the `operator` role (or `auditor` to read), a scope that covers only the task, and an `expires_in` of a few hours, and revoke it when the task ends. The [prompt library](https://docs.qblackbit.com/prompts/index.md) asks for exactly that.

Other ways in: mutual TLS with client certificates from the daemon's own ML-DSA-87 authority, and single sign-on through OpenID Connect with PKCE. SAML is (Planned).

## Dual control

The operations a tenant's access policy lists need approval from other people who may perform them. By default: destroying a key (`key.destroy`), exporting one (`key.export`), changing the access policy (`access.policy`) and importing with looser export rules.

1. The request answers `202` with an approval and does nothing.
2. Other principals approve it: `POST /v1/sys/approvals/{id}/approve`. The requester cannot approve their own request, and neither can a break-glass session.
3. Once approved, the **same request** is sent again, unchanged, with the header `x-aegis-approval: <id>`. It runs once. A changed request answers `409`.

Every step is in the [audit chain](https://docs.qblackbit.com/concepts/audit.md). `GET /v1/sys/approvals` lists what is pending; a requester can withdraw with `POST /v1/sys/approvals/{id}/cancel`, and an approver can refuse with `POST /v1/sys/approvals/{id}/deny`.

## Break-glass

A holder of the `emergency` role can start a session (`POST /v1/sys/break-glass`) with a written reason and a length, and acts as an administrator of their tenant until it ends. The start and the end are recorded with an `ALARM` in the audit chain, and `GET /v1/sys/info` shows the alarm while any session runs.

Next: [Signed updates and rollback](https://docs.qblackbit.com/concepts/updates.md).
