registry(auth): require auth for image pulls (audit F11)
Forgejo 16 mints an anonymous ("ghost user") registry token on /v2/token and
grants it Read on every package regardless of repo visibility, so all 18 app
images were world-downloadable — including images of private repos
(siriusdevops-site, phs-site, sirius-growth-*, sgs-leadgen).
* FORGEJO__service__REQUIRE_SIGNIN_VIEW=true: /v2/token answers UNAUTHORIZED
to anonymous clients, anonymous manifests get 401. This is the documented
switch in routers/api/packages/container (Authenticate) and
services/context/package.go (determineAccessMode). Side effect: the Forgejo
web UI/API becomes login-only for anonymous visitors.
* imagePullSecrets: [forgejo-pull] on all 18 workloads that pull from the
registry (osint, piedmont, sirius-growth, siriusdevops). The
kubernetes.io/dockerconfigjson Secret is per-namespace and out of band
(never in git); docs/registry-pull-auth.md documents why, how to recreate
it, and the verification commands. No containerd-level credential.
This commit is contained in:
parent
cea26863ec
commit
bc942e2571
20 changed files with 169 additions and 0 deletions
|
|
@ -58,6 +58,17 @@ spec:
|
||||||
# Bot signup lockdown: admin-only account creation (web + API).
|
# Bot signup lockdown: admin-only account creation (web + API).
|
||||||
- name: FORGEJO__service__DISABLE_REGISTRATION
|
- name: FORGEJO__service__DISABLE_REGISTRATION
|
||||||
value: "true"
|
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.
|
||||||
|
- name: FORGEJO__service__REQUIRE_SIGNIN_VIEW
|
||||||
|
value: "true"
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: data
|
- name: data
|
||||||
mountPath: /data
|
mountPath: /data
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-app
|
app: osint-app
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-camera-service
|
app: osint-camera-service
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-ingester
|
app: osint-ingester
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-nats
|
app: osint-nats
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-news-scraper
|
app: osint-news-scraper
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-news-summarizer
|
app: osint-news-summarizer
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-db
|
app: osint-db
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: osint-titiler
|
app: osint-titiler
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: piedmont-contact
|
app: piedmont-contact
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: piedmont-site
|
app: piedmont-site
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sgs-leadgen-ncda
|
app: sgs-leadgen-ncda
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
kubernetes.io/hostname: siriussec
|
kubernetes.io/hostname: siriussec
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sgs-leadgen
|
app: sgs-leadgen
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
# local-path is a node-local volume: the pod must run where the PV is.
|
# local-path is a node-local volume: the pod must run where the PV is.
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sirius-growth-contact
|
app: sirius-growth-contact
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sirius-growth-blog
|
app: sirius-growth-blog
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sirius-growth-portal
|
app: sirius-growth-portal
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: sirius-growth-site
|
app: sirius-growth-site
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: siriusdevops-contact
|
app: siriusdevops-contact
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: siriusdevops-site
|
app: siriusdevops-site
|
||||||
spec:
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: forgejo-pull
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: dedicated
|
- key: dedicated
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
||||||
122
docs/registry-pull-auth.md
Normal file
122
docs/registry-pull-auth.md
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
# Registry pull authentication (Forgejo container registry)
|
||||||
|
|
||||||
|
Status: **enforced** since 2026-11-27 (audit finding F11). Every workload that pulls
|
||||||
|
`forgejo.siriusdevops.com/sirius/*` carries `imagePullSecrets: [forgejo-pull]`, and the
|
||||||
|
registry refuses to mint tokens for anonymous clients.
|
||||||
|
|
||||||
|
## What was wrong
|
||||||
|
|
||||||
|
Forgejo 16 (Gitea 1.22 lineage) grants anonymous callers the **ghost user** and then treats
|
||||||
|
that ghost as `perm.AccessModeRead` on *every* package — including packages of **private**
|
||||||
|
repos. Source: `services/context/package.go::determineAccessMode` (case 3: owner visibility
|
||||||
|
`public` → `Read` for `doer == nil`), reached from
|
||||||
|
`routers/api/packages/container/*::Authenticate`, which mints a ghost token *unless*
|
||||||
|
`setting.Service.RequireSignInView` is set.
|
||||||
|
|
||||||
|
Measured before the fix (2026-11-27T05:11Z): an unauthenticated `/v2/token` returned a JWT
|
||||||
|
with `{"UserID": -1, "Scope": ""}` and that token returned `200` for
|
||||||
|
`/v2/sirius/osint-dashboard/manifests/…`. `sirius/siriusdevops`, `sirius/websites` and
|
||||||
|
`sirius/sirius-growth` are **private** repos and their images (`siriusdevops-site`, `phs-site`,
|
||||||
|
`sirius-growth-*`, `sgs-leadgen`) were publicly pullable too — so "make the repo private" is
|
||||||
|
*not* a mitigation on this version.
|
||||||
|
|
||||||
|
## The switch
|
||||||
|
|
||||||
|
`apps/base/forgejo/deployment.yaml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: FORGEJO__service__REQUIRE_SIGNIN_VIEW
|
||||||
|
value: "true"
|
||||||
|
```
|
||||||
|
|
||||||
|
Effects:
|
||||||
|
|
||||||
|
* `/v2/token` → `401 {"errors":[{"code":"UNAUTHORIZED",...}]}` for an anonymous client, and
|
||||||
|
`/v2/<repo>/manifests/<ref>` → `401` with a `WWW-Authenticate` challenge.
|
||||||
|
* 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.
|
||||||
|
* CI pushes are unaffected — workflows authenticate with `REGISTRY_TOKEN` (`write:package`).
|
||||||
|
|
||||||
|
## The credential
|
||||||
|
|
||||||
|
A dedicated non-admin user, `registry-reader` (visibility `limited`, `read:package` scope).
|
||||||
|
Its token lives **only** in the Kubernetes Secrets — never in git, never in a manifest.
|
||||||
|
|
||||||
|
Secret `forgejo-pull` (`kubernetes.io/dockerconfigjson`) must exist in every namespace whose
|
||||||
|
pods pull from the registry. Currently: `osint`, `piedmont`, `sirius-growth`, `siriusdevops`.
|
||||||
|
|
||||||
|
These Secrets are **out of band** (Flux does not manage Secrets in this cluster). A namespace
|
||||||
|
that is recreated by a Flux prune loses its copy — recreate it before the pods reschedule.
|
||||||
|
|
||||||
|
### Recreate it
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. token (mint a fresh one; never echo it)
|
||||||
|
kubectl -n forgejo exec deploy/forgejo -- su-exec git forgejo admin user generate-access-token \
|
||||||
|
--username registry-reader --raw --scopes read:package --token-name pull-k8s-$(date +%Y%m%d)
|
||||||
|
# (if the user itself is gone: POST /api/v1/admin/users with visibility "limited",
|
||||||
|
# then the command above; the password is only needed for interactive login and is
|
||||||
|
# never used by containerd.)
|
||||||
|
|
||||||
|
# 2. build the dockerconfigjson without printing it
|
||||||
|
umask 077
|
||||||
|
read -r -s -p 'token: ' RT; echo
|
||||||
|
python3 - "$RT" > /tmp/dc.json <<'PY'
|
||||||
|
import base64, json, sys
|
||||||
|
t = sys.argv[1].strip()
|
||||||
|
print(json.dumps({"auths": {"forgejo.siriusdevops.com": {
|
||||||
|
"username": "registry-reader", "password": t,
|
||||||
|
"auth": base64.b64encode(f"registry-reader:{t}".encode()).decode()}}}))
|
||||||
|
PY
|
||||||
|
|
||||||
|
# 3. one Secret per namespace
|
||||||
|
for ns in osint piedmont sirius-growth siriusdevops; do
|
||||||
|
kubectl create secret generic forgejo-pull -n "$ns" \
|
||||||
|
--type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=/tmp/dc.json \
|
||||||
|
--dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
done
|
||||||
|
shred -u /tmp/dc.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a namespace
|
||||||
|
|
||||||
|
`kubectl create secret` as above **and** `imagePullSecrets: [{name: forgejo-pull}]` in the
|
||||||
|
pod spec (or on the namespace's ServiceAccount) — do not add the secret to workloads that do
|
||||||
|
not pull from this registry.
|
||||||
|
|
||||||
|
## Why not a node-level credential
|
||||||
|
|
||||||
|
Containerd is deliberately left with no registry credential
|
||||||
|
(`config_path = ""` in `/etc/containerd/config.toml`, no `/etc/containerd/certs.d/*/hosts.toml`
|
||||||
|
on any node). A node-level token would be one credential shared by every workload on every
|
||||||
|
node; `imagePullSecrets` scopes the read grant to the namespace that needs it and keeps the
|
||||||
|
audit trail per-pod.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# anonymous must be refused
|
||||||
|
curl -s -o /dev/null -w '%{http_code}\n' \
|
||||||
|
'https://forgejo.siriusdevops.com/v2/token?service=container_registry&scope=repository:sirius/osint-dashboard:pull' # 401
|
||||||
|
curl -s -o /dev/null -w '%{http_code}\n' \
|
||||||
|
https://forgejo.siriusdevops.com/v2/sirius/osint-dashboard/manifests/amd64-54897b49bc57 # 401
|
||||||
|
|
||||||
|
# authenticated two-stage flow must work
|
||||||
|
T=$(curl -s -u "registry-reader:$RT" \
|
||||||
|
'https://forgejo.siriusdevops.com/v2/token?service=container_registry&scope=repository:sirius/osint-dashboard:pull' \
|
||||||
|
| python3 -c 'import json,sys;print(json.load(sys.stdin)["token"])')
|
||||||
|
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $T" \
|
||||||
|
-H 'Accept: application/vnd.oci.image.index.v1+json' \
|
||||||
|
https://forgejo.siriusdevops.com/v2/sirius/osint-dashboard/manifests/amd64-54897b49bc57 # 200
|
||||||
|
|
||||||
|
# no global credential on the nodes
|
||||||
|
for h in siriussec rpi; do ssh "$h" 'grep -E "^\s*config_path" /etc/containerd/config.toml; find /etc/containerd -name hosts.toml'; done
|
||||||
|
```
|
||||||
|
|
||||||
|
A pod that pulls without the secret now fails with
|
||||||
|
`failed to authorize: ... 401 Unauthorized` → `ErrImagePull`, which is the intended negative
|
||||||
|
control.
|
||||||
Loading…
Reference in a new issue