diff --git a/apps/base/forgejo/deployment.yaml b/apps/base/forgejo/deployment.yaml index 4f0cc1e..fe34eb8 100644 --- a/apps/base/forgejo/deployment.yaml +++ b/apps/base/forgejo/deployment.yaml @@ -58,17 +58,17 @@ spec: # Bot signup lockdown: admin-only account creation (web + API). - name: FORGEJO__service__DISABLE_REGISTRATION value: "true" - # Registry hardening (audit F11): Forgejo hands an anonymous - # ("ghost user") token to /v2/token and grants Read on every - # package, regardless of the owning repo's visibility, so all app - # images were world-downloadable. With REQUIRE_SIGNIN_VIEW the - # token endpoint answers UNAUTHORIZED to anonymous clients and - # containerd pulls need a dockerconfigjson secret per namespace - # (`forgejo-pull`, created out of band — docs/registry-pull-auth.md). - # Side effect: the Forgejo web UI/API is login-only for anonymous - # visitors, including the public repos. + # Public-repo browsing is ON. Audit F11 had turned this on because + # Forgejo issues anonymous ("ghost user") registry tokens at + # /v2/token with Read on every package, so with public browsing + # every app image was world-pullable. That coupling is now cut at + # the edge instead: a Cloudflare zone custom rule ("Block anonymous + # Forgejo registry tokens") blocks /v2/token unless the request + # carries Basic auth, so anonymous pulls get 403 while containerd + # (which sends its `forgejo-pull` dockerconfigjson credentials) + # still pulls. Re-check that rule before turning this back to true. - name: FORGEJO__service__REQUIRE_SIGNIN_VIEW - value: "true" + value: "false" volumeMounts: - name: data mountPath: /data diff --git a/docs/registry-pull-auth.md b/docs/registry-pull-auth.md index b9e4a20..fd04cee 100644 --- a/docs/registry-pull-auth.md +++ b/docs/registry-pull-auth.md @@ -1,8 +1,10 @@ # Registry pull authentication (Forgejo container registry) -Status: **enforced** since 2026-11-27 (audit finding F11). Every workload that pulls +Status: **enforced** since 2026-11-27 (audit finding F11), re-implemented at the edge on +2026-12-02 so public repos can be browsed anonymously again. Every workload that pulls `forgejo.siriusdevops.com/sirius/*` carries `imagePullSecrets: [forgejo-pull]`, and the -registry refuses to mint tokens for anonymous clients. +registry refuses to mint tokens for anonymous clients — now via a Cloudflare WAF rule rather +than `REQUIRE_SIGNIN_VIEW`. ## What was wrong @@ -22,25 +24,39 @@ with `{"UserID": -1, "Scope": ""}` and that token returned `200` for ## The switch -`apps/base/forgejo/deployment.yaml`: +`apps/base/forgejo/deployment.yaml` now runs with public browsing **on**: ```yaml - name: FORGEJO__service__REQUIRE_SIGNIN_VIEW - value: "true" + value: "false" +``` + +and the registry guard moved to the edge — Cloudflare zone `siriusdevops.com`, phase +`http_request_firewall_custom`, rule **"Block anonymous Forgejo registry tokens"**: + +``` +(http.host eq "forgejo.siriusdevops.com") and (starts_with(http.request.uri.path, "/v2/token")) +and (not any(http.request.headers["authorization"][*] contains "Basic")) ``` Effects: -* `/v2/token` → `401 {"errors":[{"code":"UNAUTHORIZED",...}]}` for an anonymous client, and - `/v2//manifests/` → `401` with a `WWW-Authenticate` challenge. +* Anonymous `/v2/token` → `403` from Cloudflare (never reaches Forgejo, so no ghost token is + minted). `/v2/` still answers the normal `401` challenge, so registry clients keep their + auth flow. * Authenticated callers (basic auth: username + access token) still get the two-stage flow: - `/v2/token` (returns a scoped JWT) → `Bearer ` on `/v2/...`. -* The **web UI and the REST API are login-only for anonymous visitors**. Public repos - (`homek8s`, `onionwire`, `osint-dashboard`, …) are no longer browsable or clonable without a - Forgejo account. This is deliberate: the instance is a dev/infra host, not a public code - forge; the public *sites* are served from the cluster, not from Forgejo. + `/v2/token` (returns a scoped JWT) → `Bearer ` on `/v2/...`. Verified 2026-12-02 with + the `registry-reader` credential: token minted, `manifests/` → `200`. +* Public repos (`homek8s`, `onionwire`, `osint-dashboard`, `gcloud-lab`, `netsec-agent`, …) are + browsable and clonable anonymously again; private repos still 404 for anonymous visitors. +* Package **metadata** (`/api/v1/packages/...` listing, tags) is still readable anonymously — + only token minting is blocked, so blobs stay protected. * CI pushes are unaffected — workflows authenticate with `REGISTRY_TOKEN` (`write:package`). +**Order matters when changing this:** the WAF rule must be live *before* (or at the same time +as) setting `REQUIRE_SIGNIN_VIEW=false`. Flipping the env var alone re-opens anonymous pulls of +every image, including those of private repos. + ## The credential A dedicated non-admin user, `registry-reader` (visibility `limited`, `read:package` scope).