Skip to content

Commit

Permalink
Merge pull request #486 from smalinet/standard-labels
Browse files Browse the repository at this point in the history
Standard labels
  • Loading branch information
matthyx authored Aug 27, 2024
2 parents e7455d3 + dd2eb82 commit 44eb372
Show file tree
Hide file tree
Showing 121 changed files with 4,021 additions and 1,020 deletions.
10 changes: 4 additions & 6 deletions charts/kubescape-operator/assets/host-scanner-definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: host-scanner
name: {{ .Values.hostScanner.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app: host-scanner
k8s-app: kubescape-host-scanner
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.hostScanner.name "tier" .Values.global.namespaceTier) | nindent 4 }}
spec:
selector:
matchLabels:
name: host-scanner
{{- include "kubescape-operator.selectorLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.hostScanner.name) | nindent 12 }}
template:
metadata:
labels:
kubescape.io/ignore: "true"
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.hostScanner.name "tier" .Values.global.namespaceTier) | nindent 8 }}
kubescape.io/tier: "core"
name: host-scanner
{{- if $components.otelCollector.enabled }}
otel: enabled
{{- end }}
Expand Down
3 changes: 1 addition & 2 deletions charts/kubescape-operator/assets/kubescape-cronjob-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ apiVersion: batch/v1
labels:
app: {{ .Values.kubescapeScheduler.name }}
tier: {{ .Values.global.namespaceTier }}
kubescape.io/ignore: "true"
kubescape.io/tier: "core"
armo.tier: "kubescape-scan"
spec:
Expand Down Expand Up @@ -36,7 +35,7 @@ apiVersion: batch/v1
runAsUser: 100
resources:
{{ toYaml .Values.kubescapeScheduler.resources | indent 18 }}
args:
args:
- -method=post
- -scheme=http
- -host={{ .Values.operator.name }}:{{ .Values.operator.service.port }}
Expand Down
5 changes: 2 additions & 3 deletions charts/kubescape-operator/assets/kubevuln-cronjob-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ apiVersion: batch/v1
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.kubevulnScheduler.name }}
kubescape.io/ignore: "true"
kubescape.io/tier: "core"
tier: {{ .Values.global.namespaceTier }}
armo.tier: "vuln-scan"
spec:
schedule: "{{ .Values.kubevulnScheduler.scanSchedule }}"
schedule: "{{ .Values.kubevulnScheduler.scanSchedule }}"
successfulJobsHistoryLimit: {{ .Values.kubevulnScheduler.successfulJobsHistoryLimit }}
failedJobsHistoryLimit: {{ .Values.kubevulnScheduler.failedJobsHistoryLimit }}
jobTemplate:
Expand All @@ -36,7 +35,7 @@ apiVersion: batch/v1
runAsUser: 100
resources:
{{ toYaml .Values.kubevulnScheduler.resources | indent 18 }}
args:
args:
- -method=post
- -scheme=http
- -host={{ .Values.operator.name }}:{{ .Values.operator.service.port }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ apiVersion: batch/v1
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.registryScanScheduler.name }}
kubescape.io/ignore: "true"
kubescape.io/tier: "core"
tier: {{ .Values.global.namespaceTier }}
armo.tier: "registry-scan"
Expand Down Expand Up @@ -36,7 +35,7 @@ apiVersion: batch/v1
runAsUser: 100
resources:
{{ toYaml .Values.registryScanScheduler.resources | indent 18 }}
args:
args:
- -method=post
- -scheme=http
- -host={{ .Values.operator.name }}:{{ .Values.operator.service.port }}
Expand Down
103 changes: 103 additions & 0 deletions charts/kubescape-operator/templates/_common.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{{/* validate alertCRD.scopeClustered and alertCRD.scopeNamespaced are mutual exclusive */}}
{{- if and .Values.alertCRD.scopeClustered .Values.alertCRD.scopeNamespaced }}
{{- fail "alertCRD.scopeClustered and alertCRD.scopeNamespaced cannot both be true" }}
{{- end }}

{{- define "checksums" -}}
capabilitiesConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "components-configmap.yaml") . | sha256sum }}
cloudConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "cloudapi-configmap.yaml") . | sha256sum }}
cloudSecret: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "cloud-secret.yaml" ) . | sha256sum }}
hostScannerConfig: {{ include (printf "%s/kubescape/host-scanner-definition-configmap.yaml" $.Template.BasePath ) . | sha256sum }}
matchingRulesConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "matchingRules-configmap.yaml") . | sha256sum }}
nodeAgentConfig: {{ include (printf "%s/node-agent/configmap.yaml" $.Template.BasePath) . | sha256sum }}
operatorConfig: {{ include (printf "%s/operator/configmap.yaml" $.Template.BasePath) . | sha256sum }}
otelConfig: {{ include (printf "%s/otel-collector/configmap.yaml" $.Template.BasePath) . | sha256sum }}
proxySecret: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.proxySecretDirectory "proxy-secret.yaml") . | sha256sum }}
synchronizerConfig: {{ include (printf "%s/synchronizer/configmap.yaml" $.Template.BasePath) . | sha256sum }}
{{- end -}}


