From c6b56221133dba00803abdbd07de032a221a5e11 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Sun, 12 Jul 2026 20:25:39 +0000 Subject: [PATCH] fix(ci): authenticate tramiton-core fetch in the agent image build (main deploys) (#143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PR `check` job authenticates the private tramiton-core git fetch, but the main-branch **`deploy-agent`** job builds `Dockerfile.agent` where cargo also fetches tramiton-core — inside the image build, with no credentials — so **agent image builds on main fail**. Fix: inject the PAT as a **BuildKit secret** (never baked into an image layer). - `Dockerfile.agent`: `RUN --mount=type=secret,id=tramiton_token …` applies the same `https`-insteadOf rewrite + `CARGO_NET_GIT_FETCH_WITH_CLI=true` before `cargo build`. - `deploy-agent`: `DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN …`, reusing the existing `TRAMITON_FETCH_TOKEN` secret. Only the agent image depends on tramiton-core (dashboard/mcp/docs unaffected). **Self-tests on merge** — changing `Dockerfile.agent` makes `detect-changes` run `deploy-agent`. Note: couldn't fully run the image build locally (no PAT value on hand + no `.dockerignore` so the context is large), but this mirrors the working PR-stage auth and uses standard BuildKit secret injection. Assumes the deploy runner's Docker daemon supports BuildKit (docker:27-cli → yes). --------- Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Reviewed-on: https://gitea.meghsakha.com/sharang/compliance-scanner-agent/pulls/143 --- .gitea/workflows/ci.yml | 7 ++++++- Dockerfile.agent | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index aba5c09..d8ec3a1 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -191,13 +191,18 @@ jobs: image: docker:27-cli steps: - name: Build, push and trigger orca redeploy + env: + # PAT for fetching the private tramiton-core git dependency during the + # image build (injected as a BuildKit secret, never baked into a layer). + TRAMITON_FETCH_TOKEN: ${{ secrets.TRAMITON_FETCH_TOKEN }} run: | apk add --no-cache git curl openssl git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD IMAGE=registry.meghsakha.com/compliance-agent echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin - docker build -f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" . + DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \ + -f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" . docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}" PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy agent"}}' "${GITHUB_SHA}") SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}') diff --git a/Dockerfile.agent b/Dockerfile.agent index 891a6b0..adc4a9d 100644 --- a/Dockerfile.agent +++ b/Dockerfile.agent @@ -2,7 +2,16 @@ FROM rust:1.94-bookworm AS builder WORKDIR /app COPY . . -RUN cargo build --release -p compliance-agent +# compliance-agent depends on the private tramiton-core git repo. 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=tramiton_token,env=TRAMITON_FETCH_TOKEN ... +RUN --mount=type=secret,id=tramiton_token \ + if [ -s /run/secrets/tramiton_token ]; then \ + git config --global \ + url."https://sharang:$(cat /run/secrets/tramiton_token)@gitea.meghsakha.com/".insteadOf \ + "ssh://git@gitea.meghsakha.com:22222/"; \ + fi && \ + CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release -p compliance-agent 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/*