Repository navigation
feat(api): the installation registry's token endpoint and grants (part of #215) - #529
Merged
Merged
Conversation
…t of #215) ADR 0030: Distribution's token authentication with the control plane as token service. A grant (pull, or pull and push for a build) is issued for an action until its deadline, its password stored hashed and the grant audited. GET /api/v1/registry/token answers a five-minute EdDSA token for the grant's repository only, signed with a new installation key whose public half is written as a JWKS for Distribution. Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 14 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
CodeQL read the grant's random 32-byte secret as a person's password. It is hashed like API tokens now, SHA-256 bound to its purpose (shipkeep:registry_grant:), and named a secret in the code and the column; clients still send it as the password of basic auth. Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 27, 2026
…e project (part of #215) (#530) Part of #215 (M3.3), following ADR 0030. This puts the installation's registry in the control plane's Compose project and serves it under `/v2/` on the control plane's name. **It builds on #529** (token endpoint and grants) and contains its commit until #529 merges. The base is `main` so that merging #529 does not close this PR. ## What changed - **`registry` service** in `deploy/control-plane/compose.yml`: CNCF Distribution 3.1.2, pinned by digest. - It is configured by the new `registry.yml`, with token authentication. Its realm (the control plane's `/api/v1/registry/token`) and its service (`SHIPKEEP_DOMAIN`) come from the environment. - Images live in the `registry-data` volume, which is not in the instance backup. - It reads the JWKS from the `registry-auth` volume, which the control plane writes (`REGISTRY_JWKS_FILE`) and the registry mounts read-only. - It starts once the control plane is healthy, so the key exists. - **Separate machine**: the Compose Caddy sends `/v2` and `/v2/*` to the registry uncompressed, and everything else to the API as before. - **Single machine**: - `compose.single-machine.yml` publishes the registry on `127.0.0.1:5000`, in the control plane's slice, capped at 256 MiB; - the agent keeps a third fixed route before the control plane's: `shipkeep-control-plane-registry`, with host plus path `/v2`, `/v2/*`, to `control_plane.route.registry`; - that setting defaults to `127.0.0.1:5000`, so existing agent configurations need no change, and a non-loopback value is refused. No action can name or remove the route (tested). - **Image**: the control plane image creates `/var/lib/shipkeep-registry`, owned by `node`, so that the new volume is writable. - **Installer and bundle**: - the bundle and the installer ship `registry.yml`; - the single-machine checks refuse a busy port 5000; - `install_test.sh` checks the merged Compose configuration. - **Docs**: INSTALL (files, upgrade, port, route) and SPEC. ## How it was tested - **Distribution 3.1.2**: the environment variables do override `realm` and `service` from `registry.yml`. Tested against a real `registry:3.1.2` with an EdDSA token: 401 with the right realm, then 202 for an allowed push. - **Caddyfile**: `caddy adapt` with the pinned Caddy image confirms the routing (`/v2` and `/v2/*` to the registry, the rest compressed to the API). - **Agent routes on a real Caddy** (pinned image, internal TLS): - `/v2`, `/v2/` and `/v2/org/app/blobs/uploads/` reach the registry upstream; - `/`, `/api/v1/registry/token`, `/v2x` and `/web/v2/` reach the control plane; - plain HTTP gets a 308 to HTTPS; - a Host header with another port matches no route, the existing bound. - **Merged Compose configuration** (`docker compose config` with both files): realm, service, port `127.0.0.1:5000`, `depends_on` healthy, the read-only volumes, the slice and the limit. - **Go**: `go test ./agent/...` and `golangci-lint` are clean. New cases cover the route order and paths, default and named registry upstreams, non-loopback values refused, and the fixed routes out of reach of `RemoveRoute`. ## Security considerations - The registry accepts only tokens signed with the installation's key: anonymous requests get 401 with the realm. Its port is published on loopback only, and only on a single machine. - The JWKS volume holds only the public key. The private key never leaves the control plane's database, where it is encrypted. - A route written before this change keeps working: the agent adds the registry route ahead of it, and an action can never remove it. - Known limit, per ADR 0030: on a single machine, the server's Docker reaches the registry through the control plane's public name, via the egress proxy. Behind a NAT that does not loop back, Git builds do not work in this version. INSTALL will say so once builds ship. --------- Signed-off-by: samuel mbabhazi <[email protected]>
This was referenced Nov 27, 2026
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 27, 2026
…wrong (#538) The registry token test (#529) builds a wrong secret by replacing the last character of a real one with `A`. When the secret already ended with `A`, one time in 64, nothing changed and the case answered 200. #536's integration run hit it. The last character is now always replaced by a different one (`B` if it was `A`). The test passed three times in a row locally (PostgreSQL). Test only, no change to the code. Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 27, 2026
… then deploys the image (part of #215) (#537) Part of #215 (M3.3), per ADR 0030. This connects the pieces already merged: the registry and its grants (#529, #530), the agent's `BuildImage` (#533) and the build lane (#532). A Git application with a Dockerfile now builds when it deploys, and its replicas run the image that was built. ## What changed - **Configuration**: an application whose configuration is a repository's may use `build.type: dockerfile`. Railpack and Nixpacks are still refused with `unsupported_build_type` (new text, in the web UI and in French). An application created from an image still runs an image. - **Release**: - `releaseDraft(config, { repository })` plans a build. Its image is `<control plane host>/<organization>/<application>:<release number>` (`builtImage`), set once the store knows the number; - `repositoryPath` reads paths the way the agent does: `./api/` → `api`, `.` → the root; - the commit was already kept (#527). - **Planner** (`building` and `built` stages): the replicas are placed first, then `build_image` runs on the first one's server, at the commit, with the context, the Dockerfile and the args. Its digest becomes the release's (`record_build`). A failed build gives its cause in words: its output, its time limit, a server without a builder. - **Runner**: - the GitHub token is minted **outside any transaction** (`RepositorySource.buildAccess`): read access to that one repository, under its current name. If GitHub cannot be reached, the run waits and tries again; - the push grant (#529) is issued at enqueue time and lasts as long as the action; - `release.image_built` is audited with the digest and the commit; - every pull from the installation's registry carries a **pull-only grant**. - **Store**: an action's `buildImage.imageDigest` is read back, only if it is a valid `sha256:` digest. - **SPEC**: the build stage. Open question: the token is not revoked when the build ends yet (it expires within the hour). ## How it was tested - **Planner unit tests**: - the full order, from `queued` through `building` and `built` to `succeeded`; - the exact build step (first replica's node, normalized paths, the tag), with the default context and Dockerfile; - every replica pulls `<repository>@<built digest>`; - each failure cause and its text, with nothing deployed afterwards; - no digest, no commit, a release already built. - **Agent action**: `BuildImage` carries the URL, the commit, the token and the push grant, and round-trips through protobuf. A build without its access is refused. - **Integration** (`git-builds.integration.spec.ts`, PostgreSQL, fake GitHub, real pipeline and token endpoint): - the deploy creates `…/<app>:1`, and the build is the only action queued; - the token is scoped to `repositoryIds: [777]`, `contents: read`; - the push grant is accepted by the token endpoint for pull and push on that repository; - after the agent's answer, the digest is recorded and audited; - the pull goes to `<repo>@<digest>` with a grant that gets `pull` only; - both grants are audited, and the token never appears in the audit log. - **Suites**: - API: lint, typecheck, 411 unit tests; - integration, all suites run: only the known environment failures (PostgreSQL 18 error codes, specs that need a container runtime); - web: 398 tests. ## Security considerations - **The token** is minted for one repository and read access, travels only inside the encrypted action, and is never logged or audited. It is not revoked yet (open question). - **The grants**: pushing only for the build, only to the application's repository, until the action's deadline. Servers only pull. - **No GitHub call holds a database transaction.** Signed-off-by: samuel mbabhazi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #215 (M3.3), following ADR 0030. This is the control plane side of the installation's own registry: the token service that CNCF Distribution delegates authentication to. Nothing calls
RegistryGrants.issueyet. The build and pull actions will do so in the next PRs.What changed
registry_grants, tenant-scoped with RLS):{organizationId}/{applicationId}: pull, or pull and push for a build, until the action's deadline;{organizationId}.{grantId}, so that the anonymous endpoint can read the grant within its tenant;registry.grant_issued(system actor). Grants expired for a day are removed when the organization is issued another one.GET /api/v1/registry/token:{token, access_token, expires_in, issued_at}. The token is an EdDSA JWT for the control plane's host, valid 5 minutes and never past the grant's deadline;WWW-Authenticate: Basic, and never says what was wrong.registry(Ed25519), created and audited like the CA and confirmation keys;REGISTRY_JWKS_FILEat start, for Distribution'sauth.token.jwks.Next PRs: the registry in the control plane's Compose project and its
/v2/routes (Compose Caddy, and the agent's route on one machine); then the build itself (agentBuildImagewith rootless BuildKit, the pipeline's build step, grants on the pull actions).How it was tested
EdDSAtokens with a JWKS file, checkskid,audandexp, and enforces the per-repository access claim. I checked this against a realregistry:3.1.2before writing the code.registry-token.spec.ts) cover user names, basic headers, passwords and scopes, with malicious inputs:*, uppercase, newlines;registry-tokens-http.integration.spec.ts):registry-distribution.integration.spec.ts, Testcontainers): a build grant pushes to its repository, another repository is refused, a pull grant cannot push, and a forged signature is refused. Testcontainers has no runtime in my sandbox, so I ran this test once against the host's Docker, with a local-only copy of the helper, and it passed. CI runs it as written.Security considerations
installation:keys, as the CA's is.SELECT, INSERT, DELETEonregistry_grants, and noUPDATE.About 900 changed lines without generated code, over the 500 target: tests make up about 400 of them.