Skip to content

Commit 9c581c5

Browse files
batpademmanuelmathotgeohacker
authored
allow creation of pg-stac secrets from azure secret vault, refs #186 (#187)
* allow creation of pg-stac secrets from azure secret vault, refs #186 * bump version in chart * add serviceAccount to create azure service account from values * change version in chart yaml * fix secret order since we need multiple secrets derived from a single key in the vault * bump chart version to 0.5.3-azure-test-3 and add support for Azure AKS secrets provider * refactor deployment templates to properly handle Azure AKS secrets provider configuration * bump chart version to 0.5.3-azure-test-4 * fix: update template to use correct context for Azure AKS secrets provider * fix: adjust secret reference formatting and add service account configuration for Azure AKS * fix: add volume mounts for Azure AKS secrets provider in deployment template * bump chart version to 0.5.3-azure-test-7 * bump chart version to 0.5.3-azure-test-8 and add Azure AKS secrets provider configuration * bump chart version to 0.5.3-azure-test-9 and add Azure workload identity annotation in deployment template * bump chart version to 0.5.3-azure-test-10 and add service account configuration in deployment template * use the service account name from values * name in the deploy for service account should match values * key names in vault still not working, try replacing _ with - * bump version in Chart.yaml * oops, replace _ with - everywhere * bump chart version to azure-test-14 * bump chart version to 0.5.3-azure-test-15 and update job.yaml for Azure workload identity and secrets management * bump chart version to 0.5.3-azure-test-16 and update job.yaml for conditional secret inclusion * bump chart version to 0.5.3-azure-test-17 and update job.yaml for environment variable configuration * bump chart version to 0.5.3-azure-test-18 and update job.yaml for PostgreSQL connection string format * bump chart version to 0.5.3-azure-test-19 and update job.yaml and configmap.yaml for PGADMIN_URI initialization and PostgreSQL environment variables * bump chart version to 0.5.3-azure-test-20 and update configmap.yaml to ensure PGADMIN_URI is initialized correctly * bump chart version to 0.5.3-azure-test-21 and update PGADMIN_URI initialization in configmap.yaml * bump chart version to 0.5.3-azure-test-21 and update job.yaml and configmap.yaml for PGADMIN_URI initialization and PostgreSQL environment variables * Refactor Azure integration: deprecate specific service account configuration, update pgstacBootstrap settings, and enhance documentation for Azure setup * Add support for additional labels, environment variables, and volume mounts in raster, multidim, stac, and vector configurations * Remove redundant value assignment for KEEP_ALIVE in pgstacbootstrap job configuration * Enable backups in PostgreSQL operator installation * Enable backups for PostgreSQL cluster in test configuration * Enhance cleanup step to extract and display pod logs for debugging on failure * Enhance cleanup step to extract and display logs from PGSTACBootstrap and raster pod containers for improved debugging * Refactor ServiceAccount name in RBAC configuration to use template function for consistency * Refactor endpoint exports in helm-tests workflow for consistency and clarity * Fix endpoint URLs in helm-tests workflow to include release name for proper routing * Enhance error handling in test execution by extracting and displaying pod logs for improved debugging * remove azure specifics * Update PGO_VERSION to 5.7.0 and remove backupsEnabled comment from test values * Revert chart version to 0.5.3-azure-test-21 for consistency with application versioning * Update chart version to 0.5.3-azure-test-21 for consistency with application versioning * Add service account configuration and update values.yaml with ingress and environment settings * Update database connection wait command to use POSTGRES_HOST variable * Add environment variables to wait-for-db init container * Enable pgstacBootstrap and update environment variables for database connection * Fix wait-for-db command to correctly reference POSTGRES_PORT environment variable * Enhance pgstacbootstrap job configuration by adding extra volume mounts and environment variables for LOAD_FIXTURES and KEEP_ALIVE * Refactor pgstacBootstrap to support additional environment variables and update values.yaml to use a map for extraEnvVars * Refactor deployment.yaml to correctly reference extraEnvVars in pgstacBootstrap settings and clean up values.yaml by removing unused envVars for raster and vector * Refactor pgstacBootstrap job configuration to use extraEnvFrom and extraEnvVars for environment variable management in job.yaml and values.yaml * Fix reference to extraEnvFrom in pgstacBootstrap job configuration * Refactor pgstacBootstrap configuration to add extraEnvFrom, extraVolumeMounts, and extraVolumes for improved secret management and volume handling * Fix DUMMY_ENV_VAR value type in deployment.yaml to use string format * Refactor PostgreSQL configuration and remove deprecated database setup - Introduced a unified PostgreSQL configuration structure in values.yaml, replacing the old db configuration. - Added new helper functions for managing PostgreSQL environment variables and secrets based on the selected configuration type (postgrescluster, external-plaintext, external-secret). - Removed old database-related templates (ConfigMap, Deployment, PVC, Secrets, Service) that are no longer needed. - Updated the pgstacbootstrap job and configmap templates to align with the new PostgreSQL configuration. - Implemented validation for PostgreSQL settings to ensure required fields are set based on the selected type. * Add PostgreSQL host reader and writer environment variables, and include DATABASE_URL for connection string * Added a clarifying comment in values.yaml to explain that values in the external secret (host, port, database) will override the corresponding values defined in external.host, external.port, and external.database. Confirmed that the conditional blocks in deployment.yaml were already consolidated to eliminate redundancy. The file was already using a single include statement for PostgreSQL environment variables: env: {{- include "eoapi.postgresqlEnv" $ | nindent 12 }} Removed the unused eoapi.mapLegacyPostgresql helper function from _helpers.tpl as it wasn't being referenced anywhere in the codebase. * Enhance Azure PostgreSQL setup documentation with detailed setup instructions and examples for server creation, database setup, firewall configuration, and Key Vault integration. * Remove unused ingress and values.yaml configurations * Bump chart version to 0.6.0 for release --------- Co-authored-by: Emmanuel Mathot <[email protected]> Co-authored-by: geohacker <[email protected]>
1 parent 9d7f3b7 commit 9c581c5