{{- define "configurations" -}}
{{- $createCloudSecret := (empty .Values.credentials.cloudSecret) -}}
{{- $ksOtel := empty .Values.otelCollector.disable -}}
{{- $otel := not (empty .Values.configurations.otelUrl) -}}
{{- $submit := not (empty .Values.server) -}}
continuousScan: {{ and (eq .Values.capabilities.continuousScan "enable") (not $submit) }}
createCloudSecret: {{ $createCloudSecret }}
ksOtel: {{ and $ksOtel $submit }}
otel: {{ $otel }}
otelPort : {{ if $otel }}{{ splitList ":" .Values.configurations.otelUrl | last }}{{ else }}""{{ end }}
runtimeObservability: {{ eq .Values.capabilities.runtimeObservability "enable" }}
submit: {{ $submit }}
{{- if $submit -}}
{{- if and (empty .Values.account) $createCloudSecret -}}
{{- fail "submitting is enabled but value for account is not defined: please register at https://cloud.armosec.io to get yours and re-run with --set account=<your Guid>" }}
{{- end -}}
{{- if and (empty .Values.accessKey) $createCloudSecret -}}
{{- fail "submitting is enabled but value for accessKey is not defined: To obtain an access key, go to 'Settings' -> 'Agent Access Keys' at https://cloud.armosec.io and re-run with --set accessKey=<your key>" }}
{{- end -}}
{{- if empty .Values.clusterName -}}
{{- fail "value for clusterName is not defined: re-run with --set clusterName=<your cluster name>" }}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "components" -}}
{{- $configurations := fromYaml (include "configurations" .) }}
gateway:
enabled: {{ $configurations.submit }}
hostScanner:
enabled: {{ eq .Values.capabilities.nodeScan "enable" }}
kollector:
enabled: {{ $configurations.submit }}
kubescape:
enabled: {{ or (eq .Values.capabilities.configurationScan "enable") (eq .Values.capabilities.continuousScan "enable") }}
kubescapeScheduler:
enabled: {{ and $configurations.submit (eq .Values.capabilities.configurationScan "enable") }}
kubevuln:
enabled: {{ eq .Values.capabilities.vulnerabilityScan "enable" }}
kubevulnScheduler:
enabled: {{ and $configurations.submit (eq .Values.capabilities.vulnerabilityScan "enable") }}
nodeAgent:
enabled: {{ or (eq .Values.capabilities.relevancy "enable") (eq .Values.capabilities.runtimeObservability "enable") (eq .Values.capabilities.networkPolicyService "enable") }}
operator:
enabled: true
otelCollector:
enabled: {{ or $configurations.ksOtel $configurations.otel }}
serviceDiscovery:
enabled: {{ $configurations.submit }}
storage:
enabled: true
prometheusExporter:
enabled: {{ eq .Values.capabilities.prometheusExporter "enable" }}
cloudSecret:
create: {{ $configurations.createCloudSecret }}
name: {{ if $configurations.createCloudSecret }}"cloud-secret"{{ else }}{{ .Values.credentials.cloudSecret }}{{ end }}
synchronizer:
enabled: {{ or (and $configurations.submit (eq .Values.capabilities.networkPolicyService "enable")) (and $configurations.submit (eq .Values.capabilities.runtimeObservability "enable")) }}
clamAV:
enabled: {{ eq .Values.capabilities.malwareDetection "enable" }}
customCaCertificates:
name: custom-ca-certificates
autoUpdater:
enabled: {{ eq .Values.capabilities.autoUpgrading "enable" }}
{{- end -}}

{{- define "admission-certificates" -}}
{{- $svcName := (printf "kubescape-admission-webhook.%s.svc" .Release.Namespace) -}}
{{- $ca := dict "Key" "mock-ca-key" "Cert" "mock-ca-cert" -}}
{{- $cert := dict "Key" "mock-cert-key" "Cert" "mock-cert-cert" -}}
{{- if not .Values.unittest }}
{{- $generatedCA := genCA (printf "*.%s.svc" .Release.Namespace) 1024 -}}
{{- $generatedCert := genSignedCert $svcName nil (list $svcName) 1024 $generatedCA -}}
{{- $_ := set $ca "Key" $generatedCA.Key -}}
{{- $_ := set $ca "Cert" $generatedCA.Cert -}}
{{- $_ := set $cert "Key" $generatedCert.Key -}}
{{- $_ := set $cert "Cert" $generatedCert.Cert -}}
{{- end -}}
{{- $certData := dict "ca" $ca "cert" $cert -}}
{{- toYaml $certData -}}
{{- end -}}



