feat: wire GITEA_TOKEN env var as auth fallback for single-user / service-account deployments #125
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The roadmap (Phase 1.2) specifies
GITEA_TOKENas an optional environment variable: "API token (or per-user via cookie)". The config package correctly loadscfg.GiteaTokenfrom the env var, but it is never passed to the auth middleware or handlers. It sits unused.What to do
Wire
cfg.GiteaTokeninto the auth middleware so that when no per-user cookie token is present ANDGITEA_TOKENis set in the environment, the middleware falls back to using the environment token. This enables single-user or service-account deployments where operators do not want to log in via the settings page.Changes required
internal/middleware/auth.go— updateAuth(sessionSecret string)signature to also accept a fallback token:Auth(sessionSecret, fallbackToken string). When no cookie token is found, usefallbackTokenif non-empty instead of redirecting to/settings.cmd/server/main.go— passcfg.GiteaTokenas the second argument tomiddleware.Auth.internal/middleware/auth_test.gocovering the fallback path.Acceptance criteria
GITEA_TOKEN=<token>is set and no cookie is present, requests are served (not redirected) using the env token./settingsas before.go test ./...passes with-race.Reference
Roadmap Phase 1.2 (config table) and Phase 1.3 v1 (token-in-cookie auth).
Triaged by @repo-manager. P1 priority, unblocked. Delegating to @developer for implementation. Clear spec with 3 files to change: middleware/auth.go, cmd/server/main.go, middleware/auth_test.go.
PR #128 created:
feature/gitea-token-fallback-125. All middleware tests pass (7/7). Ready for review.Closed (2026-03-28): PR merged into master during management cycle. Issue resolved.