-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubernetes specs for auditbeat file integrity monitoring (#7642)
- Loading branch information
Showing
9 changed files
with
398 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
--- | ||
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 | ||
processors: | ||
- add_cloud_metadata: | ||
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 | ||
--- | ||
# Deploy a auditbeat instance per node for node metrics retrieval | ||
apiVersion: extensions/v1beta1 | ||
kind: DaemonSet | ||
metadata: | ||
name: auditbeat | ||
namespace: kube-system | ||
labels: | ||
k8s-app: auditbeat | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: auditbeat | ||
spec: | ||
serviceAccountName: auditbeat | ||
terminationGracePeriodSeconds: 30 | ||
hostNetwork: true | ||
dnsPolicy: ClusterFirstWithHostNet | ||
containers: | ||
- name: auditbeat | ||
image: docker.elastic.co/beats/auditbeat:7.0.0-alpha1 | ||
args: [ | ||
"-c", "/etc/auditbeat.yml" | ||
] | ||
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: | ||
securityContext: | ||
runAsUser: 0 | ||
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: 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 | ||
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: 0600 | ||
name: auditbeat-config | ||
- name: modules | ||
configMap: | ||
defaultMode: 0600 | ||
name: auditbeat-daemonset-modules | ||
- name: data | ||
hostPath: | ||
path: /var/lib/auditbeat-data | ||
type: DirectoryOrCreate | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
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/v1beta1 | ||
kind: ClusterRole | ||
metadata: | ||
name: auditbeat | ||
labels: | ||
k8s-app: auditbeat | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- nodes | ||
- namespaces | ||
- pods | ||
verbs: ["get", "list", "watch"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: auditbeat | ||
namespace: kube-system | ||
labels: | ||
k8s-app: auditbeat | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Auditbeat | ||
|
||
## Ship audit information from Kubernetes to Elasticsearch | ||
|
||
### Kubernetes DaemonSet | ||
|
||
By deploying auditbeat as a [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) | ||
we ensure we get a running auditbeat daemon on each node of the cluster. | ||
|
||
Everything is deployed under `kube-system` namespace, you can change that by | ||
updating YAML manifests under this folder. | ||
|
||
### Settings | ||
|
||
We use official [Beats Docker images](https://github.com/elastic/beats-docker), | ||
as they allow external files configuration, a [ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) | ||
is used for kubernetes specific settings. Check [auditbeat-configmap.yaml](auditbeat-configmap.yaml) | ||
for details. | ||
|
||
Also, [auditbeat-daemonset.yaml](auditbeat-daemonset.yaml) uses a set of environment | ||
variables to configure Elasticsearch output: | ||
|
||
Variable | Default | Description | ||
-------- | ------- | ----------- | ||
ELASTICSEARCH_HOST | elasticsearch | Elasticsearch host | ||
ELASTICSEARCH_PORT | 9200 | Elasticsearch port | ||
ELASTICSEARCH_USERNAME | elastic | Elasticsearch username for HTTP auth | ||
ELASTICSEARCH_PASSWORD | changeme | Elasticsearch password | ||
|
||
If there is an existing `elasticsearch` service in the kubernetes cluster these | ||
defaults will use it. |
52 changes: 52 additions & 0 deletions
52
deploy/kubernetes/auditbeat/auditbeat-daemonset-configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
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 | ||
processors: | ||
- add_cloud_metadata: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Deploy a auditbeat instance per node for node metrics retrieval | ||
apiVersion: extensions/v1beta1 | ||
kind: DaemonSet | ||
metadata: | ||
name: auditbeat | ||
namespace: kube-system | ||
labels: | ||
k8s-app: auditbeat | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: auditbeat | ||
spec: | ||
serviceAccountName: auditbeat | ||
terminationGracePeriodSeconds: 30 | ||
hostNetwork: true | ||
dnsPolicy: ClusterFirstWithHostNet | ||
containers: | ||
- name: auditbeat | ||
image: docker.elastic.co/beats/auditbeat:%VERSION% | ||
args: [ | ||
"-c", "/etc/auditbeat.yml" | ||
] | ||
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: | ||
securityContext: | ||
runAsUser: 0 | ||
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: 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 | ||
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: 0600 | ||
name: auditbeat-config | ||
- name: modules | ||
configMap: | ||
defaultMode: 0600 | ||
name: auditbeat-daemonset-modules | ||
- name: data | ||
hostPath: | ||
path: /var/lib/auditbeat-data | ||
type: DirectoryOrCreate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: auditbeat | ||
subjects: | ||
- kind: ServiceAccount | ||
name: auditbeat | ||
namespace: kube-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: auditbeat | ||
apiGroup: rbac.authorization.k8s.io |
Oops, something went wrong.