Skip to content

feat(shield): migrate feature keys to host-shield.yaml #2159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/shield/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ maintainers:
- name: mavimo
email: [email protected]
type: application
version: 0.9.3
version: 0.9.4
appVersion: "1.0.0"
117 changes: 56 additions & 61 deletions charts/shield/templates/host/_configmap_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
{{/* Helper utitlies for generating the Host Shield's various ConfigMaps */}}

{{- define "host.configmap.posture" }}
{{- dict "posture" (pick . "host_posture") | toYaml }}
{{- with .posture }}
{{- dict "posture" (pick . "host_posture") | toYaml }}
{{- end }}
{{- end }}

{{- define "host.configmap.vm" }}
{{- dict "vulnerability_management" (pick . "host_vulnerability_management" "in_use") | toYaml }}
{{- with .vulnerability_management }}
{{- dict "vulnerability_management" (pick . "host_vulnerability_management" "in_use") | toYaml }}
{{- end }}
{{- end }}

{{- define "host.configmap.responding" }}
{{- dict "respond" (pick . "rapid_response") | toYaml }}
{{- define "host.configmap.respond" }}
{{- with .respond }}
{{- $config := dict "respond" (pick . "rapid_response") }}
{{- $_ := unset $config.respond.rapid_response "password"}}
{{- $config | toYaml }}
{{- end }}
{{- end }}

{{- define "host.configmap.detections" }}
{{- dict "detections" (pick . "ml_policies") | toYaml }}
{{- with .detections }}
{{- dict "detections" (pick . "ml_policies") | toYaml }}
{{- end }}
{{- end }}

{{/* Generate the 'host_shield_config.yaml' content */}}
{{- define "host.host_shield_config" }}
{{- $config := dict }}
{{- with .Values.features.posture }}
{{- $config = merge $config ((include "host.configmap.posture" .) | fromYaml) }}
{{- define "host.configmap.monitor" }}
{{- with .monitor }}
{{- $config := (pick . "app_checks" "java_management_extensions" "statsd") }}
{{- $config = merge $config (dict "prometheus" (pick .prometheus "enabled")) }}
{{- dict "monitor" $config | toYaml }}
{{- end }}
{{- end }}
{{- with .Values.features.vulnerability_management }}
{{- $config = merge $config ((include "host.configmap.vm" .) | fromYaml) }}

{{- define "host.configmap.investigations" }}
{{- with .investigations }}
{{- $config := (pick . "activity_audit" "live_logs" "network_security") }}
{{- $config = merge $config (dict "event_forwarder" (pick .event_forwarder "enabled")) }}
{{- dict "investigations" $config | toYaml }}
{{- end }}
{{- with .Values.features.respond }}
{{- $config = merge $config ((include "host.configmap.responding" .) | fromYaml) }}
{{- end }}
{{- with .Values.features.detections }}
{{- $config = merge $config ((include "host.configmap.detections" .) | fromYaml)}}

{{/* Generate the 'host-shield.yaml' content */}}
{{- define "host.host_shield_yaml" }}
{{- $config := dict }}
{{- with .Values.features }}
{{- $config = merge $config ((include "host.configmap.posture" .) | fromYaml) }}
{{- $config = merge $config ((include "host.configmap.vm" .) | fromYaml) }}
{{- $config = merge $config ((include "host.configmap.respond" .) | fromYaml) }}
{{- $config = merge $config ((include "host.configmap.detections" .) | fromYaml) }}
{{- $config = merge $config ((include "host.configmap.monitor" .) | fromYaml) }}
{{- $config = merge $config ((include "host.configmap.investigations" .) | fromYaml) }}
{{- end }}
{{- dict "features" $config | toYaml }}
{{- end }}
Expand All @@ -42,10 +64,10 @@ true
{{- end }}

