diff --git a/deployments/archie/compose.enterprise.yml b/deployments/archie/compose.enterprise.yml new file mode 100644 index 000000000..e2b27939b --- /dev/null +++ b/deployments/archie/compose.enterprise.yml @@ -0,0 +1,80 @@ +# Hardened enterprise overlay for deployments/archie/compose.yml. +# Usage: docker compose -f compose.yml -f compose.enterprise.yml up -d +# +# Ensure ./config.toml omits database.owner_url and ./secrets/* holds: +# - db_runtime_url (DML-only archie_app connection string) +# - db_owner_url (DDL archie_owner connection string, mounted only in archie-migrate) +# - age_identity (AGE-SECRET-KEY-1...) +# - admin_token_sha256 (hex SHA-256) + +services: + archie-migrate: + image: ${ARCHIE_IMAGE:-gcr.io/distroless/static-debian12:nonroot} + restart: "no" + user: "65532:65532" + read_only: true + tmpfs: + - /tmp:rw,noexec,nosuid,nodev,size=64m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + entrypoint: ["/archie/archie"] + command: ["-config", "", "migrate"] + environment: + HOME: /tmp + SSL_CERT_FILE: /etc/ssl/certs/enterprise-ca.crt + ARCHIE_DATABASE_URL_FILE: /run/secrets/db_runtime_url + ARCHIE_DATABASE_OWNER_URL_FILE: /run/secrets/db_owner_url + secrets: + - db_runtime_url + - db_owner_url + volumes: + - ./bin/archie:/archie/archie:ro + - ${ARCHIE_CA_BUNDLE:-./certs/enterprise-ca.crt}:/etc/ssl/certs/enterprise-ca.crt:ro + networks: [internal] + depends_on: + archie-db: + condition: service_healthy + + archie: + image: ${ARCHIE_IMAGE:-gcr.io/distroless/static-debian12:nonroot} + user: "65532:65532" + read_only: true + tmpfs: + - /tmp:rw,noexec,nosuid,nodev,size=128m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + - seccomp=./seccomp.json + environment: + HOME: /tmp + SSL_CERT_FILE: /etc/ssl/certs/enterprise-ca.crt + HTTPS_PROXY: ${HTTPS_PROXY:-} + HTTP_PROXY: ${HTTP_PROXY:-} + NO_PROXY: ${NO_PROXY:-localhost,127.0.0.1,archie-db} + ARCHIE_DATABASE_URL_FILE: /run/secrets/db_runtime_url + ARCHIE_AGE_IDENTITY_FILE: /run/secrets/age_identity + ARCHIE_ADMIN_TOKEN_SHA256_FILE: /run/secrets/admin_token_sha256 + secrets: + - db_runtime_url + - age_identity + - admin_token_sha256 + volumes: + - ${ARCHIE_CA_BUNDLE:-./certs/enterprise-ca.crt}:/etc/ssl/certs/enterprise-ca.crt:ro + depends_on: + archie-db: + condition: service_healthy + archie-migrate: + condition: service_completed_successfully + +secrets: + db_runtime_url: + file: ./secrets/db_runtime_url + db_owner_url: + file: ./secrets/db_owner_url + age_identity: + file: ./secrets/age_identity + admin_token_sha256: + file: ./secrets/admin_token_sha256 diff --git a/deployments/helm/archie/Chart.yaml b/deployments/helm/archie/Chart.yaml new file mode 100644 index 000000000..aeb6f88e5 --- /dev/null +++ b/deployments/helm/archie/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: archie +description: Event-driven agentic automation platform with pre-action governance and isolated extension execution. +type: application +version: 0.1.0 +appVersion: "1.0.0" +keywords: + - archie + - automation + - governance + - enterprise +maintainers: + - name: Archie Platform Team diff --git a/deployments/helm/archie/templates/_helpers.tpl b/deployments/helm/archie/templates/_helpers.tpl new file mode 100644 index 000000000..382edd18d --- /dev/null +++ b/deployments/helm/archie/templates/_helpers.tpl @@ -0,0 +1,78 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "archie.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +*/}} +{{- define "archie.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "archie.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels. +*/}} +{{- define "archie.labels" -}} +helm.sh/chart: {{ include "archie.chart" . }} +{{ include "archie.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels. +*/}} +{{- define "archie.selectorLabels" -}} +app.kubernetes.io/name: {{ include "archie.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +ServiceAccount name. +*/}} +{{- define "archie.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "archie.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Container image reference, preferring digest pinning when configured. +*/}} +{{- define "archie.image" -}} +{{- if .Values.image.digest }} +{{- printf "%s@%s" .Values.image.repository .Values.image.digest }} +{{- else }} +{{- printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) }} +{{- end }} +{{- end }} + +{{/* +Migration secret name. +*/}} +{{- define "archie.migrateSecretName" -}} +{{- default .Values.secrets.existingSecret .Values.migrate.existingSecret }} +{{- end }} diff --git a/deployments/helm/archie/templates/configmap.yaml b/deployments/helm/archie/templates/configmap.yaml new file mode 100644 index 000000000..c1921236c --- /dev/null +++ b/deployments/helm/archie/templates/configmap.yaml @@ -0,0 +1,65 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "archie.fullname" . }}-config + labels: + {{- include "archie.labels" . | nindent 4 }} +data: + config.toml: | + listen = {{ .Values.config.listen | quote }} + state_dir = {{ .Values.config.stateDir | quote }} + shutdown_grace = {{ .Values.config.shutdownGrace | quote }} + {{- if .Values.config.ageBackupRecipients }} + age_backup_recipients = [ + {{- range $i, $r := .Values.config.ageBackupRecipients }} + {{ $r | quote }}{{ if lt $i (sub (len $.Values.config.ageBackupRecipients) 1) }},{{ end }} + {{- end }} + ] + {{- end }} + + [catalogue] + disable_auto_update = {{ .Values.config.catalogue.disableAutoUpdate }} + {{- if .Values.config.catalogue.location }} + location = {{ .Values.config.catalogue.location | quote }} + {{- end }} + {{- if .Values.config.catalogue.publicKey }} + public_key = {{ .Values.config.catalogue.publicKey | quote }} + {{- end }} + + [extensions] + require_remote = {{ .Values.config.extensions.requireRemote }} + {{- if .Values.config.extensions.tls.existingSecret }} + ca_file = {{ printf "%s/ca.crt" .Values.config.extensions.tls.mountPath | quote }} + cert_file = {{ printf "%s/tls.crt" .Values.config.extensions.tls.mountPath | quote }} + key_file = {{ printf "%s/tls.key" .Values.config.extensions.tls.mountPath | quote }} + {{- end }} + {{- range $name, $ep := .Values.config.extensions.remote }} + + [extensions.remote.{{ $name }}] + address = {{ $ep.address | quote }} + {{- if $ep.serverName }} + server_name = {{ $ep.serverName | quote }} + {{- end }} + {{- end }} + {{- if and .Values.bootstrap.enabled .Values.bootstrap.publicUrl }} + bootstrap.toml: | + public_url = {{ .Values.bootstrap.publicUrl | quote }} + {{- if .Values.bootstrap.trustedProxies }} + trusted_proxies = [ + {{- range $i, $p := .Values.bootstrap.trustedProxies }} + {{ $p | quote }}{{ if lt $i (sub (len $.Values.bootstrap.trustedProxies) 1) }},{{ end }} + {{- end }} + ] + {{- end }} + + [owner] + email = {{ .Values.bootstrap.owner.email | quote }} + display_name = {{ .Values.bootstrap.owner.displayName | quote }} + + {{- if .Values.bootstrap.oidc.issuer }} + [oidc] + issuer = {{ .Values.bootstrap.oidc.issuer | quote }} + audience = {{ .Values.bootstrap.oidc.audience | quote }} + client_id = {{ .Values.bootstrap.oidc.clientId | quote }} + {{- end }} + {{- end }} diff --git a/deployments/helm/archie/templates/externalsecret.example.yaml b/deployments/helm/archie/templates/externalsecret.example.yaml new file mode 100644 index 000000000..863e5a7cf --- /dev/null +++ b/deployments/helm/archie/templates/externalsecret.example.yaml @@ -0,0 +1,31 @@ +{{- if .Values.externalSecret.enabled -}} +# Example ExternalSecret for External Secrets Operator (Vault / OpenBao / KMS). +# Enable with externalSecret.enabled=true or copy into your GitOps manifest repo. +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: {{ .Values.secrets.existingSecret }} + labels: + {{- include "archie.labels" . | nindent 4 }} +spec: + refreshInterval: {{ .Values.externalSecret.refreshInterval }} + secretStoreRef: + name: {{ .Values.externalSecret.secretStoreRef.name }} + kind: {{ .Values.externalSecret.secretStoreRef.kind }} + target: + name: {{ .Values.secrets.existingSecret }} + creationPolicy: Owner + data: + - secretKey: {{ .Values.secrets.keys.databaseUrl }} + remoteRef: + key: {{ .Values.externalSecret.remoteRefs.databaseUrlKey }} + property: {{ .Values.externalSecret.remoteRefs.databaseUrlProperty }} + - secretKey: {{ .Values.secrets.keys.ageIdentity }} + remoteRef: + key: {{ .Values.externalSecret.remoteRefs.ageIdentityKey }} + property: {{ .Values.externalSecret.remoteRefs.ageIdentityProperty }} + - secretKey: {{ .Values.secrets.keys.adminTokenSha256 }} + remoteRef: + key: {{ .Values.externalSecret.remoteRefs.adminTokenSha256Key }} + property: {{ .Values.externalSecret.remoteRefs.adminTokenSha256Property }} +{{- end }} diff --git a/deployments/helm/archie/templates/ingress.yaml b/deployments/helm/archie/templates/ingress.yaml new file mode 100644 index 000000000..15183ff8e --- /dev/null +++ b/deployments/helm/archie/templates/ingress.yaml @@ -0,0 +1,73 @@ +{{- if .Values.ingress.perimeter.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "archie.fullname" . }}-perimeter + labels: + {{- include "archie.labels" . | nindent 4 }} + app.kubernetes.io/component: perimeter-ingress + {{- with .Values.ingress.perimeter.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.perimeter.className }} + ingressClassName: {{ .Values.ingress.perimeter.className }} + {{- end }} + {{- with .Values.ingress.perimeter.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.ingress.perimeter.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ include "archie.fullname" $ }} + port: + name: http + {{- end }} + {{- end }} +{{- end }} +{{- if .Values.ingress.internal.enabled }} +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "archie.fullname" . }}-internal + labels: + {{- include "archie.labels" . | nindent 4 }} + app.kubernetes.io/component: internal-ingress + {{- with .Values.ingress.internal.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.internal.className }} + ingressClassName: {{ .Values.ingress.internal.className }} + {{- end }} + {{- with .Values.ingress.internal.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.ingress.internal.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ include "archie.fullname" $ }} + port: + name: http + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/helm/archie/templates/job-bootstrap.yaml b/deployments/helm/archie/templates/job-bootstrap.yaml new file mode 100644 index 000000000..2849847df --- /dev/null +++ b/deployments/helm/archie/templates/job-bootstrap.yaml @@ -0,0 +1,105 @@ +{{- if .Values.bootstrap.enabled -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "archie.fullname" . }}-bootstrap + labels: + {{- include "archie.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": {{ .Values.bootstrap.hookWeight | quote }} + "helm.sh/hook-delete-policy": {{ .Values.bootstrap.hookDeletePolicy | quote }} +spec: + backoffLimit: {{ .Values.bootstrap.backoffLimit }} + activeDeadlineSeconds: {{ .Values.bootstrap.activeDeadlineSeconds }} + template: + metadata: + labels: + {{- include "archie.labels" . | nindent 8 }} + app.kubernetes.io/component: bootstrap + spec: + restartPolicy: OnFailure + serviceAccountName: {{ include "archie.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: bootstrap + image: {{ include "archie.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - "-config" + - "" + - "-spec" + - "/etc/archie/bootstrap.toml" + - "bootstrap" + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + env: + - name: HOME + value: "/tmp" + - name: ARCHIE_DATABASE_URL_FILE + value: /run/secrets/archie/{{ .Values.secrets.keys.databaseUrl }} + - name: ARCHIE_BOOTSTRAP_OWNER_PASSWORD_FILE + value: /run/secrets/archie-bootstrap/{{ .Values.bootstrap.owner.passwordSecretKey }} + {{- if .Values.caBundle.enabled }} + - name: SSL_CERT_FILE + value: {{ .Values.caBundle.mountPath | quote }} + {{- end }} + resources: + {{- toYaml .Values.bootstrap.resources | nindent 12 }} + volumeMounts: + - name: config + mountPath: /etc/archie/bootstrap.toml + subPath: bootstrap.toml + readOnly: true + - name: runtime-secrets + mountPath: /run/secrets/archie + readOnly: true + - name: bootstrap-secrets + mountPath: /run/secrets/archie-bootstrap + readOnly: true + - name: tmp + mountPath: /tmp + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + mountPath: {{ .Values.caBundle.mountPath }} + subPath: {{ .Values.caBundle.key }} + readOnly: true + {{- end }} + volumes: + - name: config + configMap: + name: {{ include "archie.fullname" . }}-config + - name: runtime-secrets + secret: + secretName: {{ .Values.secrets.existingSecret }} + defaultMode: 0400 + items: + - key: {{ .Values.secrets.keys.databaseUrl }} + path: {{ .Values.secrets.keys.databaseUrl }} + - name: bootstrap-secrets + secret: + secretName: {{ .Values.bootstrap.owner.passwordSecretName }} + defaultMode: 0400 + items: + - key: {{ .Values.bootstrap.owner.passwordSecretKey }} + path: {{ .Values.bootstrap.owner.passwordSecretKey }} + - name: tmp + emptyDir: {} + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + {{- if .Values.caBundle.existingSecret }} + secret: + secretName: {{ .Values.caBundle.existingSecret }} + defaultMode: 0444 + {{- else }} + configMap: + name: {{ .Values.caBundle.existingConfigMap }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/helm/archie/templates/job-bundle-sync.yaml b/deployments/helm/archie/templates/job-bundle-sync.yaml new file mode 100644 index 000000000..ad4d9d0f8 --- /dev/null +++ b/deployments/helm/archie/templates/job-bundle-sync.yaml @@ -0,0 +1,123 @@ +{{- if .Values.bundleSync.enabled -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "archie.fullname" . }}-bundle-sync + labels: + {{- include "archie.labels" . | nindent 4 }} + annotations: + {{- if .Values.bundleSync.hooks.helm }} + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": {{ .Values.bundleSync.hookWeight | quote }} + "helm.sh/hook-delete-policy": {{ .Values.bundleSync.hookDeletePolicy | quote }} + {{- end }} + {{- if .Values.bundleSync.hooks.argocd }} + "argocd.argoproj.io/hook": PostSync + "argocd.argoproj.io/hook-delete-policy": BeforeHookCreation + {{- end }} +spec: + backoffLimit: {{ .Values.bundleSync.backoffLimit }} + activeDeadlineSeconds: {{ .Values.bundleSync.activeDeadlineSeconds }} + template: + metadata: + labels: + {{- include "archie.labels" . | nindent 8 }} + app.kubernetes.io/component: bundle-sync + spec: + restartPolicy: OnFailure + serviceAccountName: {{ include "archie.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: bundle-sync + image: {{ include "archie.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - "-config" + - "" + - "bundle" + - "apply" + - "--bundle" + - "/etc/archie/bundle/bundle.yaml" + {{- if .Values.bundleSync.bindings.enabled }} + - "--bindings" + - "/etc/archie/bindings/bindings.yaml" + {{- end }} + {{- if .Values.bundleSync.expectDigest }} + - "--expect-digest" + - {{ .Values.bundleSync.expectDigest | quote }} + {{- end }} + {{- if .Values.bundleSync.dryRun }} + - "--dry-run" + {{- end }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + env: + - name: HOME + value: "/tmp" + # Uses only the DML runtime role (archie_app), never owner_url. + - name: ARCHIE_DATABASE_URL_FILE + value: /run/secrets/archie/{{ .Values.secrets.keys.databaseUrl }} + {{- if .Values.caBundle.enabled }} + - name: SSL_CERT_FILE + value: {{ .Values.caBundle.mountPath | quote }} + {{- end }} + resources: + {{- toYaml .Values.bundleSync.resources | nindent 12 }} + volumeMounts: + - name: bundle + mountPath: /etc/archie/bundle/bundle.yaml + subPath: {{ .Values.bundleSync.bundleKey }} + readOnly: true + {{- if .Values.bundleSync.bindings.enabled }} + - name: bindings + mountPath: /etc/archie/bindings/bindings.yaml + subPath: {{ .Values.bundleSync.bindings.key }} + readOnly: true + {{- end }} + - name: runtime-secrets + mountPath: /run/secrets/archie + readOnly: true + - name: tmp + mountPath: /tmp + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + mountPath: {{ .Values.caBundle.mountPath }} + subPath: {{ .Values.caBundle.key }} + readOnly: true + {{- end }} + volumes: + - name: bundle + configMap: + name: {{ default (printf "%s-bundle" (include "archie.fullname" .)) .Values.bundleSync.existingConfigMap }} + {{- if .Values.bundleSync.bindings.enabled }} + - name: bindings + configMap: + name: {{ default (default (printf "%s-bundle" (include "archie.fullname" .)) .Values.bundleSync.existingConfigMap) .Values.bundleSync.bindings.existingConfigMap }} + {{- end }} + - name: runtime-secrets + secret: + secretName: {{ .Values.secrets.existingSecret }} + defaultMode: 0400 + items: + - key: {{ .Values.secrets.keys.databaseUrl }} + path: {{ .Values.secrets.keys.databaseUrl }} + - name: tmp + emptyDir: {} + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + {{- if .Values.caBundle.existingSecret }} + secret: + secretName: {{ .Values.caBundle.existingSecret }} + defaultMode: 0444 + {{- else }} + configMap: + name: {{ .Values.caBundle.existingConfigMap }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/helm/archie/templates/job-migrate.yaml b/deployments/helm/archie/templates/job-migrate.yaml new file mode 100644 index 000000000..998e9b05e --- /dev/null +++ b/deployments/helm/archie/templates/job-migrate.yaml @@ -0,0 +1,88 @@ +{{- if .Values.migrate.enabled -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "archie.fullname" . }}-migrate + labels: + {{- include "archie.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": {{ .Values.migrate.hookWeight | quote }} + "helm.sh/hook-delete-policy": {{ .Values.migrate.hookDeletePolicy | quote }} +spec: + backoffLimit: {{ .Values.migrate.backoffLimit }} + activeDeadlineSeconds: {{ .Values.migrate.activeDeadlineSeconds }} + template: + metadata: + labels: + {{- include "archie.labels" . | nindent 8 }} + app.kubernetes.io/component: migrate + spec: + restartPolicy: OnFailure + serviceAccountName: {{ include "archie.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: migrate + image: {{ include "archie.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - "-config" + - "" + - "migrate" + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + env: + - name: HOME + value: "/tmp" + - name: ARCHIE_DATABASE_URL_FILE + value: /run/secrets/archie-migrate/{{ .Values.secrets.keys.databaseUrl }} + - name: ARCHIE_DATABASE_OWNER_URL_FILE + value: /run/secrets/archie-migrate/{{ .Values.secrets.keys.databaseOwnerUrl }} + {{- if .Values.caBundle.enabled }} + - name: SSL_CERT_FILE + value: {{ .Values.caBundle.mountPath | quote }} + {{- end }} + resources: + {{- toYaml .Values.migrate.resources | nindent 12 }} + volumeMounts: + - name: migrate-secrets + mountPath: /run/secrets/archie-migrate + readOnly: true + - name: tmp + mountPath: /tmp + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + mountPath: {{ .Values.caBundle.mountPath }} + subPath: {{ .Values.caBundle.key }} + readOnly: true + {{- end }} + volumes: + - name: migrate-secrets + secret: + secretName: {{ include "archie.migrateSecretName" . }} + defaultMode: 0400 + items: + - key: {{ .Values.secrets.keys.databaseUrl }} + path: {{ .Values.secrets.keys.databaseUrl }} + - key: {{ .Values.secrets.keys.databaseOwnerUrl }} + path: {{ .Values.secrets.keys.databaseOwnerUrl }} + - name: tmp + emptyDir: {} + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + {{- if .Values.caBundle.existingSecret }} + secret: + secretName: {{ .Values.caBundle.existingSecret }} + defaultMode: 0444 + {{- else }} + configMap: + name: {{ .Values.caBundle.existingConfigMap }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/helm/archie/templates/networkpolicy.yaml b/deployments/helm/archie/templates/networkpolicy.yaml new file mode 100644 index 000000000..1fd0417f3 --- /dev/null +++ b/deployments/helm/archie/templates/networkpolicy.yaml @@ -0,0 +1,189 @@ +{{- if .Values.networkPolicy.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ include "archie.fullname" . }}-default-deny + labels: + {{- include "archie.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: + {{- include "archie.selectorLabels" . | nindent 6 }} + policyTypes: + - Ingress + - Egress +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ include "archie.fullname" . }}-allow + labels: + {{- include "archie.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: + {{- include "archie.selectorLabels" . | nindent 6 }} + policyTypes: + - Ingress + - Egress + ingress: + {{- if .Values.ingress.perimeter.enabled }} + - ports: + - protocol: TCP + port: 8080 + {{- if or .Values.networkPolicy.ingress.perimeter.namespaceSelector .Values.networkPolicy.ingress.perimeter.podSelector }} + from: + - {{- if .Values.networkPolicy.ingress.perimeter.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.ingress.perimeter.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.ingress.perimeter.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.ingress.perimeter.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- if .Values.ingress.internal.enabled }} + - ports: + - protocol: TCP + port: 8080 + {{- if or .Values.networkPolicy.ingress.internal.namespaceSelector .Values.networkPolicy.ingress.internal.podSelector }} + from: + - {{- if .Values.networkPolicy.ingress.internal.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.ingress.internal.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.ingress.internal.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.ingress.internal.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.enabled }} + - ports: + - protocol: TCP + port: {{ .Values.metrics.port }} + {{- if or .Values.networkPolicy.ingress.metrics.namespaceSelector .Values.networkPolicy.ingress.metrics.podSelector }} + from: + - {{- if .Values.networkPolicy.ingress.metrics.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.ingress.metrics.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.ingress.metrics.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.ingress.metrics.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + egress: + # DNS resolution + - ports: + - protocol: UDP + port: 53 + - protocol: TCP + port: 53 + {{- if or .Values.networkPolicy.egress.dns.namespaceSelector .Values.networkPolicy.egress.dns.podSelector }} + to: + - {{- if .Values.networkPolicy.egress.dns.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.egress.dns.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.egress.dns.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.egress.dns.podSelector | nindent 12 }} + {{- end }} + {{- end }} + # PostgreSQL / PgBouncer session pool + - ports: + - protocol: TCP + port: {{ .Values.networkPolicy.egress.postgres.port }} + {{- if or .Values.networkPolicy.egress.postgres.cidrs .Values.networkPolicy.egress.postgres.namespaceSelector .Values.networkPolicy.egress.postgres.podSelector }} + to: + {{- range .Values.networkPolicy.egress.postgres.cidrs }} + - ipBlock: + cidr: {{ . | quote }} + {{- end }} + {{- if or .Values.networkPolicy.egress.postgres.namespaceSelector .Values.networkPolicy.egress.postgres.podSelector }} + - {{- if .Values.networkPolicy.egress.postgres.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.egress.postgres.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.egress.postgres.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.egress.postgres.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + # OIDC Identity Provider + - ports: + - protocol: TCP + port: {{ .Values.networkPolicy.egress.oidc.port }} + {{- if .Values.networkPolicy.egress.oidc.cidrs }} + to: + {{- range .Values.networkPolicy.egress.oidc.cidrs }} + - ipBlock: + cidr: {{ . | quote }} + {{- end }} + {{- end }} + {{- if or .Values.proxy.httpsProxy .Values.proxy.httpProxy .Values.networkPolicy.egress.proxy.cidrs }} + # Corporate egress proxy + - ports: + - protocol: TCP + port: {{ .Values.networkPolicy.egress.proxy.port }} + {{- if .Values.networkPolicy.egress.proxy.cidrs }} + to: + {{- range .Values.networkPolicy.egress.proxy.cidrs }} + - ipBlock: + cidr: {{ . | quote }} + {{- end }} + {{- end }} + {{- end }} + {{- if or .Values.config.extensions.remote .Values.networkPolicy.egress.extensions.cidrs .Values.networkPolicy.egress.extensions.namespaceSelector .Values.networkPolicy.egress.extensions.podSelector }} + # Remote gRPC+mTLS extension endpoints + - ports: + {{- range .Values.networkPolicy.egress.extensions.ports }} + - protocol: TCP + port: {{ . }} + {{- end }} + {{- if or .Values.networkPolicy.egress.extensions.cidrs .Values.networkPolicy.egress.extensions.namespaceSelector .Values.networkPolicy.egress.extensions.podSelector }} + to: + {{- range .Values.networkPolicy.egress.extensions.cidrs }} + - ipBlock: + cidr: {{ . | quote }} + {{- end }} + {{- if or .Values.networkPolicy.egress.extensions.namespaceSelector .Values.networkPolicy.egress.extensions.podSelector }} + - {{- if .Values.networkPolicy.egress.extensions.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.egress.extensions.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.egress.extensions.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.egress.extensions.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- if or .Values.telemetry.otlpEndpoint .Values.networkPolicy.egress.otlp.cidrs .Values.networkPolicy.egress.otlp.namespaceSelector .Values.networkPolicy.egress.otlp.podSelector }} + # OpenTelemetry collector + - ports: + - protocol: TCP + port: {{ .Values.networkPolicy.egress.otlp.port }} + {{- if or .Values.networkPolicy.egress.otlp.cidrs .Values.networkPolicy.egress.otlp.namespaceSelector .Values.networkPolicy.egress.otlp.podSelector }} + to: + {{- range .Values.networkPolicy.egress.otlp.cidrs }} + - ipBlock: + cidr: {{ . | quote }} + {{- end }} + {{- if or .Values.networkPolicy.egress.otlp.namespaceSelector .Values.networkPolicy.egress.otlp.podSelector }} + - {{- if .Values.networkPolicy.egress.otlp.namespaceSelector }} + namespaceSelector: + {{- toYaml .Values.networkPolicy.egress.otlp.namespaceSelector | nindent 12 }} + {{- end }} + {{- if .Values.networkPolicy.egress.otlp.podSelector }} + podSelector: + {{- toYaml .Values.networkPolicy.egress.otlp.podSelector | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployments/helm/archie/templates/poddisruptionbudget.yaml b/deployments/helm/archie/templates/poddisruptionbudget.yaml new file mode 100644 index 000000000..3eb5f18f0 --- /dev/null +++ b/deployments/helm/archie/templates/poddisruptionbudget.yaml @@ -0,0 +1,17 @@ +{{- if .Values.podDisruptionBudget.enabled -}} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "archie.fullname" . }} + labels: + {{- include "archie.labels" . | nindent 4 }} +spec: + {{- if not (kindIs "invalid" .Values.podDisruptionBudget.minAvailable) }} + minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} + {{- else }} + maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }} + {{- end }} + selector: + matchLabels: + {{- include "archie.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/deployments/helm/archie/templates/service.yaml b/deployments/helm/archie/templates/service.yaml new file mode 100644 index 000000000..3b12a7332 --- /dev/null +++ b/deployments/helm/archie/templates/service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "archie.fullname" . }} + labels: + {{- include "archie.labels" . | nindent 4 }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + - name: metrics + port: {{ .Values.service.metricsPort }} + targetPort: metrics + protocol: TCP + selector: + {{- include "archie.selectorLabels" . | nindent 4 }} diff --git a/deployments/helm/archie/templates/serviceaccount.yaml b/deployments/helm/archie/templates/serviceaccount.yaml new file mode 100644 index 000000000..d2f32d79f --- /dev/null +++ b/deployments/helm/archie/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "archie.serviceAccountName" . }} + labels: + {{- include "archie.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} +{{- end }} diff --git a/deployments/helm/archie/templates/servicemonitor.yaml b/deployments/helm/archie/templates/servicemonitor.yaml new file mode 100644 index 000000000..bef021c6f --- /dev/null +++ b/deployments/helm/archie/templates/servicemonitor.yaml @@ -0,0 +1,20 @@ +{{- if .Values.metrics.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "archie.fullname" . }} + labels: + {{- include "archie.labels" . | nindent 4 }} + {{- with .Values.metrics.serviceMonitor.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + {{- include "archie.selectorLabels" . | nindent 6 }} + endpoints: + - port: metrics + path: {{ .Values.metrics.path }} + interval: {{ .Values.metrics.serviceMonitor.interval }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} +{{- end }} diff --git a/deployments/helm/archie/templates/statefulset.yaml b/deployments/helm/archie/templates/statefulset.yaml new file mode 100644 index 000000000..28f438797 --- /dev/null +++ b/deployments/helm/archie/templates/statefulset.yaml @@ -0,0 +1,190 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "archie.fullname" . }} + labels: + {{- include "archie.labels" . | nindent 4 }} +spec: + serviceName: {{ include "archie.fullname" . }} + # Active-Passive HA in Enterprise v1 requires a single active replica. + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "archie.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "archie.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "archie.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: archie + image: {{ include "archie.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - "-config" + - "/etc/archie/config.toml" + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + - name: metrics + containerPort: {{ .Values.metrics.port }} + protocol: TCP + env: + - name: HOME + value: "/tmp" + - name: ARCHIE_DATABASE_URL_FILE + value: /run/secrets/archie/{{ .Values.secrets.keys.databaseUrl }} + - name: ARCHIE_AGE_IDENTITY_FILE + value: /run/secrets/archie/{{ .Values.secrets.keys.ageIdentity }} + - name: ARCHIE_ADMIN_TOKEN_SHA256_FILE + value: /run/secrets/archie/{{ .Values.secrets.keys.adminTokenSha256 }} + {{- if .Values.caBundle.enabled }} + - name: SSL_CERT_FILE + value: {{ .Values.caBundle.mountPath | quote }} + {{- end }} + {{- if .Values.proxy.httpsProxy }} + - name: HTTPS_PROXY + value: {{ .Values.proxy.httpsProxy | quote }} + {{- end }} + {{- if .Values.proxy.httpProxy }} + - name: HTTP_PROXY + value: {{ .Values.proxy.httpProxy | quote }} + {{- end }} + {{- if or .Values.proxy.httpsProxy .Values.proxy.httpProxy }} + - name: NO_PROXY + value: {{ .Values.proxy.noProxy | quote }} + {{- end }} + {{- if .Values.telemetry.otlpEndpoint }} + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: {{ .Values.telemetry.otlpEndpoint | quote }} + {{- end }} + {{- with .Values.extraEnv }} + {{- toYaml . | nindent 12 }} + {{- end }} + startupProbe: + httpGet: + path: /startupz + port: http + initialDelaySeconds: {{ .Values.probes.startup.initialDelaySeconds }} + periodSeconds: {{ .Values.probes.startup.periodSeconds }} + timeoutSeconds: {{ .Values.probes.startup.timeoutSeconds }} + failureThreshold: {{ .Values.probes.startup.failureThreshold }} + livenessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }} + periodSeconds: {{ .Values.probes.liveness.periodSeconds }} + timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }} + failureThreshold: {{ .Values.probes.liveness.failureThreshold }} + readinessProbe: + httpGet: + path: /readyz + port: http + initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }} + periodSeconds: {{ .Values.probes.readiness.periodSeconds }} + timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }} + failureThreshold: {{ .Values.probes.readiness.failureThreshold }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: config + mountPath: /etc/archie/config.toml + subPath: config.toml + readOnly: true + - name: runtime-secrets + mountPath: /run/secrets/archie + readOnly: true + - name: tmp + mountPath: /tmp + - name: state + mountPath: {{ .Values.config.stateDir }} + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + mountPath: {{ .Values.caBundle.mountPath }} + subPath: {{ .Values.caBundle.key }} + readOnly: true + {{- end }} + {{- if .Values.config.extensions.tls.existingSecret }} + - name: extensions-tls + mountPath: {{ .Values.config.extensions.tls.mountPath }} + readOnly: true + {{- end }} + volumes: + - name: config + configMap: + name: {{ include "archie.fullname" . }}-config + - name: runtime-secrets + secret: + secretName: {{ .Values.secrets.existingSecret }} + defaultMode: 0400 + items: + - key: {{ .Values.secrets.keys.databaseUrl }} + path: {{ .Values.secrets.keys.databaseUrl }} + - key: {{ .Values.secrets.keys.ageIdentity }} + path: {{ .Values.secrets.keys.ageIdentity }} + - key: {{ .Values.secrets.keys.adminTokenSha256 }} + path: {{ .Values.secrets.keys.adminTokenSha256 }} + - name: tmp + emptyDir: {} + {{- if not .Values.persistence.enabled }} + - name: state + emptyDir: {} + {{- else if .Values.persistence.existingClaim }} + - name: state + persistentVolumeClaim: + claimName: {{ .Values.persistence.existingClaim }} + {{- end }} + {{- if .Values.caBundle.enabled }} + - name: ca-bundle + {{- if .Values.caBundle.existingSecret }} + secret: + secretName: {{ .Values.caBundle.existingSecret }} + defaultMode: 0444 + {{- else }} + configMap: + name: {{ .Values.caBundle.existingConfigMap }} + {{- end }} + {{- end }} + {{- if .Values.config.extensions.tls.existingSecret }} + - name: extensions-tls + secret: + secretName: {{ .Values.config.extensions.tls.existingSecret }} + defaultMode: 0400 + {{- end }} + {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} + volumeClaimTemplates: + - metadata: + name: state + labels: + {{- include "archie.labels" . | nindent 10 }} + spec: + accessModes: + {{- toYaml .Values.persistence.accessModes | nindent 10 }} + {{- if .Values.persistence.storageClass }} + storageClassName: {{ .Values.persistence.storageClass | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- end }} diff --git a/deployments/helm/archie/values-dev.yaml b/deployments/helm/archie/values-dev.yaml new file mode 100644 index 000000000..5f98a99ca --- /dev/null +++ b/deployments/helm/archie/values-dev.yaml @@ -0,0 +1,32 @@ +# Development stage overlay: isolated non-prod database, key, and relaxed egress for local testing. + +image: + tag: "dev" + pullPolicy: IfNotPresent + +config: + catalogue: + disableAutoUpdate: false + extensions: + requireRemote: true + +persistence: + size: "2Gi" + +resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "500m" + memory: "512Mi" + +networkPolicy: + enabled: false + +podDisruptionBudget: + enabled: false + +metrics: + serviceMonitor: + enabled: false diff --git a/deployments/helm/archie/values-prod.yaml b/deployments/helm/archie/values-prod.yaml new file mode 100644 index 000000000..143246cae --- /dev/null +++ b/deployments/helm/archie/values-prod.yaml @@ -0,0 +1,70 @@ +# Production stage overlay: full restricted hardening, split ingress, remote mTLS extensions, and PDB. + +replicaCount: 1 + +image: + # Always pin an immutable cosign-verified digest in production (for example "sha256:..."). + digest: "" + pullPolicy: IfNotPresent + +terminationGracePeriodSeconds: 45 + +config: + shutdownGrace: "30s" + catalogue: + disableAutoUpdate: true + extensions: + requireRemote: true + +persistence: + enabled: true + size: "20Gi" + +resources: + requests: + cpu: "500m" + memory: "512Mi" + limits: + cpu: "2000m" + memory: "2Gi" + +ingress: + perimeter: + enabled: true + className: "external-nginx" + annotations: + nginx.ingress.kubernetes.io/ssl-redirect: "true" + nginx.ingress.kubernetes.io/limit-rps: "25" + hosts: + - host: hooks.archie.example.com + paths: + - /hooks + - /webhooks + tls: + - secretName: archie-prod-perimeter-tls + hosts: + - hooks.archie.example.com + internal: + enabled: true + className: "internal-nginx" + annotations: + nginx.ingress.kubernetes.io/ssl-redirect: "true" + hosts: + - host: archie.internal.example.com + paths: + - / + tls: + - secretName: archie-prod-internal-tls + hosts: + - archie.internal.example.com + +networkPolicy: + enabled: true + +metrics: + serviceMonitor: + enabled: true + +podDisruptionBudget: + enabled: true + maxUnavailable: 1 diff --git a/deployments/helm/archie/values-staging.yaml b/deployments/helm/archie/values-staging.yaml new file mode 100644 index 000000000..d3f13bcf1 --- /dev/null +++ b/deployments/helm/archie/values-staging.yaml @@ -0,0 +1,57 @@ +# Staging stage overlay: mirrors production hardening and ingress isolation with its own DB and keys. + +image: + # Pin digest before promoting from dev to staging. + digest: "" + +config: + catalogue: + disableAutoUpdate: true + extensions: + requireRemote: true + +persistence: + size: "5Gi" + +resources: + requests: + cpu: "250m" + memory: "256Mi" + limits: + cpu: "1000m" + memory: "1Gi" + +ingress: + perimeter: + enabled: true + className: "external-nginx" + hosts: + - host: hooks.staging.archie.example.com + paths: + - /hooks + - /webhooks + tls: + - secretName: archie-staging-perimeter-tls + hosts: + - hooks.staging.archie.example.com + internal: + enabled: true + className: "internal-nginx" + hosts: + - host: archie.staging.internal.example.com + paths: + - / + tls: + - secretName: archie-staging-internal-tls + hosts: + - archie.staging.internal.example.com + +networkPolicy: + enabled: true + +metrics: + serviceMonitor: + enabled: true + +podDisruptionBudget: + enabled: false diff --git a/deployments/helm/archie/values.yaml b/deployments/helm/archie/values.yaml new file mode 100644 index 000000000..32849aa1d --- /dev/null +++ b/deployments/helm/archie/values.yaml @@ -0,0 +1,285 @@ +# Default production-oriented values for Archie Enterprise (Active-Passive v1). +# Pair with values-dev.yaml, values-staging.yaml, or values-prod.yaml. + +replicaCount: 1 + +image: + repository: ghcr.io/samcharles93/archie + tag: "v1.0.0" + # Set digest (e.g. "sha256:...") to pin the exact immutable artifact in staging and prod. + digest: "" + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + name: "" + annotations: {} + automountServiceAccountToken: false + +# Exceeds config.shutdownGrace (30s) so active requests and run checkpoints drain on SIGTERM. +terminationGracePeriodSeconds: 45 + +podAnnotations: {} +podLabels: {} + +podSecurityContext: + runAsNonRoot: true + runAsUser: 65532 + runAsGroup: 65532 + fsGroup: 65532 + fsGroupChangePolicy: OnRootMismatch + seccompProfile: + type: RuntimeDefault + +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 65532 + capabilities: + drop: + - ALL + +config: + listen: "0.0.0.0:8080" + stateDir: "/var/lib/archie" + shutdownGrace: "30s" + # Public age1... backup recipients used alongside the primary sealing identity. + ageBackupRecipients: [] + catalogue: + # Must be set together with publicKey when overriding the default catalogue mirror. + location: "" + publicKey: "" + disableAutoUpdate: true + extensions: + # Kubernetes restricted PSS forbids CLONE_NEWUSER namespaces; require remote gRPC+mTLS extensions. + requireRemote: true + tls: + # Secret holding ca.crt, tls.crt, and tls.key for mTLS client authentication to extensions. + existingSecret: "" + mountPath: "/etc/archie/extensions-tls" + # Map extension key or name to { address: "ext.ns.svc:50051", serverName: "ext.internal" }. + remote: {} + +secrets: + # Secret holding database-url, age-identity, and admin-token-sha256 for runtime pods. + existingSecret: "archie-runtime-secrets" + keys: + databaseUrl: "database-url" + databaseOwnerUrl: "database-owner-url" + ageIdentity: "age-identity" + adminTokenSha256: "admin-token-sha256" + +caBundle: + enabled: false + existingConfigMap: "" + existingSecret: "" + key: "ca-certificates.crt" + mountPath: "/etc/ssl/certs/archie-ca.crt" + +proxy: + httpsProxy: "" + httpProxy: "" + noProxy: "localhost,127.0.0.1,.svc,.cluster.local" + +telemetry: + otlpEndpoint: "" + +extraEnv: [] + +persistence: + enabled: true + existingClaim: "" + storageClass: "" + accessModes: + - ReadWriteOnce + size: "10Gi" + +resources: + requests: + cpu: "250m" + memory: "256Mi" + limits: + cpu: "1000m" + memory: "1Gi" + +probes: + startup: + initialDelaySeconds: 2 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 30 + liveness: + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 3 + failureThreshold: 3 + readiness: + initialDelaySeconds: 2 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 3 + +migrate: + enabled: true + # Dedicated migration secret holding database-owner-url and database-url. + # Keeps DDL credentials completely out of the runtime StatefulSet. + existingSecret: "archie-migrate-secrets" + hookWeight: "-5" + hookDeletePolicy: "before-hook-creation,hook-succeeded" + backoffLimit: 3 + activeDeadlineSeconds: 300 + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "500m" + memory: "256Mi" + +bootstrap: + enabled: false + hookWeight: "-1" + hookDeletePolicy: "before-hook-creation,hook-succeeded" + backoffLimit: 2 + activeDeadlineSeconds: 180 + publicUrl: "" + trustedProxies: [] + owner: + email: "" + displayName: "Platform Owner" + passwordSecretName: "archie-bootstrap-secrets" + passwordSecretKey: "owner-password" + oidc: + issuer: "" + audience: "" + clientId: "" + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "500m" + memory: "256Mi" + +bundleSync: + enabled: false + hooks: + helm: true + argocd: true + hookWeight: "5" + hookDeletePolicy: "before-hook-creation,hook-succeeded" + backoffLimit: 2 + activeDeadlineSeconds: 180 + # ConfigMap holding bundle.yaml (and optional bindings.yaml). + existingConfigMap: "" + bundleKey: "bundle.yaml" + bindings: + enabled: true + # Optional separate ConfigMap for stage-local bindings; falls back to bundleSync.existingConfigMap. + existingConfigMap: "" + key: "bindings.yaml" + expectDigest: "" + dryRun: false + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "500m" + memory: "256Mi" + +service: + type: ClusterIP + port: 8080 + metricsPort: 9090 + annotations: {} + +metrics: + port: 9090 + path: "/metrics" + serviceMonitor: + enabled: false + interval: "30s" + scrapeTimeout: "10s" + labels: {} + +ingress: + # External edge ingress admitting webhook intake (/hooks/ and /webhooks/) only. + perimeter: + enabled: false + className: "" + annotations: {} + hosts: [] + tls: [] + # Internal corporate VPN / SSO ingress serving Dashboard, /api/, and OIDC routes. + internal: + enabled: false + className: "" + annotations: {} + hosts: [] + tls: [] + +networkPolicy: + enabled: true + ingress: + perimeter: + namespaceSelector: {} + podSelector: {} + internal: + namespaceSelector: {} + podSelector: {} + metrics: + namespaceSelector: {} + podSelector: {} + egress: + dns: + namespaceSelector: + kubernetes.io/metadata.name: kube-system + podSelector: + k8s-app: kube-dns + postgres: + port: 5432 + cidrs: [] + namespaceSelector: {} + podSelector: {} + oidc: + port: 443 + cidrs: [] + proxy: + port: 3128 + cidrs: [] + extensions: + ports: + - 50051 + cidrs: [] + namespaceSelector: {} + podSelector: {} + otlp: + port: 4317 + cidrs: [] + namespaceSelector: {} + podSelector: {} + +podDisruptionBudget: + enabled: false + maxUnavailable: 1 + minAvailable: null + +externalSecret: + enabled: false + refreshInterval: "1h" + secretStoreRef: + name: "vault-backend" + kind: "ClusterSecretStore" + remoteRefs: + databaseUrlKey: "archie/prod/database" + databaseUrlProperty: "runtime_url" + ageIdentityKey: "archie/prod/age" + ageIdentityProperty: "identity" + adminTokenSha256Key: "archie/prod/admin" + adminTokenSha256Property: "token_sha256" diff --git a/docs/enterprise/compliance-control-mapping.md b/docs/enterprise/compliance-control-mapping.md new file mode 100644 index 000000000..12eeee4be --- /dev/null +++ b/docs/enterprise/compliance-control-mapping.md @@ -0,0 +1,54 @@ +# Enterprise Compliance Control Mapping + +Archie enforces preventive, detective, and corrective controls in code and deployment files. This guide maps each control to its source code, deployment files, `go test -short` tests, and compliance frameworks. It covers SOC 2 (CC6, CC7, CC8), ISO/IEC 27001:2022, SOX ITGC, and APRA CPS 234. + +## Control Matrix + +| Control area | Archie code | Deployment files | Automated test proof | Framework mapping | +| --- | --- | --- | --- | --- | +| Database role split | `pg.Migrate` (`owner_url`) vs DML-only `url` checked by `pg.VerifySchema` (`internal/platform/pg/pg.go`) | `job-migrate.yaml` mounts `owner_url`; `statefulset.yaml` and `compose.enterprise.yml` omit `owner_url` | `TestMissingMigrations` (`internal/platform/pg/pg_test.go`), `TestLoadMigrateConfigRequiresOnlyDatabaseRoles` (`internal/app/archie/config_test.go`) | SOC 2 CC6.1, CC6.3; ISO 27001 A.5.15, A.8.2; SOX ITGC Access; CPS 234 (15-17) | +| API and setup gate | Cedar policy checks on every route (`internal/app/archie/api.go`, `modules/governance/access.go`) and closed gate (`internal/app/archie/gate.go`) | Split internal vs perimeter ingress (`ingress.yaml`) | `TestEveryOperationIsAuthorized`, `TestUnwiredAuthorizerRefuses` (`internal/app/archie/access_test.go`), `TestClosedGateServesOnlySetup`, `TestGateIsNotBypassedByPathTricks` (`internal/app/archie/gate_test.go`), `TestEnforcementFailsClosedAndRecordsDecisions` (`modules/governance/enforce_test.go`) | SOC 2 CC6.1, CC6.2; ISO 27001 A.5.15, A.8.3; SOX ITGC Access; CPS 234 (15-18) | +| Identity and SSO | Confidential OIDC, role mapping, SSO-only mode, session limits, and back-channel logout (`modules/governance/oidc.go`, `identity.go`) | Headless `archie bootstrap` (`job-bootstrap.yaml`, `internal/app/archie/bootstrap.go`) | `TestAuthenticateRequest` (`modules/governance/auth_test.go`), `TestAuthenticationSettingsRejectUntrustedOrigins`, `TestPasswordVerification` (`modules/governance/identity_test.go`), `TestLoadBootstrapSpecAndEnvFiles` (`internal/app/archie/bootstrap_test.go`) | SOC 2 CC6.1, CC6.2; ISO 27001 A.5.17, A.8.5; SOX ITGC Access; CPS 234 (15-17) | +| Four-eyes SoD and step-up | Cedar judgement (`modules/judgement/`), passkey checks (`modules/approvals/`), and SoD rule blocking self-approval | Stage-local autonomy caps; prod approval gates | `TestDashboardAnswerComesFromAnAccountWhoseRoleMayApprove`, `TestIrreversibleActionsNeedFreshAuthentication` (`modules/approvals/dashboard_test.go`), `TestExecuteApprovedRunsOnlyWhatThePersonSaw` (`modules/judgement/judgement_test.go`), `TestChatProhibitsPrivilegedActions` (`modules/judgement/chat_test.go`) | SOC 2 CC6.3, CC8.1; ISO 27001 A.5.3; SOX ITGC Changes; CPS 234 (16-18) | +| Keys and secrets | Label-bound `age` X25519 sealing (`internal/platform/seal/seal.go`), `*_FILE` loading (`config.go`), `archie rekey`, and log redaction (`auditjson/`) | `*_FILE` mounts in `statefulset.yaml` and `compose.enterprise.yml`; `externalsecret.example.yaml` | `TestSealedValueOpensOnlyWhereItBelongs` (`internal/platform/seal/seal_test.go`), `TestCredentialRoutesNeverReturnASecret`, `TestBearerTokenByIDRespectsScope` (`modules/connectors/credentials_test.go`), `TestStoredPayloadKeepsCredentialsOut` (`internal/platform/auditjson/auditjson_test.go`), `TestLoadConfigRuntimeAndEnvFiles` (`internal/app/archie/config_test.go`) | SOC 2 CC6.1, CC6.7; ISO 27001 A.8.24; SOX ITGC Access; CPS 234 (15-20) | +| Pod and extension isolation | `RemoteGRPCRuntime` over mTLS (`modules/connectors/internal/host/remote.go`) and `LocalNamespaceRuntime` with egress tunnel (`egress/tunnel.go`) | `restricted` PSS in `statefulset.yaml`; `seccomp.json` in `compose.enterprise.yml`; `networkpolicy.yaml` | `TestRemoteGRPCRequiresMTLSAndEnforcesTrust` (`modules/connectors/internal/host/remote_test.go`), `TestCommandConfinesOnlyWithEgress`, `TestNamespaceLimitRefusesDisabledNamespaces` (`modules/connectors/internal/host/host_test.go`), `TestTunnelEnforcesAllowListBeforeCorporateProxy` (`modules/connectors/internal/egress/tunnel_test.go`) | SOC 2 CC6.6, CC6.7; ISO 27001 A.8.20, A.8.22; SOX ITGC Ops; CPS 234 (16-18) | +| Supply chain and webhooks | Ed25519-signed catalogues with SHA-256 checks (`catalogue/`) and pre-parse HMAC checks (`modules/events/verify.go`) | Digest-pinned images (`values-prod.yaml`); `[catalogue]` mirror; perimeter `/hooks/` ingress | `TestFetchRefusesAnArtifactWhoseDigestDoesNotMatch`, `TestAcceptRefusesGrantsTheExtensionNeverDeclared`, `TestVerifyRefusesAForgedOrMalformedCatalogue` (`modules/connectors/internal/catalogue/catalogue_test.go`), `TestReadOCIChecksSignatureAndPackagePin` (`oci_test.go`), `TestHMACSourceVerifiesBeforeParsing` (`modules/events/verify_test.go`) | SOC 2 CC7.1, CC8.1; ISO 27001 A.8.25, A.8.28; SOX ITGC Changes; CPS 234 (21-22) | +| Audit, tracing, and changes | Append-only `audit.events` (`SELECT`, `INSERT`), stdout JSON audit logs, OTel trace IDs, `archie bundle`, and change windows | `servicemonitor.yaml`; SIEM log shipping; `values-{dev,staging,prod}.yaml` | `TestEveryDecisionIsRecorded`, `TestAllowedDecisionNeedsItsRecord` (`modules/governance/decisions_test.go`), `TestReadAuditRoleBoundary` (`modules/governance/access_test.go`), `TestTimingHoldsChangingActionsOutsideTheSchedule` (`modules/governance/timing_test.go`), `TestAutonomyIsEarnedSlowlyAndLostAtOnce` (`modules/judgement/autonomy_test.go`) | SOC 2 CC7.2, CC7.3, CC8.1; ISO 27001 A.8.15, A.8.32; SOX ITGC Changes, Ops; CPS 234 (23-28) | +| Availability and deletion record | `/healthz`, `/startupz`, `/readyz` (`health/health.go`), `ClaimServe` lock (`pg/pg.go`), and deletion ledger (`deletions/deletions.go`) | RWO PVC in `statefulset.yaml`; `poddisruptionbudget.yaml`; `dr-and-backup.md` drill | `TestProbesSeparateStartupFromReadiness` (`internal/platform/health/health_test.go`), `TestLogRecordsEachDeletion` (`internal/platform/deletions/deletions_test.go`), `TestForgetCommitsThenRecords`, `TestReapplyDeletionsAppliesEveryRecordedNote` (`modules/memory/notes_test.go`) | SOC 2 CC7.4, A1.2; ISO 27001 A.5.30; SOX ITGC Ops; CPS 234 (19, 25) | + +## Framework Alignment Summary + +### SOC 2 (CC6, CC7, CC8) + +- **CC6 (Access Controls):** Archie enforces OIDC SSO, Cedar checks on every route (`TestEveryOperationIsAuthorized`), DML-only database roles, `age` sealing, and default-deny `NetworkPolicy`. +- **CC7 (System Operations):** Archie checks webhook HMACs before parsing (`TestHMACSourceVerifiesBeforeParsing`), runs as UID `65532` with a read-only root filesystem, and exposes `/healthz`, `/startupz`, `/readyz`, stdout JSON audit logs, and `/metrics`. +- **CC8 (Change Management):** Archie splits `archie migrate` from serving pods, signs extension catalogues, promotes stages with `archie bundle`, checks change windows (`TestTimingHoldsChangingActionsOutsideTheSchedule`), and enforces SoD on approvals. + +### ISO/IEC 27001:2022 + +- **Access Rights (A.5.15, A.5.17, A.8.2, A.8.5):** Separate `archie_owner` and `archie_app` roles limit schema rights. OIDC role mapping, SSO-only mode, and passkey checks gate high-risk actions. +- **Crypto and Networks (A.8.20, A.8.22, A.8.24):** Deployments use PostgreSQL `sslmode=verify-full`, TLS 1.3 mTLS for remote gRPC extensions, `age` keys with backup recipients, and `HTTPS_PROXY` allow-lists. +- **Logs, Supply Chain, and Continuity (A.8.15, A.8.25, A.8.32, A.5.30):** Append-only audit logs, Ed25519-signed catalogues, `task check` (`golangci-lint`, `gosec`, `go test -short`), and quarterly DR drills cover daily operations. + +### SOX ITGC + +- **Access to Programs and Data:** Only `archie migrate` holds DDL rights. Runtime pods cannot change schemas, edit audit rows, or return secrets (`TestCredentialRoutesNeverReturnASecret`). +- **Program Changes:** Stages stay isolated across `dev`, `staging`, and `prod`. Digest-pinned OCI images, `archie bundle diff` and `apply`, and four-eyes SoD gate all changes. +- **Computer Operations:** `ClaimServe` blocks serving pods during database restores. `shutdown_grace` drains active runs cleanly. `memory.ReapplyDeletions` keeps deleted notes removed after a snapshot restore. + +### APRA CPS 234 + +- **Asset Controls and Testing (Paragraphs 15-22):** Controls scale with impact via Cedar guards, extension trust ceilings (`TestGuardExtensionsDecideAtTheLowestCeiling`), mTLS checks, and automated `task check` suites. +- **Detection and Recovery (Paragraphs 23-28):** Pre-parse webhook checks, stdout JSON audit streams to SIEM/WORM storage, OpenTelemetry trace IDs, and quarterly DR drills provide full audit trails. + +## Continuous Gate + +Run the repository gate, Helm lint, and prose checks before each release and audit: + +```bash +task check +helm lint deployments/helm/archie -f deployments/helm/archie/values-prod.yaml +vale docs/enterprise/*.md +``` + +`task check` runs `go test -short ./...`, `golangci-lint` (including `gosec`), and generated schema and OpenAPI checks. diff --git a/docs/enterprise/deployment-architecture.md b/docs/enterprise/deployment-architecture.md new file mode 100644 index 000000000..bee9784ff --- /dev/null +++ b/docs/enterprise/deployment-architecture.md @@ -0,0 +1,82 @@ +# Enterprise Deployment Architecture + +Archie runs as a single static binary (`cmd/archie`) backed by PostgreSQL. Regulated deployments isolate each stage, separate DDL from DML credentials, split external webhook ingress from internal operator access, and enforce strict pod or container boundaries. + +## Multi-Stage Isolation Zones + +Deploy Archie into three independent stages: `dev`, `staging`, and `prod`. Each stage runs its own Archie instance and shares no runtime state with any other stage. + +| Resource | `dev` | `staging` | `prod` | +| --- | --- | --- | --- | +| Kubernetes namespace or host | `archie-dev` | `archie-staging` | `archie-prod` | +| PostgreSQL database | Isolated dev instance | Isolated staging instance | Managed HA PostgreSQL (`sslmode=verify-full`) | +| `age` sealing key | Stage-local `age_identity` | Stage-local `age_identity` | Stage-local `age_identity` with offline `age_backup_recipients` | +| OIDC client | Non-prod IdP client | Staging IdP client | Production IdP confidential client | +| Earned autonomy | Local to `dev` | Local to `staging` | Built independently in `prod` | +| Helm overlay | `values-dev.yaml` | `values-staging.yaml` | `values-prod.yaml` | + +Earned autonomy in `staging` never promotes to `prod`. Promote declarative configuration (workflows, Cedar policies, judgement rules, and action-type metadata) with `archie bundle`. Keep credentials, OIDC bindings, target hosts, and autonomy counters local to each stage. + +Pin container images by immutable SHA-256 digest (`image.digest` in Helm) and verify cosign signatures before deploying to `staging` and `prod`. Set `[catalogue]` `disable_auto_update = true` and mirror signed extension catalogues internally in air-gapped stages. + +### Stage Promotion Models + +Choose one of two promotion workflows depending on your delivery pipeline: + +1. **Push CI/CD (GitHub Actions, GitLab CI, or Jenkins):** + - On pull requests, run `archie bundle validate` offline to check workflow YAML, Cedar policy syntax, judgement rules, and stage `Bindings` without database access. + - Export the tested bundle from `staging` and record its canonical SHA-256 digest (`Bundle.Digest()`). + - After manual change approval, the `prod` pipeline runs `archie bundle apply --expect-digest ` over HTTPS using `ARCHIE_URL` and `ARCHIE_TOKEN_FILE`. The CI runner never touches PostgreSQL directly. +2. **Pull GitOps (Argo CD or Flux):** + - Store the stage Helm values (`values-staging.yaml`, `values-prod.yaml`), `bundle.yaml`, and stage-local `bindings.yaml` in Git. + - Enable `bundleSync.enabled: true` in `deployments/helm/archie` to run `templates/job-bundle-sync.yaml` as an Argo CD `PostSync` or Helm `post-install,post-upgrade` Job. + - The Job mounts the bundle `ConfigMap`, uses only the runtime `archie_app` database secret (`ARCHIE_DATABASE_URL_FILE`), and applies unchanged bundles idempotently with optional `expectDigest` verification. + +## Split Ingress and Network Boundaries + +Separate external webhook delivery from operator and administrator access using two ingress resources (`deployments/helm/archie/templates/ingress.yaml`): + +1. **Perimeter webhook ingress (`ingress.perimeter`):** Expose only webhook intake paths (`/hooks/` for `cmd/archie` intake and `/webhooks/` where routed by a reverse proxy). Terminate TLS at the edge and apply rate limits. The `events` module verifies each payload's HMAC signature before parsing JSON (`modules/events/verify.go`). +2. **Internal operator ingress (`ingress.internal`):** Serve the Dashboard, `/api/`, and OIDC routes behind a corporate VPN or internal load balancer. Never expose `/api/` or the setup surface on the perimeter ingress. + +Enforce default-deny `NetworkPolicy` rules (`deployments/helm/archie/templates/networkpolicy.yaml`) in `staging` and `prod`. Permit ingress only from the perimeter ingress controller (port `8080`), internal ingress controller (port `8080`), and Prometheus scraper (port `9090` on `/metrics`). Permit egress only to DNS (`53`), PostgreSQL or PgBouncer (`5432`), the OIDC issuer (`443`), configured remote extension endpoints, the corporate proxy (`HTTPS_PROXY`), and the OpenTelemetry collector (`4317`). + +## Database Role Split and PgBouncer Session Pooling + +Archie separates schema ownership from runtime operations across two PostgreSQL roles: + +- **`archie_owner` (`ARCHIE_DATABASE_OWNER_URL_FILE`):** Holds DDL rights. Used only by `archie migrate` inside the Helm pre-install/pre-upgrade `Job` (`job-migrate.yaml`) or the Compose `archie-migrate` init service (`deployments/archie/compose.enterprise.yml`). +- **`archie_app` (`ARCHIE_DATABASE_URL_FILE`):** Holds only `USAGE` and DML privileges (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, and `SELECT` on `public.goose_db_version`). The runtime `StatefulSet` and Compose `archie` service mount only this credential. At startup, `pg.VerifySchema` (`internal/platform/pg/pg.go`) checks that every embedded migration is applied and fails closed if the schema lags behind. + +### PgBouncer Session-Pooling Requirement for `ClaimServe` + +At boot, `cmd/archie` calls `pg.ClaimServe` (`internal/platform/pg/pg.go`). `ClaimServe` opens a dedicated connection via `db.Conn(ctx)` and acquires a shared PostgreSQL session advisory lock (`pg_try_advisory_lock_shared(hashtextextended('archie.serve.owner', 0))`). It holds that lock for the entire lifetime of the serving process. A database restore takes the same key exclusively so no serving pod can start or run during a restore window. + +If you deploy PgBouncer in front of PostgreSQL, configure `pool_mode = session` for Archie's runtime pool. PgBouncer `transaction` and `statement` pooling modes share server backends across clients and release or drop session advisory locks between transactions. Direct connections to the HA PostgreSQL primary also satisfy this requirement. + +## Pod Security and Extension Confinement + +Extension execution differs between Kubernetes and Docker Compose because Kubernetes `restricted` Pod Security Standards forbid user namespaces. + +| Control | Kubernetes (`deployments/helm/archie`) | Hardened Compose (`deployments/archie/compose.enterprise.yml`) | +| --- | --- | --- | +| User and root filesystem | `runAsNonRoot: true`, UID/GID `65532`, read-only root filesystem, `allowPrivilegeEscalation: false`, `capabilities.drop: [ALL]` | `user: "65532:65532"`, `read_only: true`, `tmpfs: /tmp`, `cap_drop: [ALL]`, `no-new-privileges:true` | +| Seccomp profile | `seccompProfile.type: RuntimeDefault` | `deployments/archie/seccomp.json` (Docker default plus `clone` for namespaces) | +| Extension runtime | `RemoteGRPCRuntime` over mTLS or Unix socket (`require_remote = true`) | `LocalNamespaceRuntime` (`CLONE_NEWUSER` and `CLONE_NEWNET`) | +| Egress proxy and PKI | `HTTPS_PROXY`, `NO_PROXY`, and `SSL_CERT_FILE` propagated to runtime and `NetworkPolicy` | `HTTPS_PROXY`, `NO_PROXY`, and `SSL_CERT_FILE` propagated into confined namespaces | + +In Kubernetes, run extensions as separate Pods or sidecars under `restricted` Pod Security Standards and isolate them with `NetworkPolicy`. Configure `[extensions]` in `config.toml` (`templates/configmap.yaml`) with `require_remote = true`, TLS 1.3 mTLS certificates (`ca_file`, `cert_file`, `key_file`), and explicit `[extensions.remote.]` targets. If neither `RemoteGRPCRuntime` nor `LocalNamespaceRuntime` is available, `modules/connectors/internal/host/remote.go` fails closed. + +In Docker Compose and VM hosts, `LocalNamespaceRuntime` confines each extension binary in its own user and network namespace behind an allow-list forward proxy (`modules/connectors/internal/egress/tunnel.go`). The tunnel enforces Archie's host allow-list and loopback checks before chaining allowed traffic through `HTTPS_PROXY`. + +## Probes, Graceful Drain, and High Availability + +`cmd/archie` exposes three health endpoints (`internal/platform/health/health.go`): + +- `/healthz`: Liveness probe. Returns `200` while the HTTP server process is alive. +- `/startupz`: Startup probe. Verifies database connectivity and confirms the deletion ledger is consistent before Kubernetes routes traffic or triggers liveness checks. +- `/readyz`: Readiness probe. Requires `/startupz` checks plus completion of owner setup (`gate.go`), and returns `503` as soon as `SIGTERM` begins draining. + +Set `terminationGracePeriodSeconds` (`45` seconds in `values-prod.yaml`) higher than `shutdown_grace` (`30s`) so in-flight HTTP requests and run checkpoints finish before `SIGKILL`. + +Enterprise v1 runs Active-Passive HA with `replicaCount: 1` on a `StatefulSet` backed by a `ReadWriteOnce` PVC for `state_dir`. Never scale `replicaCount` above `1` in v1 without shared `state_dir` storage and v2 Active-Active coordination (`LISTEN/NOTIFY` hub, lease election, and object-lock deletion ledger). diff --git a/docs/enterprise/dr-and-backup.md b/docs/enterprise/dr-and-backup.md new file mode 100644 index 000000000..334160ca0 --- /dev/null +++ b/docs/enterprise/dr-and-backup.md @@ -0,0 +1,65 @@ +# Disaster Recovery and Backup Runbook + +Archie keeps durable state across three separate stores: PostgreSQL, the `age` sealing keys, and the external deletion ledger (`deletions.jsonl`). Back up and protect each store independently. Restoring PostgreSQL alone is never enough if `age` keys or the deletion ledger are lost. + +## Recovery Objectives + +| Store | What it holds | RPO target | RTO target | Backup mechanism | +| --- | --- | --- | --- | --- | +| PostgreSQL (`archie` database) | Workflows, runs, approvals, events, governance, sealed credentials, audit events | 5 minutes or less | 30 minutes | Automated base snapshots plus continuous WAL archiving (PITR) | +| `age` recovery keys (`age_backup_recipients`) | Ability to open sealed connector credentials and event HMAC secrets | Zero key loss | Immediate on restore | Offline escrow in enterprise secret manager or HSM vault | +| Deletion ledger (`state_dir/deletions.jsonl`) | Append-only record of deleted memory notes | Zero acknowledged deletion loss | 15 minutes | Independent PVC or host volume snapshots replicated off-cluster | + +## Independent Backup Strategy + +### 1. PostgreSQL Database + +Back up the PostgreSQL cluster using continuous WAL archiving and scheduled base backups so you can restore to a point in time. + +- Back up as the `postgres` or `archie_owner` administrative role, not `archie_app`. +- Include the `public.goose_db_version` table and every Archie module schema (`runs`, `connectors`, `events`, `governance`, `deliveries`, `judgement`, `approvals`, `memory`, `alerts`, `proposals`, `chat`, and `audit`). +- Exclude `state_dir` and `age` private keys from database backup media so a database dump alone cannot decrypt stored credentials. + +### 2. `age` Sealing Keys and Key Rotation + +`internal/platform/seal/seal.go` seals connector credentials (`connectors.credentials`) and webhook secrets (`events.sources.hmac_secret_sealed`) with `age` X25519 keys bound to record labels. If the active `age_identity` and all `age_backup_recipients` are lost, every sealed secret in the database is unrecoverable. + +Protect sealing keys with two controls: + +1. **Configure offline backup recipients:** Generate a recovery `age` keypair in your enterprise vault (`archie -new-age-identity` or `age-keygen`) and list its public `age1...` string under `age_backup_recipients` in `config.toml`. Keep the matching `AGE-SECRET-KEY-1...` offline in your secret manager. +2. **Rotate keys with `archie rekey`:** Rotate compromised or expiring `age` identities atomically using `archie rekey`. The command takes a PostgreSQL advisory lock (`archie.rekey.owner`). It opens every sealed credential and webhook secret with the old identity, re-seals and checks decryption with the new identity in one transaction, and writes a JSON audit log. + +Never delete the old identity from your vault until the post-rotation database backup completes. + +### 3. External Deletion Ledger (`deletions.jsonl`) + +When a user deletes a memory note, `modules/memory` commits the deletion in PostgreSQL and appends an `Entry` (`table`, `org_id`, `id`, `at`) to `deletions.jsonl` inside `state_dir` (`internal/platform/deletions/deletions.go`). Each append uses `flock` and `fsync` on both the file and parent directories so the record outlives the database. + +Keep `state_dir` on an independent `ReadWriteOnce` persistent volume (or dedicated host volume in Compose) and snapshot it separately from PostgreSQL. Never restore `state_dir` from a snapshot older than the database snapshot you are restoring. If `deletions.jsonl` is lost on an instance that previously recorded deletions, `memory.ReapplyDeletions` returns `deletions.ErrUnsafeRollback` and stops startup rather than exposing deleted notes. + +## Restore Procedure + +Follow these steps to recover a stage from backup: + +1. **Stop active Archie pods or containers:** Scale the `StatefulSet` to `0` (`kubectl scale statefulset archie --replicas=0`) or run `docker compose stop archie`. +2. **Acquire the exclusive serve lock:** If restoring onto an active PostgreSQL instance, hold `pg_advisory_lock(hashtextextended('archie.serve.owner', 0))` in your restore session so no stray Archie process can pass `pg.ClaimServe` before recovery finishes. +3. **Restore PostgreSQL:** Restore the base snapshot and replay WAL logs to the target recovery timestamp. Verify `public.goose_db_version` is intact. +4. **Restore or preserve `state_dir`:** Keep the existing `state_dir` volume containing the latest `deletions.jsonl`, or restore the newest `state_dir` backup taken at or after the database restore timestamp. +5. **Restore `age` key material:** Ensure `ARCHIE_AGE_IDENTITY_FILE` mounts a valid `age_identity` (or the backup identity stored in your vault if the primary key was lost). If you recover with the backup identity, run `archie rekey` right after startup to rotate to a new runtime key. +6. **Run migrations and start Archie:** Run the `archie migrate` Job if the restored snapshot precedes the deployed binary schema version, then scale the `StatefulSet` back to `1`. +7. **Verify reconciliation and readiness:** Watch stdout JSON logs for `applied the record of deletions` (`memory.ReapplyDeletions`) and confirm `/startupz` and `/readyz` return `200`. + +## Restore Verification Drill + +Run this drill in `staging` each quarter and after any backup architecture change. Record the completion timestamp, operator, and measured RTO in your compliance log. + +1. Sign in to the `staging` instance and create a test memory note. Record its note ID and confirm it appears in `GET /api/memory/notes`. +2. Take an on-demand PostgreSQL snapshot (`pre-deletion snapshot`). +3. Delete the test memory note through the UI or API. Verify `state_dir/deletions.jsonl` contains a new JSON line matching the deleted note ID. +4. Scale the `staging` Archie `StatefulSet` to `0`. +5. Restore the `staging` PostgreSQL database to the `pre-deletion snapshot` taken in step 2. Leave `state_dir` untouched. +6. Verify the deleted note row is temporarily present again in PostgreSQL before Archie starts. +7. Scale the `staging` Archie `StatefulSet` back to `1`. +8. Check pod logs for `applied the record of deletions` and wait for `/readyz` to return `200`. +9. Query `GET /api/memory/notes` and PostgreSQL to confirm the test note remains deleted. +10. Verify credential decryption works using the backup `age` recipient key (or perform a test `archie rekey` rotation and confirm an existing connector still passes health checks).