fix(forgejo): allow anonymous public-repo browsing, block anon registry tokens at CF edge

REQUIRE_SIGNIN_VIEW was the F11 mitigation for ghost-user /v2/token grants,
but it also forced every public repo to a login page. Move the guard to a
Cloudflare custom rule that blocks /v2/token unless the request carries
Basic auth, and turn public browsing back on.
This commit is contained in:
Lance Walters 2026-12-01 22:27:43 -05:00
commit b909456a3e
2 changed files with 37 additions and 21 deletions

View file

@ -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/<repo>/manifests/<ref>` → `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 <jwt>` 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 <jwt>` on `/v2/...`. Verified 2026-12-02 with
the `registry-reader` credential: token minted, `manifests/<ref>` → `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).