Skip to content

Commit df6979c

Browse files
v0nNemizezSimen Andrè Vikestrand Skogummittal-ishaan
authored
Openshift Security Context Constraints and updated ClusterRole with access to internal prometheus. (#267)
* Add OpenShift support with SecurityContextConstraints and updated ClusterRole permissions * fix: changed roleRef * feat: changes to clusterrolebinding and own values file for openshift * fix: added scheme value to be able to switch between http and https * feat: update OpenShift support with service account name change, SCC adjustments, and enhanced probe configurations * Update charts/opencost/templates/_helpers.tpl Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * Update charts/opencost/templates/scc.yaml Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * fix: removing duplicate code * fix: update SCC condition to use enableSCC value in scc.yaml, renaming file * fix: update OpenShift SCC condition to use enableSCC value in clusterrolebinding.yaml * fix: remove unused testvalues.yaml file * fix: correct formatting of enableSCC value in values.yaml * Update charts/opencost/templates/scc.yaml Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * feat: add OpenShift specific values file for Opencost deployment * Update charts/opencost/templates/clusterrolebinding.yaml Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * feat: update OpenShift cluster role to enable Prometheus access * fix: linting * Update charts/opencost/templates/_helpers.tpl Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * Update charts/opencost/templates/clusterrole.yaml Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> * feat: add scheme configuration for Thanos query service * feat: add scheme configuration for in-cluster Prometheus --------- Signed-off-by: Simen Andre Vikestrand Skogum <v0nNemizez@gmail.com> Co-authored-by: Simen Andrè Vikestrand Skogum <sas@eika.no> Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com>
1 parent 886dbf0 commit df6979c

File tree

8 files changed

+101
-5
lines changed

8 files changed

+101
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.idea

charts/opencost/Chart.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ keywords:
99
- finops
1010
- monitoring
1111
- opencost
12-
version: 2.0.2
12+
13+
version: 2.1.0
14+
1315
maintainers:
1416
- name: jessegoodier
1517
- name: toscott

charts/opencost/templates/_helpers.tpl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Create the name of the controller service account to use
8484
{{- if .Values.serviceAccount.create -}}
8585
{{- default (include "opencost.fullname" .) .Values.serviceAccount.name }}
8686
{{- else -}}
87-
{{- default "default" .Values.serviceAccount.name }}
87+
{{- default "opencost" .Values.serviceAccount.name }}
8888
{{- end -}}
8989
{{- end -}}
9090

@@ -102,8 +102,9 @@ Create the name of the controller service account to use
102102
{{- $host := tpl .Values.opencost.prometheus.internal.serviceName . }}
103103
{{- $ns := tpl .Values.opencost.prometheus.internal.namespaceName . }}
104104
{{- $clusterName := .Values.clusterName }}
105+
{{- $scheme := .Values.opencost.prometheus.internal.scheme | default "http"}}
105106
{{- $port := .Values.opencost.prometheus.internal.port | int }}
106-
{{- printf "http://%s.%s.svc.%s:%d" $host $ns $clusterName $port -}}
107+
{{- printf "%s://%s.%s.svc.%s:%d" $scheme $host $ns $clusterName $port -}}
107108
{{- end -}}
108109
{{- end -}}
109110

@@ -118,7 +119,8 @@ Check that either thanos external or internal is defined
118119
{{- $ns := .Values.opencost.prometheus.thanos.internal.namespaceName }}
119120
{{- $clusterName := .Values.clusterName }}
120121
{{- $port := .Values.opencost.prometheus.thanos.internal.port | int }}
121-
{{- printf "http://%s.%s.svc.%s:%d" $host $ns $clusterName $port -}}
122+
{{- $scheme := .Values.opencost.prometheus.thanos.internal.scheme | default "http"}}
123+
{{- printf "%s://%s.%s.svc.%s:%d" $scheme $host $ns $clusterName $port -}}
122124
{{- end -}}
123125
{{- end -}}
124126

@@ -192,6 +194,11 @@ apiVersion: networking.k8s.io/v1beta1
192194
{{- end -}}
193195
{{- end -}}
194196

197+
198+
{{- define "opencost.sccName" -}}
199+
{{include "opencost.fullname" .}}-scc
200+
{{- end -}}
201+
195202
{{- /*
196203
Compute a checksum based on the rendered content of specific ConfigMaps and Secrets.
197204
*/ -}}
@@ -209,3 +216,4 @@ apiVersion: networking.k8s.io/v1beta1
209216
{{- end -}}
210217
{{- $checksum | sha256sum -}}
211218
{{- end -}}
219+

charts/opencost/templates/clusterrole.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,19 @@ rules:
7878
- get
7979
- list
8080
- watch
81+
82+
{{- if and .Values.opencost.platforms.openshift.enabled .Values.opencost.platforms.openshift.enablePromAccess }}
83+
- apiGroups:
84+
- monitoring.coreos.com
85+
resources:
86+
- prometheuses
87+
- thanosrulers
88+
verbs:
89+
- get
90+
- list
91+
- watch
92+
- create
93+
- update
94+
- patch
95+
{{- end }}
8196
{{- end }}

charts/opencost/templates/clusterrolebinding.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,19 @@ subjects:
3939
namespace: {{ include "opencost.namespace" . }}
4040
---
4141
{{- end }}
42+
43+
{{- if and .Values.opencost.platforms.openshift.enabled .Values.opencost.platforms.openshift.enableSCC }}
44+
apiVersion: rbac.authorization.k8s.io/v1
45+
kind: RoleBinding
46+
metadata:
47+
name: opencost-scc-binding
48+
namespace: {{include "opencost.namespace" .}}
49+
subjects:
50+
- kind: ServiceAccount
51+
name: {{template "opencost.serviceAccountName"}}
52+
namespace: {{include "opencost.namespace" .}}
53+
roleRef:
54+
kind: Role
55+
name: system:openshift:scc:{{ include "opencost.sccName" . }}
56+
apiGroup: rbac.authorization.k8s.io
57+
{{- end}}

charts/opencost/templates/scc.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- if and .Values.opencost.platforms.openshift.enabled .Values.opencost.platforms.openshift.enableSCC }}
2+
apiVersion: security.openshift.io/v1
3+
kind: SecurityContextConstraints
4+
metadata:
5+
name: {{include "opencost.sccName" .}}
6+
priority: 10
7+
allowPrivilegedContainer: false
8+
allowHostDirVolumePlugin: false
9+
allowHostIPC: false
10+
allowHostNetwork: false
11+
allowHostPID: false
12+
allowHostPorts: false
13+
allowPrivilegeEscalation: false
14+
readOnlyRootFilesystem: false
15+
allowedCapabilities:
16+
- CHOWN
17+
- FOWNER
18+
- FSETID
19+
- KILL
20+
- NET_BIND_SERVICE
21+
- SETFCAP
22+
- SETGID
23+
- SETPCAP
24+
- SETUID
25+
runAsUser:
26+
type: MustRunAs
27+
uid: 1001
28+
seLinuxContext:
29+
type: MustRunAs
30+
fsGroup:
31+
type: RunAsAny
32+
supplementalGroups:
33+
type: RunAsAny
34+
volumes:
35+
- configMap
36+
- downwardAPI
37+
- emptyDir
38+
- persistentVolumeClaim
39+
- projected
40+
- secret
41+
{{- end}}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This Helm values file is a modified version of `values.yaml`.
2+
# This file is meant to be used by users deploying Opencost to OpenShift (OCP) clusters. For more configuration options, see `values.yaml`.
3+
opencost:
4+
platforms:
5+
openshift:
6+
enabled: true
7+

