A security audit found five ways one tenant could reach another tenant's data or act on its behalf. All five are closed here. 1. Clone directories were shared. Every producer and consumer resolved a checkout to `<git_clone_base>/<sanitized-name>`, so two tenants that onboarded a target with the same name got one directory: the second one to scan fetched the first one's `origin` instead of cloning its own, and then scanned it. Checkouts are now `<base>/<tenant>/<name>` through a single helper, `pipeline::git::clone_dir`, which every call site uses — the orchestrator, PR review, ingest, the graph build, the chat embedding build and the file-content reader. Both segments collapse to one safe path component, and the tenant segment additionally carries a digest whenever collapsing was lossy, so two distinct tenant ids can never map to one directory. 2. One SSH deploy key authenticated every tenant's clone. A tenant that added the agent's key to a repository made that repository readable by any other tenant that named its URL. Per-tenant key management is R1, so at MVP the key is gone entirely: `RepoCredentials` is HTTPS-token only, an `ssh://`/`git@` URL is rejected with a message pointing at the HTTPS URL and a token, and `SSH_KEY_PATH`, the generator, the `/api/v1/settings/ssh-public-key` endpoint, the dashboard panel that advertised the key and the onboarding docs are all removed. 3. `serve_artifact` had no tenant check. Runner blobs are addressed by content hash and the hash is in the job record, so any valid runner key could fetch any tenant's control-logic source. The blob store is now per tenant (`<base>/tenants/<tenant>/blobs/…`) and the read is bound to the tenant the key is bound to; another tenant's digest is simply not there. 4. The runner scope check accepted the `werkbank:runner` scope *or* any key whose product was `pruefwerk`, which made every product API key a runner key able to lease and complete other tenants' jobs. The scope is now required. 5. Webhooks created databases before authenticating. A POST with any `tenant_id` reached `for_tenant_id`, whose index-ensure materializes `<prefix>_<tenant_id>` — an unauthenticated write primitive. The target lookup now goes through `DatabasePool::for_existing_tenant_id`, which creates nothing; an unknown tenant or target is a 404. Also: the static `WERKBANK_RUNNER_TOKEN` names no tenant, so a holder acts for all of them. It is still accepted in dev, where it is the only option before the platform is wired up, and refused when `app_env.is_hardened()`. URL-scheme and SSRF validation (file://, local paths, server-side `source_ref`) is deliberately untouched — that is #256. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
88 lines
4.0 KiB
Docker
88 lines
4.0 KiB
Docker
FROM rust:1.94-bookworm AS builder
|
|
|
|
WORKDIR /app
|
|
COPY . .
|
|
# compliance-agent depends on the private firmwerk git repo (platform/firmwerk). Authenticate
|
|
# the fetch with a PAT passed as a BuildKit secret (never baked into a layer).
|
|
# Build with: DOCKER_BUILDKIT=1 docker build --secret id=git_token,env=PLATFORM_CI_TOKEN ...
|
|
RUN --mount=type=secret,id=git_token \
|
|
if [ -s /run/secrets/git_token ]; then \
|
|
git config --global \
|
|
url."https://platform-ci:$(cat /run/secrets/git_token)@git.breakpilot.com/".insteadOf \
|
|
"ssh://git@git.breakpilot.com:22222/"; \
|
|
fi && \
|
|
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release -p compliance-agent
|
|
|
|
# A throwaway stage that packs a real nix store (store paths + the validity DB)
|
|
# into a compressed bootstrap tarball. Only the tarball is copied into the final
|
|
# image, so we don't carry a raw /nix copy layer.
|
|
FROM nixos/nix:latest AS nixseed
|
|
RUN tar -C / -czf /nix-bootstrap.tar.gz nix
|
|
|
|
FROM debian:bookworm-slim
|
|
RUN apt-get update && apt-get install -y ca-certificates libssl3 git curl python3 python3-pip npm golang-go php-cli && rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Cargo (minimal, for cargo metadata / cargo audit / generate-lockfile)
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal
|
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
|
RUN cargo install cargo-audit
|
|
|
|
# Install Composer for PHP dependency resolution
|
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
|
|
|
# Install Bundler for Ruby dependency resolution
|
|
RUN apt-get update && apt-get install -y ruby && rm -rf /var/lib/apt/lists/* && gem install bundler
|
|
|
|
# Install syft for SBOM generation
|
|
RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
|
|
|
# Install gitleaks for secret detection
|
|
RUN curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.21.2/gitleaks_8.21.2_linux_x64.tar.gz \
|
|
| tar -xz -C /usr/local/bin gitleaks
|
|
|
|
# Install semgrep for static analysis
|
|
RUN pip3 install --break-system-packages semgrep
|
|
|
|
# Install ruff for Python linting
|
|
RUN pip3 install --break-system-packages ruff
|
|
|
|
# Real nix for the firmwerk reproducible-build firmware SBOM.
|
|
#
|
|
# nix-portable's proot fallback can't run here: user namespaces are blocked by
|
|
# the container's default seccomp/apparmor profile, and orca exposes no way to
|
|
# relax it. So ship a *real* nix and disable its build sandbox
|
|
# (`sandbox = false`) — a plain gcc/make firmware build needs no user namespace,
|
|
# so it runs fine under the locked-down profile with no proot involved.
|
|
#
|
|
# The store is shipped as a bootstrap tarball and seeded onto /nix at first
|
|
# start (see docker/agent-entrypoint.sh), so a persistent /nix volume survives
|
|
# redeploys. A missing/broken nix just falls back to the analysis-only SBOM.
|
|
COPY --from=nixseed /nix-bootstrap.tar.gz /opt/nix-bootstrap.tar.gz
|
|
ENV PATH="/nix/var/nix/profiles/default/bin:${PATH}"
|
|
RUN mkdir -p /etc/nix && printf '%s\n' \
|
|
'experimental-features = nix-command flakes' \
|
|
'sandbox = false' \
|
|
'build-users-group =' \
|
|
'substituters = https://cache.nixos.org' \
|
|
'trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' \
|
|
> /etc/nix/nix.conf
|
|
|
|
COPY --from=builder /app/target/release/compliance-agent /usr/local/bin/compliance-agent
|
|
COPY docker/agent-entrypoint.sh /usr/local/bin/agent-entrypoint.sh
|
|
# OSCAL control-catalog snapshot: lets control mapping run without the
|
|
# breakpilot-compliance backend. The entrypoint seeds it into
|
|
# BREAKPILOT_SNAPSHOT_DIR on start (copy-if-absent).
|
|
COPY --from=builder /app/compliance-agent/controls/snapshot /opt/breakpilot/oscal-snapshot
|
|
RUN chmod +x /usr/local/bin/agent-entrypoint.sh
|
|
|
|
# Copy documentation for the help chat assistant
|
|
COPY --from=builder /app/README.md /app/README.md
|
|
COPY --from=builder /app/docs /app/docs
|
|
ENV HELP_DOCS_PATH=/app
|
|
|
|
EXPOSE 3001 3002
|
|
|
|
# Seeds /nix (fresh volume) from the bootstrap tarball, then runs the agent.
|
|
ENTRYPOINT ["/usr/local/bin/agent-entrypoint.sh"]
|
|
|