Skip to content

Access control

An API token works only with keys in its own container. Inside that container, three settings narrow it further: a key list (which keys it may name), actions (what it may do) and a firewall (which networks it may be used from). Read what each action covers before you rely on actions: two of them overlap. A dashboard session is held to none of this.

  • Tenant: your account. Your first sign-in to the dashboard creates it. Every key, API token, container and firewall belongs to one tenant, and no credential reaches another tenant's.
  • Container: a group of keys, API tokens and firewalls inside a tenant. Every tenant starts with a default container, named Default, which can be renamed but not deleted. Each key, API token and firewall is created in one container and stays there; nothing moves between containers. To an API token, a key in another container does not exist: it gets the same answer as for an id that was never issued.
  • API token: the bearer credential that runs the cryptographic operations (see authentication). It lives in the container it was issued in. Only a dashboard session can issue, restrict or revoke an API token, so an API token cannot change its own settings or issue another.
  • Key list (key_ids): either every key in the API token's container, including keys created later, or a list of 1 to 100 of them. Every key is the default (null in the API). An API token with a list gets 403 key_not_allowed for any key not on it, cannot create keys, and sees only its listed keys in GET /v1/keys and GET /v1/usage. A listed key that is later destroyed stays on the list and allows nothing; the list never widens to the whole container.
  • Actions (allowed_actions): what the API token may do. There are twelve: encrypt, decrypt, wrap, unwrap, rewrap and rotate use or rotate a key, create, rename, delete and restore manage keys, retire retires a key's old versions, and read lists keys and reads a key, its audit log and usage. A new API token has none unless you choose some. An action it was not given is refused with 403 action_not_allowed. create works only for an API token with no key list; the others apply only to the keys its key list allows. The route each action covers, the two that overlap, and which actions older API tokens lack are under what each action covers.
  • Firewall: a named list of 1 to 64 IPv4 or IPv6 addresses and networks, in one container. An API token is held to at most one firewall, from its own container, and one firewall can hold many API tokens. An API token held to a firewall gets 403 ip_not_allowed from any other address; one with no firewall can be used from anywhere. See firewalls.
  • Dashboard session: your sign-in to the dashboard. It sees every container and is held to no key list, actions or firewall. It cannot run encrypt, decrypt, wrap, unwrap or rewrap. See dashboard sessions.

For an API token calling POST /v1/keys/{id}/encrypt, decrypt, wrap, unwrap or rewrap, rypt runs these checks in this order and answers with the first that fails. "Recorded" means a row in the audit log of the key named in the path.

Step Check Refused with Recorded
1 The Authorization header holds a well-formed API token 401 unauthorized No
2 Its prefix names an API token that has not been revoked 401 unauthorized No
3 If the API token is held to a firewall, the request comes from one of its networks 403 ip_not_allowed No
4 The API token is within its rate limit 429 rate_limited No
5 The secret matches 401 unauthorized, or 503 unavailable when rypt cannot start checking it within 5 seconds No
6 The {id} in the path is a UUID 404 not_found No
7 If the API token has a key list, {id} is on it 403 key_not_allowed Yes, see below
8 The key exists in the API token's container and is not destroyed 404 not_found No
9 The API token was given this action for this key 403 action_not_allowed, or 503 unavailable when rypt cannot evaluate its permissions within 2 seconds The 403, see below; not the 503
10 The body is JSON, sent as application/json, at most 128 KiB 400 invalid_request, 415 unsupported_media_type, 413 payload_too_large No
11 The key is not pending deletion 409 key_pending_deletion Yes
12 The fields decode and fit the limits 400 invalid_base64, 400 invalid_request, 400 invalid_dek_length, 413 payload_too_large Yes
13 For encrypt, wrap and rewrap on a key of a paid tier, the tenant's billing is in good standing 402 billing_required Yes
14 For encrypt, wrap and rewrap on a Free (free) key, this UTC month's 10,000 operations are not used up 429 ops_cap_reached Yes
15 The encryption or decryption itself 400 invalid_ciphertext, 500 internal_error Yes

A request that passes every step answers 200, is recorded, and counts as one operation. A path that is not a route answers 404 not_found, and a wrong method 405 method_not_allowed; neither is recorded.

Whether a refusal at step 7 or 9 leaves a row depends on the id in the path; which refusals are recorded gives the rule, and covers refusals on other routes.

