DocsSecrets of a repository and of an org

Secrets of a repository and of an org

A repository or an org holds its own secrets on the desk server (#246), as GitHub does. A check on main or an image build gets the value when its config names the secret. No change of the cluster adds a secret.

Scopes

Scope Who sets it Who lists it Which repositories get it
A repository merge on the repository read on the repository that repository
An org (the owner part of the slug) an admin of the org, or of the server a member of the org all repositories of the org, or the selected ones

A repository secret wins over an org secret of the same id. An org never reaches the repositories of another org: the secrets of acme are not visible to beta/app, also when both use the same id.

Commands

desk secret set <id> [--repo <owner/repo> | --org <org>] [--from-env <VAR>] [--visibility all|selected --repos <a/x,a/y>]
desk secret list [--repo <owner/repo> | --org <org>] [--json]
desk secret rm <id> [--repo <owner/repo> | --org <org>]

Without --org the command uses --repo, or the repository of the work folder. The value of set comes from standard input or from the variable that --from-env names. It is never an argument, so no shell history holds it. An agent runs sealkeep run <name> -e VALUE=<name> -- desk secret set npmtoken --org acme --from-env VALUE: sealkeep puts the value in the environment of that one command.

The id has 1 to 64 lowercase letters, digits, dashes or underscores, and starts with a letter or a digit. It is the id that secrets of a check names ({"NODE_AUTH_TOKEN": "npmtoken"}) and that secrets of an image names. A value is at most 64 KiB and is not empty. A selected org secret names at least one repository of that org; an all secret names none.

The list shows, for each secret, who set it, when, and when a run last used it. It never shows a value.

Calls

Call Right
GET /v1/repos/<owner>/<repo>/secrets read on the repository
PUT and DELETE /v1/repos/<owner>/<repo>/secrets/<id> with {"value": "<text>"} merge on the repository
GET /v1/orgs/<org>/secrets a member of the org, or an admin of the server
PUT /v1/orgs/<org>/secrets/<id> with {"value", "visibility": "all"|"selected", "repos": ["<org>/<repo>"]}, and DELETE an admin of the org, or an admin of the server

How a run gets a secret

  1. The config names a secret: secrets of a check (#131) or of an image.
  2. The runner claims the run. The server looks up each named id: first among the secrets of the repository, then among the org secrets whose visibility names the repository. It puts the values it found in the claim, secretValues. The claim travels to the runner that holds the lease.
  3. Each value that a run reads is a row of secret_reads: the run, the scope, the id and the time. There is no value in it.
  4. The runner uses a secret of the claim before the variable DESK_BUILD_SECRET_<ID> of its own pod, so the old way keeps working for an id that no scope holds.
  5. The runner keeps the value out of every live part of the log and out of the final log: each occurrence becomes [secret].
  6. The rules of #131 still apply: only a check on main after a landing, and an image build of a landing, name secrets. A proposal, the gate of a landing, a bisect and desk try run with none.
  7. If a scope holds the secret and the server cannot read it, the run ends with an error that names the reason and does not start with a wrong value.

Encryption

The format is the one of GitHub (a sealed box), and the key of the instance is kept as Forgejo keeps its SECRET_KEY: apart from the database.

  1. A keypair for each scope. A scope, org:<name> or repo:<id>, has an X25519 keypair (secret_keys). The public key is a call away: GET .../secrets-key.
  2. The client seals. desk secret set asks for the public key and encrypts the value to it on your machine: an ephemeral X25519 key, HKDF-SHA256 and AES-256-GCM. The scope and the id are in the key derivation and in the authenticated data. The server and its logs never see the text. A caller that cannot seal may send {"value": ...}, and the server seals it the same way.
  3. The server stores the box. It opens the box once when it is set, to refuse a box that is sealed for another scope or id. It opens it again only when it hands the value to a run.
  4. The private key is wrapped. The key of the instance wraps the private key of each scope with AES-256-GCM. A copy of the database holds boxes and wrapped keys, and no key that opens them.
  5. The key of the instance is 32 random bytes. The first server that starts makes it and keeps it in the object store as instance/secrets-key-<id>. The id is the one row of secrets_instance, so servers that start together agree on one key, and the database holds no key. The variable DESK_SECRETS_KEY (base64 of 32 bytes, with DESK_SECRETS_KEY_ID) replaces it, for a deployment that keeps the key in Vault or in a Secret.

So a row copied to another scope or id does not open, a scope can be destroyed alone by deleting its keypair, and the copy of the database and the object store are two things to steal. A key that is lost makes the stored secrets unreadable: set them again.

The runners

Encryption does not isolate tenants on a runner. The pool serves every org, and the sandbox of a check is the process level (docs/runs.md). A secret of an org reaches the runner that takes a run of that org, and that runner also takes the runs of other orgs. An org that needs isolation runs its own runners: desk runner add <name> --org <org>.