diff --git a/charts/crowdsec/templates/agent-daemonSet.yaml b/charts/crowdsec/templates/agent-daemonSet.yaml index a0998b4..08cdc3c 100644 --- a/charts/crowdsec/templates/agent-daemonSet.yaml +++ b/charts/crowdsec/templates/agent-daemonSet.yaml @@ -1,4 +1,12 @@ {{- if and (.Values.agent.enabled) (not .Values.agent.isDeployment) }} +{{- $hasKubernetes := false -}} +{{- if .Values.agent.additionalAcquisition }} +{{- range .Values.agent.additionalAcquisition }} +{{- if eq .source "kubernetes" }} +{{- $hasKubernetes = true -}} +{{- end }} +{{- end }} +{{- end }} apiVersion: apps/v1 kind: DaemonSet metadata: @@ -37,8 +45,8 @@ spec: {{ toYaml .Values.agent.podLabels | trim | indent 8 }} {{- end }} spec: - {{- if .Values.agent.serviceAccountName }} - serviceAccountName: {{ .Values.agent.serviceAccountName }} + {{- if or .Values.agent.serviceAccountName $hasKubernetes }} + serviceAccountName: {{ default (printf "%s-agent" .Release.Name) .Values.agent.serviceAccountName }} {{- end }} {{- with .Values.agent.tolerations }} tolerations: diff --git a/charts/crowdsec/templates/agent-deployment.yaml b/charts/crowdsec/templates/agent-deployment.yaml index 6e820e6..3497968 100644 --- a/charts/crowdsec/templates/agent-deployment.yaml +++ b/charts/crowdsec/templates/agent-deployment.yaml @@ -1,4 +1,12 @@ {{- if and (.Values.agent.enabled) (.Values.agent.isDeployment) }} +{{- $hasKubernetes := false -}} +{{- if .Values.agent.additionalAcquisition }} +{{- range .Values.agent.additionalAcquisition }} +{{- if eq .source "kubernetes" }} +{{- $hasKubernetes = true -}} +{{- end }} +{{- end }} +{{- end }} apiVersion: apps/v1 kind: Deployment metadata: @@ -39,8 +47,8 @@ spec: {{ toYaml .Values.agent.podLabels | trim | indent 8 }} {{- end }} spec: - {{- if .Values.agent.serviceAccountName }} - serviceAccountName: {{ .Values.agent.serviceAccountName }} + {{- if or .Values.agent.serviceAccountName $hasKubernetes }} + serviceAccountName: {{ default (printf "%s-agent" .Release.Name) .Values.agent.serviceAccountName }} {{- end }} {{- with .Values.agent.tolerations }} tolerations: diff --git a/charts/crowdsec/templates/role.yaml b/charts/crowdsec/templates/role.yaml index d07021d..4c69ef8 100644 --- a/charts/crowdsec/templates/role.yaml +++ b/charts/crowdsec/templates/role.yaml @@ -24,4 +24,28 @@ rules: verbs: ["create"] {{- end }} {{- end }} +--- +{{- end }} +{{- $hasKubernetes := false -}} +{{- if .Values.agent.additionalAcquisition }} +{{- range .Values.agent.additionalAcquisition }} +{{- if eq .source "kubernetes" }} +{{- $hasKubernetes = true -}} +{{- end }} +{{- end }} +{{- end }} +{{- if $hasKubernetes }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ .Release.Name }}-logs +rules: + - apiGroups: [""] + resources: + - pods + - pods/log + verbs: + - get + - list + - watch {{- end }} diff --git a/charts/crowdsec/templates/rolebinding.yaml b/charts/crowdsec/templates/rolebinding.yaml index fbedd25..c6c168d 100644 --- a/charts/crowdsec/templates/rolebinding.yaml +++ b/charts/crowdsec/templates/rolebinding.yaml @@ -23,5 +23,27 @@ subjects: name: {{ .Release.Name }}-configmap-updater-sa namespace: {{ .Release.Namespace }} {{- end }} +--- {{- end }} +{{- $hasKubernetes := false -}} +{{- if .Values.agent.additionalAcquisition }} +{{- range .Values.agent.additionalAcquisition }} +{{- if eq .source "kubernetes" }} +{{- $hasKubernetes = true -}} +{{- end }} +{{- end }} +{{- end }} +{{- if $hasKubernetes }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ .Release.Name }}-logs +subjects: + - kind: ServiceAccount + name: {{ default (printf "%s-agent" .Release.Name) .Values.agent.serviceAccountName }} + namespace: {{ .Release.Namespace }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ .Release.Name }}-logs {{- end }} diff --git a/charts/crowdsec/templates/serviceaccount.yaml b/charts/crowdsec/templates/serviceaccount.yaml index 8abf238..e38a8e7 100644 --- a/charts/crowdsec/templates/serviceaccount.yaml +++ b/charts/crowdsec/templates/serviceaccount.yaml @@ -14,4 +14,24 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded "helm.sh/hook-weight": "-1" {{- end }} -{{- end }} \ No newline at end of file +{{- end }} +--- +{{- $hasKubernetes := false -}} +{{- if .Values.agent.additionalAcquisition }} +{{- range .Values.agent.additionalAcquisition }} +{{- if eq .source "kubernetes" }} +{{- $hasKubernetes = true -}} +{{- end }} +{{- end }} +{{- end }} +{{ if $hasKubernetes }} +apiVersion: v1 +kind: ServiceAccount +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Release.Name }}-agent + labels: + k8s-app: {{ .Release.Name }} + type: pod-log-reader + version: v1 +{{- end }} diff --git a/charts/crowdsec/values.schema.json b/charts/crowdsec/values.schema.json index 84f83e7..aa0b8c3 100644 --- a/charts/crowdsec/values.schema.json +++ b/charts/crowdsec/values.schema.json @@ -141,6 +141,9 @@ { "$ref": "#/definitions/KubernetesSource" }, + { + "$ref": "#/definitions/KubernetesPodSource" + }, { "$ref": "#/definitions/VictoriaLogsSource" } @@ -1070,6 +1073,34 @@ }, "required": ["source", "url", "query"] }, + "KubernetesPodSource": { + "type": "object", + "description": "https://docs.crowdsec.net/docs/next/log_processor/data_sources/kubernetes/", + "additionalProperties": false, + "properties": { + "source": { + "const": "kubernetes" + }, + "namespace": { + "type": "string", + "description": "The namespace where the pods are located." + }, + "selector": { + "type": "string", + "description": "Label selector to filter pods (e.g. 'app=nginx,env=prod')." + }, + "labels": { + "$ref": "#/definitions/Labels" + }, + "log_level": { + "type": "string", + "description": "Log level for this datasource." + } + }, + "required": [ + "source" + ] + }, "KubernetesSource": { "type": "object", "description": "https://docs.crowdsec.net/docs/next/log_processor/data_sources/kubernetes_audit/",