File tree

6 files changed

+399
-10
lines changed

6 files changed

+399
-10
lines changed

docs/azure.md

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
# Microsoft Azure Setup
2+
3+
## Using Azure Managed PostgreSQL
4+
5+
With the unified PostgreSQL configuration, connecting to an Azure managed PostgreSQL instance has become more straightforward. Here's how to set it up:
6+
7+
1. **Create an Azure PostgreSQL server**: Create a PostgreSQL server using the Azure portal or the Azure CLI.
8+
9+
```bash
10+
# Example of creating an Azure PostgreSQL flexible server
11+
az postgres flexible-server create \
12+
--resource-group myResourceGroup \
13+
--name mypostgresserver \
14+
--location westus \
15+
--admin-user myusername \
16+
--admin-password mypassword \
17+
--sku-name Standard_B1ms
18+
```
19+
20+
2. **Create a PostgreSQL database**: After creating the server, create a database for your EOAPI deployment.
21+
22+
```bash
23+
# Create a database on the Azure PostgreSQL server
24+
az postgres flexible-server db create \
25+
--resource-group myResourceGroup \
26+
--server-name mypostgresserver \
27+
--database-name eoapi
28+
```
29+
30+
3. **Configure firewall rules**: Ensure that the PostgreSQL server allows connections from your Kubernetes cluster's IP address.
31+
32+
```bash
33+
# Allow connections from your AKS cluster's outbound IP
34+
az postgres flexible-server firewall-rule create \
35+
--resource-group myResourceGroup \
36+
--server-name mypostgresserver \
37+
--name AllowAKS \
38+
--start-ip-address <AKS-outbound-IP> \
39+
--end-ip-address <AKS-outbound-IP>
40+
```
41+
42+
4. **Store PostgreSQL credentials in Azure Key Vault**: Create secrets in your Azure Key Vault to store the database connection information.
43+
44+
```bash
45+
# Create Key Vault secrets for PostgreSQL connection
46+
az keyvault secret set --vault-name your-keyvault-name --name db-host --value "mypostgresserver.postgres.database.azure.com"
47+
az keyvault secret set --vault-name your-keyvault-name --name db-port --value "5432"
48+
az keyvault secret set --vault-name your-keyvault-name --name db-name --value "eoapi"
49+
az keyvault secret set --vault-name your-keyvault-name --name db-username --value "myusername@mypostgresserver"
50+
az keyvault secret set --vault-name your-keyvault-name --name db-password --value "mypassword"
51+
```
52+
53+
## Azure Configuration for eoapi-k8s
54+
55+
When deploying on Azure, you'll need to configure several settings in your values.yaml file. Below are the configurations needed for proper integration with Azure services.
56+
57+
### Common Azure Configuration
58+
59+
First, configure the service account with Azure Workload Identity:
60+
61+
```yaml
62+
# Service Account Configuration
63+
serviceAccount:
64+
create: true
65+
annotations:
66+
azure.workload.identity/client-id: "your-client-id"
67+
azure.workload.identity/tenant-id: "your-tenant-id"
68+
```
69+
70+
### Unified PostgreSQL Configuration
71+
72+
Use the unified PostgreSQL configuration with the `external-secret` type to connect to your Azure managed PostgreSQL:
73+
74+
```yaml
75+
# Configure PostgreSQL connection to use Azure managed PostgreSQL with secrets from Key Vault
76+
postgresql:
77+
# Use external-secret type to get credentials from a pre-existing secret
78+
type: "external-secret"
79+
80+
# Basic connection information
81+
external:
82+
host: "mypostgresserver.postgres.database.azure.com" # Can be overridden by secret values
83+
port: "5432" # Can be overridden by secret values
84+
database: "eoapi" # Can be overridden by secret values
85+
86+
# Reference to a secret that will be created by Azure Key Vault integration
87+
existingSecret:
88+
name: "azure-pg-credentials"
89+
keys:
90+
username: "username" # Secret key for the username
91+
password: "password" # Secret key for the password
92+
host: "host" # Secret key for the host (optional)
93+
port: "port" # Secret key for the port (optional)
94+
database: "database" # Secret key for the database name (optional)
95+
```
96+
97+
With this configuration, you're telling the PostgreSQL components to use an external PostgreSQL database and to get its connection details from a Kubernetes secret named `azure-pg-credentials`. This secret will be created using Azure Key Vault integration as described below.
98+
99+
### Disable internal PostgreSQL cluster
100+
101+
When using Azure managed PostgreSQL, you should disable the internal PostgreSQL cluster:
102+
103+
```yaml
104+
postgrescluster:
105+
enabled: false
106+
```
107+
108+
### Azure Key Vault Integration
109+
110+
To allow your Kubernetes pods to access PostgreSQL credentials stored in Azure Key Vault, create a SecretProviderClass:
111+
112+
```yaml
113+
apiVersion: secrets-store.csi.x-k8s.io/v1
114+
kind: SecretProviderClass
115+
metadata:
116+
name: azure-pg-secret-provider
117+
spec:
118+
provider: azure
119+
parameters:
120+
usePodIdentity: "false"
121+
clientID: "your-client-id"
122+
keyvaultName: "your-keyvault-name"
123+
tenantId: "your-tenant-id"
124+
objects: |
125+
array:
126+
- |
127+
objectName: db-host
128+
objectType: secret
129+
objectAlias: host
130+
- |
131+
objectName: db-port
132+
objectType: secret
133+
objectAlias: port
134+
- |
135+
objectName: db-name
136+
objectType: secret
137+
objectAlias: database
138+
- |
139+
objectName: db-username
140+
objectType: secret
141+
objectAlias: username
142+
- |
143+
objectName: db-password
144+
objectType: secret
145+
objectAlias: password
146+
secretObjects:
147+
- secretName: azure-pg-credentials
148+
type: Opaque
149+
data:
150+
- objectName: host
151+
key: host
152+
- objectName: port
153+
key: port
154+
- objectName: database
155+
key: database
156+
- objectName: username
157+
key: username
158+
- objectName: password
159+
key: password
160+
```
161+
162+
### Service Configuration
163+
164+
For services that need to mount the Key Vault secrets, add the following configuration to each service (pgstacBootstrap, raster, stac, vector, multidim):
165+
166+
```yaml
167+
# Define a common volume configuration for all services
168+
commonVolumeConfig: &commonVolumeConfig
169+
labels:
170+
azure.workload.identity/use: "true"
171+
extraVolumeMounts:
172+
- name: azure-keyvault-secrets
173+
mountPath: /mnt/secrets-store
174+
readOnly: true
175+
extraVolumes:
176+
- name: azure-keyvault-secrets
177+
csi:
178+
driver: secrets-store.csi.k8s.io
179+
readOnly: true
180+
volumeAttributes:
181+
secretProviderClass: azure-pg-secret-provider
182+
183+
# Apply the common volume configuration to each service
184+
pgstacBootstrap:
185+
enabled: true
186+
settings:
187+
<<: *commonVolumeConfig
188+
189+
raster:
190+
enabled: true
191+
settings:
192+
<<: *commonVolumeConfig
193+
194+
stac:
195+
enabled: true
196+
settings:
197+
<<: *commonVolumeConfig
198+
199+
vector:
200+
enabled: true
201+
settings:
202+
<<: *commonVolumeConfig
203+
204+
multidim:
205+
enabled: false # set to true if needed
206+
settings:
207+
<<: *commonVolumeConfig
208+
```
209+
210+
## Azure Managed Identity Setup
211+
212+
To use Azure Managed Identity with your Kubernetes cluster:
213+
214+
1. **Enable Workload Identity on your AKS cluster**:
215+
```bash
216+
az aks update -g <resource-group> -n <cluster-name> --enable-workload-identity
217+
```
218+
219+
2. **Create a Managed Identity**:
220+
```bash
221+
az identity create -g <resource-group> -n eoapi-identity
222+
```
223+
224+
3. **Configure Key Vault access**:
225+
```bash
226+
# Get the client ID of the managed identity
227+
CLIENT_ID=$(az identity show -g <resource-group> -n eoapi-identity --query clientId -o tsv)
228+
229+
# Grant access to Key Vault
230+
az keyvault set-policy -n <keyvault-name> --secret-permissions get list --spn $CLIENT_ID
231+
```
232+
233+
4. **Create a federated identity credential** to connect the Kubernetes service account to the Azure managed identity:
234+
```bash
235+
az identity federated-credential create \
236+
--name eoapi-federated-credential \
237+
--identity-name eoapi-identity \
238+
--resource-group <resource-group> \
239+
--issuer <aks-oidc-issuer> \
240+
--subject system:serviceaccount:<namespace>:eoapi-sa
241+
```
242+
243+
## Complete Example
244+
245+
Here's a complete example configuration for connecting EOAPI to an Azure managed PostgreSQL database:
246+
247+
```yaml
248+
# Service Account Configuration with Azure Workload Identity
249+
serviceAccount:
250+
create: true
251+
annotations:
252+
azure.workload.identity/client-id: "12345678-1234-1234-1234-123456789012"
253+
azure.workload.identity/tenant-id: "87654321-4321-4321-4321-210987654321"
254+
255+
# Unified PostgreSQL Configuration - using external-secret type
256+
postgresql:
257+
type: "external-secret"
258+
external:
259+
host: "mypostgresserver.postgres.database.azure.com"
260+
port: "5432"
261+
database: "eoapi"
262+
existingSecret:
263+
name: "azure-pg-credentials"
264+
keys:
265+
username: "username"
266+
password: "password"
267+
host: "host"
268+
port: "port"
269+
database: "database"
270+
271+
# Disable internal PostgreSQL cluster
272+
postgrescluster:
273+
enabled: false
274+
275+
# Define common volume configuration with Azure Key Vault integration
276+
commonVolumeConfig: &commonVolumeConfig
277+
labels:
278+
azure.workload.identity/use: "true"
279+
extraVolumeMounts:
280+
- name: azure-keyvault-secrets
281+
mountPath: /mnt/secrets-store
282+
readOnly: true
283+
extraVolumes:
284+
- name: azure-keyvault-secrets
285+
csi:
286+
driver: secrets-store.csi.k8s.io
287+
readOnly: true
288+
volumeAttributes:
289+
secretProviderClass: azure-pg-secret-provider
290+
291+
# Apply the common volume configuration to each service
292+
pgstacBootstrap:
293+
enabled: true
294+
settings:
295+
<<: *commonVolumeConfig
296+
297+
stac:
298+
enabled: true
299+
settings:
300+
<<: *commonVolumeConfig
301+
302+
raster:
303+
enabled: true
304+
settings:
305+
<<: *commonVolumeConfig
306+
307+
vector:
308+
enabled: true
309+
settings:
310+
<<: *commonVolumeConfig
311+
312+
multidim:
313+
enabled: false
314+
settings:
315+
<<: *commonVolumeConfig
316+
```
317+
318+
Make sure to create the SecretProviderClass as shown in the "Azure Key Vault Integration" section above before deploying EOAPI with this configuration.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "eoapi.serviceAccountName" . }}
6+
labels:
7+
app: eoapi-{{ .Release.Name }}
8+
{{- range $key, $value := .Values.serviceAccount.labels }}
9+
{{ $key }}: {{ $value | quote }}
10+
{{- end }}
11+
{{- if .Values.serviceAccount.annotations }}
12+
annotations:
13+
{{- range $key, $value := .Values.serviceAccount.annotations }}
14+
{{ $key }}: {{ $value | quote }}
15+
{{- end }}
16+
{{- end }}
17+
automountServiceAccountToken: {{ default true .Values.serviceAccount.automount }}
18+
{{- end }}

