2026-03-07 14:30:36 +00:00
|
|
|
variable "tls_secret_name" {
|
2026-03-14 08:51:45 +00:00
|
|
|
type = string
|
2026-03-07 14:30:36 +00:00
|
|
|
sensitive = true
|
|
|
|
|
}
|
[ci skip] Infrastructure hardening: security, monitoring, reliability, maintainability
Phase 1 - Critical Security:
- Netbox: move hardcoded DB/superuser passwords to variables
- MeshCentral: disable public registration, add Authentik auth
- Traefik: disable insecure API dashboard (api.insecure=false)
- Traefik: configure forwarded headers with Cloudflare trusted IPs
Phase 2 - Security Hardening:
- Add security headers middleware (HSTS, X-Frame-Options, nosniff, etc.)
- Add Kyverno pod security policies in audit mode (privileged, host
namespaces, SYS_ADMIN, trusted registries)
- Tighten rate limiting (avg=10, burst=50)
- Add Authentik protection to grampsweb
Phase 3 - Monitoring & Alerting:
- Add critical service alerts (PostgreSQL, MySQL, Redis, Headscale,
Authentik, Loki)
- Increase Loki retention from 7 to 30 days (720h)
- Add predictive PV filling alert (predict_linear)
- Re-enable Hackmd and Privatebin down alerts
Phase 4 - Reliability:
- Add resource requests/limits to Redis, DBaaS, Technitium, Headscale,
Vaultwarden, Uptime Kuma
- Increase Alloy DaemonSet memory to 512Mi/1Gi
Phase 6 - Maintainability:
- Extract duplicated tiers locals to terragrunt.hcl generate block
(removed from 67 stacks)
- Replace hardcoded NFS IP 10.0.10.15 with var.nfs_server (114
instances across 63 files)
- Replace hardcoded Redis/PostgreSQL/MySQL/Ollama/mail host references
with variables across ~35 stacks
- Migrate xray raw ingress resources to ingress_factory modules
2026-02-23 22:05:28 +00:00
|
|
|
variable "nfs_server" { type = string }
|
|
|
|
|
variable "postgresql_host" { type = string }
|
2026-02-24 23:02:33 +00:00
|
|
|
variable "woodpecker_forgejo_url" { type = string }
|
2026-02-22 21:30:25 +00:00
|
|
|
|
2026-03-14 17:15:48 +00:00
|
|
|
data "vault_kv_secret_v2" "secrets" {
|
|
|
|
|
mount = "secret"
|
|
|
|
|
name = "woodpecker"
|
|
|
|
|
}
|
|
|
|
|
|
add generic multi-user cluster onboarding system
Data-driven user onboarding: add a JSON entry to Vault KV k8s_users,
apply vault + platform + woodpecker stacks, and everything is auto-generated.
Vault stack: namespace creation, per-user Vault policies with secret isolation
via identity entities/aliases, K8s deployer roles, CI policy update.
Platform stack: domains field in k8s_users type, TLS secrets per user namespace,
user domains merged into Cloudflare DNS, user-roles ConfigMap mounted in portal.
Woodpecker stack: admin list auto-generated from k8s_users, WOODPECKER_OPEN=true.
K8s-portal: dual-track onboarding (general/namespace-owner), namespace-owner
dashboard with Vault/kubectl commands, setup script adds Vault+Terraform+Terragrunt,
contributing page with CI pipeline template, versioned image tags in CI pipeline.
New: stacks/_template/ with copyable stack template for namespace-owners.
2026-03-15 22:23:36 +00:00
|
|
|
data "vault_kv_secret_v2" "platform" {
|
|
|
|
|
mount = "secret"
|
|
|
|
|
name = "platform"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals {
|
|
|
|
|
k8s_users = jsondecode(data.vault_kv_secret_v2.platform.data["k8s_users"])
|
|
|
|
|
|
|
|
|
|
# Build admin list: existing admin + all namespace-owner usernames
|
|
|
|
|
woodpecker_admins = join(",", concat(
|
|
|
|
|
["ViktorBarzin"],
|
|
|
|
|
[for name, user in local.k8s_users : name if user.role == "namespace-owner"]
|
|
|
|
|
))
|
|
|
|
|
}
|
2026-02-22 21:30:25 +00:00
|
|
|
|
|
|
|
|
resource "kubernetes_namespace" "woodpecker" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "woodpecker"
|
|
|
|
|
labels = {
|
|
|
|
|
"resource-governance/custom-quota" = "true"
|
|
|
|
|
tier = local.tiers.edge
|
|
|
|
|
}
|
|
|
|
|
}
|
[infra] Suppress Goldilocks vpa-update-mode label drift on all namespaces [ci skip]
## Context
Wave 3B-continued: the Goldilocks VPA dashboard (stacks/vpa) runs a Kyverno
ClusterPolicy `goldilocks-vpa-auto-mode` that mutates every namespace with
`metadata.labels["goldilocks.fairwinds.com/vpa-update-mode"] = "off"`. This
is intentional — Terraform owns container resource limits, and Goldilocks
should only provide recommendations, never auto-update. The label is how
Goldilocks decides per-namespace whether to run its VPA in `off` mode.
Effect on Terraform: every `kubernetes_namespace` resource shows the label
as pending-removal (`-> null`) on every `scripts/tg plan`. Dawarich survey
2026-04-18 confirmed the drift. Cluster-side count: 88 namespaces carry the
label (`kubectl get ns -o json | jq ... | wc -l`). Every TF-managed namespace
is affected.
This commit brings the intentional admission drift under the same
`# KYVERNO_LIFECYCLE_V1` discoverability marker introduced in c9d221d5 for
the ndots dns_config pattern. The marker now stands generically for any
Kyverno admission-webhook drift suppression; the inline comment records
which specific policy stamps which specific field so future grep audits
show why each suppression exists.
## This change
107 `.tf` files touched — every stack's `resource "kubernetes_namespace"`
resource gets:
```hcl
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"]]
}
```
Injection was done with a brace-depth-tracking Python pass (`/tmp/add_goldilocks_ignore.py`):
match `^resource "kubernetes_namespace" ` → track `{` / `}` until the
outermost closing brace → insert the lifecycle block before the closing
brace. The script is idempotent (skips any file that already mentions
`goldilocks.fairwinds.com/vpa-update-mode`) so re-running is safe.
Vault stack picked up 2 namespaces in the same file (k8s-users produces
one, plus a second explicit ns) — confirmed via file diff (+8 lines).
## What is NOT in this change
- `stacks/trading-bot/main.tf` — entire file is `/* … */` commented out
(paused 2026-04-06 per user decision). Reverted after the script ran.
- `stacks/_template/main.tf.example` — per-stack skeleton, intentionally
minimal. User keeps it that way. Not touched by the script (file
has no real `resource "kubernetes_namespace"` — only a placeholder
comment).
- `.terraform/` copies (e.g. `stacks/metallb/.terraform/modules/...`) —
gitignored, won't commit; the live path was edited.
- `terraform fmt` cleanup of adjacent pre-existing alignment issues in
authentik, freedify, hermes-agent, nvidia, vault, meshcentral. Reverted
to keep the commit scoped to the Goldilocks sweep. Those files will
need a separate fmt-only commit or will be cleaned up on next real
apply to that stack.
## Verification
Dawarich (one of the hundred-plus touched stacks) showed the pattern
before and after:
```
$ cd stacks/dawarich && ../../scripts/tg plan
Before:
Plan: 0 to add, 2 to change, 0 to destroy.
# kubernetes_namespace.dawarich will be updated in-place
(goldilocks.fairwinds.com/vpa-update-mode -> null)
# module.tls_secret.kubernetes_secret.tls_secret will be updated in-place
(Kyverno generate.* labels — fixed in 8d94688d)
After:
No changes. Your infrastructure matches the configuration.
```
Injection count check:
```
$ rg -c 'KYVERNO_LIFECYCLE_V1: goldilocks-vpa-auto-mode' stacks/ | awk -F: '{s+=$2} END {print s}'
108
```
## Reproduce locally
1. `git pull`
2. Pick any stack: `cd stacks/<name> && ../../scripts/tg plan`
3. Expect: no drift on the namespace's goldilocks.fairwinds.com/vpa-update-mode label.
Closes: code-dwx
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 21:15:27 +00:00
|
|
|
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"]]
|
|
|
|
|
}
|
2026-02-22 21:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_resource_quota" "woodpecker" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "tier-quota"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
hard = {
|
|
|
|
|
"requests.cpu" = "16"
|
|
|
|
|
"requests.memory" = "16Gi"
|
resource quota review: fix OOM risks, close quota gaps, add HA protections
Phase 1 - OOM fixes:
- dashy: increase memory limit 512Mi→1Gi (was at 99% utilization)
- caretta DaemonSet: set explicit resources 300Mi/512Mi (was at 85-98%)
- mysql-operator: add Helm resource values 256Mi/512Mi, create namespace
with tier label (was at 92% of LimitRange default)
- prowlarr, flaresolverr, annas-archive-stacks: add explicit resources
(outgrowing 256Mi LimitRange defaults)
- real-estate-crawler celery: add resources 512Mi/3Gi (608Mi actual, no
explicit resources)
Phase 2 - Close quota gaps:
- nvidia, real-estate-crawler, trading-bot: remove custom-quota=true
labels so Kyverno generates tier-appropriate quotas
- descheduler: add tier=1-cluster label for proper classification
Phase 3 - Reduce excessive quotas:
- monitoring: limits.memory 240Gi→64Gi, limits.cpu 120→64
- woodpecker: limits.memory 128Gi→32Gi, limits.cpu 64→16
- GPU tier default: limits.memory 96Gi→32Gi, limits.cpu 48→16
Phase 4 - Kubelet protection:
- Add cpu: 200m to systemReserved and kubeReserved in kubelet template
Phase 5 - HA improvements:
- cloudflared: add topology spread (ScheduleAnyway) + PDB (maxUnavailable:1)
- grafana: add topology spread + PDB via Helm values
- crowdsec LAPI: add topology spread + PDB via Helm values
- authentik server: add topology spread via Helm values
- authentik worker: add topology spread + PDB via Helm values
2026-03-08 18:17:46 +00:00
|
|
|
"limits.memory" = "32Gi"
|
2026-02-22 21:30:25 +00:00
|
|
|
pods = "60"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "tls_secret" {
|
|
|
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
}
|
|
|
|
|
|
migrate consuming stacks to ESO + remove k8s-dashboard static token
Phase 9: ExternalSecret migration across 26 stacks:
Fully migrated (vault data source removed, ESO delivers secrets):
- speedtest, shadowsocks, wealthfolio, plotting-book, f1-stream, tandoor
- n8n, dawarich, diun, netbox, onlyoffice, tuya-bridge
- hackmd (ESO template for DB URL), health (ESO template for DB URL)
- trading-bot (ESO template for DATABASE_URL + 7 secret env vars)
- forgejo (removed unused vault data source)
Partially migrated (vault kept for plan-time, ESO added for runtime):
- immich, linkwarden, nextcloud, paperless-ngx (jsondecode for homepage)
- claude-memory, rybbit, url, webhook_handler (plan-time in locals/jobs)
- woodpecker, openclaw, resume (plan-time in helm values/jobs/modules)
17 stacks unchanged (all plan-time: homepage annotations, configmaps,
module inputs) — vault data source works with OIDC auth.
Phase 17a: Remove k8s-dashboard static admin token secret.
Users now get tokens via: vault write kubernetes/creds/dashboard-admin
2026-03-15 19:05:04 +00:00
|
|
|
resource "kubernetes_manifest" "external_secret" {
|
|
|
|
|
manifest = {
|
|
|
|
|
apiVersion = "external-secrets.io/v1beta1"
|
|
|
|
|
kind = "ExternalSecret"
|
|
|
|
|
metadata = {
|
|
|
|
|
name = "woodpecker-secrets"
|
|
|
|
|
namespace = "woodpecker"
|
|
|
|
|
}
|
|
|
|
|
spec = {
|
|
|
|
|
refreshInterval = "15m"
|
|
|
|
|
secretStoreRef = {
|
|
|
|
|
name = "vault-kv"
|
|
|
|
|
kind = "ClusterSecretStore"
|
|
|
|
|
}
|
|
|
|
|
target = {
|
|
|
|
|
name = "woodpecker-secrets"
|
|
|
|
|
}
|
|
|
|
|
dataFrom = [{
|
|
|
|
|
extract = {
|
|
|
|
|
key = "woodpecker"
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
depends_on = [kubernetes_namespace.woodpecker]
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# DB credentials from Vault database engine (rotated every 24h)
|
2026-03-17 07:39:29 +00:00
|
|
|
# ExternalSecret provides WOODPECKER_DATABASE_DATASOURCE injected via
|
|
|
|
|
# server.extraSecretNamesForEnvFrom — auto-updates when password rotates
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
resource "kubernetes_manifest" "db_external_secret" {
|
2026-03-17 07:39:29 +00:00
|
|
|
field_manager {
|
|
|
|
|
force_conflicts = true
|
|
|
|
|
}
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
manifest = {
|
|
|
|
|
apiVersion = "external-secrets.io/v1beta1"
|
|
|
|
|
kind = "ExternalSecret"
|
|
|
|
|
metadata = {
|
|
|
|
|
name = "woodpecker-db-creds"
|
|
|
|
|
namespace = "woodpecker"
|
|
|
|
|
}
|
|
|
|
|
spec = {
|
|
|
|
|
refreshInterval = "15m"
|
|
|
|
|
secretStoreRef = {
|
|
|
|
|
name = "vault-database"
|
|
|
|
|
kind = "ClusterSecretStore"
|
|
|
|
|
}
|
|
|
|
|
target = {
|
|
|
|
|
name = "woodpecker-db-creds"
|
|
|
|
|
template = {
|
|
|
|
|
data = {
|
2026-03-17 07:39:29 +00:00
|
|
|
WOODPECKER_DATABASE_DATASOURCE = "postgres://woodpecker:{{ .password }}@${var.postgresql_host}:5432/woodpecker?sslmode=disable"
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
data = [{
|
|
|
|
|
secretKey = "password"
|
|
|
|
|
remoteRef = {
|
|
|
|
|
key = "static-creds/pg-woodpecker"
|
|
|
|
|
property = "password"
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
depends_on = [kubernetes_namespace.woodpecker]
|
migrate consuming stacks to ESO + remove k8s-dashboard static token
Phase 9: ExternalSecret migration across 26 stacks:
Fully migrated (vault data source removed, ESO delivers secrets):
- speedtest, shadowsocks, wealthfolio, plotting-book, f1-stream, tandoor
- n8n, dawarich, diun, netbox, onlyoffice, tuya-bridge
- hackmd (ESO template for DB URL), health (ESO template for DB URL)
- trading-bot (ESO template for DATABASE_URL + 7 secret env vars)
- forgejo (removed unused vault data source)
Partially migrated (vault kept for plan-time, ESO added for runtime):
- immich, linkwarden, nextcloud, paperless-ngx (jsondecode for homepage)
- claude-memory, rybbit, url, webhook_handler (plan-time in locals/jobs)
- woodpecker, openclaw, resume (plan-time in helm values/jobs/modules)
17 stacks unchanged (all plan-time: homepage annotations, configmaps,
module inputs) — vault data source works with OIDC auth.
Phase 17a: Remove k8s-dashboard static admin token secret.
Users now get tokens via: vault write kubernetes/creds/dashboard-admin
2026-03-15 19:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 21:30:25 +00:00
|
|
|
resource "kubernetes_config_map" "git_crypt_key" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "git-crypt-key"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
"key" = filebase64("${path.root}/../../.git/git-crypt/keys/default")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 21:21:12 +00:00
|
|
|
# Database init job - REMOVED: database and user already exist.
|
|
|
|
|
# The job used -U root which doesn't work with CNPG (superuser is 'postgres').
|
|
|
|
|
# Vault DB engine manages the woodpecker credentials via rotation.
|
2026-02-22 21:30:25 +00:00
|
|
|
|
truenas deprecation: migrate all non-immich storage to proxmox NFS
- Migrate 7 backup CronJobs to Proxmox host NFS (192.168.1.127)
(etcd, mysql, postgresql, nextcloud, redis, vaultwarden, plotting-book)
- Migrate headscale backup, ebook2audiobook, osm_routing to Proxmox NFS
- Migrate servarr (lidarr, readarr, soulseek) NFS refs to Proxmox
- Remove 79 orphaned TrueNAS NFS module declarations from 49 stacks
- Delete stacks/platform/modules/ (27 dead module copies, 65MB)
- Update nfs-truenas StorageClass to point to Proxmox (192.168.1.127)
- Remove iscsi DNS record from config.tfvars
- Fix woodpecker persistence config and alertmanager PV
Only Immich (8 PVCs, ~1.4TB) remains on TrueNAS.
2026-04-12 14:35:39 +01:00
|
|
|
# Woodpecker server data is on local-path (node-local storage), NOT NFS.
|
|
|
|
|
# The old NFS PV was unused — PVC was already bound to local-path PV.
|
|
|
|
|
# No PV management needed here.
|
2026-02-22 21:30:25 +00:00
|
|
|
|
|
|
|
|
# Helm release for Woodpecker CI
|
2026-03-16 19:12:01 +00:00
|
|
|
# Database datasource is now injected from ExternalSecret via envFrom
|
2026-02-22 21:30:25 +00:00
|
|
|
resource "helm_release" "woodpecker" {
|
|
|
|
|
name = "woodpecker"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
repository = "oci://ghcr.io/woodpecker-ci/helm"
|
|
|
|
|
chart = "woodpecker"
|
|
|
|
|
version = "3.5.1"
|
|
|
|
|
|
|
|
|
|
values = [
|
|
|
|
|
templatefile("${path.module}/values.yaml", {
|
2026-03-14 17:15:48 +00:00
|
|
|
github_client_id = data.vault_kv_secret_v2.secrets.data["github_client_id"]
|
|
|
|
|
github_client_secret = data.vault_kv_secret_v2.secrets.data["github_client_secret"]
|
|
|
|
|
agent_secret = data.vault_kv_secret_v2.secrets.data["agent_secret"]
|
|
|
|
|
forgejo_client_id = data.vault_kv_secret_v2.secrets.data["forgejo_client_id"]
|
|
|
|
|
forgejo_client_secret = data.vault_kv_secret_v2.secrets.data["forgejo_client_secret"]
|
2026-02-24 23:02:33 +00:00
|
|
|
forgejo_url = var.woodpecker_forgejo_url
|
add generic multi-user cluster onboarding system
Data-driven user onboarding: add a JSON entry to Vault KV k8s_users,
apply vault + platform + woodpecker stacks, and everything is auto-generated.
Vault stack: namespace creation, per-user Vault policies with secret isolation
via identity entities/aliases, K8s deployer roles, CI policy update.
Platform stack: domains field in k8s_users type, TLS secrets per user namespace,
user domains merged into Cloudflare DNS, user-roles ConfigMap mounted in portal.
Woodpecker stack: admin list auto-generated from k8s_users, WOODPECKER_OPEN=true.
K8s-portal: dual-track onboarding (general/namespace-owner), namespace-owner
dashboard with Vault/kubectl commands, setup script adds Vault+Terraform+Terragrunt,
contributing page with CI pipeline template, versioned image tags in CI pipeline.
New: stacks/_template/ with copyable stack template for namespace-owners.
2026-03-15 22:23:36 +00:00
|
|
|
woodpecker_admins = local.woodpecker_admins
|
2026-02-22 21:30:25 +00:00
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
timeout = 600
|
2026-04-15 21:21:12 +00:00
|
|
|
depends_on = [kubernetes_manifest.db_external_secret]
|
2026-02-22 21:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-07 17:18:57 +00:00
|
|
|
# Patch hostAliases onto the woodpecker-server StatefulSet — the chart 3.5.1
|
|
|
|
|
# does NOT expose this field, so we have to do it after the helm release.
|
|
|
|
|
# Keeps the OAuth/forge-API path off the WAN gateway (forgejo.viktorbarzin.me
|
|
|
|
|
# resolves to the public IP via DNS, which round-trips through Cloudflare
|
|
|
|
|
# and routinely tripped 30s context-deadline timeouts when fetching pipeline
|
|
|
|
|
# config). 10.0.20.200 is the Traefik LB that fronts forgejo internally;
|
|
|
|
|
# Traefik serves the *.viktorbarzin.me wildcard so SNI verification still
|
|
|
|
|
# passes.
|
|
|
|
|
resource "null_resource" "woodpecker_server_host_alias" {
|
|
|
|
|
triggers = {
|
2026-05-08 07:42:56 +00:00
|
|
|
# Re-run on every helm_release version bump or values change.
|
|
|
|
|
helm_version = helm_release.woodpecker.version
|
|
|
|
|
helm_values = sha256(join("", helm_release.woodpecker.values))
|
2026-05-07 17:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
|
|
|
|
command = <<-BASH
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
kubectl -n woodpecker patch statefulset/woodpecker-server --type=strategic --patch '{"spec":{"template":{"spec":{"hostAliases":[{"ip":"10.0.20.200","hostnames":["forgejo.viktorbarzin.me"]}]}}}}'
|
|
|
|
|
kubectl -n woodpecker rollout status statefulset/woodpecker-server --timeout=120s
|
|
|
|
|
BASH
|
|
|
|
|
interpreter = ["/bin/bash", "-c"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
depends_on = [helm_release.woodpecker]
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 21:30:25 +00:00
|
|
|
# ClusterRoleBinding - build pods need cluster-admin to PATCH deployments across namespaces
|
|
|
|
|
resource "kubernetes_cluster_role_binding" "woodpecker" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "woodpecker"
|
|
|
|
|
}
|
|
|
|
|
subject {
|
|
|
|
|
kind = "ServiceAccount"
|
|
|
|
|
name = "woodpecker-agent"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
role_ref {
|
|
|
|
|
kind = "ClusterRole"
|
|
|
|
|
name = "cluster-admin"
|
|
|
|
|
api_group = "rbac.authorization.k8s.io"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Also bind the default SA (pipeline pods run as default)
|
|
|
|
|
resource "kubernetes_cluster_role_binding" "woodpecker_default" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "woodpecker-default"
|
|
|
|
|
}
|
|
|
|
|
subject {
|
|
|
|
|
kind = "ServiceAccount"
|
|
|
|
|
name = "default"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
role_ref {
|
|
|
|
|
kind = "ClusterRole"
|
|
|
|
|
name = "cluster-admin"
|
|
|
|
|
api_group = "rbac.authorization.k8s.io"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 19:06:12 +00:00
|
|
|
# --- Vault → Woodpecker Secret Sync ---
|
|
|
|
|
# Syncs secrets from Vault KV (secret/ci/global) to Woodpecker global secrets via API.
|
|
|
|
|
# Runs every 6 hours. Secrets are created/updated via Woodpecker REST API.
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_config_map" "vault_woodpecker_sync" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "vault-woodpecker-sync"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data = {
|
2026-03-15 19:37:00 +00:00
|
|
|
"sync.sh" = <<-SCRIPT
|
2026-03-15 19:06:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
|
|
|
|
VAULT_ADDR="http://vault-active.vault.svc.cluster.local:8200"
|
2026-03-15 23:12:52 +00:00
|
|
|
WP_API="http://woodpecker-server.woodpecker.svc.cluster.local/api"
|
2026-03-15 19:06:12 +00:00
|
|
|
|
|
|
|
|
# Authenticate to Vault via K8s SA
|
2026-03-15 23:12:52 +00:00
|
|
|
SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
|
|
|
|
VAULT_TOKEN=$(curl -sf -X POST "$VAULT_ADDR/v1/auth/kubernetes/login" \
|
|
|
|
|
-d "{\"role\":\"woodpecker-sync\",\"jwt\":\"$SA_TOKEN\"}" | jq -r .auth.client_token)
|
2026-03-15 19:06:12 +00:00
|
|
|
|
2026-03-15 23:12:52 +00:00
|
|
|
if [ -z "$VAULT_TOKEN" ] || [ "$VAULT_TOKEN" = "null" ]; then
|
2026-03-15 19:06:12 +00:00
|
|
|
echo "ERROR: Failed to authenticate to Vault"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Get Woodpecker API token from Vault
|
2026-03-15 23:12:52 +00:00
|
|
|
WP_TOKEN=$(curl -sf -H "X-Vault-Token: $VAULT_TOKEN" \
|
|
|
|
|
"$VAULT_ADDR/v1/secret/data/ci/global" | jq -r '.data.data.woodpecker_api_token // empty')
|
2026-03-15 19:06:12 +00:00
|
|
|
|
2026-03-15 23:12:52 +00:00
|
|
|
if [ -z "$WP_TOKEN" ]; then
|
2026-03-15 19:06:12 +00:00
|
|
|
echo "ERROR: No woodpecker_api_token in secret/ci/global"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Sync global secrets
|
2026-03-15 23:12:52 +00:00
|
|
|
SECRETS=$(curl -sf -H "X-Vault-Token: $VAULT_TOKEN" \
|
|
|
|
|
"$VAULT_ADDR/v1/secret/data/ci/global" | jq -r '.data.data | to_entries[] | select(.key != "woodpecker_api_token") | @base64')
|
2026-03-15 19:06:12 +00:00
|
|
|
|
|
|
|
|
synced=0
|
2026-03-15 23:12:52 +00:00
|
|
|
for entry in $SECRETS; do
|
|
|
|
|
NAME=$(echo "$entry" | base64 -d | jq -r .key)
|
|
|
|
|
VALUE=$(echo "$entry" | base64 -d | jq -r .value)
|
2026-03-15 19:06:12 +00:00
|
|
|
|
|
|
|
|
# Try PATCH first (update), fall back to POST (create)
|
2026-04-15 21:43:48 +00:00
|
|
|
# Include all event types so secrets work for manual/cron-triggered pipelines too
|
2026-03-15 23:12:52 +00:00
|
|
|
STATUS=$(curl -sf -o /dev/null -w "%%{http_code}" -X PATCH "$WP_API/secrets/$NAME" \
|
|
|
|
|
-H "Authorization: Bearer $WP_TOKEN" \
|
2026-03-15 19:06:12 +00:00
|
|
|
-H "Content-Type: application/json" \
|
2026-04-15 21:43:48 +00:00
|
|
|
-d "{\"name\":\"$NAME\",\"value\":\"$VALUE\",\"events\":[\"cron\",\"deployment\",\"manual\",\"push\",\"tag\"]}" 2>/dev/null || echo "000")
|
2026-03-15 19:06:12 +00:00
|
|
|
|
2026-03-15 23:12:52 +00:00
|
|
|
if [ "$STATUS" != "200" ]; then
|
|
|
|
|
curl -sf -X POST "$WP_API/secrets" \
|
|
|
|
|
-H "Authorization: Bearer $WP_TOKEN" \
|
2026-03-15 19:06:12 +00:00
|
|
|
-H "Content-Type: application/json" \
|
2026-04-15 21:43:48 +00:00
|
|
|
-d "{\"name\":\"$NAME\",\"value\":\"$VALUE\",\"events\":[\"cron\",\"deployment\",\"manual\",\"push\",\"tag\"]}" > /dev/null
|
2026-03-15 19:06:12 +00:00
|
|
|
fi
|
2026-03-15 23:12:52 +00:00
|
|
|
synced=$((synced + 1))
|
2026-03-15 19:06:12 +00:00
|
|
|
done
|
2026-03-15 23:12:52 +00:00
|
|
|
echo "Synced $synced global secrets from Vault to Woodpecker"
|
2026-03-15 19:06:12 +00:00
|
|
|
SCRIPT
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_cron_job_v1" "vault_secret_sync" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "vault-woodpecker-sync"
|
|
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
schedule = "0 */6 * * *"
|
|
|
|
|
successful_jobs_history_limit = 3
|
|
|
|
|
failed_jobs_history_limit = 3
|
|
|
|
|
concurrency_policy = "Forbid"
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
name = "sync"
|
2026-03-15 23:12:52 +00:00
|
|
|
image = "alpine"
|
|
|
|
|
command = ["/bin/sh", "-c", "apk add --no-cache curl jq && /bin/sh /scripts/sync.sh"]
|
2026-03-15 19:06:12 +00:00
|
|
|
volume_mount {
|
|
|
|
|
name = "sync-script"
|
|
|
|
|
mount_path = "/scripts"
|
|
|
|
|
}
|
|
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "10m"
|
|
|
|
|
memory = "32Mi"
|
|
|
|
|
}
|
|
|
|
|
limits = {
|
|
|
|
|
memory = "64Mi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "sync-script"
|
|
|
|
|
config_map {
|
|
|
|
|
name = kubernetes_config_map.vault_woodpecker_sync.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
restart_policy = "OnFailure"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
[infra] Sweep dns_config ignore_changes across all pod-owning resources [ci skip]
## Context
Wave 3A (commit c9d221d5) added the `# KYVERNO_LIFECYCLE_V1` marker to the
27 pre-existing `ignore_changes = [...dns_config]` sites so they could be
grepped and audited. It did NOT address pod-owning resources that were
simply missing the suppression entirely. Post-Wave-3A sampling (2026-04-18)
found that navidrome, f1-stream, frigate, servarr, monitoring, crowdsec,
and many other stacks showed perpetual `dns_config` drift every plan
because their `kubernetes_deployment` / `kubernetes_stateful_set` /
`kubernetes_cron_job_v1` resources had no `lifecycle {}` block at all.
Root cause (same as Wave 3A): Kyverno's admission webhook stamps
`dns_config { option { name = "ndots"; value = "2" } }` on every pod's
`spec.template.spec.dns_config` to prevent NxDomain search-domain flooding
(see `k8s-ndots-search-domain-nxdomain-flood` skill). Without `ignore_changes`
on every Terraform-managed pod-owner, Terraform repeatedly tries to strip
the injected field.
## This change
Extends the Wave 3A convention by sweeping EVERY `kubernetes_deployment`,
`kubernetes_stateful_set`, `kubernetes_daemon_set`, `kubernetes_cron_job_v1`,
`kubernetes_job_v1` (+ their `_v1` variants) in the repo and ensuring each
carries the right `ignore_changes` path:
- **kubernetes_deployment / stateful_set / daemon_set / job_v1**:
`spec[0].template[0].spec[0].dns_config`
- **kubernetes_cron_job_v1**:
`spec[0].job_template[0].spec[0].template[0].spec[0].dns_config`
(extra `job_template[0]` nesting — the CronJob's PodTemplateSpec is
one level deeper)
Each injection / extension is tagged `# KYVERNO_LIFECYCLE_V1: Kyverno
admission webhook mutates dns_config with ndots=2` inline so the
suppression is discoverable via `rg 'KYVERNO_LIFECYCLE_V1' stacks/`.
Two insertion paths are handled by a Python pass (`/tmp/add_dns_config_ignore.py`):
1. **No existing `lifecycle {}`**: inject a brand-new block just before the
resource's closing `}`. 108 new blocks on 93 files.
2. **Existing `lifecycle {}` (usually for `DRIFT_WORKAROUND: CI owns image tag`
from Wave 4, commit a62b43d1)**: extend its `ignore_changes` list with the
dns_config path. Handles both inline (`= [x]`) and multiline
(`= [\n x,\n]`) forms; ensures the last pre-existing list item carries
a trailing comma so the extended list is valid HCL. 34 extensions.
The script skips anything already mentioning `dns_config` inside an
`ignore_changes`, so re-running is a no-op.
## Scale
- 142 total lifecycle injections/extensions
- 93 `.tf` files touched
- 108 brand-new `lifecycle {}` blocks + 34 extensions of existing ones
- Every Tier 0 and Tier 1 stack with a pod-owning resource is covered
- Together with Wave 3A's 27 pre-existing markers → **169 greppable
`KYVERNO_LIFECYCLE_V1` dns_config sites across the repo**
## What is NOT in this change
- `stacks/trading-bot/main.tf` — entirely commented-out block (`/* … */`).
Python script touched the file, reverted manually.
- `_template/main.tf.example` skeleton — kept minimal on purpose; any
future stack created from it should either inherit the Wave 3A one-line
form or add its own on first `kubernetes_deployment`.
- `terraform fmt` fixes to pre-existing alignment issues in meshcentral,
nvidia/modules/nvidia, vault — unrelated to this commit. Left for a
separate fmt-only pass.
- Non-pod resources (`kubernetes_service`, `kubernetes_secret`,
`kubernetes_manifest`, etc.) — they don't own pods so they don't get
Kyverno dns_config mutation.
## Verification
Random sample post-commit:
```
$ cd stacks/navidrome && ../../scripts/tg plan → No changes.
$ cd stacks/f1-stream && ../../scripts/tg plan → No changes.
$ cd stacks/frigate && ../../scripts/tg plan → No changes.
$ rg -c 'KYVERNO_LIFECYCLE_V1' stacks/ --include='*.tf' --include='*.tf.example' \
| awk -F: '{s+=$2} END {print s}'
169
```
## Reproduce locally
1. `git pull`
2. `rg 'KYVERNO_LIFECYCLE_V1' stacks/ | wc -l` → 169+
3. `cd stacks/navidrome && ../../scripts/tg plan` → expect 0 drift on
the deployment's dns_config field.
Refs: code-seq (Wave 3B dns_config class closed; kubernetes_manifest
annotation class handled separately in 8d94688d for tls_secret)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 21:19:48 +00:00
|
|
|
lifecycle {
|
|
|
|
|
# KYVERNO_LIFECYCLE_V1: Kyverno admission webhook mutates dns_config with ndots=2
|
|
|
|
|
ignore_changes = [spec[0].job_template[0].spec[0].template[0].spec[0].dns_config]
|
|
|
|
|
}
|
2026-03-15 19:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 21:30:25 +00:00
|
|
|
module "ingress" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
2026-04-16 13:45:04 +00:00
|
|
|
dns_type = "non-proxied"
|
2026-02-22 21:30:25 +00:00
|
|
|
namespace = kubernetes_namespace.woodpecker.metadata[0].name
|
|
|
|
|
name = "ci"
|
|
|
|
|
service_name = "woodpecker-server"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
2026-03-07 16:41:36 +00:00
|
|
|
extra_annotations = {
|
|
|
|
|
"gethomepage.dev/enabled" = "true"
|
|
|
|
|
"gethomepage.dev/name" = "Woodpecker CI"
|
|
|
|
|
"gethomepage.dev/description" = "CI/CD pipelines"
|
|
|
|
|
"gethomepage.dev/icon" = "woodpecker-ci.png"
|
|
|
|
|
"gethomepage.dev/group" = "Development & CI"
|
|
|
|
|
"gethomepage.dev/pod-selector" = ""
|
|
|
|
|
}
|
2026-02-22 21:30:25 +00:00
|
|
|
}
|