--- apiVersion: v1 kind: ConfigMap metadata: name: auditbeat-config namespace: kube-system labels: k8s-app: auditbeat data: auditbeat.yml: |- auditbeat.config.modules: # Mounted `auditbeat-daemonset-modules` configmap: path: ${path.config}/modules.d/*.yml # Reload module configs as they change: reload.enabled: false # When using containerd as runtime, a configuration like the following one # can be used to monitor files in containers using autodiscover. #auditbeat.autodiscover: # providers: # - type: kubernetes # host: ${NODE_NAME} # templates: # - config: # - module: 'file_integrity' # paths: # - '/run/containerd/io.containerd.runtime.v1.linux/k8s.io/${data.kubernetes.container.id}/rootfs/bin' # - '/run/containerd/io.containerd.runtime.v1.linux/k8s.io/${data.kubernetes.container.id}/rootfs/etc' # scan_at_start: false # recursive: true processors: - add_cloud_metadata: - add_process_metadata: match_pids: ['process.pid'] include_fields: ['container.id'] - add_kubernetes_metadata: host: ${NODE_NAME} default_indexers.enabled: false default_matchers.enabled: false indexers: - container: matchers: - fields.lookup_fields: ['container.id'] cloud.id: ${ELASTIC_CLOUD_ID} cloud.auth: ${ELASTIC_CLOUD_AUTH} output.elasticsearch: hosts: ['${ELASTICSEARCH_HOST:elasticsearch}:${ELASTICSEARCH_PORT:9200}'] username: ${ELASTICSEARCH_USERNAME} password: ${ELASTICSEARCH_PASSWORD} --- apiVersion: v1 kind: ConfigMap metadata: name: auditbeat-daemonset-modules namespace: kube-system labels: k8s-app: auditbeat data: system.yml: |- - module: file_integrity paths: - /hostfs/bin - /hostfs/usr/bin - /hostfs/sbin - /hostfs/usr/sbin - /hostfs/etc exclude_files: - '(?i)\.sw[nop]$' - '~$' - '/\.git($|/)' scan_at_start: true scan_rate_per_sec: 50 MiB max_file_size: 100 MiB hash_types: [sha1] recursive: true - module: auditd audit_rules: | # Executions -a always,exit -F arch=b64 -S execve,execveat -k exec # Unauthorized access attempts -a always,exit -F arch=b64 -S open,creat,truncate,ftruncate,openat,open_by_handle_at -F exit=-EACCES -k access -a always,exit -F arch=b64 -S open,creat,truncate,ftruncate,openat,open_by_handle_at -F exit=-EPERM -k access --- # Deploy a auditbeat instance per node for node metrics retrieval apiVersion: apps/v1 kind: DaemonSet metadata: name: auditbeat namespace: kube-system labels: k8s-app: auditbeat spec: selector: matchLabels: k8s-app: auditbeat template: metadata: labels: k8s-app: auditbeat spec: serviceAccountName: auditbeat terminationGracePeriodSeconds: 30 hostNetwork: true hostPID: true # Required by auditd module dnsPolicy: ClusterFirstWithHostNet containers: - name: auditbeat image: docker.elastic.co/beats/auditbeat:7.15.2 args: [ "-c", "/etc/auditbeat.yml", "-e", ] env: - name: ELASTICSEARCH_HOST value: elasticsearch - name: ELASTICSEARCH_PORT value: "9200" - name: ELASTICSEARCH_USERNAME value: elastic - name: ELASTICSEARCH_PASSWORD value: changeme - name: ELASTIC_CLOUD_ID value: - name: ELASTIC_CLOUD_AUTH value: - name: NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName securityContext: runAsUser: 0 # If using Red Hat OpenShift uncomment this: #privileged: true capabilities: add: # Capabilities needed for auditd module - 'AUDIT_READ' - 'AUDIT_WRITE' - 'AUDIT_CONTROL' resources: limits: memory: 200Mi requests: cpu: 100m memory: 100Mi volumeMounts: - name: config mountPath: /etc/auditbeat.yml readOnly: true subPath: auditbeat.yml - name: modules mountPath: /usr/share/auditbeat/modules.d readOnly: true - name: data mountPath: /usr/share/auditbeat/data - name: bin mountPath: /hostfs/bin readOnly: true - name: sbin mountPath: /hostfs/sbin readOnly: true - name: usrbin mountPath: /hostfs/usr/bin readOnly: true - name: usrsbin mountPath: /hostfs/usr/sbin readOnly: true - name: etc mountPath: /hostfs/etc readOnly: true # Directory with root filesystems of containers executed with containerd, this can be # different with other runtimes. This volume is needed to monitor the file integrity # of files in containers. - name: run-containerd mountPath: /run/containerd readOnly: true volumes: - name: bin hostPath: path: /bin - name: usrbin hostPath: path: /usr/bin - name: sbin hostPath: path: /sbin - name: usrsbin hostPath: path: /usr/sbin - name: etc hostPath: path: /etc - name: config configMap: defaultMode: 0640 name: auditbeat-config - name: modules configMap: defaultMode: 0640 name: auditbeat-daemonset-modules - name: data hostPath: # When auditbeat runs as non-root user, this directory needs to be writable by group (g+w). path: /var/lib/auditbeat-data type: DirectoryOrCreate - name: run-containerd hostPath: path: /run/containerd type: DirectoryOrCreate --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: auditbeat subjects: - kind: ServiceAccount name: auditbeat namespace: kube-system roleRef: kind: ClusterRole name: auditbeat apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: auditbeat namespace: kube-system subjects: - kind: ServiceAccount name: auditbeat namespace: kube-system roleRef: kind: Role name: auditbeat apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: auditbeat-kubeadm-config namespace: kube-system subjects: - kind: ServiceAccount name: auditbeat namespace: kube-system roleRef: kind: Role name: auditbeat-kubeadm-config apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: auditbeat labels: k8s-app: auditbeat rules: - apiGroups: [""] resources: - nodes - namespaces - pods verbs: ["get", "list", "watch"] - apiGroups: ["apps"] resources: - replicasets verbs: ["get", "list", "watch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: auditbeat # should be the namespace where auditbeat is running namespace: kube-system labels: k8s-app: auditbeat rules: - apiGroups: - coordination.k8s.io resources: - leases verbs: ["get", "create", "update"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: auditbeat-kubeadm-config namespace: kube-system labels: k8s-app: auditbeat rules: - apiGroups: [""] resources: - configmaps resourceNames: - kubeadm-config verbs: ["get"] --- apiVersion: v1 kind: ServiceAccount metadata: name: auditbeat namespace: kube-system labels: k8s-app: auditbeat ---