Skip to content

Commit c2fe3ed

Browse files
authored
Merge pull request #2 from opencrvs/add-secrets
Add secrets
2 parents 581eac6 + 9c71706 commit c2fe3ed

24 files changed

+260
-206
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Please note that not all features from the Docker Swarm solution are supported y
77
- Manual Helm installation and upgrade only
88
- Manual initial user configuration for MinIO, MongoDB, Elasticsearch
99
- No data reset feature available
10+
- Any kind of secrets (Logins and passwords, etc) should be created manually
1011

1112
---
1213

charts/opencrvs-services/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# 🚧 Work in Progress
2+
3+
# General documentation
4+
5+
Helm chart to deploy all OpenCRVS services on Kubernetes cluster.
6+
7+
# Dependencies Configuration
8+
9+
<table>
10+
<thead>
11+
<tr>
12+
<th>Name</th>
13+
<th>Default</th>
14+
<th>Description</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
<tr>
19+
<td>elasticsearch_host</td>
20+
<td>elasticsearch.opencrvs-deps-dev.svc.cluster.local:9200</td>
21+
<td>Elasticsearch configuration, including the hostname and port. TODO: Consider defining the port as a separate variable.</td>
22+
</tr>
23+
<tr>
24+
<td>influxdb.host</td>
25+
<td>influxdb-0.influxdb.opencrvs-deps-dev.svc.cluster.local</td>
26+
<td>InfluxDB hostname configuration.</td>
27+
</tr>
28+
<tr>
29+
<td>influxdb.port</td>
30+
<td>8086</td>
31+
<td>InfluxDB port configuration.</td>
32+
</tr>
33+
<tr>
34+
<td>influxdb.db</td>
35+
<td>ocrvs</td>
36+
<td>InfluxDB database name.</td>
37+
</tr>
38+
<tr>
39+
<td>fhir_url</td>
40+
<td>http://hearth.opencrvs-deps-dev.svc.cluster.local:3447/fhir</td>
41+
<td>FHIR URL Endpoint. TODO: Add description for FHIR URL configuration.</td>
42+
</tr>
43+
<tr>
44+
<td>minio.host</td>
45+
<td>minio-0.minio.opencrvs-deps-dev.svc.cluster.local</td>
46+
<td>MinIO hostname configuration.</td>
47+
</tr>
48+
<tr>
49+
<td>minio.port</td>
50+
<td>3535</td>
51+
<td>MinIO port configuration.</td>
52+
</tr>
53+
<tr>
54+
<td>mongodb_host</td>
55+
<td>mongodb-0.mongodb.opencrvs-deps-dev.svc.cluster.local</td>
56+
<td>MongoDB hostname configuration.</td>
57+
</tr>
58+
<tr>
59+
<td>hostname</td>
60+
<td>farajaland.com</td>
61+
<td>Hostname for OpenCRVS application, without wildcard or subdomain. Example: hostname: opencrvs.localhost</td>
62+
</tr>
63+
<tr>
64+
<td>dev_mode</td>
65+
<td>false</td>
66+
<td>Developer mode flag. TODO: Check the usage and purpose of this variable.</td>
67+
</tr>
68+
<tr>
69+
<td>env</td>
70+
<td>{}</td>
71+
<td>Global environment variables, each variable defined here is available to all workloads (service) deployed by helm chart. See example at [values.yaml](values.yaml)</td>
72+
</tr>
73+
<tr>
74+
<td>&ltservice_name&gt.env</td>
75+
<td>{}</td>
76+
<td>Service level environment variables, each variable defined here is available to particular workload (service) only. See example for `config` microservice at [values.yaml](values.yaml)</td>
77+
</tr>
78+
<tr>
79+
<td>&ltservice_name&gt.secrets</td>
80+
<td>{}</td>
81+
<td>Mapping kubernetes secrets as environment variables. For more information see [Mapping secrets](#mapping-secrets)</td>
82+
</tr>
83+
</tbody>
84+
</table>
85+
86+
# Microservice environment variables configuration
87+
88+
<pre>Do we need this section?</pre>
89+
90+
Helm chart allows to define environment variables in following scopes:
91+
- **Global variables** are defined at top level of values file and is added to all containers. See `env` key in [values.yaml](values.yaml)
92+
- **Service level variables** are defined for each particular service. See `<service_name>.env` key in [values.yaml](values.yaml)
93+
- **Secret environment variables** are defined at service level as `<service_name>.secrets` key, see [values.yaml](values.yaml).
94+
95+
# Mapping secrets
96+
97+
Suppose we need to store ES_HOST variable as a secret since it contains url with login and password for Elastic search.
98+
Kubernetes secret is key/value object usually created from `.env` file, for example:
99+
```
100+
ES_HOST=user:randompass@elasticsearch:9200
101+
```
102+
103+
Mapping needs to be added for particular service to access variable inside workload (service), e/g for `search` service to access ES_HOST following configuration is needed:
104+
```
105+
search:
106+
secrets:
107+
elasticsearch-secret:
108+
- ES_HOST
109+
```
110+
111+
In some cases variable name (key) stored in kubernetes secret doesn't match with environment variable
112+
```
113+
secrets:
114+
<secret_name>:
115+
- <secret_key>:<environment_variable>
116+
```
117+
Summary:
118+
- `secret_name`, name of Kubernetes secret object
119+
- `secret_key`, key (variable name) inside Kubernetes secret data property
120+
- `environment_variable`, environment variable name inside container. If `secret_key` value `environment_variable` are the same, last one can be omitted.

charts/opencrvs-services/TODO.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ We are starting development, but helm charts already exist and once we setup ser
4848
- check if it's possible to build post-deploy job for opencrvs-services chart
4949
3. Add workflow for creating users in ELK and mongo
5050
- check if it's possible to build post-deploy job for dependencies chart
51+
5152
# Monitoring
5253
5354
1. Review option of replacing ELK with something more simple
@@ -58,12 +59,19 @@ Automatically issue SSL secret for traefix, check possibility to issue valid SSL
5859
5960
# Fixes
6061
61-
1. Fix events
62-
2. Fix clients:
63-
- [16:11:44.470] ERROR: Failed to connect to MongoDB. Retrying...
64-
- HTTP 500 https://config.opencrvs.localhost/publicConfig
65-
62+
1. Fix events variables
6663
6764
# Check
6865
69-
- https://kubernetes.io/docs/concepts/storage/volumes/#image
66+
- https://kubernetes.io/docs/concepts/storage/volumes/#image
67+
68+
# Secrets
69+
70+
There is a need to store secrets for Mongo, Elastic search, etc.
71+
72+
Easiest option is to store values as kubernetes secrets
73+
```
74+
kubectl create secret generic opencrvs-shared-secrets --from-env-file=.env.qa
75+
```
76+
77+
And then pass as shared secret name
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{/*
2+
3+
render-env-vars
4+
---
5+
This is a helper template that dynamically generates environment variables and secret references for Kubernetes Deployments.
6+
It accounts for both global and service-specific environment variables and secrets.
7+
8+
Parameters:
9+
- .ServiceName: The name of the microservice, which is used to access service-specific values.
10+
- .Values: The top-level Values object for the Helm chart.
11+
*/}}
12+
13+
{{- define "render-env-vars" -}}
14+
{{- $service_name := .service_name }}
15+
{{/* Loop through and generate global environment variables */}}
16+
{{- range $k, $v := .Values.env }}
17+
- name: {{ $k }}
18+
value: {{ $v | quote }}
19+
{{- end }}
20+
{{/* Access the service-specific values using the service name */}}
21+
{{- with index .Values $service_name }}
22+
{{/* Loop through and generate service-specific environment variables */}}
23+
{{- range $k, $v := .env }}
24+
- name: {{ $k }}
25+
value: {{ $v | quote }}
26+
{{- end }}
27+
{{/* Loop through and generate secret references for service-specific secrets */}}
28+
{{- range $secret_name, $secret_values := .secrets }}
29+
{{- range $secret_value := $secret_values }}
30+
{{- $secret := split ":" $secret_value }}
31+
- name: {{ $secret._1 | default $secret._0 }}
32+
valueFrom:
33+
secretKeyRef:
34+
name: {{ $secret_name }}
35+
key: {{ $secret._0 | quote}}
36+
{{- end }}
37+
{{- end }}
38+
{{- end }}
39+
{{- end }}