helm-chart/eoapi/templates/services/deployment.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ spec:
3030
metadata:
3131
labels:
3232
app: {{ $serviceName }}-{{ $.Release.Name }}
33+
{{- with index $v "settings" "labels" }}
34+
{{- toYaml . | nindent 8 }}
35+
{{- end }}
3336
spec:
34-
serviceAccountName: eoapi-sa-{{ $.Release.Name }}
3537
containers:
3638
- image: {{ index $v "image" "name" }}:{{ index $v "image" "tag" }}
3739
name: {{ $serviceName }}
@@ -88,6 +90,15 @@ spec:
8890
name: {{ $secret }}
8991
{{- end }}
9092
{{- end }}
93+
{{- with index $v "settings" "extraVolumeMounts" }}
94+
volumeMounts:
95+
{{- toYaml . | nindent 10 }}
96+
{{- end }}
97+
volumes:
98+
{{- with index $v "settings" "extraVolumes" }}
99+
{{- toYaml . | nindent 8 }}
100+
{{- end }}
101+
serviceAccountName: {{ include "eoapi.serviceAccountName" $ }}
91102
{{- with index $v "settings" "affinity" }}
92103
affinity:
93104
{{- toYaml . | nindent 8 }}

helm-chart/eoapi/templates/services/rbac.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
{{- if .Values.apiServices }}
2-
---
3-
apiVersion: v1
4-
kind: ServiceAccount
5-
metadata:
6-
name: eoapi-sa-{{ $.Release.Name }}
7-
labels:
8-
app: eoapi-{{ $.Release.Name }}
9-
---
102
apiVersion: rbac.authorization.k8s.io/v1
113
kind: Role
124
metadata:
@@ -26,7 +18,7 @@ metadata:
2618
app: eoapi-{{ $.Release.Name }}
2719
subjects:
2820
- kind: ServiceAccount
29-
name: eoapi-sa-{{ $.Release.Name }}
21+
name: {{ include "eoapi.serviceAccountName" . }}
3022
namespace: {{ $.Release.Namespace }}
3123
roleRef:
3224
kind: Role

helm-chart/eoapi/test-k3s-unittest-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ testing: true
33
ingress:
44
enabled: true
55
className: "traefik"
6+
postgrescluster:
7+
enabled: true
68
pgstacBootstrap:
79
enabled: true
810
settings:

0 commit comments

Comments
 (0)