What the order means in practice:

  • The firewall is checked right after rypt finds the API token by its prefix, before the rate limit and before the secret. A request from outside the firewall gets 403 ip_not_allowed whatever its secret, and does not spend the API token's rate limit. So a caller who has only an API token's 8-character prefix, from outside its firewall, learns that the API token exists and is held to a firewall.
  • The rate limit is charged before the secret is checked. Requests with a real prefix and a wrong secret spend that API token's limit, and once it is spent they get 429 rate_limited instead of 401 unauthorized. Requests the firewall refuses do not spend it. rypt does not return an API token's prefix after it is issued.
  • Step 7 depends only on the API token's key list and the id, not on whether the key exists. Step 8 comes before the actions are checked, so an id that is not a live key of the API token's container gets 404 not_found whatever the API token's actions, the same answer as an id that was never issued. The check at step 9 is told the tenant and the container of both the API token and the key, and allows nothing across either, and every lookup rypt then makes for the request is limited to the API token's container: three separate checks keep an API token inside its container.
  • Steps 7 to 9 run before the body is read, so a refused request gets its 403 or 404 even with a malformed body: an unknown id with a malformed body gets 404, not 400.
  • Step 9 fails closed. If rypt cannot evaluate the API token's permissions, it refuses with 503 unavailable and the message could not check what this api token may do; retry shortly; it never allows the request instead.
  • POST /v1/keys/{id}/rotate runs steps 1 to 9 with the rotate action, waits for a slot among the key changes in flight, then finds the key again and runs step 11. On a key of a paid tier it then checks the tenant's billing as at step 13 (402 billing_required), and on a Free (free) key its monthly cap as at step 14 (429 ops_cap_reached), and it refuses a key that already has 10 versions retiring (409 too_many_retiring_versions); all three refusals are recorded. Then comes the rotation; rotate a key lists its answers. It takes no body and does not count as an operation.
  • PATCH /v1/keys/{id} (rename), DELETE /v1/keys/{id} (delete) and POST /v1/keys/{id}/restore (restore) run steps 1 to 9 with the action of the same name. Rename then reads its body (step 10). Each then waits for a slot among the key changes in flight and finds the key again; only rename refuses a key pending deletion (step 11). None has a billing or cap check, and none counts as an operation.
  • POST /v1/keys/{id}/versions/{version}/retire (retire a version) and POST /v1/keys/{id}/retention (set how many versions a key keeps) run steps 1 to 9 with the retire action, and POST /v1/keys/{id}/versions/{version}/restore (restore a version) with the restore action. A version in the path that is not a short id (a whole number, such as 2) then gets 404 not_found, and retention reads its body (step 10). Each then waits for a slot among the key changes in flight, finds the key again and refuses a key pending deletion (step 11). Retiring a version then checks, on a paid key, the tenant's billing as at step 13, and on a Free key its monthly cap as at step 14; restoring a version and setting how many versions a key keeps have no billing or cap check. None counts as an operation. Retire a version by hand and the two sections after it list their answers.
  • POST /v1/keys (create) names no key. It runs steps 1 to 5, reads its body (step 10), then refuses an API token that has a key list (403 key_not_allowed), and then one that lacks the create action (403 action_not_allowed, or 503 unavailable as at step 9). So on this route, unlike the routes above, a malformed body gets 400 even from an API token that may not create keys. After that it checks the name and tier, waits for a slot among the key changes in flight, and checks the container, billing, and that the name is free. Create a key shows both refusals.

A bearer token that does not start with ry_ is treated as a dashboard session. rypt verifies it (401 unauthorized if that fails), refuses a sign-in that belongs to no tenant with 403 no_tenant, and applies a rate limit per user (429 rate_limited). After that, nothing on this page applies to it: no firewall, no key list, no actions, and every container is in reach.

  • encrypt, decrypt, wrap, unwrap and rewrap refuse a dashboard session with 403 api_token_required, before the path is looked at.
  • It can create, list, read, rename, rotate, delete and restore keys, retire and restore their versions, set how many versions they keep, and read audit logs and usage, in every container, with no action check.
  • Only a dashboard session can issue, restrict and revoke API tokens, manage containers and firewalls, read the permission record, destroy a key at once with Delete now, and use billing. An API token on those routes gets 403 session_required.
{
  "error": "api_token_required",
  "message": "this endpoint requires an api token, not a console session",
  "request_id": "f8612160-4ea6-4cf8-9a4e-b89ac8407cf4"
}
{
  "error": "session_required",
  "message": "this endpoint requires a console session, not an api token",
  "request_id": "741d9c2f-f8d8-4cec-8db2-138afe0fe1e4"
}

Whoever can sign in to your dashboard can lift every restriction on this page. rypt has no per-user permissions: the role GET /v1/me reports (owner, admin or member) limits nothing.

These use one API token. Its key list is one key, 0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0 ($KEY_ID), its only action is decrypt, and it is held to a firewall that lists 203.0.113.0/24. $OTHER_KEY_ID is another key in the same container. Unless an example says otherwise, the requests come from 203.0.113.7, inside the firewall.

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/encrypt" \
  -H "Authorization: Bearer $RYPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"plaintext": "aGVsbG8gd29ybGQ="}'