148 changes: 50 additions & 98 deletions charts/kubescape-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,103 +1,55 @@
{{/* validate alertCRD.scopeClustered and alertCRD.scopeNamespaced are mutual exclusive */}}
{{- if and .Values.alertCRD.scopeClustered .Values.alertCRD.scopeNamespaced }}
{{- fail "alertCRD.scopeClustered and alertCRD.scopeNamespaced cannot both be true" }}
{{/*
Expand the name of the chart.
*/}}
{{- define "kubescape-operator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "checksums" -}}
capabilitiesConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "components-configmap.yaml") . | sha256sum }}
cloudConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "cloudapi-configmap.yaml") . | sha256sum }}
cloudSecret: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "cloud-secret.yaml" ) . | sha256sum }}
hostScannerConfig: {{ include (printf "%s/kubescape/host-scanner-definition-configmap.yaml" $.Template.BasePath ) . | sha256sum }}
matchingRulesConfig: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.configMapsDirectory "matchingRules-configmap.yaml") . | sha256sum }}
nodeAgentConfig: {{ include (printf "%s/node-agent/configmap.yaml" $.Template.BasePath) . | sha256sum }}
operatorConfig: {{ include (printf "%s/operator/configmap.yaml" $.Template.BasePath) . | sha256sum }}
otelConfig: {{ include (printf "%s/otel-collector/configmap.yaml" $.Template.BasePath) . | sha256sum }}
proxySecret: {{ include (printf "%s/%s/%s" $.Template.BasePath $.Values.global.proxySecretDirectory "proxy-secret.yaml") . | sha256sum }}
synchronizerConfig: {{ include (printf "%s/synchronizer/configmap.yaml" $.Template.BasePath) . | sha256sum }}
{{- end -}}


{{- define "configurations" -}}
{{- $createCloudSecret := (empty .Values.credentials.cloudSecret) -}}
{{- $ksOtel := empty .Values.otelCollector.disable -}}
{{- $otel := not (empty .Values.configurations.otelUrl) -}}
{{- $submit := not (empty .Values.server) -}}
continuousScan: {{ and (eq .Values.capabilities.continuousScan "enable") (not $submit) }}
createCloudSecret: {{ $createCloudSecret }}
ksOtel: {{ and $ksOtel $submit }}
otel: {{ $otel }}
otelPort : {{ if $otel }}{{ splitList ":" .Values.configurations.otelUrl | last }}{{ else }}""{{ end }}
runtimeObservability: {{ eq .Values.capabilities.runtimeObservability "enable" }}
submit: {{ $submit }}
{{- if $submit -}}
{{- if and (empty .Values.account) $createCloudSecret -}}
{{- fail "submitting is enabled but value for account is not defined: please register at https://cloud.armosec.io to get yours and re-run with --set account=<your Guid>" }}
{{- end -}}
{{- if and (empty .Values.accessKey) $createCloudSecret -}}
{{- fail "submitting is enabled but value for accessKey is not defined: To obtain an access key, go to 'Settings' -> 'Agent Access Keys' at https://cloud.armosec.io and re-run with --set accessKey=<your key>" }}
{{- end -}}
{{- if empty .Values.clusterName -}}
{{- fail "value for clusterName is not defined: re-run with --set clusterName=<your cluster name>" }}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "components" -}}
{{- $configurations := fromYaml (include "configurations" .) }}
gateway:
enabled: {{ $configurations.submit }}
hostScanner:
enabled: {{ eq .Values.capabilities.nodeScan "enable" }}
kollector:
enabled: {{ $configurations.submit }}
kubescape:
enabled: {{ or (eq .Values.capabilities.configurationScan "enable") (eq .Values.capabilities.continuousScan "enable") }}
kubescapeScheduler:
enabled: {{ and $configurations.submit (eq .Values.capabilities.configurationScan "enable") }}
kubevuln:
enabled: {{ eq .Values.capabilities.vulnerabilityScan "enable" }}
kubevulnScheduler:
enabled: {{ and $configurations.submit (eq .Values.capabilities.vulnerabilityScan "enable") }}
nodeAgent:
enabled: {{ or (eq .Values.capabilities.relevancy "enable") (eq .Values.capabilities.runtimeObservability "enable") (eq .Values.capabilities.networkPolicyService "enable") }}
operator:
enabled: true
otelCollector:
enabled: {{ or $configurations.ksOtel $configurations.otel }}
serviceDiscovery:
enabled: {{ $configurations.submit }}
storage:
enabled: true
prometheusExporter:
enabled: {{ eq .Values.capabilities.prometheusExporter "enable" }}
cloudSecret:
create: {{ $configurations.createCloudSecret }}
name: {{ if $configurations.createCloudSecret }}"cloud-secret"{{ else }}{{ .Values.credentials.cloudSecret }}{{ end }}
synchronizer:
enabled: {{ or (and $configurations.submit (eq .Values.capabilities.networkPolicyService "enable")) (and $configurations.submit (eq .Values.capabilities.runtimeObservability "enable")) }}
clamAV:
enabled: {{ eq .Values.capabilities.malwareDetection "enable" }}
customCaCertificates:
name: custom-ca-certificates
autoUpdater:
enabled: {{ eq .Values.capabilities.autoUpgrading "enable" }}
{{- end -}}