charts/opencost/values.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ opencost:
350350
namespaceName: prometheus-system
351351
# -- Service port of in-cluster Prometheus
352352
port: 80
353+
# -- Scheme to use for in-cluster Prometheus
354+
scheme: http
353355
amp:
354356
# -- Use Amazon Managed Service for Prometheus (AMP)
355357
enabled: false # If true, opencost will be configured to remote_write and query from Amazon Managed Service for Prometheus.
@@ -364,6 +366,7 @@ opencost:
364366
serviceName: my-thanos-query
365367
namespaceName: opencost
366368
port: 10901
369+
scheme: http
367370
external:
368371
enabled: false
369372
url: 'https://thanos-query.example.com/thanos'
@@ -547,6 +550,9 @@ opencost:
547550
monitoringServiceAccountName: prometheus-k8s
548551
# -- Namespace of the Prometheus serviceaccount to bind to the Resource Reader Role Binding.
549552
monitoringServiceAccountNamespace: openshift-monitoring
550-
553+
# -- If true, set Security Context Constraints on serviceaccount for read/write premissions
554+
enableSCC: false
555+
# -- If true, enable internal prom access
556+
enablePromAccess: false
551557
# -- A list of volumes to be added to the pod
552558
extraVolumes: []

0 commit comments

Comments
 (0)