charts/opencrvs-services/templates/auth-deployment.yaml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,18 @@ spec:
6666
- name: CONFIG_TOKEN_EXPIRY_SECONDS
6767
value: '604800'
6868
- name: METRICS_URL
69-
value: http://metrics.{{ .Release.Namespace }}.svc.cluster.local:1050 # FIXME: harcoded
69+
value: http://metrics.{{ .Release.Namespace }}.svc.cluster.local:1050
7070
- name: NOTIFICATION_SERVICE_URL
7171
value: http://notification.{{ .Release.Namespace }}.svc.cluster.local:2020/
7272
- name: USER_MANAGEMENT_URL
73-
value: http://user-mgnt.{{ .Release.Namespace }}.svc.cluster.local:3030/ # FIXME: hardcoded
73+
value: http://user-mgnt.{{ .Release.Namespace }}.svc.cluster.local:3030/
7474
- name: AUTH_PORT
7575
value: "4040"
7676
- name: COUNTRY_CONFIG_URL_INTERNAL
77-
value: http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040 # FIXME: harcoded
77+
value: http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040
7878
- name: DOMAIN
7979
value: "{{ .Release.Namespace }}.svc.cluster.local"
80-
{{- range $k, $v := .Values.env }}
81-
- name: {{ $k }}
82-
value: {{ $v | quote }}
83-
{{- end }}
84-
{{- range $k, $v := .Values.auth.env }}
85-
- name: {{ $k }}
86-
value: {{ $v | quote }}
87-
{{- end }}
80+
{{- include "render-env-vars" (dict "service_name" "auth" "Values" .Values) }}
8881
ports:
8982
- containerPort: 4040
9083
protocol: TCP

