Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ PrivateTmp=true
ProtectHome=true
ProtectSystem=strict
# SQLite needs write access to the WAL index of the databases it copies.
ReadWritePaths=/srv/standard/backups/k3s-applications /srv/standard/volumes/uptime-kuma /srv/standard/volumes/monitoring /var/lib/node_exporter/textfile_collector
ReadWritePaths=/srv/standard/backups/k3s-applications /srv/standard/volumes/monitoring /var/lib/node_exporter/textfile_collector
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ sqlite_backup() {
tar -C "$dir" --exclude="./${db}" --exclude="./${db}-*" --exclude=./lost+found \
-cf "${work_dir}/${name}-files.tar" .
}
sqlite_backup "${volumes}/uptime-kuma/uptime-pvc" kuma.db uptime-kuma
sqlite_backup "${volumes}/monitoring/grafana-pvc" grafana.db grafana

# Vaultwarden: the vault itself is in the PostgreSQL dump; the volume keeps the
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/network-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Only the in-cluster callers may reach the backend (RFC v3 §12): the admin
# dashboard and the website (tRPC, esign agent proxy), the Telegram bot (tRPC
# and its socket), the IdP (access-changed events on /internal/events) and
# Uptime Kuma (health monitoring).
# Kuvasz (uptime monitoring).
# Nothing reaches it from outside the cluster since the Ingress was removed.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
Expand Down Expand Up @@ -41,10 +41,10 @@ spec:
app: auth
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: uptime-kuma
kubernetes.io/metadata.name: kuvasz
podSelector:
matchLabels:
app: uptime-kuma
app: kuvasz
ports:
- port: 3000
protocol: TCP
121 changes: 121 additions & 0 deletions apps/kuvasz/deployment-gate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# oauth2-proxy as a Traefik forwardAuth endpoint. It admits only people whose
# `groups` claim (their roles, inheritance expanded) contains it-member, and
# guards nothing but Kuvasz's sign-in routes, so status pages and push
# heartbeats stay public and Kuvasz keeps its own sessions.
# Redirect URI: https://uptime.polinetwork.org/oauth2/callback
apiVersion: v1
kind: Service
metadata:
name: kuvasz-gate
labels:
app: kuvasz-gate
spec:
ports:
- name: http
port: 4180
targetPort: 4180
selector:
app: kuvasz-gate
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kuvasz-gate
spec:
replicas: 1
selector:
matchLabels:
app: kuvasz-gate
template:
metadata:
labels:
app: kuvasz-gate
spec:
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: oauth2-proxy
image: quay.io/oauth2-proxy/oauth2-proxy:v7.15.6@sha256:c3415e8660af553f5e18f5d90db050614c02493c0ac6260ac59442f6d9b12048
imagePullPolicy: IfNotPresent
args:
- --http-address=0.0.0.0:4180
- --provider=oidc
- --oidc-issuer-url=https://auth.polinetwork.org/api/auth
- --scope=openid profile email polinetwork:identity
- --code-challenge-method=S256
- --redirect-url=https://uptime.polinetwork.org/oauth2/callback
- --whitelist-domain=uptime.polinetwork.org
- --oidc-groups-claim=groups
- --allowed-group=it-member
# Access is decided by role, not by address, and Telegram-only
# accounts may have no (verified) email: identify people by sub.
- --oidc-email-claim=sub
- --email-domain=*
- --insecure-oidc-allow-unverified-email=true
# forwardAuth mode: 202 for an admitted person, otherwise a
# redirect to auth.polinetwork.org or a 403.
- --upstream=static://202
- --reverse-proxy=true
- --trusted-proxy-ip=10.52.0.0/16
- --skip-provider-button=true
# The gate is only crossed while signing in to Kuvasz, so a short
# session makes every sign-in re-check the role.
- --cookie-name=_kuvasz_gate
- --cookie-secure=true
- --cookie-samesite=lax
- --cookie-expire=15m
- --silence-ping-logging=true
env:
- name: OAUTH2_PROXY_CLIENT_ID
valueFrom:
secretKeyRef:
name: azure-kv
key: gate-client-id
- name: OAUTH2_PROXY_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: azure-kv
key: gate-client-secret
- name: OAUTH2_PROXY_COOKIE_SECRET
valueFrom:
secretKeyRef:
name: azure-kv
key: gate-cookie-secret
ports:
- containerPort: 4180
startupProbe:
httpGet:
path: /ping
port: 4180
periodSeconds: 2
failureThreshold: 30
readinessProbe:
httpGet:
path: /ready
port: 4180
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
livenessProbe:
httpGet:
path: /ping
port: 4180
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests:
cpu: "5m"
memory: "16Mi"
limits:
memory: "64Mi"
138 changes: 138 additions & 0 deletions apps/kuvasz/deployment-kuvasz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
apiVersion: v1
kind: Service
metadata:
name: kuvasz
labels:
app: kuvasz
spec:
ports:
- name: http
port: 8080
targetPort: 8080
selector:
app: kuvasz
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kuvasz
spec:
replicas: 1
# A second instance would run every check twice and send duplicate alerts.
strategy:
type: Recreate
selector:
matchLabels:
app: kuvasz
template:
metadata:
labels:
app: kuvasz
spec:
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: kuvasz
image: kuvaszmonitoring/kuvasz:4.7.0@sha256:e511ec42bcf2e64a6147ba17bff85fcf565dec54a24099c5e448d7767a07f335
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: TZ
value: "Europe/Rome"
- name: DATABASE_HOST
value: "postgres-service.postgres.svc.cluster.local"
- name: DATABASE_NAME
value: "kuvasz"
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: azure-kv
key: db-user
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: azure-kv
key: db-pass
# Sign-in only through auth.polinetwork.org; with OIDC on, Kuvasz
# disables its username/password form (ADMIN_USER is unused).
# Kuvasz cannot check roles, so the it-member restriction lives in
# the gate in front of /oauth (ingress.yaml).
# Redirect URI: https://uptime.polinetwork.org/oauth/callback/oidc
# Post-logout URI: https://uptime.polinetwork.org/auth/logout
- name: ENABLE_OIDC
value: "true"
- name: OIDC_ISSUER
value: "https://auth.polinetwork.org/api/auth"
- name: OIDC_CLIENT_ID
valueFrom:
secretKeyRef:
name: azure-kv
key: oidc-client-id
- name: OIDC_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: azure-kv
key: oidc-client-secret
# Bounds how long someone removed from IT keeps an open session.
- name: AUTH_MAX_AGE
value: "28800"
# Kuvasz builds its OIDC redirect URI from these headers; Traefik
# sets X-Forwarded-Host, the forwarded-https middleware the scheme.
- name: MICRONAUT_SERVER_HOST_RESOLUTION_HOST_HEADER
value: "X-Forwarded-Host"
- name: MICRONAUT_SERVER_HOST_RESOLUTION_PROTOCOL_HEADER
value: "X-Forwarded-Proto"
# The image is pinned; upgrades go through this file.
- name: ENABLE_CHECK_UPDATES
value: "false"
startupProbe:
httpGet:
path: /api/v2/health
port: 8080
periodSeconds: 2
failureThreshold: 90
readinessProbe:
httpGet:
path: /api/v2/health
port: 8080
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
livenessProbe:
httpGet:
path: /api/v2/health
port: 8080
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests:
cpu: "50m"
memory: "384Mi"
limits:
memory: "768Mi"
volumeMounts:
- name: config
mountPath: /config
readOnly: true
# The only path Kuvasz writes to (YAML exports).
- name: tmp
mountPath: /tmp
volumes:
- name: config
configMap:
name: kuvasz-config
- name: tmp
emptyDir:
sizeLimit: 64Mi
45 changes: 45 additions & 0 deletions apps/kuvasz/external-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# The role and database are created once by hand on postgres-service:
# CREATE ROLE kuvasz LOGIN PASSWORD '...';
# CREATE DATABASE kuvasz OWNER kuvasz;
# Kuvasz creates and migrates its own `kuvasz` schema on startup.
#
# Two OIDC clients on auth.polinetwork.org (see ingress.yaml):
# - kuvasz-oidc-*: Kuvasz's own sign-in.
# - kuvasz-gate-oidc-*: oauth2-proxy, which admits only it-member to Kuvasz's
# sign-in routes. kuvasz-gate-cookie-secret is 32 random bytes, base64url:
# openssl rand -base64 32 | tr -- '+/' '-_'
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: azure-kv
spec:
refreshInterval: 1h
secretStoreRef:
kind: ClusterSecretStore
name: kv-pn-apps
target:
name: azure-kv
creationPolicy: Owner
deletionPolicy: Retain
data:
- secretKey: db-user
remoteRef:
key: kuvasz-postgres-user
- secretKey: db-pass
remoteRef:
key: kuvasz-postgres-password
- secretKey: oidc-client-id
remoteRef:
key: kuvasz-oidc-client-id
- secretKey: oidc-client-secret
remoteRef:
key: kuvasz-oidc-client-secret
- secretKey: gate-client-id
remoteRef:
key: kuvasz-gate-oidc-client-id
- secretKey: gate-client-secret
remoteRef:
key: kuvasz-gate-oidc-client-secret
- secretKey: gate-cookie-secret
remoteRef:
key: kuvasz-gate-cookie-secret
Loading
Loading