2024-12-27 21:23:05 +00:00
|
|
|
variable "tls_secret_name" {}
|
|
|
|
|
variable "name" {}
|
2024-12-29 17:11:30 +00:00
|
|
|
variable "tag" {
|
|
|
|
|
default = "latest"
|
|
|
|
|
}
|
2026-01-10 16:28:12 +00:00
|
|
|
variable "tier" { type = string }
|
2026-01-10 19:27:14 +00:00
|
|
|
variable "sync_id" {
|
|
|
|
|
type = string
|
|
|
|
|
default = null # If not passed, we won't run banksync
|
|
|
|
|
}
|
|
|
|
|
variable "budget_encryption_password" {
|
2026-03-14 08:51:45 +00:00
|
|
|
type = string
|
|
|
|
|
default = null # If not passed, we won't run banksync ;known after initial installation
|
2026-03-07 14:30:36 +00:00
|
|
|
sensitive = true
|
2026-01-10 19:27:14 +00:00
|
|
|
}
|
[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 }
|
2026-03-07 16:41:36 +00:00
|
|
|
variable "homepage_annotations" {
|
|
|
|
|
type = map(string)
|
|
|
|
|
default = {}
|
|
|
|
|
}
|
2024-12-27 21:23:05 +00:00
|
|
|
|
2026-03-02 02:04:22 +00:00
|
|
|
module "nfs_data" {
|
|
|
|
|
source = "../../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "actualbudget-${var.name}-data"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/actualbudget/${var.name}"
|
|
|
|
|
}
|
|
|
|
|
|
feat(storage): migrate 12 SQLite NFS PVCs to proxmox-lvm (Wave 1)
Add proxmox-lvm PVCs with pvc-autoresizer annotations for all
SQLite-backed services. Deployments updated to use new block storage
PVCs. Old NFS modules retained for 1-week rollback.
Services: ntfy, freshrss, insta2spotify, actualbudget (x3),
wealthfolio, navidrome (DB only), audiobookshelf config,
headscale, forgejo, uptime-kuma.
Also: set Recreate strategy on ntfy, forgejo, insta2spotify,
wealthfolio (required for RWO volumes).
2026-04-04 16:26:59 +03:00
|
|
|
resource "kubernetes_persistent_volume_claim" "data_proxmox" {
|
|
|
|
|
wait_until_bound = false
|
|
|
|
|
metadata {
|
|
|
|
|
name = "actualbudget-${var.name}-data-proxmox"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
annotations = {
|
|
|
|
|
"resize.topolvm.io/threshold" = "80%"
|
|
|
|
|
"resize.topolvm.io/increase" = "100%"
|
|
|
|
|
"resize.topolvm.io/storage_limit" = "5Gi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
access_modes = ["ReadWriteOnce"]
|
|
|
|
|
storage_class_name = "proxmox-lvm"
|
|
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
storage = "1Gi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-27 21:23:05 +00:00
|
|
|
resource "kubernetes_deployment" "actualbudget" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "actualbudget-${var.name}"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
labels = {
|
2026-01-10 16:28:12 +00:00
|
|
|
app = "actualbudget-${var.name}"
|
|
|
|
|
tier = var.tier
|
2024-12-27 21:23:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
2025-01-06 22:05:26 +00:00
|
|
|
strategy {
|
|
|
|
|
type = "Recreate"
|
|
|
|
|
}
|
2024-12-27 21:23:05 +00:00
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "actualbudget-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
annotations = {
|
2025-01-07 19:48:39 +00:00
|
|
|
"diun.enable" = "false" # daily updates; pretty noisy
|
2024-12-30 14:01:38 +00:00
|
|
|
"diun.include_tags" = "^${var.tag}$"
|
2024-12-27 21:23:05 +00:00
|
|
|
}
|
|
|
|
|
labels = {
|
|
|
|
|
app = "actualbudget-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
2024-12-29 17:11:30 +00:00
|
|
|
image = "actualbudget/actual-server:${var.tag}"
|
2024-12-27 21:23:05 +00:00
|
|
|
name = "actualbudget"
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
container_port = 5006
|
|
|
|
|
}
|
2026-03-23 10:52:43 +02:00
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "15m"
|
2026-04-06 11:58:00 +03:00
|
|
|
memory = "320Mi"
|
2026-03-23 10:52:43 +02:00
|
|
|
}
|
|
|
|
|
limits = {
|
2026-04-06 11:58:00 +03:00
|
|
|
memory = "400Mi"
|
2026-03-23 10:52:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-27 21:23:05 +00:00
|
|
|
volume_mount {
|
|
|
|
|
name = "data"
|
|
|
|
|
mount_path = "/data"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "data"
|
2026-03-02 02:04:22 +00:00
|
|
|
persistent_volume_claim {
|
feat(storage): migrate 12 SQLite NFS PVCs to proxmox-lvm (Wave 1)
Add proxmox-lvm PVCs with pvc-autoresizer annotations for all
SQLite-backed services. Deployments updated to use new block storage
PVCs. Old NFS modules retained for 1-week rollback.
Services: ntfy, freshrss, insta2spotify, actualbudget (x3),
wealthfolio, navidrome (DB only), audiobookshelf config,
headscale, forgejo, uptime-kuma.
Also: set Recreate strategy on ntfy, forgejo, insta2spotify,
wealthfolio (required for RWO volumes).
2026-04-04 16:26:59 +03:00
|
|
|
claim_name = kubernetes_persistent_volume_claim.data_proxmox.metadata[0].name
|
2024-12-27 21:23:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "actualbudget" {
|
|
|
|
|
metadata {
|
2025-01-14 22:53:04 +00:00
|
|
|
name = "budget-${var.name}"
|
2024-12-27 21:23:05 +00:00
|
|
|
namespace = "actualbudget"
|
|
|
|
|
labels = {
|
|
|
|
|
app = "actualbudget-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "actualbudget-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
port = 80
|
|
|
|
|
target_port = 5006
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 22:53:04 +00:00
|
|
|
module "ingress" {
|
2026-03-14 08:51:45 +00:00
|
|
|
source = "../../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
name = "budget-${var.name}"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
rybbit_site_id = "3e6b6b68088a"
|
2026-03-07 16:41:36 +00:00
|
|
|
extra_annotations = var.homepage_annotations
|
2024-12-27 21:23:05 +00:00
|
|
|
}
|
2026-01-10 19:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "random_string" "api-key" {
|
|
|
|
|
length = 32
|
|
|
|
|
lower = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_deployment" "actualbudget-http-api" {
|
|
|
|
|
count = var.budget_encryption_password != null ? 1 : 0
|
|
|
|
|
metadata {
|
|
|
|
|
name = "actualbudget-http-api-${var.name}"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
labels = {
|
|
|
|
|
app = "actualbudget-http-api-${var.name}"
|
|
|
|
|
tier = var.tier
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
|
|
|
|
strategy {
|
|
|
|
|
type = "RollingUpdate"
|
|
|
|
|
}
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "actualbudget-http-api-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "actualbudget-http-api-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
image = "jhonderson/actual-http-api:latest"
|
|
|
|
|
name = "actualbudget"
|
2026-03-07 00:28:02 +00:00
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "50m"
|
2026-03-22 15:22:29 +02:00
|
|
|
memory = "768Mi"
|
2026-03-07 00:28:02 +00:00
|
|
|
}
|
|
|
|
|
limits = {
|
2026-03-22 15:22:29 +02:00
|
|
|
memory = "768Mi"
|
2026-03-07 00:28:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-10 19:27:14 +00:00
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
container_port = 5007
|
|
|
|
|
}
|
|
|
|
|
env {
|
|
|
|
|
name = "ACTUAL_SERVER_URL"
|
2026-04-06 12:22:57 +03:00
|
|
|
value = "http://budget-${var.name}.actualbudget.svc.cluster.local"
|
2026-01-10 19:27:14 +00:00
|
|
|
}
|
|
|
|
|
env {
|
|
|
|
|
name = "ACTUAL_SERVER_PASSWORD"
|
|
|
|
|
value = var.budget_encryption_password
|
|
|
|
|
}
|
|
|
|
|
env {
|
|
|
|
|
name = "API_KEY"
|
|
|
|
|
value = random_string.api-key.result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "actualbudget-http-api" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "budget-http-api-${var.name}"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
labels = {
|
|
|
|
|
app = "actualbudget-http-api-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "actualbudget-http-api-${var.name}"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
port = 80
|
|
|
|
|
target_port = 5007
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_cron_job_v1" "bank-sync" {
|
|
|
|
|
count = var.sync_id != null && var.budget_encryption_password != null ? 1 : 0
|
|
|
|
|
metadata {
|
|
|
|
|
name = "bank-sync-${var.name}"
|
|
|
|
|
namespace = "actualbudget"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
concurrency_policy = "Replace"
|
|
|
|
|
failed_jobs_history_limit = 5
|
|
|
|
|
schedule = "0 0 * * *" # Daily
|
2026-04-05 19:29:17 +03:00
|
|
|
starting_deadline_seconds = 60
|
2026-01-10 19:27:14 +00:00
|
|
|
successful_jobs_history_limit = 10
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
2026-04-05 19:29:17 +03:00
|
|
|
backoff_limit = 1
|
|
|
|
|
ttl_seconds_after_finished = 300
|
2026-01-10 19:27:14 +00:00
|
|
|
template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
name = "bank-sync"
|
|
|
|
|
image = "curlimages/curl"
|
|
|
|
|
command = ["/bin/sh", "-c", <<-EOT
|
2026-04-05 19:29:17 +03:00
|
|
|
PUSHGATEWAY="http://prometheus-prometheus-pushgateway.monitoring:9091/metrics/job/bank-sync-${var.name}"
|
|
|
|
|
START=$(date +%s)
|
|
|
|
|
|
|
|
|
|
HTTP_CODE=$(curl -s -o /tmp/response.txt -w '%%{http_code}' \
|
|
|
|
|
-X POST --location \
|
|
|
|
|
'http://budget-http-api-${var.name}/v1/budgets/${var.sync_id}/accounts/banksync' \
|
|
|
|
|
--header 'accept: application/json' \
|
|
|
|
|
--header 'budget-encryption-password: ${var.budget_encryption_password}' \
|
|
|
|
|
--header 'x-api-key: ${random_string.api-key.result}')
|
|
|
|
|
|
|
|
|
|
END=$(date +%s)
|
|
|
|
|
DURATION=$((END - START))
|
|
|
|
|
|
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
|
|
|
SUCCESS=1
|
|
|
|
|
LAST_SUCCESS=$END
|
|
|
|
|
else
|
|
|
|
|
SUCCESS=0
|
|
|
|
|
LAST_SUCCESS=0
|
|
|
|
|
echo "Bank sync failed with HTTP $HTTP_CODE:"
|
|
|
|
|
cat /tmp/response.txt
|
|
|
|
|
echo ""
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat <<METRICS | curl -s --data-binary @- "$PUSHGATEWAY"
|
|
|
|
|
# HELP bank_sync_success Whether the last bank sync succeeded (1=ok, 0=fail)
|
|
|
|
|
# TYPE bank_sync_success gauge
|
|
|
|
|
bank_sync_success $SUCCESS
|
|
|
|
|
# HELP bank_sync_duration_seconds Duration of the last bank sync run
|
|
|
|
|
# TYPE bank_sync_duration_seconds gauge
|
|
|
|
|
bank_sync_duration_seconds $DURATION
|
|
|
|
|
# HELP bank_sync_last_success_timestamp Unix timestamp of the last successful sync
|
|
|
|
|
# TYPE bank_sync_last_success_timestamp gauge
|
|
|
|
|
bank_sync_last_success_timestamp $LAST_SUCCESS
|
|
|
|
|
METRICS
|
2026-01-10 19:27:14 +00:00
|
|
|
EOT
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|