Skip to content

Commit d78775b

Browse files
Add configs to mount custom ca certs to opencost container (#303)
* Add configs to mount custom ca certs to opencost container Signed-off-by: Ishaan Mittal <ishaanmittal123@gmail.com>
1 parent 3be258b commit d78775b

File tree

5 files changed

+100
-28
lines changed

5 files changed

+100
-28
lines changed

charts/opencost/Chart.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ name: opencost
44
description: OpenCost and OpenCost UI
55
type: application
66
keywords:
7-
- cloud-costs
8-
- cost-optimization
9-
- finops
10-
- monitoring
11-
- opencost
12-
version: 2.2.9
7+
- cloud-costs
8+
- cost-optimization
9+
- finops
10+
- monitoring
11+
- opencost
12+
version: 2.3.0
1313
maintainers:
14-
- name: jessegoodier
15-
- name: toscott
16-
- name: mittal-ishaan
17-
- name: brito-rafa
18-
email: rafa@stormforge.io
14+
- name: jessegoodier
15+
- name: toscott
16+
- name: mittal-ishaan
17+
- name: brito-rafa
18+
email: rafa@stormforge.io
1919
home: https://github.com/opencost/opencost-helm-chart

charts/opencost/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ $ helm install opencost opencost/opencost
215215
| opencost.ui.uiPath | string | `/` | Base path for serving the UI. Requires building a custom image using the build argument "ui_path". |
216216
| opencost.ui.useDefaultFqdn | bool | `false` | |
217217
| opencost.ui.useIPv6 | bool | `true` | |
218+
| opencost.updateCaTrust.enabled | bool | `false` | Enable update of CA trust(Mount custom CA certificates to the opencost container) |
219+
| opencost.updateCaTrust.securityContext | object | `{}` | Security context for the init container that mounts the custom CA certificates |
220+
| opencost.updateCaTrust.caCertsSecret | string | `"ca-certs-secret"` | Name of the Secret containing custom CA certificates to mount to the opencost container |
221+
| opencost.updateCaTrust.caCertsConfig | string | `"ca-certs-config"` | Name of the ConfigMap containing CA certificates to mount to the opencost container |
222+
| opencost.updateCaTrust.resources | object | `{}` | Resources for the init container |
218223
| pdb.enabled | bool | `false` | |
219224
| pdb.minAvailable | int | `nil` | Minimum number of pods that must be available after the eviction |
220225
| pdb.maxUnavailable | int | `nil` | Maximum number of pods that can be unavailable after the eviction |

charts/opencost/templates/_helpers.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,12 @@ apiVersion: networking.k8s.io/v1beta1
222222
{{- $checksum | sha256sum -}}
223223
{{- end -}}
224224

225+
{{- define "opencost.caCertsSecretConfig.check" }}
226+
{{- if .Values.opencost.updateCaTrust.enabled }}
227+
{{- if and .Values.opencost.updateCaTrust.caCertsSecret .Values.opencost.updateCaTrust.caCertsConfig }}
228+
{{- fail "Both caCertsSecret and caCertsConfig are defined. Please specify only one." }}
229+
{{- else if and (not .Values.opencost.updateCaTrust.caCertsSecret) (not .Values.opencost.updateCaTrust.caCertsConfig) }}
230+
{{- fail "Neither caCertsSecret nor caCertsConfig is defined, but updateCaTrust is enabled. Please specify one." }}
231+
{{- end }}
232+
{{- end }}
233+
{{- end }}

charts/opencost/templates/deployment.yaml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{- include "isPrometheusConfigValid" . }}
22
{{- include "kubeRBACProxyBearerTokenCheck" . }}
3+
{{ include "opencost.caCertsSecretConfig.check" . }}
34
apiVersion: apps/v1
45
kind: Deployment
56
metadata:
@@ -50,20 +51,44 @@ spec:
5051
{{- with.Values.opencost.topologySpreadConstraints }}
5152
topologySpreadConstraints: {{- toYaml . | nindent 8 }}
5253
{{- end }}
53-
{{- if (and .Values.plugins.enabled .Values.plugins.install.enabled )}}
5454
initContainers:
55+
{{- if (and .Values.plugins.enabled .Values.plugins.install.enabled ) }}
5556
- name: plugin-installer
5657
image: {{ .Values.plugins.install.fullImageName }}
5758
command: ["sh", "/install/install_plugins.sh"]
58-
{{- with .Values.plugins.install.securityContext }}
59+
{{- with .Values.plugins.install.securityContext }}
5960
securityContext: {{- toYaml . | nindent 12 }}
60-
{{- end }}
61+
{{- end }}
6162
volumeMounts:
6263
- name: install-script
6364
mountPath: /install
6465
- name: plugins-dir
6566
mountPath: {{ .Values.plugins.folder }}
66-
{{- end }}
67+
{{- end }}
68+
{{- if .Values.opencost.updateCaTrust.enabled }}
69+
- name: update-ca-trust
70+
image: {{ include "opencost.fullImageName" . }}
71+
imagePullPolicy: {{ .Values.opencost.exporter.image.pullPolicy }}
72+
{{- with .Values.opencost.updateCaTrust.securityContext }}
73+
securityContext: {{- toYaml . | nindent 12 }}
74+
{{- end }}
75+
{{- with .Values.opencost.updateCaTrust.resources }}
76+
resources:
77+
{{- toYaml . | nindent 12 }}
78+
{{- end }}
79+
command:
80+
- 'sh'
81+
- '-c'
82+
- >
83+
mkdir -p /etc/ssl/certs;
84+
update-ca-certificates;
85+
volumeMounts:
86+
- name: ca-certs-secret
87+
mountPath: "/usr/local/share/ca-certificates"
88+
- name: ssl-path
89+
mountPath: "/etc/ssl/certs"
90+
readOnly: false
91+
{{- end}}
6792
containers:
6893
- name: {{ include "opencost.fullname" . }}
6994
image: {{ include "opencost.fullImageName" . }}
@@ -281,7 +306,7 @@ spec:
281306
- name: {{ $key }}
282307
value: {{ $value | quote }}
283308
{{- end }}
284-
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
309+
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.updateCaTrust.enabled}}
285310
volumeMounts:
286311
{{- if .Values.plugins.enabled }}
287312
- mountPath: /opt/opencost/plugin
@@ -315,6 +340,13 @@ spec:
315340
- name: cloud-integration
316341
mountPath: /var/configs/cloud-integration
317342
{{- end }}
343+
{{- if .Values.opencost.updateCaTrust.enabled }}
344+
- name: ca-certs-secret
345+
mountPath: "/usr/local/share/ca-certificates"
346+
- name: ssl-path
347+
mountPath: "/etc/ssl/certs"
348+
readOnly: false
349+
{{- end }}
318350
{{- with .Values.opencost.exporter.extraVolumeMounts }}
319351
{{- toYaml . | nindent 12 }}
320352
{{- end }}
@@ -412,7 +444,7 @@ spec:
412444
{{- toYaml . | nindent 12 }}
413445
{{- end }}
414446
{{- end }}
415-
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.ui.enabled }}
447+
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.ui.enabled .Values.opencost.updateCaTrust.enabled }}
416448
volumes:
417449
{{- if .Values.plugins.enabled }}
418450
{{- if .Values.plugins.install.enabled}}
@@ -461,6 +493,19 @@ spec:
461493
emptyDir: {}
462494
{{- end }}
463495
{{- end }}
496+
{{- if .Values.opencost.updateCaTrust.enabled }}
497+
- name: ca-certs-secret
498+
{{- if .Values.opencost.updateCaTrust.caCertsSecret }}
499+
secret:
500+
defaultMode: 420
501+
secretName: {{ .Values.opencost.updateCaTrust.caCertsSecret }}
502+
{{- else }}
503+
configMap:
504+
name: {{ .Values.opencost.updateCaTrust.caCertsConfig }}
505+
{{- end }}
506+
- name: ssl-path
507+
emptyDir: {}
508+
{{- end }}
464509
{{- with .Values.extraVolumes }}
465510
{{- toYaml . | nindent 8 }}
466511
{{- end }}

