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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|