Phase 3+4 of default-deny ingress plan. Replaces the `protected = bool` (default
false → unprotected) variable in `modules/kubernetes/ingress_factory` with
`auth = string` enum (default "required" → fail-closed). Touches every
ingress_factory caller so the audit decision is recorded explicitly in code.
ingress_factory (Phase 3):
- `auth = "required"`: standard Authentik forward-auth (the legacy
`protected = true` semantic).
- `auth = "public"`: forward-auth via the new `authentik-forward-auth-public`
middleware → dedicated public outpost → guest auto-bind. Logged-in users
keep their real identity.
- `auth = "none"`: no Authentik middleware. For Anubis-fronted content, native
client APIs (Git, /v2/, WebDAV), webhook receivers, the Authentik outpost
itself.
- `effective_anti_ai` default flips ON only when `auth = "none"` (auth-gated
ingresses don't need anti-AI noise; the auth flow already discourages bots).
Audit pass (Phase 4) across 96 ingress_factory call sites:
- 49 explicit `protected = true` → `auth = "required"`
- 8 explicit `protected = false` → `auth = "none"` (5) or `auth = "public"` (3)
- 64 previously-default (no protected line) → `auth = "required"` ADDED, then
reviewed individually:
* 9 Anubis-fronted (blog, www, kms, travel, f1, cyberchef, jsoncrack,
homepage, wrongmove UI, privatebin) → `auth = "none"`
* 22 native-client / programmatic surfaces (Forgejo Git+/v2/, webhook
handler, claude-memory MCP, Nextcloud WebDAV, Matrix, Vault CLI/OIDC,
xray VPN, ntfy, woodpecker webhooks, n8n triggers, ntfy push, dawarich
location ingestion, immich frame kiosk, headscale CP, send anonymous
drops, rybbit beacon, vaultwarden API, Authentik UI itself + outposts) →
`auth = "none"`
* Remaining ~33 → `auth = "required"` confirmed (admin tools, internal
UIs, services without app-level auth)
- Smoke-test promotions to `auth = "public"`: fire-planner public UI,
k8s-portal API, insta2spotify callback.
Three call sites in wrapper modules (`stacks/freedify/factory/`,
`stacks/reverse-proxy/modules/reverse_proxy/`) keep their internal `protected`
bool — they translate to `auth` internally, out of scope for this rename.
Behavior change: previously-default ingresses now fail closed (require
Authentik login) unless explicitly flipped to `auth = "none"` or
`auth = "public"`. This is the audit goal — no more accidentally-unprotected
surfaces. Sites that were intentionally public (Anubis content, native APIs,
webhooks) are now explicitly recorded as `auth = "none"`.
Drive-by: `modules/create-vm/main.tf` picked up cosmetic alignment via
`terraform fmt -recursive` during the audit. Behavior-neutral.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
218 lines
6.7 KiB
HCL
218 lines
6.7 KiB
HCL
variable "tls_secret_name" {
|
|
type = string
|
|
sensitive = true
|
|
}
|
|
variable "nfs_server" { type = string }
|
|
|
|
resource "kubernetes_namespace" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
labels = {
|
|
"istio-injection" : "disabled"
|
|
tier = local.tiers.edge
|
|
}
|
|
}
|
|
lifecycle {
|
|
# KYVERNO_LIFECYCLE_V1: goldilocks-vpa-auto-mode ClusterPolicy stamps this label on every namespace
|
|
ignore_changes = [metadata[0].labels["goldilocks.fairwinds.com/vpa-update-mode"]]
|
|
}
|
|
}
|
|
|
|
module "tls_secret" {
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
tls_secret_name = var.tls_secret_name
|
|
}
|
|
|
|
resource "kubernetes_persistent_volume_claim" "data_encrypted" {
|
|
wait_until_bound = false
|
|
metadata {
|
|
name = "forgejo-data-encrypted"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
annotations = {
|
|
"resize.topolvm.io/threshold" = "80%"
|
|
"resize.topolvm.io/increase" = "50%"
|
|
"resize.topolvm.io/storage_limit" = "50Gi"
|
|
}
|
|
}
|
|
spec {
|
|
access_modes = ["ReadWriteOnce"]
|
|
storage_class_name = "proxmox-lvm-encrypted"
|
|
resources {
|
|
requests = {
|
|
storage = "30Gi"
|
|
}
|
|
}
|
|
}
|
|
lifecycle {
|
|
# pvc-autoresizer expands this PVC up to storage_limit; ignore drift on
|
|
# requests.storage. To bump the floor manually: temporarily remove this
|
|
# block, apply the new size, re-add the block, apply again.
|
|
ignore_changes = [spec[0].resources[0].requests]
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_deployment" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
labels = {
|
|
app = "forgejo"
|
|
tier = local.tiers.edge
|
|
}
|
|
}
|
|
spec {
|
|
replicas = 1
|
|
strategy {
|
|
type = "Recreate"
|
|
}
|
|
selector {
|
|
match_labels = {
|
|
app = "forgejo"
|
|
}
|
|
}
|
|
template {
|
|
metadata {
|
|
labels = {
|
|
app = "forgejo"
|
|
}
|
|
}
|
|
spec {
|
|
# fsGroup chowns the mounted PVC to GID 1000 (the forgejo user) on
|
|
# mount. Without this, /data is owned by root and the
|
|
# `[packages].CHUNKED_UPLOAD_PATH` default at /data/tmp is not
|
|
# writable, crashlooping the pod when packages is enabled. Pre-23-day
|
|
# Forgejo ran without packages on so this never surfaced.
|
|
security_context {
|
|
fs_group = 1000
|
|
}
|
|
container {
|
|
name = "forgejo"
|
|
image = "codeberg.org/forgejo/forgejo:11"
|
|
env {
|
|
name = "USER_UID"
|
|
value = 1000
|
|
}
|
|
env {
|
|
name = "USER_GID"
|
|
value = 1000
|
|
}
|
|
# Root URL for OAuth2 redirect callbacks
|
|
env {
|
|
name = "FORGEJO__server__ROOT_URL"
|
|
value = "https://forgejo.viktorbarzin.me"
|
|
}
|
|
# Disable local registration — only allow OAuth2 (Authentik)
|
|
env {
|
|
name = "FORGEJO__service__DISABLE_REGISTRATION"
|
|
value = "false"
|
|
}
|
|
env {
|
|
name = "FORGEJO__service__ALLOW_ONLY_EXTERNAL_REGISTRATION"
|
|
value = "true"
|
|
}
|
|
env {
|
|
name = "FORGEJO__openid__ENABLE_OPENID_SIGNIN"
|
|
value = "false"
|
|
}
|
|
# Allow webhook delivery to internal k8s services AND to the public
|
|
# ingress hostnames Forgejo's own webhooks point to (ci.viktorbarzin.me
|
|
# for Woodpecker pipelines).
|
|
env {
|
|
name = "FORGEJO__webhook__ALLOWED_HOST_LIST"
|
|
value = "*.svc.cluster.local,ci.viktorbarzin.me,*.viktorbarzin.me"
|
|
}
|
|
# Default DELIVER_TIMEOUT is 5s — too tight for the Cloudflare-tunnel
|
|
# round-trip on first request after pod restart (cold TLS handshake
|
|
# can hit 6-8s). 30s comfortably covers retries.
|
|
env {
|
|
name = "FORGEJO__webhook__DELIVER_TIMEOUT"
|
|
value = "30"
|
|
}
|
|
# OCI registry (container packages). Default-on in Forgejo v11 but
|
|
# explicit so it can't be silently disabled by an upstream config
|
|
# change. CHUNKED_UPLOAD_PATH defaults to `data/tmp/package-upload`
|
|
# under Forgejo's AppDataPath (resolves to a writable subdir of
|
|
# /data/gitea/) — overriding to /data/tmp directly hits a perms
|
|
# issue because /data is the volume mount root and is not chowned
|
|
# to the forgejo user.
|
|
env {
|
|
name = "FORGEJO__packages__ENABLED"
|
|
value = "true"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/data"
|
|
}
|
|
resources {
|
|
requests = {
|
|
cpu = "15m"
|
|
memory = "1Gi"
|
|
}
|
|
limits = {
|
|
memory = "1Gi"
|
|
}
|
|
}
|
|
port {
|
|
name = "http"
|
|
container_port = 3000
|
|
protocol = "TCP"
|
|
}
|
|
}
|
|
volume {
|
|
name = "data"
|
|
persistent_volume_claim {
|
|
claim_name = kubernetes_persistent_volume_claim.data_encrypted.metadata[0].name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
lifecycle {
|
|
# KYVERNO_LIFECYCLE_V1: Kyverno admission webhook mutates dns_config with ndots=2
|
|
ignore_changes = [spec[0].template[0].spec[0].dns_config]
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_service" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
labels = {
|
|
"app" = "forgejo"
|
|
}
|
|
}
|
|
|
|
spec {
|
|
selector = {
|
|
app = "forgejo"
|
|
}
|
|
port {
|
|
port = 80
|
|
target_port = 3000
|
|
}
|
|
}
|
|
}
|
|
module "ingress" {
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
# Git + OCI registry (/v2/) — native clients (git, docker/podman) use HTTP
|
|
# basic-auth / bearer tokens, NOT browser sessions. Forward-auth would 302
|
|
# them into a redirect they can't follow.
|
|
auth = "none"
|
|
dns_type = "non-proxied"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
name = "forgejo"
|
|
tls_secret_name = var.tls_secret_name
|
|
# OCI registry pushes ship full image layer blobs in one request; default
|
|
# Traefik buffering chokes on anything past a few hundred MB.
|
|
max_body_size = "5g"
|
|
extra_annotations = {
|
|
"gethomepage.dev/enabled" = "true"
|
|
"gethomepage.dev/name" = "Forgejo"
|
|
"gethomepage.dev/description" = "Git hosting"
|
|
"gethomepage.dev/icon" = "forgejo.png"
|
|
"gethomepage.dev/group" = "Development & CI"
|
|
"gethomepage.dev/pod-selector" = ""
|
|
"uptime.viktorbarzin.me/external-monitor-path" = "/api/healthz"
|
|
}
|
|
}
|