Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Ability to read additioal config files
Browse files Browse the repository at this point in the history
Add the possibility to pass additional config files to fluent-bit, so the audit logs can be shipped to additional destinations, eg splunk
  • Loading branch information
mreiger authored Jul 1, 2021
2 parents d84db0a + 41f4040 commit 3189f35
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 6 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ COPY .git Makefile go.* *.go /work/
COPY pkg/ /work/pkg/
RUN make bin/audit-forwarder

FROM fluent/fluent-bit:1.7.3-debug
# Need to keep fluent-bit version below 1.7.5 for now,
# due to bug https://github.com/fluent/fluent-bit/issues/3699
FROM fluent/fluent-bit:1.7.4-debug

COPY --from=builder /work/bin/audit-forwarder /fluent-bit/bin/
COPY *.conf /fluent-bit/etc/
COPY fluent-bit.conf /fluent-bit/etc/
COPY parsers.conf /fluent-bit/etc/
COPY null.conf /fluent-bit/etc/add/

CMD ["/fluent-bit/bin/audit-forwarder"]
5 changes: 4 additions & 1 deletion fluent-bit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Name tail
Path ${AUDIT_LOG_PATH}
DB /audit.db
Tag audit
Parser audit
Read_from_Head On
Buffer_Chunk_Size 2MB
Expand All @@ -14,7 +15,7 @@

[OUTPUT]
Name forward
Match *
Match audit
Host ${AUDIT_TAILER_HOST}
Port ${AUDIT_TAILER_PORT}
Require_ack_response True
Expand All @@ -25,3 +26,5 @@
tls.crt_file ${TLS_CRT_FILE}
tls.key_file ${TLS_KEY_FILE}
tls.vhost ${TLS_VHOST}

@INCLUDE add/*.conf
36 changes: 36 additions & 0 deletions kind/audit/add/splunk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

[FILTER]
Name rewrite_tag
Match audit
Rule $kind Event tosplunk true

[FILTER]
Name nest
Match tosplunk
Operation nest
Wildcard *
Nest_under event

[FILTER]
Name record_modifier
Match tosplunk
Record host cluster-name
Record sourcetype kube:apiserver:auditlog
Record source apiserver-pod-name
Record index REPLACE_WITH_SPLUNK_INDEX

[OUTPUT]
Name splunk
Match tosplunk
Host REPLACE_WITH_SPLUNK_HEC_ENDPOINT
Port REPLACE_WITH_PORT
Splunk_Token REPLACE_WITH_SPLUNK_HEC_TOKEN
TLS On
TLS.Verify On
Retry_Limit False
Splunk_Send_Raw On

[OUTPUT]
Name stdout
Match tosplunk
Format json_lines
2 changes: 1 addition & 1 deletion kind/konnectivity-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
- --service-account-token-path=/var/run/secrets/tokens/konnectivity-agent-token
command:
- /proxy-agent
image: k8s.gcr.io/kas-network-proxy/proxy-agent:v0.0.12
image: k8s.gcr.io/kas-network-proxy/proxy-agent:v0.0.15
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
Expand Down
32 changes: 32 additions & 0 deletions kind/kustomize-auditforwarder-splunk/kube-apiserver_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- op: add
path: /spec/containers/1
value:
image: ghcr.io/metal-stack/audit-forwarder:pr-add-splunk
imagePullPolicy: Always
name: audit-forwarder
env:
- name: AUDIT_KUBECFG
value: "/kube.config"
- name: AUDIT_LOG_LEVEL
value: "info"
volumeMounts:
- mountPath: /auditlog
name: auditlog
- mountPath: /kube.config
name: kubeconfig
- mountPath: /fluent-bit/etc/add
name: add-config
- op: add
path: /spec/volumes/0
value:
hostPath:
path: /etc/kubernetes/audit/kube.config
type: File
name: kubeconfig
- op: add
path: /spec/volumes/0
value:
hostPath:
path: /etc/kubernetes/audit/add
type: Directory
name: add-config
7 changes: 7 additions & 0 deletions kind/kustomize-auditforwarder-splunk/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- kube-apiserver.yaml
patches:
- path: kube-apiserver_patch.yaml
target:
kind: Pod
name: kube-apiserver
2 changes: 1 addition & 1 deletion kind/kustomize-auditforwarder/kube-apiserver_patch.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- op: add
path: /spec/containers/1
value:
image: ghcr.io/metal-stack/audit-forwarder:pr-rework-proxy
image: ghcr.io/metal-stack/audit-forwarder:pr-add-splunk
imagePullPolicy: Always
name: audit-forwarder
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- --delete-existing-uds-file=true
command:
- /proxy-server
image: k8s.gcr.io/kas-network-proxy/proxy-server:v0.0.12
image: k8s.gcr.io/kas-network-proxy/proxy-server:v0.0.15
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
Expand Down
31 changes: 31 additions & 0 deletions kind/make-audit-forwarder-splunk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# First check if a forwarder has already been applied and get the kube-apiserver manifest if it isn't.
if grep forwarder kind-etc-kubernetes/manifests/kube-apiserver.yaml >/dev/null; then
echo "Forwarder config already applied."
if [ ! -f kustomize-auditforwarder-splunk/kube-apiserver.yaml ]; then
echo "No saved kube-apiserver manifest exists, exiting."
exit
else
if grep forwarder kustomize-auditforwarder-splunk/kube-apiserver.yaml >/dev/null; then
echo "Saved config contains forwarder too, can not patch. Exiting."
exit
fi
fi
else
echo "Getting kube-apiserver manifest."
cp kind-etc-kubernetes/manifests/kube-apiserver.yaml kustomize-auditforwarder-splunk/
fi

# Patch the generated kind kubeconfig with the apiserver URL valid from within the cluster.

echo "Generating the in-cluster kubeconfig:"

# Get the IP and port from the apiserver manifest:
line=`grep kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint kustomize-auditforwarder-splunk/kube-apiserver.yaml`
apiserver=${line##*kubeadm.kubernetes.io\/kube-apiserver.advertise-address.endpoint:?}

sed "s+https://.*$+https://$apiserver+" kube.config >kind-etc-kubernetes/audit/kube.config

echo "Patching and applying the kube-apiserver manifest:"
kustomize build kustomize-auditforwarder-splunk >kind-etc-kubernetes/manifests/kube-apiserver.yaml
1 change: 1 addition & 0 deletions null.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# An empty fluent-bit config file so that the @INCLUDE directive in fluent-bit.conf does not fail.

0 comments on commit 3189f35

Please sign in to comment.