Skip to content

Multi-tenancy: per-team tokens, and releases for this fork - #1

Merged
awbx merged 5 commits into
mainfrom
per-team-tokens
Nov 14, 2026
Merged

awbx merged 5 commits into
mainfrom
per-team-tokens

Conversation

@awbx

@awbx awbx commented Nov 14, 2026 •

Copy link
Copy Markdown

What

Turns the fork into a multi-tenant Turborepo remote cache with its own releases.

  1. Per-team tokens (feat(auth)). TURBO_TOKENS_DIR is a directory with one file per team: the file name is the team (TURBO_TEAM), the content is the lowercase hex SHA-256 of that team's token.
    • Every /v8/artifacts request must carry the token of the team it names. The team comes from slug, else teamId, through the same function (team_from_query) that builds the storage key.
    • No header or an unknown token: 401. Another team's token: 403 {"error":"TURBO_TOKEN is not for this team"}. No team named: 403, because this mode has no default namespace.
    • The directory is re-read every 10 s, so tenants can be added, removed or rotated without a restart. Dotfiles (Kubernetes ..data) are skipped, and so are malformed files (with a warning).
    • An unreadable directory at start stops the server. Later, the last good set is kept and an error is logged.
    • TURBO_TOKEN and TURBO_TOKENS_DIR together: the server refuses to start.
    • /management/health stays open.
    • With TURBO_TOKENS_DIR unset, behaviour is unchanged.
  2. cargo-auditable in Dockerfile, so an SBOM of the scratch image lists the crates in the binary. A local check with Syft found 282 components, runtime crates only (no wiremock).
  3. README leads with multi-tenancy: the problem, the model, tokens and hashes, Kubernetes, adding/removing/rotating tenants, cleanup, migration from a shared token, and security notes. Shared-token and open modes come after as "also supported". Upstream is credited, along with why the fork exists.
  4. Releases:
    • release.yml runs by hand from main with a version. It commits the Action's binaries on a release commit tagged v<version> and pushes the multi-arch image ghcr.io/13axis/turbo-cache-server:<version>, :<major>.<minor>, :latest. The image gets BuildKit provenance, a GitHub build provenance attestation, and a CycloneDX SBOM per platform attached as an OCI referrer (Syft 1.54.1 and ORAS 1.3.4, checksum-checked). It then creates the GitHub release (binaries, SHA256SUMS, SBOMs, attestations) from CHANGELOG.md.
    • snapshot.yml, run by hand, builds an amd64 sha-<commit> test image with its SBOM.
    • ci.yml now runs on PRs only. build.yml runs only when packaging changes. warm-build-cache.yml is removed. The build cache lives in this repo's package.
    • Adds CHANGELOG.md, SECURITY.md and a PR template.

Proposed first release: v5.1.0, based on upstream 5.0.4.

Why

With one shared token, any project can read or poison another project's cache by changing TURBO_TEAM. Per-team tokens bind each token to its namespace.

Checks

  • cargo fmt --all -- --check: clean
  • cargo clippy --locked --all-targets -- -D warnings: clean
  • cargo test --all-features --locked: 60 unit and 46 HTTP tests pass. New tests: 14 unit tests for team tokens (including a Kubernetes-style symlink swap), 2 for team extraction, and 16 HTTP tests in tests/e2e/team_tokens.rs.
  • Not run locally: the Docker build (no daemon here) and the release/snapshot workflows. build.yml runs on this PR and exercises the Dockerfile change.

awbx added 5 commits November 14, 2026 00:28
With one shared TURBO_TOKEN, any team that can use the cache can read and
overwrite every other team's artifacts by changing TURBO_TEAM. TURBO_TOKENS_DIR
binds each token to one team: the directory holds one file per team, named
after the team, containing the SHA-256 hex of that team's token.

- A request must name its team (slug, else teamId, the same extraction
  storage uses) and carry that team's token. No header or an unknown token
  is 401; a token of another team, or no team named, is 403.
- The directory is re-read every 10 seconds, so teams can be added, removed
  or rotated without a restart; dotfiles (Kubernetes' ..data links) are
  ignored. An unreadable directory at start stops the server; later, the
  last good set is kept.
- Setting both TURBO_TOKEN and TURBO_TOKENS_DIR stops the server.
- With TURBO_TOKENS_DIR unset, behaviour is unchanged. The health check
  stays open.
The release image is scratch plus one static binary, so an SBOM of it
listed no crates. cargo-auditable records the binary's dependency tree in
a section of the binary, which Syft and Trivy read: the SBOM now lists the
crates the server runs with, and no dev-dependencies.
The README now presents the fork: one cache shared by many teams, each
with a token bound to its namespace. It covers the problem a shared token
leaves open, the model, tokens and hashes, Kubernetes, adding, removing
and rotating tenants without a restart, cleanup, migration from a shared
TURBO_TOKEN and security notes. The shared-token and open modes follow as
also supported, unchanged. Upstream is credited, and images and the Action
point at this repository.
- release.yml, run by hand from main with a version: tags v<version> on a
  release commit carrying the Action's binaries, pushes the multi-arch
  image as <version>, <major>.<minor> and latest with BuildKit provenance,
  a build provenance attestation and a CycloneDX SBOM per platform
  attached as an OCI referrer (Syft and ORAS pinned and checksum-checked),
  and creates the GitHub release from CHANGELOG.md.
- snapshot.yml, by hand: an amd64 test image sha-<commit> with its SBOM.
- ci.yml on pull requests only; build.yml only when packaging changes;
  warm-build-cache.yml removed. The build cache lives in this repository's
  package.
- CHANGELOG.md (5.1.0, based on upstream 5.0.4), SECURITY.md and a pull
  request template.
@awbx
awbx merged commit baf34a4 into main Nov 14, 2026
7 checks passed
@awbx
awbx deleted the per-team-tokens branch November 14, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant