|
3 | 3 | apiVersion: v1 |
4 | 4 | kind: ConfigMap |
5 | 5 | metadata: |
| 6 | + # Generate a unique name for the ConfigMap |
6 | 7 | name: {{ include "opensecurity.fullname" . }}-init-job-config |
7 | | - namespace: {{ .Release.Namespace }} |
| 8 | + namespace: "{{ .Release.Namespace }}" |
8 | 9 | labels: |
9 | | - {{ include "opensecurity.labels" . | nindent 4 }} |
| 10 | + # Include standard Helm labels |
| 11 | + {{- include "opensecurity.labels" . | nindent 4 }} |
10 | 12 | app.kubernetes.io/component: init-job-config |
11 | 13 | data: |
12 | | - {{- $cfg := default (dict) .Values.opensecurity.initJob.config }} |
13 | | - {{- $names := default (dict) .Values.opensecurity.initJob.envVarNames }} |
| 14 | + # --- IMPORTANT --- |
| 15 | + # This ConfigMap stores non-sensitive configuration. |
| 16 | + # Sensitive values like PGPASSWORD, DEFAULT_DEX_USER_PASSWORD |
| 17 | + # MUST be stored in a Kubernetes Secret and referenced directly in the Job/Pod spec. |
| 18 | + # DEX_PRIVATE_CLIENT_SECRET is included here with a default for compatibility, |
| 19 | + # but ideally should also be sourced from a secret if not using the default "SECRET". |
| 20 | + # --- |
14 | 21 |
|
15 | | - {{- /* Auth Service Name */}} |
16 | | - {{- $authSvcKey := default "AUTH_SERVICE_NAME" (index $names "authServiceName") }} |
17 | | - {{- $authSvcVal := default "core-service" (index $cfg "authServiceName") }} |
| 22 | + {{- /* bring config and envVarNames into safe maps */}} |
| 23 | + {{- $config := default (dict) .Values.opensecurity.initJob.config }} |
| 24 | + {{- $names := default (dict) .Values.opensecurity.initJob.envVarNames }} |
| 25 | + {{- $global := default (dict) .Values.global }} |
| 26 | + {{- /* Bring secrets config into a safe map for default checking */}} |
| 27 | + {{- $secrets := default (dict) .Values.opensecurity.initJob.secrets }} |
| 28 | + |
| 29 | + |
| 30 | + # --- Auth Service URL Components --- |
| 31 | + {{- $authSvcKey := default "AUTH_SERVICE_NAME" (get $names "authServiceName") }} |
| 32 | + {{- $authSvcVal := default "auth-service" (get $config "authServiceName") }} |
18 | 33 | {{ $authSvcKey }}: {{ $authSvcVal | quote }} |
19 | 34 |
|
20 | | - {{- /* Auth Namespace */}} |
21 | | - {{- $authNsKey := default "AUTH_NAMESPACE" (index $names "authNamespace") }} |
22 | | - {{- $authNsVal := default .Release.Namespace (index $cfg "authNamespace") }} |
| 35 | + {{- $authNsKey := default "AUTH_NAMESPACE" (get $names "authNamespace") }} |
| 36 | + {{- $authNsVal := default .Release.Namespace (get $config "authNamespace") }} |
23 | 37 | {{ $authNsKey }}: {{ $authNsVal | quote }} |
24 | 38 |
|
25 | | - {{- /* Auth Port */}} |
26 | | - {{- $authPortKey := default "AUTH_SERVICE_PORT" (index $names "authPort") }} |
27 | | - {{- $authPortVal := default "8251" (index $cfg "authPort") }} |
| 39 | + {{- $authPortKey := default "AUTH_SERVICE_PORT" (get $names "authPort") }} |
| 40 | + {{- $authPortVal := default "8251" (get $config "authPort") }} |
28 | 41 | {{ $authPortKey }}: {{ $authPortVal | quote }} |
29 | 42 |
|
30 | | - {{- /* Optional Auth Health Path */}} |
31 | | - {{- $authHealthVal := index $cfg "authHealthPath" }} |
32 | | - {{- if $authHealthVal }} |
33 | | - {{- $authHealthKey := default "AUTH_HEALTH_PATH" (index $names "authHealthPath") }} |
34 | | - {{ $authHealthKey }}: {{ $authHealthVal | quote }} |
| 43 | + {{- with get $config "authHealthPath" }} |
| 44 | + {{- $authHealthKey := default "AUTH_HEALTH_PATH" (get $names "authHealthPath") }} |
| 45 | + {{ $authHealthKey }}: {{ . | quote }} |
35 | 46 | {{- end }} |
| 47 | + |
| 48 | + # --- Default Admin/Dex User --- |
| 49 | + {{- $adminEmailKey := default "DEFAULT_ADMIN_EMAIL" (get $names "defaultAdminEmail") }} |
| 50 | + {{- $adminEmailVal := default "[email protected]" (get $config "defaultAdminEmail") }} |
| 51 | + {{ $adminEmailKey }}: {{ $adminEmailVal | quote }} |
| 52 | + |
| 53 | + {{- $dexEmailKey := default "DEFAULT_DEX_USER_EMAIL" (get $names "defaultDexUserEmail") }} |
| 54 | + {{- $dexEmailVal := default "[email protected]" (get $config "defaultDexUserEmail") }} # Get from values or fallback |
| 55 | + {{ $dexEmailKey }}: {{ $dexEmailVal | quote }} |
| 56 | + |
| 57 | + {{- $dexUserNameKey := default "DEFAULT_DEX_USER_NAME" (get $names "defaultDexUserName") }} |
| 58 | + {{- $dexUserNameVal := default "admin" (get $config "defaultDexUserName") }} # Get from values or fallback |
| 59 | + {{ $dexUserNameKey }}: {{ $dexUserNameVal | quote }} |
| 60 | + |
| 61 | + # --- PostgreSQL Connection Info (excluding password) --- |
| 62 | + {{- $pgSrc := default (dict) .Values.authDatabase }} |
| 63 | + {{- $pgHost := default (printf "%s-postgresql-primary.%s.svc.cluster.local" $.Release.Name $.Release.Namespace) (get $pgSrc "host") }} |
| 64 | + {{- $pgPort := default "5432" (get $pgSrc "port") }} |
| 65 | + {{- $pgDb := default "auth" (get $pgSrc "name") }} |
| 66 | + {{- $pgUser := default "postgres" (get $pgSrc "user") }} # User is set here |
| 67 | + {{- $pgSsl := default "disable" (get $pgSrc "sslMode") }} |
| 68 | + |
| 69 | + {{- $pgHostKey := default "PGHOST" (get $names "pgHost") }} |
| 70 | + {{ $pgHostKey }}: {{ $pgHost | quote }} |
| 71 | + |
| 72 | + {{- $pgPortKey := default "PGPORT" (get $names "pgPort") }} |
| 73 | + {{ $pgPortKey }}: {{ $pgPort | quote }} |
| 74 | + |
| 75 | + {{- $pgDbKey := default "PGDATABASE" (get $names "pgDatabase") }} |
| 76 | + {{ $pgDbKey }}: {{ $pgDb | quote }} |
| 77 | + |
| 78 | + {{- $pgUserKey := default "PGUSER" (get $names "pgUser") }} |
| 79 | + {{ $pgUserKey }}: {{ $pgUser | quote }} # Value from $pgUser variable above |
| 80 | + |
| 81 | + {{- $pgSslKey := default "PGSSLMODE" (get $names "pgSslMode") }} |
| 82 | + {{ $pgSslKey }}: {{ $pgSsl | quote }} |
| 83 | + |
| 84 | + # --- Dex Configuration --- |
| 85 | + {{- $dexGrpcKey := default "DEX_GRPC_ADDR" (get $names "dexGrpcAddr") }} |
| 86 | + {{- $dexGrpcVal := default (printf "%s-dex.%s.svc.cluster.local:5557" $.Release.Name $.Release.Namespace) (get $config "dexGrpcAddr") }} |
| 87 | + {{ $dexGrpcKey }}: {{ $dexGrpcVal | quote }} |
| 88 | + |
| 89 | + {{- $dexPublicUrisKey := default "DEX_PUBLIC_CLIENT_REDIRECT_URIS" (get $names "dexPublicClientRedirectUris") }} |
| 90 | + {{- $dexPublicUrisVal := default (printf "https://%s/callback,http://%s/callback,http://localhost:3000/callback,http://localhost:8080/callback" (get $global "domain") (get $global "domain")) (get $config "dexPublicClientRedirectUris") }} |
| 91 | + {{ $dexPublicUrisKey }}: {{ $dexPublicUrisVal | quote }} |
| 92 | + |
| 93 | + {{- $dexPrivateUrisKey := default "DEX_PRIVATE_CLIENT_REDIRECT_URIS" (get $names "dexPrivateClientRedirectUris") }} |
| 94 | + {{- $dexPrivateUrisVal := default (printf "https://%s/callback" (get $global "domain")) (get $config "dexPrivateClientRedirectUris") }} |
| 95 | + {{ $dexPrivateUrisKey }}: {{ $dexPrivateUrisVal | quote }} |
| 96 | + |
| 97 | + {{- $dexPublicClientIdKey := default "DEX_PUBLIC_CLIENT_ID" (get $names "dexPublicClientId") }} |
| 98 | + {{- $dexPublicClientIdVal := default "public-client" (get $config "dexPublicClientId") }} # Default 'public-client' |
| 99 | + {{ $dexPublicClientIdKey }}: {{ $dexPublicClientIdVal | quote }} |
| 100 | + |
| 101 | + {{- $dexPrivateClientIdKey := default "DEX_PRIVATE_CLIENT_ID" (get $names "dexPrivateClientId") }} |
| 102 | + {{- $dexPrivateClientIdVal := default "private-client" (get $config "dexPrivateClientId") }} # Provide a default or require in values |
| 103 | + {{ $dexPrivateClientIdKey }}: {{ $dexPrivateClientIdVal | quote }} |
| 104 | + |
| 105 | + {{- $dexHttpHealthKey := default "DEX_HTTP_HEALTH_URL" (get $names "dexHttpHealthUrl") }} |
| 106 | + {{- $dexHttpHealthVal := default (printf "http://%s-dex.%s.svc.cluster.local:5556/dex/healthz" $.Release.Name $.Release.Namespace) (get $config "dexHttpHealthUrl") }} # Construct default health URL |
| 107 | + {{ $dexHttpHealthKey }}: {{ $dexHttpHealthVal | quote }} |
| 108 | + |
| 109 | + # --- BEGIN: Add Dex Private Client Secret with Default --- |
| 110 | + {{- $dexPrivSecretKey := default "DEX_PRIVATE_CLIENT_SECRET" (get $names "dexPrivateClientSecret") }} |
| 111 | + {{- /* Get value from secrets if defined, otherwise default to "SECRET" */}} |
| 112 | + {{- $dexPrivSecretVal := get $secrets "dexPrivateClientSecret" | default "SECRET" }} |
| 113 | + {{ $dexPrivSecretKey }}: {{ $dexPrivSecretVal | quote }} |
| 114 | + # --- END: Add Dex Private Client Secret with Default --- |
| 115 | + |
| 116 | + # --- Other Hardcoded/Constructed Values --- |
| 117 | + {{- $workspaceNameKey := default "WORKSPACE_NAME" (get $names "workspaceName") }} |
| 118 | + {{ $workspaceNameKey }}: "main" # Hardcoded as per snippet |
| 119 | + |
| 120 | + {{- $dexCallbackKey := default "DEX_CALLBACK_URL" (get $names "dexCallbackUrl") }} |
| 121 | + {{- $dexCallbackVal := default (printf "https://%s/dex/callback,http://%s/dex/callback,http://localhost:3000/dex/callback,http://localhost:8080/dex/callback" (get $global "domain") (get $global "domain")) (get $config "dexCallbackUrl") }} |
| 122 | + {{ $dexCallbackKey }}: {{ $dexCallbackVal | quote }} |
| 123 | + |
| 124 | + {{- $dexAuthDomainKey := default "DEX_AUTH_DOMAIN" (get $names "dexAuthDomain") }} |
| 125 | + {{- $dexAuthDomainVal := default (printf "http://%s-dex.%s.svc.cluster.local:5556/dex" $.Release.Name $.Release.Namespace) (get $config "dexAuthDomain") }} |
| 126 | + {{ $dexAuthDomainKey }}: {{ $dexAuthDomainVal | quote }} |
| 127 | + |
36 | 128 | {{- end }} |
0 commit comments