Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## What and why

<!-- The behaviour that changes, and the reason. -->

## Checks

- [ ] `cargo fmt --all -- --check`
- [ ] `cargo clippy --locked --all-targets -- -D warnings`
- [ ] `cargo test --all-features --locked`
- [ ] Tests added for the changed behaviour
- [ ] README and CHANGELOG.md (under "Unreleased") updated if users see the change
4 changes: 2 additions & 2 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
group: linux-buildcache-${{ matrix.arch }}-${{ github.ref }}
cancel-in-progress: false
env:
# Keep caches in the existing public package so fork PRs can restore anonymously.
CACHE_REF: ghcr.io/brunojppb/turbo-cache-server:buildcache-${{ matrix.arch }}
# Keep caches in the repository's public package so fork PRs can restore anonymously.
CACHE_REF: ghcr.io/${{ github.repository }}:buildcache-${{ matrix.arch }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Stage release version
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
name: Build binary
# Only when the packaging could change: it builds on three runners.
on:
pull_request:
paths:
- Cargo.toml
- Cargo.lock
- rust-toolchain.toml
- Dockerfile
- Dockerfile.release
- .github/workflows/build*.yml
- .github/scripts/**
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: false
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: "CI Checks"
# Pull requests only: main only changes through them.
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
packaging-contract:
Expand Down
277 changes: 190 additions & 87 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# A test image of any commit, between releases: run by hand on a branch.
#
# It builds the image from source (./Dockerfile, linux/amd64 only, one
# runner) and pushes it as ghcr.io/<owner>/turbo-cache-server:sha-<sha12>,
# never as a version or latest, with its CycloneDX SBOM (Syft) attached to
# the pushed digest as an OCI 1.1 referrer (ORAS). Releases are release.yml.
name: Snapshot image
on:
workflow_dispatch:

permissions:
contents: read
packages: write

concurrency:
group: snapshot-${{ github.ref }}
cancel-in-progress: false

jobs:
image:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Build and push
id: push
env:
REPOSITORY: ${{ github.repository }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTOR: ${{ github.actor }}
run: |
set -euo pipefail
image="ghcr.io/${REPOSITORY,,}"
tag="$image:sha-${GITHUB_SHA::12}"
rust=$(python3 -c 'import tomllib; print(tomllib.load(open("rust-toolchain.toml", "rb"))["toolchain"]["channel"])')
# The source label links the package to this repository, which is
# what lets this job's token push to it.
docker build --build-arg RUST_VERSION="$rust" \
--label "org.opencontainers.image.source=https://github.com/$REPOSITORY" \
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
-t "$tag" .
echo "$TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin
docker push "$tag"
digest=$(docker image inspect --format '{{index .RepoDigests 0}}' "$tag")
echo "### Snapshot image" >> "$GITHUB_STEP_SUMMARY"
echo "\`$tag@${digest#*@}\`" >> "$GITHUB_STEP_SUMMARY"
echo "image=$image" >> "$GITHUB_OUTPUT"
echo "digest=${digest#*@}" >> "$GITHUB_OUTPUT"

# Same tools, versions and checks as release.yml.
- name: SBOM
env:
IMAGE: ${{ steps.push.outputs.image }}
DIGEST: ${{ steps.push.outputs.digest }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTOR: ${{ github.actor }}
SYFT_VERSION: 1.54.1
SYFT_SHA256: c069905b391cc4c20a5ba65ad5c10be2a7ba074f8ea6ad203e24d14e303dad47
ORAS_VERSION: 1.3.4
ORAS_SHA256: f27adb935022d94df8dc77719c322dda592c78a0d57a6f7dcdd8d900b248c454
run: |
set -euo pipefail
[[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "no digest: '$DIGEST'" >&2; exit 1; }
bin="$RUNNER_TEMP/sbom-tools"
mkdir -p "$bin"
curl -fsSL -o "$bin/syft.tgz" "https://github.com/anchore/syft/releases/download/v$SYFT_VERSION/syft_${SYFT_VERSION}_linux_amd64.tar.gz"
curl -fsSL -o "$bin/oras.tgz" "https://github.com/oras-project/oras/releases/download/v$ORAS_VERSION/oras_${ORAS_VERSION}_linux_amd64.tar.gz"
printf '%s %s\n' "$SYFT_SHA256" "$bin/syft.tgz" "$ORAS_SHA256" "$bin/oras.tgz" | sha256sum -c --quiet
tar -xzf "$bin/syft.tgz" -C "$bin" syft
tar -xzf "$bin/oras.tgz" -C "$bin" oras
ref="$IMAGE@$DIGEST"
cd "$RUNNER_TEMP"
SYFT_CHECK_FOR_APP_UPDATE=false \
SYFT_REGISTRY_AUTH_AUTHORITY=ghcr.io \
SYFT_REGISTRY_AUTH_USERNAME="$ACTOR" \
SYFT_REGISTRY_AUTH_PASSWORD="$TOKEN" \
"$bin/syft" scan "registry:$ref" --quiet --select-catalogers +sbom-cataloger \
-o cyclonedx-json=turbo-cache-server.cdx.json
jq -e 'any(.components[]; .name == "actix-web")' turbo-cache-server.cdx.json >/dev/null \
|| { echo "the SBOM lists no Rust crates" >&2; exit 1; }
printf '%s' "$TOKEN" | "$bin/oras" attach --no-tty \
-u "$ACTOR" --password-stdin \
--artifact-type application/vnd.cyclonedx+json \
--format go-template --template '{{.digest}}' \
"$ref" turbo-cache-server.cdx.json:application/vnd.cyclonedx+json > sbom-digest
printf '%s' "$TOKEN" | "$bin/oras" discover --no-tty -u "$ACTOR" --password-stdin \
--artifact-type application/vnd.cyclonedx+json --format json "$ref" > referrers.json
jq -e --arg d "$(cat sbom-digest)" 'any(.referrers[]; .digest == $d)' referrers.json >/dev/null \
|| { echo "SBOM $(cat sbom-digest) not among the referrers of $ref" >&2; cat referrers.json >&2; exit 1; }
echo "SBOM: CycloneDX, $(jq '.components | length' turbo-cache-server.cdx.json) components, attached as \`$(cat sbom-digest)\`" >> "$GITHUB_STEP_SUMMARY"
15 changes: 0 additions & 15 deletions .github/workflows/warm-build-cache.yml

This file was deleted.

4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Read this file before changing the repository. Keep these instructions short and
- `src/startup.rs` composes the Actix app, routes, middleware, settings, and storage.
- `src/routes/` handles the HTTP contract; `src/routes/artifacts.rs` maps artifact requests, responses, and metadata.
- `src/storage.rs` owns S3 operations and translates storage failures.
- `src/auth/` handles the optional shared `TURBO_TOKEN`.
- `src/auth/` handles authentication: the optional shared `TURBO_TOKEN`, or per-team tokens from `TURBO_TOKENS_DIR` (`team_tokens.rs`).
- `src/app_settings.rs` reads environment settings; `src/telemetry.rs` sets up tracing and metrics.
- `tests/e2e/` exercises the server over HTTP with a Wiremock S3 endpoint.
- `action/`, `Dockerfile`, and `.github/workflows/` package, test, and release the server.
Expand All @@ -21,7 +21,7 @@ Read this file before changing the repository. Keep these instructions short and
- Keep this one crate unless a concrete change needs a new module or crate. Put domain decisions in Rust types and functions close to the behavior they govern. Do not copy a database-oriented DDD layer structure into this server.
- Keep HTTP parsing, status codes, and response shapes at the route seam; keep bucket access and S3 error translation in `storage.rs`. Wire concrete dependencies in `startup.rs`.
- Preserve streaming for artifact uploads and downloads. Do not buffer whole artifacts merely to simplify a change.
- Treat request paths, query values, headers, and stored metadata as untrusted. Keep team and artifact key handling consistent across PUT, GET, and HEAD. A team name is a storage namespace, not an authenticated account: `TURBO_TOKEN` is one optional shared server token.
- Treat request paths, query values, headers, and stored metadata as untrusted. Keep team and artifact key handling consistent across PUT, GET, and HEAD. A team name is a storage namespace. With `TURBO_TOKEN` (one shared token) or no token, it is not authenticated; with `TURBO_TOKENS_DIR`, each token is bound to one team, so the team the token is checked for must be the namespace the request reads or writes (`team_from_query` serves both).
- Do not log tokens, credentials, artifact contents, or unbounded client-supplied values. Keep secrets out of `Debug` output and tracing fields.
- Prefer an existing dependency or a small local function before adding a crate. Record a consequential architecture choice and its reason in the PR or a short ADR when it needs lasting explanation.
- Add a focused regression test for changed behavior. A prose rule that can be checked reliably should become a test or CI check when it matters.
Expand Down
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

All notable changes to this fork are listed here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and releases follow
[Semantic Versioning](https://semver.org/).

This fork continues the version line of
[brunojppb/turbo-cache-server](https://github.com/brunojppb/turbo-cache-server):
each release names the upstream version it is based on. Its tags start with
`v` (`v5.1.0`), upstream's do not (`5.0.4`). Changes made upstream are in
[upstream's releases](https://github.com/brunojppb/turbo-cache-server/releases).

## [Unreleased]

## [5.1.0]

Based on upstream 5.0.4.

### Added

- Multi-tenancy: per-team tokens. `TURBO_TOKENS_DIR` names a directory with
one file per team (the file name is the team, the content the SHA-256 hex
of its token). A request must carry the token of the team it names: no or
an unknown token is `401`, another team's token or no team named is `403`.
The directory is re-read every 10 seconds, so teams are added, removed and
rotated without a restart. See "Multi-tenancy: per-team tokens" in the
README.
- Release images carry a CycloneDX SBOM per platform, attached to the image
digest as an OCI 1.1 referrer, and a build provenance attestation; release
binaries have provenance attestations too.
- Images are also tagged `<major>.<minor>`.

### Changed

- The server refuses to start when both `TURBO_TOKEN` and `TURBO_TOKENS_DIR`
are set, or when `TURBO_TOKENS_DIR` cannot be read. With
`TURBO_TOKENS_DIR` unset, behaviour is the same as upstream 5.0.4.
- Binaries are built with cargo-auditable, which embeds their dependency list
for SBOM and vulnerability scanners.
- Images are published as `ghcr.io/13axis/turbo-cache-server`, and the GitHub
Action is `13axis/turbo-cache-server@v<version>`.

[Unreleased]: https://github.com/13axis/turbo-cache-server/compare/v5.1.0...HEAD
[5.1.0]: https://github.com/13axis/turbo-cache-server/releases/tag/v5.1.0
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tonic = "0.14.2"
secrecy = "0.10.3"
tracing-actix-web = "0.7"
subtle = "2"
sha2 = "0.10"

[dev-dependencies]
pretty_assertions = "1.4.1"
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ ARG RUST_VERSION=1.100.0
FROM rust:${RUST_VERSION}-alpine AS chef
WORKDIR /app
RUN apk add --no-cache musl-dev perl make && \
cargo install --locked cargo-chef --version 0.1.78
cargo install --locked cargo-chef --version 0.1.78 && \
cargo install --locked cargo-auditable --version 0.7.7

FROM chef AS planner
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
Expand All @@ -17,7 +18,9 @@ RUN cargo chef cook --release --locked --recipe-path recipe.json
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
COPY src ./src
COPY tests ./tests
RUN cargo build --release --locked --bin decay
# cargo-auditable embeds the dependency tree in the binary, so SBOM tools
# (Syft, Trivy) list the crates the server actually runs with.
RUN cargo auditable build --release --locked --bin decay

# Export a binary directly; no image registry or temporary container needed.
FROM scratch AS artifact
Expand Down
Loading
Loading