Skip to content

Commit

Permalink
Add SA,SCC and OpenShift changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mershad-manesh committed Aug 16, 2023
1 parent fe22d9f commit 170f3a9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 15 deletions.
10 changes: 10 additions & 0 deletions horizon/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{- if include "onOpenShift" . }}
Thank you for installing OpenNMS {{ .Values.core.image.tag | default .Chart.AppVersion }} on RedHat OpenShift.
{{- else}}
Thank you for installing OpenNMS {{ .Values.core.image.tag | default .Chart.AppVersion }}.
{{- end }}


Your release is named "{{ .Release.Name }}", used for:
- Customer/Deployment identifier.
Expand All @@ -17,11 +22,16 @@ OpenNMS Core: https://onms-core.{{ include "core.domain" . }}/opennms/index.jsp
Grafana: https://grafana.{{ include "core.domain" . }}/
{{- end }}

{{- if include "onOpenShift" . }}

Enjoy! (Replace me with a statement about OpenShift)
{{- else }}
To learn more about the release, try:

$ helm status {{ .Release.Name }}
$ helm get all {{ .Release.Name }}
$ kubectl get all -n {{ .Release.Name }}
{{- end }}

{{- if not .Values.core.configuration.alwaysRollDeployment }}

Expand Down
21 changes: 21 additions & 0 deletions horizon/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,24 @@ Define Customer/Environment Domain
{{- define "core.domain" -}}
{{- printf "%s.%s" .Release.Name .Values.domain -}}
{{- end }}

{{/*
SecurityContextConstraints apiVersion
*/}}
{{- define "scc.apiVersion" -}}
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1" -}}
security.openshift.io/v1
{{- end }}
{{- end }}

{{/*
Are we running in an OpenShift cluster.
*/}}
{{- define "onOpenShift" -}}
{{- $sccApiVersion := include "scc.apiVersion" . -}}
{{- if not (empty $sccApiVersion) }}
{{- printf "true" -}}
{{- else }}
{{- printf "false" -}}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions horizon/templates/opennms-core.sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if include "onOpenShift" . }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: sneakyminion
namespace: {{ .Release.Name }}
{{- end }}
46 changes: 46 additions & 0 deletions horizon/templates/opennms-core.scc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{- if include "onOpenShift" . }}
---
kind: SecurityContextConstraints
metadata:
name: opennms-scc
namespace: {{ .Release.Name }}
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegeEscalation: true
allowPrivilegedContainer: false
allowedCapabilities:
- NET_BIND_SERVICE
- NET_RAW
- NET_ADMIN
apiVersion: security.openshift.io/v1
defaultAddCapabilities:
- NET_RAW
- NET_ADMIN
fsGroup:
type: RunAsAny
groups: []
priority: 10
readOnlyRootFilesystem: false
requiredDropCapabilities: null
runAsUser:
type: MustRunAsRange
seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
supplementalGroups:
type: RunAsAny
users: []
volumes:
- configMap
- csi
- downwardAPI
- emptyDir
- ephemeral
- persistentVolumeClaim
- projected
- secret
{{- end }}
35 changes: 20 additions & 15 deletions horizon/templates/opennms-core.statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ spec:
{{- if .Values.core.configuration.alwaysRollDeployment }}
rollme: {{ randAlphaNum 5 | quote }}
{{- end }}
openshift.io/scc: opennms-scc
kubectl.kubernetes.io/default-container: "onms"
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
# capabilities:
# add:
# - NET_ADMIN
# - NET_RAW
# fsGroup: 10001
capabilities:
add:
- NET_ADMIN
- NET_RAW
terminationGracePeriodSeconds: {{ .Values.core.terminationGracePeriodSeconds | default 120 }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -52,9 +52,9 @@ spec:
image: {{ .Values.core.configuration.alecImage.repository }}:{{ .Values.core.configuration.alecImage.tag }}
imagePullPolicy: {{ .Values.core.configuration.alecImage.pullPolicy }}
command: [ cp, /plugins/opennms-alec-plugin.kar, /opennms-deploy ]
securityContext: # To guarantee ownership of the KAR file so that OpenNMS won't complain.
runAsUser: 10001
runAsGroup: 10001
#securityContext: # To guarantee ownership of the KAR file so that OpenNMS won't complain.
# runAsUser: 10001
# runAsGroup: 10001
volumeMounts:
- name: deploy
mountPath: /opennms-deploy # Required by the init script - DEPLOY_DIR
Expand All @@ -64,9 +64,9 @@ spec:
image: {{ .Values.core.configuration.cortexTssImage.repository }}:{{ .Values.core.configuration.cortexTssImage.tag }}
imagePullPolicy: {{ .Values.core.configuration.cortexTssImage.pullPolicy }}
command: [ cp, /plugins/opennms-cortex-tss-plugin.kar, /opennms-deploy ]
securityContext: # To guarantee ownership of the KAR file so that OpenNMS won't complain.
runAsUser: 10001
runAsGroup: 10001
#securityContext: # To guarantee ownership of the KAR file so that OpenNMS won't complain.
# runAsUser: 10001
# runAsGroup: 10001
volumeMounts:
- name: deploy
mountPath: /opennms-deploy # Required by the init script - DEPLOY_DIR
Expand Down Expand Up @@ -105,14 +105,19 @@ spec:
containers:
- name: onms
image: {{ $image }}
# TODO:: Move this into Values file
serviceAccountName: sneakyminion
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
# capabilities:
# add:
# - NET_ADMIN
# - NET_RAW
capabilities:
add:
- NET_ADMIN
- NET_RAW
sysctls:
- name: net.ipv4.ping_group_range
value: 0 429496729
imagePullPolicy: {{ .Values.core.image.pullPolicy }}
args:
- -s
Expand Down
3 changes: 3 additions & 0 deletions horizon/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ promtail:
limits:
cpu: 50m
memory: 64Mi

scc: {}
# apiVersion: ""

0 comments on commit 170f3a9

Please sign in to comment.