|
| 1 | +{{- if .Values.ironControl.enabled }} |
| 2 | +{{- $secretEnv := include "centaur.secretEnvName" . }} |
| 3 | +{{- $prefix := .Values.secretManager.envPrefix }} |
| 4 | +# iron-control — Rails control plane for authenticated API access and encrypted |
| 5 | +# secret storage. The chart owns the Deployment shape (image, port, env, |
| 6 | +# security context) so operators tune it via `helm upgrade`. It runs against a |
| 7 | +# dedicated `iron_control_production` database on the bundled Postgres (a separate logical |
| 8 | +# DB so its Rails schema_migrations table never collides with the API's dbmate |
| 9 | +# table); the create-db init container provisions that DB idempotently. All |
| 10 | +# secret material — the primary DB URL, the bootstrap user/API-key, the three |
| 11 | +# ActiveRecord encryption keys, and SECRET_KEY_BASE — comes from the shared |
| 12 | +# infra Secret via explicit secretKeyRefs (NOT envFrom, which would leak the |
| 13 | +# API's ai_v2 DATABASE_URL into iron-control's env). |
| 14 | +apiVersion: v1 |
| 15 | +kind: Service |
| 16 | +metadata: |
| 17 | + name: {{ include "centaur.ironControlName" . }} |
| 18 | + labels: |
| 19 | +{{ include "centaur.componentLabels" (dict "root" . "component" "iron-control") | nindent 4 }} |
| 20 | +spec: |
| 21 | + selector: |
| 22 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "iron-control") | nindent 4 }} |
| 23 | + ports: |
| 24 | + - name: http |
| 25 | + port: {{ .Values.ironControl.service.httpPort }} |
| 26 | + targetPort: {{ .Values.ironControl.service.httpPort }} |
| 27 | +--- |
| 28 | +apiVersion: apps/v1 |
| 29 | +kind: Deployment |
| 30 | +metadata: |
| 31 | + name: {{ include "centaur.ironControlName" . }} |
| 32 | + labels: |
| 33 | +{{ include "centaur.componentLabels" (dict "root" . "component" "iron-control") | nindent 4 }} |
| 34 | +spec: |
| 35 | + replicas: {{ .Values.ironControl.replicaCount }} |
| 36 | + selector: |
| 37 | + matchLabels: |
| 38 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "iron-control") | nindent 6 }} |
| 39 | + template: |
| 40 | + metadata: |
| 41 | + annotations: |
| 42 | + checksum/infra-secrets: {{ include "centaur.infraSecretsChecksum" . }} |
| 43 | + labels: |
| 44 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "iron-control") | nindent 8 }} |
| 45 | + spec: |
| 46 | + automountServiceAccountToken: false |
| 47 | + {{- with .Values.global.imagePullSecrets }} |
| 48 | + imagePullSecrets: |
| 49 | +{{ toYaml . | nindent 8 }} |
| 50 | + {{- end }} |
| 51 | + initContainers: |
| 52 | + # Create the dedicated logical DB on the bundled Postgres. Idempotent: |
| 53 | + # guarded by a pg_database existence check, and the CREATE tolerates a |
| 54 | + # lost race against a concurrent replica. Connects as the admin (ai_v2) |
| 55 | + # DSN, whose `tempo` superuser can create databases. |
| 56 | + - name: create-db |
| 57 | + image: {{ printf "%s:%s" .Values.postgres.image.repository .Values.postgres.image.tag | quote }} |
| 58 | + imagePullPolicy: {{ .Values.postgres.image.pullPolicy }} |
| 59 | + command: |
| 60 | + - /bin/sh |
| 61 | + - -ec |
| 62 | + - | |
| 63 | + exists=$(psql "$ADMIN_DATABASE_URL" -tAc \ |
| 64 | + "SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'") |
| 65 | + if [ "$exists" != "1" ]; then |
| 66 | + psql "$ADMIN_DATABASE_URL" -c "CREATE DATABASE \"$DB_NAME\"" || true |
| 67 | + fi |
| 68 | + env: |
| 69 | + - name: ADMIN_DATABASE_URL |
| 70 | + valueFrom: |
| 71 | + secretKeyRef: |
| 72 | + name: {{ $secretEnv }} |
| 73 | + key: {{ printf "%sDATABASE_URL" $prefix }} |
| 74 | + - name: DB_NAME |
| 75 | + value: {{ .Values.ironControl.database.name | quote }} |
| 76 | + securityContext: |
| 77 | +{{ toYaml .Values.containerSecurityContext | nindent 12 }} |
| 78 | + seccompProfile: |
| 79 | + type: RuntimeDefault |
| 80 | + containers: |
| 81 | + - name: iron-control |
| 82 | + image: {{ printf "%s:%s" .Values.ironControl.image.repository .Values.ironControl.image.tag | quote }} |
| 83 | + imagePullPolicy: {{ .Values.ironControl.image.pullPolicy }} |
| 84 | + env: |
| 85 | + # Explicit secretKeyRefs only — never envFrom the shared Secret, or |
| 86 | + # its DATABASE_URL (ai_v2) would leak into iron-control's env. Env |
| 87 | + # var names match the IRON_CONTROL_* secret keys 1:1 (except |
| 88 | + # SECRET_KEY_BASE, which Rails reads by its standard name). The DB |
| 89 | + # URL carries connection info only (no database path) so each Rails |
| 90 | + # connection's db name comes from the image's database.yml. |
| 91 | + - name: IRON_CONTROL_DATABASE_URL |
| 92 | + valueFrom: |
| 93 | + secretKeyRef: |
| 94 | + name: {{ $secretEnv }} |
| 95 | + key: {{ printf "%sIRON_CONTROL_DATABASE_URL" $prefix }} |
| 96 | + - name: IRON_CONTROL_INITIAL_USER_EMAIL |
| 97 | + valueFrom: |
| 98 | + secretKeyRef: |
| 99 | + name: {{ $secretEnv }} |
| 100 | + key: {{ printf "%sIRON_CONTROL_INITIAL_USER_EMAIL" $prefix }} |
| 101 | + - name: IRON_CONTROL_INITIAL_USER_PASSWORD |
| 102 | + valueFrom: |
| 103 | + secretKeyRef: |
| 104 | + name: {{ $secretEnv }} |
| 105 | + key: {{ printf "%sIRON_CONTROL_INITIAL_USER_PASSWORD" $prefix }} |
| 106 | + - name: IRON_CONTROL_INITIAL_API_KEY |
| 107 | + valueFrom: |
| 108 | + secretKeyRef: |
| 109 | + name: {{ $secretEnv }} |
| 110 | + key: {{ printf "%sIRON_CONTROL_INITIAL_API_KEY" $prefix }} |
| 111 | + - name: IRON_CONTROL_AR_ENCRYPTION_PRIMARY_KEY |
| 112 | + valueFrom: |
| 113 | + secretKeyRef: |
| 114 | + name: {{ $secretEnv }} |
| 115 | + key: {{ printf "%sIRON_CONTROL_AR_ENCRYPTION_PRIMARY_KEY" $prefix }} |
| 116 | + - name: IRON_CONTROL_AR_ENCRYPTION_DETERMINISTIC_KEY |
| 117 | + valueFrom: |
| 118 | + secretKeyRef: |
| 119 | + name: {{ $secretEnv }} |
| 120 | + key: {{ printf "%sIRON_CONTROL_AR_ENCRYPTION_DETERMINISTIC_KEY" $prefix }} |
| 121 | + - name: IRON_CONTROL_AR_ENCRYPTION_KEY_DERIVATION_SALT |
| 122 | + valueFrom: |
| 123 | + secretKeyRef: |
| 124 | + name: {{ $secretEnv }} |
| 125 | + key: {{ printf "%sIRON_CONTROL_AR_ENCRYPTION_KEY_DERIVATION_SALT" $prefix }} |
| 126 | + - name: SECRET_KEY_BASE |
| 127 | + valueFrom: |
| 128 | + secretKeyRef: |
| 129 | + name: {{ $secretEnv }} |
| 130 | + key: {{ printf "%sIRON_CONTROL_SECRET_KEY_BASE" $prefix }} |
| 131 | + - name: RAILS_ENV |
| 132 | + value: {{ .Values.ironControl.railsEnv | quote }} |
| 133 | + - name: PORT |
| 134 | + value: {{ .Values.ironControl.service.httpPort | quote }} |
| 135 | + - name: RAILS_LOG_TO_STDOUT |
| 136 | + value: "1" |
| 137 | + - name: RAILS_SERVE_STATIC_FILES |
| 138 | + value: "1" |
| 139 | + ports: |
| 140 | + - containerPort: {{ .Values.ironControl.service.httpPort }} |
| 141 | + name: http |
| 142 | + startupProbe: |
| 143 | + httpGet: |
| 144 | + path: /up |
| 145 | + port: http |
| 146 | + failureThreshold: 30 |
| 147 | + periodSeconds: 10 |
| 148 | + timeoutSeconds: 5 |
| 149 | + readinessProbe: |
| 150 | + httpGet: |
| 151 | + path: /up |
| 152 | + port: http |
| 153 | + failureThreshold: 6 |
| 154 | + periodSeconds: 10 |
| 155 | + timeoutSeconds: 5 |
| 156 | + livenessProbe: |
| 157 | + httpGet: |
| 158 | + path: /up |
| 159 | + port: http |
| 160 | + failureThreshold: 6 |
| 161 | + periodSeconds: 10 |
| 162 | + timeoutSeconds: 5 |
| 163 | + securityContext: |
| 164 | +{{ toYaml .Values.containerSecurityContext | nindent 12 }} |
| 165 | + # No readOnlyRootFilesystem — Rails writes to tmp/ at runtime. |
| 166 | + seccompProfile: |
| 167 | + type: RuntimeDefault |
| 168 | + resources: |
| 169 | +{{ toYaml .Values.ironControl.resources | nindent 12 }} |
| 170 | +{{- if .Values.networkPolicy.enabled }} |
| 171 | +--- |
| 172 | +apiVersion: networking.k8s.io/v1 |
| 173 | +kind: NetworkPolicy |
| 174 | +metadata: |
| 175 | + name: {{ include "centaur.ironControlName" . }} |
| 176 | + labels: |
| 177 | +{{ include "centaur.componentLabels" (dict "root" . "component" "iron-control") | nindent 4 }} |
| 178 | +spec: |
| 179 | + podSelector: |
| 180 | + matchLabels: |
| 181 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "iron-control") | nindent 6 }} |
| 182 | + policyTypes: |
| 183 | + - Ingress |
| 184 | + - Egress |
| 185 | + ingress: |
| 186 | + # The API is the natural control-plane caller. Widen this when a concrete |
| 187 | + # client integrates. (kubectl port-forward works regardless — it arrives |
| 188 | + # via the kubelet, not pod-to-pod.) |
| 189 | + - from: |
| 190 | + - podSelector: |
| 191 | + matchLabels: |
| 192 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "api") | nindent 14 }} |
| 193 | + ports: |
| 194 | + - protocol: TCP |
| 195 | + port: {{ .Values.ironControl.service.httpPort }} |
| 196 | + egress: |
| 197 | +{{- if .Values.postgres.enabled }} |
| 198 | + - to: |
| 199 | + - podSelector: |
| 200 | + matchLabels: |
| 201 | +{{ include "centaur.componentSelectorLabels" (dict "root" . "component" "postgres") | nindent 14 }} |
| 202 | + ports: |
| 203 | + - protocol: TCP |
| 204 | + port: 5432 |
| 205 | +{{- end }} |
| 206 | + # Outbound HTTPS (external DB DSNs, IdPs, etc.). |
| 207 | + - ports: |
| 208 | + - protocol: TCP |
| 209 | + port: 443 |
| 210 | +{{- end }} |
| 211 | +{{- end }} |
0 commit comments