From 8eae5b40cf1b04e9f012b96d402bb45b01f5bb0e Mon Sep 17 00:00:00 2001 From: Rapha Date: Thu, 26 Nov 2026 12:01:48 +0100 Subject: [PATCH] chore: remove Gotenberg basic auth on SKE The NetworkPolicy already lets only the backend reach Gotenberg, so the credentials add nothing. Drop --api-enable-basic-auth, Gotenberg's env Secret and the backend's GOTENBERG_API_BASIC_AUTH_* vars. Local dev can no longer use the remote Gotenberg, so compose.yml gets a gotenberg service that the backend's predev script starts. Co-Authored-By: Claude Opus 5.5 --- .../workflows/backend-deploy-stackit-ske.yml | 1 - README_DEV.md | 6 ++++- apps/backend/.env.sample | 2 -- apps/backend/package.json | 3 ++- apps/backend/src/config.ts | 10 -------- .../services/document-extraction-service.ts | 4 ---- compose.yml | 21 ++++++++++++++++ infra/k8s/base/gotenberg/deployment.yaml | 9 +++---- infra/k8s/deploy/render-and-apply.sh | 10 +++----- infra/k8s/deploy/sync-env-secrets.sh | 24 +++++++------------ 10 files changed, 42 insertions(+), 48 deletions(-) diff --git a/.github/workflows/backend-deploy-stackit-ske.yml b/.github/workflows/backend-deploy-stackit-ske.yml index 5c2679034..30418ef44 100644 --- a/.github/workflows/backend-deploy-stackit-ske.yml +++ b/.github/workflows/backend-deploy-stackit-ske.yml @@ -165,7 +165,6 @@ jobs: OVERLAY: ${{ steps.target.outputs.overlay }} DIGEST: ${{ needs.build.outputs.digest }} BACKEND_SECRET: ${{ steps.secrets.outputs.backend }} - GOTENBERG_SECRET: ${{ steps.secrets.outputs.gotenberg }} run: bash infra/k8s/deploy/render-and-apply.sh - name: Wait for rollout ⏳ diff --git a/README_DEV.md b/README_DEV.md index a75ecacb3..963b61159 100644 --- a/README_DEV.md +++ b/README_DEV.md @@ -142,7 +142,7 @@ You'll need accounts and API keys for: #### Required for Backend - **Mistral AI**: API key from https://console.mistral.ai/ -- **Gotenberg**: URL and credentials for Gotenberg service (PDF conversion) +- **Gotenberg**: runs locally in Docker, no account needed. Set `GOTENBERG_URL=http://localhost:3001` (see [Development](#-development)) - **Sentry**: DSN from https://sentry.io/ (for error monitoring) - **Redis**: Connection string (for the API rate limiting queue) @@ -242,6 +242,10 @@ No environment configuration needed. This is a static page displayed during main ## 💻 Development +The backend's `npm run dev` (also via `turbo dev`) first starts Gotenberg in Docker on +`http://localhost:3001` (`compose.yml`), so Docker must be running. Stop it with +`docker compose stop gotenberg`. + **Using Turborepo (recommended):** ```bash diff --git a/apps/backend/.env.sample b/apps/backend/.env.sample index c7f090dee..58328ff79 100644 --- a/apps/backend/.env.sample +++ b/apps/backend/.env.sample @@ -36,8 +36,6 @@ SENTRY_ORG=... SENTRY_PROJECT=... # Gotenberg -GOTENBERG_API_BASIC_AUTH_USERNAME=... -GOTENBERG_API_BASIC_AUTH_PASSWORD=... GOTENBERG_URL=... # Feature Flags diff --git a/apps/backend/package.json b/apps/backend/package.json index bb72a6299..dd8b967b6 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -33,7 +33,8 @@ "auth:rotate-passwords": "tsx supabase/scripts/rotate-user-passwords.ts", "auth:assess-inactive-users": "tsx supabase/scripts/process-inactive-users.ts -- --dry-run", "auth:notify-inactive-users": "tsx supabase/scripts/process-inactive-users.ts -- --skip-deletions", - "auth:delete-inactive-users": "tsx supabase/scripts/process-inactive-users.ts -- --deletions-only" + "auth:delete-inactive-users": "tsx supabase/scripts/process-inactive-users.ts -- --deletions-only", + "predev": "docker compose -f ../../compose.yml up -d --quiet-pull gotenberg" }, "dependencies": { "@ai-sdk/mcp": "2.0.91", diff --git a/apps/backend/src/config.ts b/apps/backend/src/config.ts index 9d339a8d9..a8a369238 100644 --- a/apps/backend/src/config.ts +++ b/apps/backend/src/config.ts @@ -23,8 +23,6 @@ export interface Config { defaultDocumentProcessingModel: string; sentryDsn: string; gotenbergUrl: string; - gotenbergApiBasicAuthUsername: string; - gotenbergApiBasicAuthPassword: string; presencePenalty: number; frequencyPenalty: number; featureFlagMcpParlaAllowed: boolean; @@ -117,12 +115,6 @@ export function verifyConfig(): void { if (!process.env.GOTENBERG_URL && !process.env.CI) { throw new Error("GOTENBERG_URL must be defined"); } - if (!process.env.GOTENBERG_API_BASIC_AUTH_USERNAME && !process.env.CI) { - throw new Error("GOTENBERG_API_BASIC_AUTH_USERNAME must be defined"); - } - if (!process.env.GOTENBERG_API_BASIC_AUTH_PASSWORD && !process.env.CI) { - throw new Error("GOTENBERG_API_BASIC_AUTH_PASSWORD must be defined"); - } if ( process.env.FEATURE_FLAG_MCP_PARLA_ALLOWED === "true" && !process.env.MCP_PARLA_URL @@ -210,8 +202,6 @@ export const config: Config = { defaultDocumentProcessingModel: process.env.DEFAULT_DOCUMENT_PROCESSING_MODEL, sentryDsn: process.env.SENTRY_DSN, gotenbergUrl: process.env.GOTENBERG_URL, - gotenbergApiBasicAuthUsername: process.env.GOTENBERG_API_BASIC_AUTH_USERNAME, - gotenbergApiBasicAuthPassword: process.env.GOTENBERG_API_BASIC_AUTH_PASSWORD, presencePenalty: parseFloat(process.env.PRESENCE_PENALTY || "0"), frequencyPenalty: parseFloat(process.env.FREQUENCY_PENALTY || "0"), featureFlagMcpParlaAllowed: diff --git a/apps/backend/src/services/document-extraction-service.ts b/apps/backend/src/services/document-extraction-service.ts index 33539bd4f..f2c230cd0 100644 --- a/apps/backend/src/services/document-extraction-service.ts +++ b/apps/backend/src/services/document-extraction-service.ts @@ -206,14 +206,10 @@ export class WordDocumentExtractionService { "/forms/libreoffice/convert", config.gotenbergUrl, ).toString(); - const authHeader = `Basic ${Buffer.from( - `${config.gotenbergApiBasicAuthUsername}:${config.gotenbergApiBasicAuthPassword}`, - ).toString("base64")}`; const res = await fetch(endpoint, { method: "POST", headers: { - Authorization: authHeader, Accept: "application/pdf", }, body: form, diff --git a/compose.yml b/compose.yml index 04dd74bd7..cebac4219 100644 --- a/compose.yml +++ b/compose.yml @@ -25,6 +25,10 @@ services: # can keep localhost for `turbo dev`. A real env var beats the mounted .env environment: SUPABASE_URL: http://host.docker.internal:54321 + GOTENBERG_URL: http://gotenberg:3000 + depends_on: + gotenberg: + condition: service_healthy # Liveness probe. Using fetch since the slim image ships no curl/wget. healthcheck: test: @@ -40,3 +44,20 @@ services: start_period: 10s mem_limit: 2g cpus: 1 + + # Document → PDF conversion. `npm run dev` in apps/backend starts it on its own (predev). + gotenberg: + container_name: baergpt-gotenberg + # Keep in sync with infra/k8s/base/gotenberg/deployment.yaml. + image: gotenberg/gotenberg:8.37.0@sha256:f29984bd1e226bf1b93ba90af06000afa8b315853e99d27b9aaa41b93f15c769 + command: ["gotenberg", "--chromium-disable-routes"] + ports: + # 3000 is the backend's. Loopback only, as Gotenberg has no auth. + - "127.0.0.1:3001:3000" + healthcheck: + test: ["CMD", "curl", "-fsS", "http://localhost:3000/health"] + interval: 10s + timeout: 5s + retries: 18 + start_period: 10s + mem_limit: 2g diff --git a/infra/k8s/base/gotenberg/deployment.yaml b/infra/k8s/base/gotenberg/deployment.yaml index 5f7ce3046..e8ffe36b6 100644 --- a/infra/k8s/base/gotenberg/deployment.yaml +++ b/infra/k8s/base/gotenberg/deployment.yaml @@ -48,15 +48,12 @@ spec: drop: ["ALL"] # 8.37.0+: older LibreOffice has memory bugs in the DOCX import. image: gotenberg/gotenberg:8.37.0@sha256:f29984bd1e226bf1b93ba90af06000afa8b315853e99d27b9aaa41b93f15c769 - # The backend only uses the LibreOffice route. - args: ["gotenberg", "--api-enable-basic-auth", "--chromium-disable-routes"] + # The backend only uses the LibreOffice route. No basic auth: the NetworkPolicy lets + # only the backend reach Gotenberg. + args: ["gotenberg", "--chromium-disable-routes"] ports: - name: http containerPort: 3000 - envFrom: - # The deploy workflow replaces this with gotenberg-env-a or -b, filled from 1Password. - - secretRef: - name: gotenberg-env # GOTENBERG_API_BASIC_AUTH_USERNAME/PASSWORD volumeMounts: - name: tmp mountPath: /tmp diff --git a/infra/k8s/deploy/render-and-apply.sh b/infra/k8s/deploy/render-and-apply.sh index cbf439a57..f223d24fa 100755 --- a/infra/k8s/deploy/render-and-apply.sh +++ b/infra/k8s/deploy/render-and-apply.sh @@ -1,18 +1,17 @@ #!/usr/bin/env bash -# Renders an environment's overlay with this deploy's image and env Secrets, and applies it. +# Renders an environment's overlay with this deploy's image and env Secret, and applies it. # # The overlay is wrapped in a temporary kustomization, so the checked-out files stay unchanged. # Before applying, it records each Deployment's revision, so roll-back.sh can undo exactly what # this deploy changed. # -# Inputs: NAMESPACE, OVERLAY (path to infra/k8s/overlays/), IMAGE_NAME, DIGEST, -# BACKEND_SECRET, and GOTENBERG_SECRET (empty where the overlay has no Gotenberg). +# Inputs: NAMESPACE, OVERLAY (path to infra/k8s/overlays/), IMAGE_NAME, DIGEST and +# BACKEND_SECRET. # Writes to the current directory, for wait-for-rollout.sh and roll-back.sh: # rendered.yaml, applied.txt, deployments.txt, revisions-before.txt set -euo pipefail : "${NAMESPACE:?}" "${OVERLAY:?}" "${IMAGE_NAME:?}" "${DIGEST:?}" "${BACKEND_SECRET:?}" -GOTENBERG_SECRET=${GOTENBERG_SECRET:-} main() { kustomize_dir=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/render.XXXXXX") @@ -45,9 +44,6 @@ images: patches: EOF use_env_secret backend "$BACKEND_SECRET" >> "$dir/kustomization.yaml" - if [[ -n "$GOTENBERG_SECRET" ]]; then - use_env_secret gotenberg "$GOTENBERG_SECRET" >> "$dir/kustomization.yaml" - fi } # A patch that points the app's Deployment at the given env Secret. The `test` fails the diff --git a/infra/k8s/deploy/sync-env-secrets.sh b/infra/k8s/deploy/sync-env-secrets.sh index 204734c1b..29e4f7be8 100755 --- a/infra/k8s/deploy/sync-env-secrets.sh +++ b/infra/k8s/deploy/sync-env-secrets.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -# Writes an environment's env from its 1Password note into the app Secrets and reports which -# Secret each Deployment should use (GitHub step outputs `backend` and `gotenberg`). +# Writes an environment's env from its 1Password note into the backend Secret and reports which +# Secret the Deployment should use (GitHub step output `backend`). # -# Each app has two Secrets, -env-a and -env-b. A changed env goes into the one not +# The app has two Secrets, -env-a and -env-b. A changed env goes into the one not # in use, so the other keeps the previous env and `kubectl rollout undo` restores code and env # together. An unchanged env keeps the Secret in use, so the pods don't restart. # @@ -17,23 +17,18 @@ main() { trap 'rm -rf "$work_dir"' EXIT op read "$ENV_NOTE_REF" > "$work_dir/note.env" - split_note "$work_dir/note.env" "$work_dir/backend.env" "$work_dir/gotenberg.env" + backend_env_from_note "$work_dir/note.env" "$work_dir/backend.env" sync_app backend "$work_dir/backend.env" - # Sandbox uses staging's Gotenberg. - if [[ "$NAMESPACE" != "sandbox" ]]; then - sync_app gotenberg "$work_dir/gotenberg.env" - fi } # The backend gets every variable except the Cloud Foundry sizing keys in the same note. -# Gotenberg only reads its basic-auth credentials. The note is read again on every deploy, -# so a variable removed from it disappears from the Secret too. -split_note() { - local note=$1 backend_env=$2 gotenberg_env=$3 +# The note is read again on every deploy, so a variable removed from it disappears from the +# Secret too. +backend_env_from_note() { + local note=$1 backend_env=$2 local line key value : > "$backend_env" - : > "$gotenberg_env" while IFS= read -r line || [[ -n "$line" ]]; do line=${line%$'\r'} # tolerate a CRLF-edited note if is_blank_or_comment "$line"; then @@ -47,9 +42,6 @@ split_note() { CF_* | GOTENBERG_MEMORY) continue ;; esac echo "$key=$value" >> "$backend_env" - if [[ "$key" == GOTENBERG_API_BASIC_AUTH_* ]]; then - echo "$key=$value" >> "$gotenberg_env" - fi done < "$note" }