{{- define "host.features.monitor_enabled" }}
{{- if or (dig (include "host.monitor_key" .) "app_checks" "enabled" false .Values.features)
(dig (include "host.monitor_key" .) "java_management_extensions" "enabled" false .Values.features)
(dig (include "host.monitor_key" .) "prometheus" "enabled" false .Values.features)
(dig (include "host.monitor_key" .) "statsd" "enabled" false .Values.features)
{{- if or .Values.features.monitor.app_checks.enabled
.Values.features.monitor.java_management_extensions.enabled
.Values.features.monitor.prometheus.enabled
.Values.features.monitor.statsd.enabled
(dig "app_checks_enabled" false .Values.host.additional_settings)
(dig "jmx" "enabled" false .Values.host.additional_settings)
(dig "prometheus" "enabled" false .Values.host.additional_settings)
Expand All @@ -56,12 +78,12 @@ true

{{/* Calculate the agent mode based on enabled features */}}
{{- define "host.configmap.agent_mode" }}
{{- $mode := "secure_light" }}
{{- $mode := "secure_light" }}
{{- if (include "host.features.netsec_enabled" .) }}
{{- $mode = "secure" }}
{{- $mode = "secure" }}
{{- end }}
{{- if (include "host.features.monitor_enabled" .) }}
{{- $mode = "monitor" }}
{{- $mode = "monitor" }}
{{- end }}
{{- dict "feature" (dict "mode" $mode) | toYaml -}}
{{- end }}
Expand All @@ -70,33 +92,16 @@ true
{{/* TODO: Kubernetes metadata */}}
{{- with .Values.features }}
{{- $config := dict
"app_checks_enabled" ((dig (include "host.monitor_key" .) "app_checks" "enabled" false .))
"audit_tap"
(dict "enabled" .investigations.audit_tap.enabled)
"drift_control"
(dict "enabled" .detections.drift_control.enabled)
"jmx"
(dict "enabled" (dig (include "host.monitor_key" .) "java_management_extensions" "enabled" false .))
"live_logs"
(dict "enabled" .investigations.live_logs.enabled)
"local_forwarder"
(dict "enabled" .investigations.event_forwarder.enabled)
"malware_control"
(dict "enabled" .detections.malware_control.enabled)
"network_topology"
(dict "enabled" .investigations.network_security.enabled)
"prometheus"
(dict "enabled" (dig (include "host.monitor_key" .) "prometheus" "enabled" false .))
"secure_audit_streams"
(dict "enabled" .investigations.activity_audit.enabled)
"statsd"
(dict "enabled" (dig (include "host.monitor_key" .) "statsd" "enabled" false .))
"sysdig_capture_enabled" .investigations.captures.enabled }}
{{- $config | toYaml }}
{{- end }}
{{- end }}

{{- define "host.configmap" }}
{{- define "host.dragent_yaml" }}
{{- $config := dict
"k8s_cluster_name" .Values.cluster_config.name
"collector" (include "common.collector_endpoint" .)
Expand All @@ -107,26 +112,16 @@ true
{{- $_ := set $config "k8s_delegated_nodes" (get $config "k8s_delegated_nodes") }}
{{- end }}
{{- if .Values.sysdig_endpoint.collector.port }}
{{- $config = merge $config (dict "collector_port" .Values.sysdig_endpoint.collector.port) }}
{{- $config = merge $config (dict "collector_port" .Values.sysdig_endpoint.collector.port) }}
{{- end }}
{{- $config = merge $config (dict "sysdig_api_endpoint" (include "common.secure_api_endpoint" .)) }}
{{- $config = merge $config (dict "sysdig_api_endpoint" (include "common.secure_api_endpoint" .)) }}
{{- if (include "common.proxy.enabled" . ) }}
{{- $config := merge $config (dict "http_proxy" (include "host.proxy_config" . | fromYaml)) }}
{{- end }}
{{- if (include "host.rapid_response_enabled" .) }}
{{- $config = merge $config (dict "rapid_response" (dict "enabled" true)) }}
{{- $config := merge $config (dict "http_proxy" (include "host.proxy_config" . | fromYaml)) }}
{{- end }}
{{- $config = merge $config (include "host.parse_features" . | fromYaml) }}
{{/* Host Scanner requires setting the host fs mount path variable, but that
parameter has not been mapped into the new schema yet. As a result,
it still needs to be set in the dragent.yaml file. */}}
{{- if .Values.features.vulnerability_management.host_vulnerability_management.enabled }}
{{/* Currently this pins the path to /host, but that is only because the final location of the
parameters has not been determined. */}}
{{- if and .Values.features.vulnerability_management.host_vulnerability_management.enabled
(not (dig "host_scanner" "host_fs_mount_path" nil .Values.host.additional_settings)) }}
{{- $config = merge $config (dict "host_scanner" (dict "host_fs_mount_path" "/host")) }}
{{- end }}
{{- if and .Values.features.vulnerability_management.host_vulnerability_management.enabled
(not (dig "host_scanner" "host_fs_mount_path" nil .Values.host.additional_settings)) }}
{{- $config = merge $config (dict "host_scanner" (dict "host_fs_mount_path" "/host")) }}
{{- end }}
{{- if or .Values.features.posture.host_posture.enabled (dig "kspm_analyzer" "enabled" false .Values.host.additional_settings) }}
{{- $config = merge $config (dict "kspm_analyzer" (dict "agent_app_name" (include "shield.name" .))) }}
Expand All @@ -139,13 +134,13 @@ true
{{- $_ := set $config "tags" (join "," $tagList) -}}
{{- end -}}
{{- if .Values.features.investigations.event_forwarder.enabled }}
{{- with .Values.features.investigations.event_forwarder }}
{{- $config = merge $config (dict "local_forwarder" (dict "enabled" .enabled "transmit_message_types" .transmit_message_types)) }}
{{- end }}
{{- with .Values.features.investigations.event_forwarder }}
{{- $config = merge $config (dict "local_forwarder" (dict "enabled" .enabled "transmit_message_types" .transmit_message_types)) }}
{{- end }}
{{- end }}
{{- $config = merge $config (include "host.configmap.agent_mode" . | fromYaml) }}
{{- if .Values.host.additional_settings }}
{{- $config = mergeOverwrite $config (include "host.config_override" . | fromYaml) }}
{{- $config = mergeOverwrite $config (include "host.config_override" . | fromYaml) }}
{{- end }}
{{- $config | toYaml }}
{{- end }}
48 changes: 0 additions & 48 deletions charts/shield/templates/host/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -173,51 +173,3 @@ capabilities:
{{- include "host.capabilities" . | nindent 4 }}
{{- end }}
{{- end -}}

{{- define "host.respond_key" }}
{{- if hasKey . "responding" }}
{{- print "responding" }}
{{- else }}
{{- print "respond" }}
{{- end }}
{{- end }}

{{- define "host.rapid_response_enabled" }}
{{- with .Values.features }}
{{- if (dig (include "host.respond_key" .) "rapid_response" "enabled" false .) }}
true
{{- end }}
{{- end }}
{{- end }}

{{- define "host.monitor_key" }}
{{- if hasKey . "monitoring" }}
{{- print "monitoring" }}
{{- else }}
{{- print "monitor" }}
{{- end }}
{{- end }}

{{- define "host.app_checks_enabled" }}
{{- if dig (include "host.monitor_key" .) "app_checks" "enabled" false . }}
true
{{- end }}
{{- end }}

{{- define "host.jmx_enabled" }}
{{- if dig (include "host.monitor_key" .) "java_mangement_extensions" "enabled" false . }}
true
{{- end }}
{{- end }}

{{- define "host.prometheus_enabled" }}
{{- if dig (include "host.monitor_key" .) "prometheus" "enabled" false . }}
true
{{- end }}
{{- end }}

{{- define "host.statsd_enabled" }}
{{- if dig (include "host.monitor_key" .) "statsd" "enabled" false . }}
true
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions charts/shield/templates/host/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ metadata:
{{- include "host.labels" . | nindent 4 }}
data:
host-shield.yaml: |
{{- include "host.host_shield_config" . | nindent 4 }}
{{- include "host.host_shield_yaml" . | nindent 4 }}
dragent.yaml: |
{{- include "host.configmap" . | nindent 4 }}
{{- include "host.dragent_yaml" . | nindent 4 }}
{{- if .Values.features.investigations.event_forwarder.enabled }}
local_forwarder_config.yaml: |
integrations:
{{- toYaml .Values.features.investigations.event_forwarder.integrations | nindent 6 }}
{{- end }}
{{- if (include "host.prometheus_enabled" .Values.features) }}
{{- if .Values.features.monitor.prometheus.enabled}}
prometheus.yaml: |
{{- with .Values.features }}
{{- toYaml (dig (include "host.monitor_key" .) "prometheus" "prometheus_yaml" list .) | nindent 4 }}
{{- toYaml .monitor.prometheus.prometheus_yaml | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/shield/templates/host/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
{{- include "common.proxy.envs" . | nindent 12 }}
{{- end }}
{{- include "common.custom_ca.envs" (merge (dict) . (dict "CACertsPath" "/opt/draios/certificates/")) | nindent 12 }}
{{- if (include "host.rapid_response_enabled" .) }}
{{- if .Values.features.respond.rapid_response.enabled }}
- name: PASSWORD
valueFrom:
secretKeyRef:
Expand Down
2 changes: 1 addition & 1 deletion charts/shield/templates/host/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if (include "host.rapid_response_enabled" .) }}
{{- if .Values.features.respond.rapid_response.enabled }}
---
apiVersion: v1
kind: Secret
Expand Down
Loading
Loading