charts/opencrvs-services/templates/client-deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ spec:
5252
- name: CONTENT_SECURITY_POLICY_WILDCARD
5353
value: "*.{{ .Values.hostname }}"
5454
- name: COUNTRY_CONFIG_URL_INTERNAL
55-
value: http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040 # FIXME: harcoded
55+
value: http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040
5656
- name: GATEWAY_URL_INTERNAL
57-
value: http://gateway.{{ .Release.Namespace }}.svc.cluster.local:7070 # FIXME: harcoded
57+
value: http://gateway.{{ .Release.Namespace }}.svc.cluster.local:7070
5858
# CHECK: Following variables are present on Dev environment
5959
# "COUNTRY_CONFIG_URL
6060
# "DECLARED_DECLARATION_SEARCH_QUERY_COUNT
6161
# "MINIO_URL
62+
{{- include "render-env-vars" (dict "service_name" "client" "Values" .Values) }}
6263
name: client
6364
ports:
6465
- containerPort: 80

charts/opencrvs-services/templates/config-deployment.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ spec:
4949
- name: config
5050
image: "ghcr.io/opencrvs/ocrvs-config:{{ .Values.image.tag }}"
5151
env:
52+
- name: CERT_PUBLIC_KEY_PATH
53+
value: /secrets/public-key.pem
5254
- name: FHIR_URL
5355
value: {{ .Values.fhir_url | quote }}
5456
- name: CLIENT_APP_URL
@@ -72,19 +74,10 @@ spec:
7274
- name: USER_MANAGEMENT_URL
7375
value: http://user-mgnt.{{ .Release.Namespace }}.svc.cluster.local:3030/
7476
- name: HEARTH_MONGO_URL
75-
value: "mongodb://{{ .Values.mongodb.mongodb_host }}/hearth-dev"
77+
value: "mongodb://{{ .Values.mongodb_host }}/hearth-dev"
7678
- name: MONGO_URL
77-
value: mongodb://{{ .Values.mongodb.mongodb_host }}/application-config
78-
{{- range $k, $v := .Values.env }}
79-
- name: {{ $k }}
80-
value: {{ $v | quote }}
81-
{{- end }}
82-
{{- range $k, $v := .Values.config.env }}
83-
- name: {{ $k }}
84-
value: {{ $v | quote }}
85-
{{- end }}
86-
- name: CERT_PUBLIC_KEY_PATH
87-
value: /secrets/public-key.pem
79+
value: mongodb://{{ .Values.mongodb_host }}/application-config
80+
{{- include "render-env-vars" (dict "service_name" "config" "Values" .Values) }}
8881
ports:
8982
- containerPort: 2021
9083
protocol: TCP

