diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08b3c55..d97c7bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,19 @@ name: ci on: [push, pull_request] +permissions: + contents: read jobs: rust: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: { node-version: 22, cache: npm, cache-dependency-path: web/package-lock.json } - run: npm ci && npm run build working-directory: web - - uses: dtolnay/rust-toolchain@1.89.0 + - uses: dtolnay/rust-toolchain@d92bbbb03544f480ed5c7ba4b54020e4ed2c4f65 # 1.89.0 with: { components: "rustfmt, clippy" } - - uses: Swatinem/rust-cache@v2 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2 - run: sudo apt-get update && sudo apt-get install -y restic postgresql-client - run: cargo fmt --all -- --check - run: cargo clippy --workspace --all-targets -- -D warnings @@ -19,15 +21,15 @@ jobs: supply-chain: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: EmbarkStudios/cargo-deny-action@v2 - - run: cargo install cargo-audit --locked && cargo audit + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2 + - run: cargo install cargo-audit --version 0.23.0 --locked && cargo audit web: runs-on: ubuntu-latest defaults: { run: { working-directory: web } } steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: { node-version: 22, cache: npm, cache-dependency-path: web/package-lock.json } - run: npm ci - run: npm run typecheck diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fa1dbfb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: release +on: + push: + tags: ["v*"] +permissions: + contents: read +jobs: + image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + binaries: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: { node-version: 22, cache: npm, cache-dependency-path: web/package-lock.json } + - run: npm ci && npm run build + working-directory: web + - uses: dtolnay/rust-toolchain@d92bbbb03544f480ed5c7ba4b54020e4ed2c4f65 # 1.89.0 + - run: cargo build --release --locked -p tessera-hub -p tessera-cli -p tessera-agent + - run: | + mkdir dist + cp target/release/tessera-hub target/release/tessera target/release/tessera-agent dist/ + tar -C dist -czf "tessera-${GITHUB_REF_NAME}-linux-x86_64.tar.gz" . + sha256sum "tessera-${GITHUB_REF_NAME}-linux-x86_64.tar.gz" > SHA256SUMS + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: linux-x86_64 + path: | + tessera-*.tar.gz + SHA256SUMS + publish: + needs: [image, binaries] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: { name: linux-x86_64 } + - uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 + with: + files: | + tessera-*.tar.gz + SHA256SUMS + generate_release_notes: true diff --git a/Dockerfile b/Dockerfile index 067a4d1..682efbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,55 @@ -FROM node:22-bookworm AS web +# syntax=docker/dockerfile:1 +# Base images are pinned by multi-arch index digest. To update, run +# `docker buildx imagetools inspect ` and replace the digest. +FROM node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb AS web WORKDIR /build COPY web/package.json web/package-lock.json* ./ RUN npm ci COPY web/ ./ RUN npm run build -FROM rust:1.89-bookworm AS rust +FROM rust:1.89-bookworm@sha256:948f9b08a66e7fe01b03a98ef1c7568292e07ec2e4fe90d88c07bb14563c84ff AS rust WORKDIR /build COPY Cargo.toml Cargo.lock* ./ COPY crates ./crates COPY --from=web /build/dist ./web/dist -RUN cargo build --release -p tessera-hub +RUN cargo build --release --locked -p tessera-hub -p tessera-cli -FROM restic/restic:0.19.1 AS restic -FROM mysql:8.4 AS mysql-client +FROM restic/restic:0.19.1@sha256:136600b6ff6843d61d355f7f71f460a166429f35de6fd11b568fece3c9a4d510 AS restic +FROM mysql:8.4@sha256:a81d043930e51745522bd5c430961cf8286f0a23f0a9a2a6e0108f7ea71b0902 AS mysql-client -FROM debian:bookworm-slim -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates postgresql-client libstdc++6 && rm -rf /var/lib/apt/lists/* -COPY --from=rust /build/target/release/tessera-hub /usr/local/bin/ +FROM debian:bookworm-slim@sha256:734a72b3d6142a71993b4bc580ca01d8ca687f77a2c422d96a961d3376b179bc +# Bookworm ships pg_dump 15, which refuses to dump a newer server. Install a +# current client from the PostgreSQL project's apt repository (PGDG) instead. +# pg_dump 17 dumps servers 9.2 through 17. +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates curl gnupg libstdc++6 \ + && install -d /usr/share/keyrings \ + && curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/pgdg.gpg \ + && echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ + && apt-get update \ + && apt-get install -y --no-install-recommends postgresql-client-17 \ + && apt-get purge -y --auto-remove curl gnupg \ + && rm -rf /var/lib/apt/lists/* +COPY --from=rust /build/target/release/tessera-hub /build/target/release/tessera /usr/local/bin/ COPY --from=restic /usr/bin/restic /usr/local/bin/restic COPY --from=mysql-client /usr/bin/mysqldump /usr/local/bin/mysqldump -RUN restic version && mysqldump --version +COPY --chmod=0755 <<'EOF2' /usr/local/bin/tessera-healthcheck +#!/bin/bash +# Minimal HTTP GET /health using bash's /dev/tcp, so the slim image needs no curl. +port="${TESSERA_LISTEN##*:}" +exec 3<>"/dev/tcp/127.0.0.1/${port:-8787}" || exit 1 +printf 'GET /health HTTP/1.0\r\nHost: localhost\r\n\r\n' >&3 +IFS= read -r status <&3 +[[ "$status" == HTTP/*" 200 "* ]] +EOF2 +RUN restic version && mysqldump --version && pg_dump --version && tessera --help >/dev/null \ + && useradd --uid 10001 --user-group --home-dir /home/tessera --create-home tessera \ + && install -d -o tessera -g tessera /data ENV TESSERA_LISTEN=0.0.0.0:8787 ENV TESSERA_DATA_DIR=/data EXPOSE 8787 VOLUME ["/data"] +USER tessera +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD ["/usr/local/bin/tessera-healthcheck"] ENTRYPOINT ["tessera-hub"] diff --git a/README.md b/README.md index d53cdbf..32f1071 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,25 @@ export TESSERA_VAULT_PASSPHRASE='choose a long private passphrase' docker compose up --build ``` -Compose publishes **127.0.0.1:8787** only. The process inside the container listens on `0.0.0.0:8787` so that published port can reach it. The image includes `pg_dump` via `postgresql-client`. +Compose publishes **127.0.0.1:8787** only. The process inside the container listens on `0.0.0.0:8787` so that published port can reach it. Compose also needs operator, token or OIDC credentials (see above); pass them through the environment. `compose.yaml` forwards the `TESSERA_*` settings documented here. + +The image runs as the non-root user `tessera` (uid 10001) with a read-only root filesystem, no capabilities and a health check on `/health`. All state lives in the `/data` volume, and database dumps are staged there too (`TMPDIR=/data`), so size that volume for one full dump per concurrent capture. It ships `tessera-hub`, the `tessera` CLI, Restic, `mysqldump` and `pg_dump` 17. Base images are pinned by digest. + +Requirements and limits to know before exposing it: + +- `TESSERA_ADMIN_TOKEN` must be at least 32 characters (`openssl rand -base64 32`). +- Audit records are kept for `TESSERA_AUDIT_RETENTION_DAYS` days (default 90). +- `TESSERA_TRUSTED_PROXIES` takes a comma-separated list of exact proxy IP addresses, not CIDR ranges. Set it when a reverse proxy terminates TLS in front of the hub, along with `TESSERA_PUBLIC_URL`; otherwise the hub sees the proxy as every client. +- Run decay's space reclamation with `docker compose exec tessera-hub tessera gc`. +- Create the operator hash with `printf '%s\n' "$pw" | docker run --rm -i --entrypoint tessera-hub --hash-operator-password`. + +Example reverse proxy (Caddy on the same host, TLS handled by Caddy; set `TESSERA_PUBLIC_URL=https://tessera.example.org` and `TESSERA_TRUSTED_PROXIES=127.0.0.1`): + +``` +tessera.example.org { + reverse_proxy 127.0.0.1:8787 +} +``` ### CLI @@ -74,7 +92,7 @@ The API accepts `{"retention":{"keep_daily":7,"keep_weekly":2,"keep_monthly":6," The same repository setup is used by new [Outpost backup profiles](docs/DATABASE-CAPTURE.md). -Rest Server's `.htpasswd` must use bcrypt entries (`htpasswd -B`); Apache `apr1` hashes from `openssl passwd -apr1` are rejected with "Invalid htpasswd entry". Restart Rest Server after changing the file (a reload signal was not enough in testing). +Rest Server's `.htpasswd` must use bcrypt entries (`htpasswd -B`); Apache `apr1` hashes from `openssl passwd -apr1` are rejected with "Invalid htpasswd entry". Restart Rest Server (do not just signal a reload) after changing the file. Run [Rest Server](https://github.com/restic/rest-server#usage) with TLS, authentication, `--append-only`, and `--private-repos`. Point its storage at the hub's `vault/outposts` directory. Both processes need filesystem access to that directory. Give Rest Server access only to `outposts`, with a separate location for its TLS and authentication files. @@ -105,7 +123,7 @@ See [docs/SPEC.md](docs/SPEC.md). Rust workspace crates: `tessera-core`, `tesser - Set `TESSERA_WORMHOLE_MTLS` to `1` or `true` to open a client-certificate listener. It also needs `TESSERA_WORMHOLE_CERT`, `TESSERA_WORMHOLE_KEY`, and `TESSERA_WORMHOLE_CLIENT_CA`. `TESSERA_WORMHOLE_LISTEN` defaults to `127.0.0.1:8788`. While that listener is up, plain HTTP upload routes answer 403. An agent needs `TESSERA_WORMHOLE_CLIENT_CERT` and `TESSERA_WORMHOLE_CLIENT_KEY` for that listener. Configure `TESSERA_WORMHOLE_CA` when the hub certificate uses a private CA. - PostgreSQL captures still run a full `pg_dump` into a private temporary file. Restic can deduplicate matching bytes in the resulting dump. Allow temporary disk space for one full dump per concurrent capture. The Docker image contains only the hub (plus Restic and the database clients): build `tessera-agent` and the `tessera` CLI separately and install them on the hosts that need them. On non-x86 hosts build x86_64 binaries natively or in CI, not under QEMU emulation (`aws-lc-sys` crashes the compiler there). -The release image includes `pg_dump`; a native hub needs it on `PATH`. +A native hub needs `pg_dump` and `mysqldump` on `PATH`; the Docker image includes them. - The command provider is outside this release. Creating a command orbit and running it returns `command provider is outside this release; use filesystem or postgres`. - OIDC supports a single issuer (authorization code with PKCE). Administrators come only from configuration (`TESSERA_OIDC_ADMIN_SUBJECTS` / `TESSERA_OIDC_ADMIN_GROUPS`); there is no first-user-becomes-admin and no self-registration. Group grants are not re-checked against the IdP during a session. diff --git a/compose.yaml b/compose.yaml index 8734b13..c20336c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,18 +9,54 @@ services: TESSERA_DATA_DIR: /data TESSERA_VAULT_PASSPHRASE: ${TESSERA_VAULT_PASSPHRASE:?Set TESSERA_VAULT_PASSPHRASE} TESSERA_ADMIN_TOKEN: + TESSERA_ADMIN_TOKEN_EXPIRES: TESSERA_OPERATOR_PASSWORD_HASH: TESSERA_OPERATOR_NAME: + TESSERA_PUBLIC_URL: + TESSERA_TRUSTED_PROXIES: + TESSERA_OIDC_ISSUER: + TESSERA_OIDC_CLIENT_ID: + TESSERA_OIDC_CLIENT_SECRET: + TESSERA_OIDC_REDIRECT_URL: + TESSERA_OIDC_ADMIN_SUBJECTS: + TESSERA_OIDC_ADMIN_GROUPS: + TESSERA_OIDC_GROUPS_CLAIM: + TESSERA_OIDC_CA_FILE: + TESSERA_WORMHOLE_LISTEN: + TESSERA_WORMHOLE_MTLS: + TESSERA_WORMHOLE_CERT: + TESSERA_WORMHOLE_KEY: + TESSERA_WORMHOLE_CLIENT_CA: + TESSERA_EXPORT_CONCURRENCY: + TESSERA_EXPORT_MIN_FREE_BYTES: + TESSERA_OUTPOST_TOKEN_DAYS: + TESSERA_REFRESH_TTL_MINUTES: + TESSERA_REFRESH_MAX_ACTIVE: TESSERA_OFFSITE_REPOSITORY: TESSERA_OFFSITE_PASSWORD_FILE: AWS_ACCESS_KEY_ID: AWS_SECRET_ACCESS_KEY: AWS_SESSION_TOKEN: AWS_REGION: + # Database dumps and exports are staged on the data volume, not in RAM. + TMPDIR: /data + RESTIC_CACHE_DIR: /tmp/restic-cache RUST_LOG: tessera_hub=info volumes: - tessera-data:/data + read_only: true + tmpfs: + - /tmp:size=256m,mode=1777 + cap_drop: [ALL] + security_opt: + - no-new-privileges:true restart: unless-stopped + healthcheck: + test: ["CMD", "/usr/local/bin/tessera-healthcheck"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 20s volumes: tessera-data: diff --git a/docs/DATABASE-CAPTURE.md b/docs/DATABASE-CAPTURE.md index 0c5a790..3dc2bf1 100644 --- a/docs/DATABASE-CAPTURE.md +++ b/docs/DATABASE-CAPTURE.md @@ -107,7 +107,7 @@ Forwarded requests are rejected in this mode, but that is not a proxy trust boundary: never reverse-proxy a development listener. Compose keeps the mode off and needs operator/API credentials even with a localhost published port. -Generate an Argon2id hash and set `TESSERA_OPERATOR_PASSWORD_HASH` to the result. The hub reads the password from stdin in hash mode. For example, from an interactive Bash shell: +In the container, run the hash mode through the image: `printf '%s\n' "$pw" | docker run --rm -i --entrypoint tessera-hub --hash-operator-password`. Generate an Argon2id hash and set `TESSERA_OPERATOR_PASSWORD_HASH` to the result. The hub reads the password from stdin in hash mode. For example, from an interactive Bash shell: ```bash read -rs -p 'Operator password: ' tessera_operator_password; printf '\n' @@ -115,7 +115,7 @@ export TESSERA_OPERATOR_PASSWORD_HASH="$(printf '%s\n' "$tessera_operator_passwo unset tessera_operator_password ``` -Set `TESSERA_OPERATOR_NAME` for the audited identity, or use the default `operator`. Serve the browser over HTTPS outside loopback. Sessions expire after eight hours or a hub restart. Browser mutations require the session's CSRF token. API and CLI callers use the separate `TESSERA_ADMIN_TOKEN`. Use the bundled HTTP CLI on the hub's loopback listener when sending the token. +Set `TESSERA_OPERATOR_NAME` for the audited identity, or use the default `operator`. Serve the browser over HTTPS outside loopback. Sessions expire after eight hours. They survive a hub restart as long as the operator credential is unchanged; rotating or removing `TESSERA_OPERATOR_PASSWORD_HASH` invalidates them. Browser mutations require the session's CSRF token. API and CLI callers use the separate `TESSERA_ADMIN_TOKEN`. Use the bundled HTTP CLI on the hub's loopback listener when sending the token. Legacy full-upload agents now need an explicit orbit assignment. With operator CSRF or an admin API token, call `PUT /api/v1/orbits/{orbit-id}/outpost` with @@ -270,7 +270,8 @@ immediately. A denial is written to the audit log at most once a minute per sour - Limiter state is in memory: it resets when the hub restarts and is not shared between hub processes. -**Shared admin token.** `TESSERA_ADMIN_TOKEN` is a transition aid. Set +**Shared admin token.** `TESSERA_ADMIN_TOKEN` is a transition aid. It must be at least +32 characters; generate one with `openssl rand -base64 32`. Set `TESSERA_ADMIN_TOKEN_EXPIRES` (`YYYY-MM-DD`, end of that day UTC, or an RFC 3339 timestamp) and the hub refuses the token after that time. Without it the hub logs a warning at start. Every use is audited as the `legacy-admin-token` service principal.