Refused at step 9 with 403:

{
  "error": "action_not_allowed",
  "message": "this api token may not encrypt with this key",
  "request_id": "488d51b0-a3f9-4e81-a24c-f23394c6d663"
}

The log of $KEY_ID gets an encrypt row with result error and error code action_not_allowed.

curl -sS -X POST "https://api.rypt.dev/v1/keys/$OTHER_KEY_ID/decrypt" \
  -H "Authorization: Bearer $RYPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ciphertext": "...base64..."}'

Refused at step 7 with 403, before the action is checked and before the body is read:

{
  "error": "key_not_allowed",
  "message": "this api token is restricted to other keys",
  "request_id": "bd63e6e9-78ce-4043-84c3-fc1ab9597dd3"
}

The log of $OTHER_KEY_ID gets a decrypt row with error code key_not_allowed.

With a ciphertext that $KEY_ID made from hello world:

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/decrypt" \
  -H "Authorization: Bearer $RYPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ciphertext": "...base64..."}'
{"plaintext":"aGVsbG8gd29ybGQ="}

It passes every step: the log of $KEY_ID gets a decrypt row with result ok, and the call counts as one operation.

curl -sS -X POST "https://api.rypt.dev/v1/keys" \
  -H "Authorization: Bearer $RYPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "orders", "tier": "free"}'

Refused with 403, because the API token has a key list. Giving it the create action would not change that:

{
  "error": "key_not_allowed",
  "message": "this api token is restricted to particular keys and cannot create one",
  "request_id": "bb96c667-98ec-4869-ac01-8327912fd994"
}

Another API token, one with no key list and without the create action, is refused with 403 too:

{
  "error": "action_not_allowed",
  "message": "this api token may not create keys",
  "request_id": "0a7802b9-78c7-4aca-ae42-d8349906e250"
}

Either refusal is recorded as a failed create_key with no key id, so it is in no key's log.

The same decrypt sent from 198.51.100.20 is refused at step 3 with 403, on this route and every other:

{
  "error": "ip_not_allowed",
  "message": "this api token may not be used from 198.51.100.20",
  "request_id": "20f303dd-791b-4cc5-86a2-a54d9ff1c1cb"
}

Nothing is recorded in the audit log.

Every route an API token can call checks one of the twelve actions:

Action Route
read GET /v1/keys, GET /v1/keys/{id}, GET /v1/keys/{id}/audit, GET /v1/usage
encrypt POST /v1/keys/{id}/encrypt
decrypt POST /v1/keys/{id}/decrypt
wrap POST /v1/keys/{id}/wrap
unwrap POST /v1/keys/{id}/unwrap
rewrap POST /v1/keys/{id}/rewrap
rotate POST /v1/keys/{id}/rotate
create POST /v1/keys
rename PATCH /v1/keys/{id}
delete DELETE /v1/keys/{id}
restore POST /v1/keys/{id}/restore, POST /v1/keys/{id}/versions/{version}/restore
retire POST /v1/keys/{id}/versions/{version}/retire, POST /v1/keys/{id}/retention

An API token given no actions at all can do nothing, not even list its container's keys.

read on GET /v1/keys and GET /v1/usage is checked for the API token's container, whatever its key list, and the lists then show only the keys its key list allows. On GET /v1/keys/{id} and its audit log it is checked for that key, after the key list and after rypt has found the key in the API token's container; for the audit log a destroyed key counts too, since its log stays readable. Without read, these get 403 action_not_allowed with the message this api token may not read keys, which, like every read, is not recorded in the audit log. When rypt cannot evaluate the API token's permissions, a read gets 503 unavailable, as every other route does.

create names no key, so a key list cannot allow it: an API token with a key list gets 403 key_not_allowed on POST /v1/keys whether or not it has create. The dashboard and the API let you give create to such an API token anyway; it has no effect until the key list is lifted.

Every request reads the API token's revocation, firewall (with its current networks), key list and actions in the same lookup that finds the API token. A change you save applies from that API token's next request; there is no delay to wait out. rypt remembers for 60 seconds that a secret verified, so that it need not hash it again, but it consults that memory only after the lookup, so it never keeps a revoked or newly restricted API token working. A request that is already past authentication when you save finishes under the settings it started with.

In the dashboard, open API tokens, press Revoke on the API token's row, and confirm with Revoke API token. From its next request the API token gets 401 unauthorized, the same answer as a token that never existed. Revoking cannot be undone: issue a new API token instead. A revoked API token stays in the list, marked Revoked, so the rows it caused in the audit log still name it. A revocation is not an entry in the permission record.