charts/opencost/values.yaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ opencost:
209209
# Path of CSV file
210210
csv_path: ""
211211

212-
213212
prometheusDataSource:
214213
# Set the resolution in second that prometheus queries will be performed at
215214
queryResolutionSeconds: 300
@@ -269,10 +268,10 @@ opencost:
269268
# -- A list of host rules used to configure the Ingress
270269
# @default -- See [values.yaml](values.yaml)
271270
hosts:
272-
- host: example.local
273-
paths:
274-
- path: /
275-
pathType: Prefix
271+
- host: example.local
272+
paths:
273+
- path: /
274+
pathType: Prefix
276275
# -- Redirect ingress to an extraPort defined on the service such as oauth-proxy
277276
servicePort: http
278277
# servicePort: oauth-proxy
@@ -324,7 +323,6 @@ opencost:
324323
# -- The max number of days that any single query will be made to construct Cloud Costs
325324
queryWindowDays: 7
326325

327-
328326
metrics:
329327
kubeStateMetrics:
330328
# -- (bool) Enable emission of pod annotations
@@ -394,7 +392,7 @@ opencost:
394392
bearer_token_key: DB_BEARER_TOKEN
395393
# -- If true, opencost will use kube-rbac-proxy to authenticate with in cluster Prometheus for openshift
396394
kubeRBACProxy: false
397-
# -- Whether to disable SSL certificate verification
395+
# -- Whether to disable SSL certificate verification
398396
insecureSkipVerify: false
399397
external:
400398
# -- Use external Prometheus (eg. Grafana Cloud)
@@ -416,7 +414,7 @@ opencost:
416414
scheme: http
417415
amp:
418416
# -- Use Amazon Managed Service for Prometheus (AMP)
419-
enabled: false # If true, opencost will be configured to remote_write and query from Amazon Managed Service for Prometheus.
417+
enabled: false # If true, opencost will be configured to remote_write and query from Amazon Managed Service for Prometheus.
420418
# -- Workspace ID for AMP
421419
workspaceId: ""
422420
thanos:
@@ -520,9 +518,9 @@ opencost:
520518
# -- A list of host rules used to configure the Ingress
521519
# @default -- See [values.yaml](values.yaml)
522520
hosts:
523-
- host: example.local
524-
paths:
525-
- /
521+
- host: example.local
522+
paths:
523+
- /
526524
# -- Redirect ingress to an extraPort defined on the service such as oauth-proxy
527525
servicePort: http-ui
528526
# servicePort: oauth-proxy
@@ -602,6 +600,21 @@ opencost:
602600
# protocol: TCP
603601
# resources: {}
604602

603+
updateCaTrust:
604+
enabled: false
605+
## Security context settings for the init container.
606+
securityContext:
607+
runAsUser: 0
608+
runAsGroup: 0
609+
runAsNonRoot: false
610+
allowPrivilegeEscalation: false
611+
readOnlyRootFilesystem: true
612+
seccompProfile:
613+
type: RuntimeDefault
614+
caCertsSecret: ca-certs-secret # The name of the Secret containing custom CA certificates to mount to the opencost container.
615+
# caCertsConfig: ca-certs-config # The name of the ConfigMap containing the CA trust configuration.
616+
resources: {}
617+
605618
platforms:
606619
openshift:
607620
# -- Enable OpenShift specific configurations

0 commit comments

Comments
 (0)