{{- define "admission-certificates" -}}
{{- $svcName := (printf "kubescape-admission-webhook.%s.svc" .Release.Namespace) -}}
{{- $ca := dict "Key" "mock-ca-key" "Cert" "mock-ca-cert" -}}
{{- $cert := dict "Key" "mock-cert-key" "Cert" "mock-cert-cert" -}}
{{- if not .Values.unittest }}
{{- $generatedCA := genCA (printf "*.%s.svc" .Release.Namespace) 1024 -}}
{{- $generatedCert := genSignedCert $svcName nil (list $svcName) 1024 $generatedCA -}}
{{- $_ := set $ca "Key" $generatedCA.Key -}}
{{- $_ := set $ca "Cert" $generatedCA.Cert -}}
{{- $_ := set $cert "Key" $generatedCert.Key -}}
{{- $_ := set $cert "Cert" $generatedCert.Cert -}}
{{- end -}}
{{- $certData := dict "ca" $ca "cert" $cert -}}
{{- toYaml $certData -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kubescape-operator.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "kubescape-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "kubescape-operator.labels" -}}
helm.sh/chart: {{ include "kubescape-operator.chart" . }}
{{ include "kubescape-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app: {{ .app }}
tier: {{ .tier }}
kubescape.io/ignore: "true"
{{- end }}

{{/*
Selector labels
*/}}
{{- define "kubescape-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "kubescape-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: {{ .app }}
{{- end }}
5 changes: 4 additions & 1 deletion charts/kubescape-operator/templates/autoupdater/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: {{ .Values.helmReleaseUpgrader.name }}
namespace: {{ .Values.ksNamespace }}
labels:
kubescape.io/ignore: "true"
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name "tier" .Values.global.namespaceTier) | nindent 4 }}
annotations:
"helm.sh/resource-policy": keep
spec:
Expand All @@ -16,6 +16,9 @@ spec:
jobTemplate:
spec:
template:
metadata:
labels:
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name "tier" .Values.global.namespaceTier) | nindent 12 }}
spec:
serviceAccountName: {{ .Values.helmReleaseUpgrader.name }}
securityContext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ metadata:
name: {{ .Values.helmReleaseUpgrader.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.helmReleaseUpgrader.name }}
tier: {{ .Values.global.namespaceTier }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name "tier" .Values.global.namespaceTier) | nindent 4 }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Values.helmReleaseUpgrader.name }}
tier: {{ .Values.global.namespaceTier }}
{{- include "kubescape-operator.selectorLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name) | nindent 6 }}
policyTypes:
- Egress
egress:
Expand Down
4 changes: 2 additions & 2 deletions charts/kubescape-operator/templates/autoupdater/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
annotations:
"helm.sh/resource-policy": keep
labels:
kubescape.io/ignore: "true"
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name "tier" .Values.global.namespaceTier) | nindent 4 }}
rules:
- apiGroups: ["*"]
resources: ["*"]
Expand All @@ -20,7 +20,7 @@ metadata:
annotations:
"helm.sh/resource-policy": keep
labels:
kubescape.io/ignore: "true"
{{- include "kubescape-operator.labels" (dict "Chart" .Chart "Release" .Release "Values" .Values "app" .Values.helmReleaseUpgrader.name "tier" .Values.global.namespaceTier) | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ .Values.helmReleaseUpgrader.name }}
Expand Down
Loading

0 comments on commit 44eb372

Please sign in to comment.