From fbc1b6a33dd23a8e40ccf3d7534a065281c17cdf Mon Sep 17 00:00:00 2001 From: rock Date: Mon, 26 Oct 2026 23:17:03 -0700 Subject: [PATCH] feat(iam): manage the Forgejo OAuth login source from a script Forgejo keeps login sources in its database and exposes no REST endpoint for them, so neither GitOps nor `tea` (whose admin command only manages users) can set them. The in-pod CLI is the only supported writer. This script wraps `gitea admin auth update-oauth` so the rename from the Authentik-era label to `zitadel` is repeatable instead of a one-off command in a shell history. Note in the header: the source name is both the button label and the callback path, so ZITADEL must have both redirect URIs registered before a rename. --- scripts/iam/forgejo-oauth-source.sh | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 scripts/iam/forgejo-oauth-source.sh diff --git a/scripts/iam/forgejo-oauth-source.sh b/scripts/iam/forgejo-oauth-source.sh new file mode 100755 index 0000000..a90de5e --- /dev/null +++ b/scripts/iam/forgejo-oauth-source.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# forgejo-oauth-source.sh — keep the Forgejo OAuth login source aligned with +# ZITADEL. +# +# Forgejo stores login sources in its database, not in GitOps, and its REST API +# does not expose them. `tea` has no auth-source command either (tea admin only +# manages users), so the supported writer is the in-pod CLI: +# gitea admin auth update-oauth +# +# The source name is the label on the "Sign in with ..." button AND the callback +# path (/user/oauth2//callback), so a rename changes the registered +# redirect URI. Register both spellings in ZITADEL (zitadel-provision.py does) +# before renaming. +# +# Usage: +# scripts/iam/forgejo-oauth-source.sh status +# scripts/iam/forgejo-oauth-source.sh rename zitadel +set -euo pipefail + +NS="${FORGEJO_NAMESPACE:-cicd}" +SEL="${FORGEJO_SELECTOR:-app.kubernetes.io/name=forgejo}" + +pod() { + kubectl -n "$NS" get pods -l "$SEL" -o jsonpath='{.items[0].metadata.name}' 2>/dev/null \ + || kubectl -n "$NS" get pods -o name | grep -m1 forgejo-gitea | cut -d/ -f2 +} + +run() { kubectl -n "$NS" exec "$(pod)" -c gitea -- gitea admin auth "$@"; } + +case "${1:-status}" in + status) run list ;; + rename) + name="${2:?usage: $0 rename }" + run update-oauth --id 1 --name "$name" + run list + ;; + *) echo "usage: $0 [status|rename ]" >&2; exit 2 ;; +esac