A firewall holds 1 to 64 entries, counted after duplicates are removed. Each entry is an IPv4 or IPv6 address, which allows that address alone, or a network in CIDR notation. 0.0.0.0/0 allows all of IPv4 and ::/0 all of IPv6. There are no deny entries and no host names. These are refused with 400 invalid_allowed_ips:

  • an empty list, or more than 64 networks;
  • text that is not an address or a CIDR network;
  • a network with bits set past its prefix, such as 203.0.113.5/24: write 203.0.113.0/24 for the network or 203.0.113.5 for the address;
  • an IPv4 address written as IPv6, such as ::ffff:203.0.113.5: write it as IPv4;
  • an entry with spaces around it.

The address checked is the one your request reached rypt's load balancer from. Behind NAT or a proxy, that is the public address the request leaves from, not your host's private address. Headers you send, X-Forwarded-For included, do not change it. The audit log records the same address as src_ip, so the row of a request from a host shows the address to allow for it. api.rypt.dev answers on both IPv4 and IPv6, and a client that connects over IPv6 is checked by its IPv6 address: if your hosts may use either, list networks from both families.

The check runs on every request the API token makes, on every route, right after rypt finds the API token by its prefix: before the rate limit is charged and before the secret is checked, so a request from outside the firewall never uses up the API token's rate limit. A refusal is 403 ip_not_allowed with the address in the message, and it is not recorded in the audit log. Firewalls apply to API tokens only; nothing restricts the address a dashboard session comes from.

A firewall's container is fixed, and only that container's API tokens can be held to it (400 invalid_firewall otherwise). A change to its networks applies to every API token held to it from that key's next request. A firewall that still holds a live API token cannot be deleted (409 firewall_in_use): set those API tokens to No firewall with Restrict, or revoke them, first.

Each container keeps a permission record: a hash chain with an entry for every API token issued in it and for every change to an API token's actions or key list. Each entry's SHA-256 hash covers the entry and the hash of the one before it, so rewriting any entry changes every hash after it, and the latest entry, the head, stands for the whole record. Firewall changes and revocations are not entries.

The head is an entry number and a 64-character hexadecimal hash. The dashboard shows it under Permission record on the API tokens page, as Latest entry and Head hash, with Copy head hash. The API returns it as permission_chain_head when an API token is issued or restricted, and from GET /v1/containers/{id}/permission-chain, which needs a dashboard session.

rypt serves the head only, never the entries, so you cannot recompute the chain yourself. Keep a copy of the head somewhere rypt cannot reach after each change you make. If the head later shows an entry number you saved with a different hash, or a higher entry number when no one has issued an API token in that container or changed one's actions or key list since, the record has changed. Checking the entries against a head needs the operator.

When API 0.14.0 went live, rypt gave read to every API token that existed then and added an entry for each to its container's record, as a change rypt made rather than one a user made. A head you saved before then is behind the record for that reason alone.

Every page under the Container menu acts on the container selected there; a new tenant has only Default. To make another, open Containers and press Create container.

  1. To hold API tokens to a firewall, open Firewalls, press Create firewall, enter a Name and the Networks, one per line, and press Create firewall.
  2. Open API tokens and press Issue API token. Enter a Name. Under What it may do, tick what it needs. The boxes are in three groups, Read keys (read), Use keys (encrypt, decrypt, wrap, unwrap, rewrap, rotate) and Manage keys (create, rename, delete, restore, retire); under the last is the note "create works only for an API token allowed every encryption key." None is ticked when the dialog opens. Press Issue API token. Copy the token: it is shown once.
  3. On the new API token's row, press Restrict. Set What it may do, in the same two groups. Under Encryption keys it may use, choose Every key, or Only these keys and tick them; an API token that is to create keys needs Every key. Under Firewall, choose a firewall or No firewall. Press Save.
  4. Under Permission record, press Copy head hash and keep the hash.

The Restrictions column sums up each API token's actions, keys and firewall. The issue dialog sets only the name and the actions; the key list and the firewall are set with Restrict afterwards. The quickstart on the dashboard's Overview page issues an API token with the actions encrypt and decrypt and no others.

These settings change only through routes that need a dashboard session, so they cannot be scripted with $RYPT_TOKEN. The dashboard uses POST /v1/api-tokens (name, container_id, allowed_actions), PATCH /v1/api-tokens/{id} (firewall_id, key_ids, allowed_actions) and DELETE /v1/api-tokens/{id}. In a PATCH, a field left out keeps its value, null lifts the firewall or the key list, and an unknown field is 400 invalid_request. An empty key_ids is 400 invalid_key_ids, and a null allowed_actions is 400 invalid_allowed_actions: send [] for no actions. POST /v1/api-tokens ignores fields it does not know, so a firewall_id or key_ids sent there is dropped without an error. Firewalls use POST /v1/firewalls (container_id, name, allowed_ips), PATCH /v1/firewalls/{id} (name, allowed_ips) and DELETE /v1/firewalls/{id}. The API reference has the schemas.