charts/opencrvs-services/templates/countryconfig-deployment.yaml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,10 @@ spec:
100100
- name: CONFIRM_REGISTRATION_URL
101101
value: http://workflow.{{ .Release.Namespace }}.svc.cluster.local:5050/confirm/registration
102102
- name: CONFIG_MONGO_URL
103-
value: mongodb://{{ .Values.mongodb.mongodb_host }}/application-config
103+
value: mongodb://{{ .Values.mongodb_host }}/application-config
104104
- name: MONGO_URL
105-
value: mongodb://{{ .Values.mongodb.mongodb_host }}/user-mgnt
106-
{{- range $k, $v := .Values.env }}
107-
- name: {{ $k }}
108-
value: {{ $v | quote }}
109-
{{- end }}
110-
{{- range $k, $v := .Values.countryconfig.env }}
111-
- name: {{ $k }}
112-
value: {{ $v | quote }}
113-
{{- end }}
105+
value: mongodb://{{ .Values.mongodb_host }}/user-mgnt
106+
{{- include "render-env-vars" (dict "service_name" "countryconfig" "Values" .Values) }}
114107
ports:
115108
- containerPort: 3040
116109
protocol: TCP

charts/opencrvs-services/templates/dashboards-deployment.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ spec:
5353
- name: OPENCRVS_METABASE_MAP_URL
5454
value: "http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040/content/map.geojson"
5555
- name: OPENCRVS_METABASE_DB_HOST
56-
value: {{ .Values.mongodb.mongodb_host | quote }}
57-
{{- range $k, $v := .Values.dashboards.env }}
58-
- name: {{ $k }}
59-
value: {{ $v | quote }}
60-
{{- end }}
56+
value: {{ .Values.mongodb_host | quote }}
57+
{{- include "render-env-vars" (dict "service_name" "dashboards" "Values" .Values) }}
6158
restartPolicy: Always

charts/opencrvs-services/templates/data-seeder.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@ spec:
2323
value: "http://gateway.{{ .Release.Namespace }}.svc.cluster.local:7070"
2424
- name: COUNTRY_CONFIG_HOST
2525
value: http://countryconfig.{{ .Release.Namespace }}.svc.cluster.local:3040
26-
{{- range $k, $v := .Values.env }}
27-
- name: {{ $k }}
28-
value: {{ $v | quote }}
29-
{{- end }}
30-
{{- range $k, $v := .Values.data_seeder.env }}
31-
- name: {{ $k }}
32-
value: {{ $v | quote }}
33-
{{- end }}
26+
{{- include "render-env-vars" (dict "service_name" "data_seeder" "Values" .Values) }}
3427
completions: 1 # Run the job once
3528
backoffLimit: 0 # Don't retry if the job fails
3629
restartPolicy: "OnFailure"

0 commit comments

Comments
 (0)