Skip to content

Commit d3d5db2

Browse files
author
Benjamin Huo
authored
Merge pull request #45 from zhu733756/dev-0.1
support for audit logs
2 parents 6e35060 + e4a4c4b commit d3d5db2

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Once installed, the Fluent Bit Operator provides the following features:
1717
- [Prerequisites](#prerequisites)
1818
- [Quick Start](#quick-start)
1919
- [Logging Stack](#logging-stack)
20+
- [Auditd](#auditd)
2021
- [API Doc](#api-doc)
2122
- [Best Practice](#best-practice)
2223
- [Plugin Grouping](#plugin-grouping)
@@ -103,6 +104,21 @@ green open ks-logstash-log-2020.04.26 uwQuoO90TwyigqYRW7MDYQ 1 1 99937 0 31.2m
103104

104105
Success!
105106

107+
#### Auditd
108+
The Linux audit framework provides a CAPP-compliant (Controlled Access Protection Profile) auditing system that reliably collects information about any security-relevant (or non-security-relevant) event on a system. Refer to `manifests/logging-stack/auditd`, it supports a method for collecting audit logs from the Linux audit framework.
109+
110+
```shell
111+
kubectl apply -f manifests/setup
112+
kubectl apply -f manifests/logging-stack/auditd
113+
```
114+
115+
Within a couple of minutes, you should observe an index available:
116+
117+
```shell
118+
$ curl localhost:9200/_cat/indices
119+
green open ks-logstash-log-2021.04.06 QeI-k_LoQZ2h1z23F3XiHg 5 1 404879 0 298.4mb 149.2mb
120+
```
121+
106122
## API Doc
107123

108124
The listing below shows supported plugins currently. It is based on Fluent Bit v1.4.6. For more information, see API docs of each plugin.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: fluent-bit-auditd-config
5+
namespace: kubesphere-logging-system
6+
data:
7+
auditd.lua: |
8+
function cb_replace(tag, timestamp, record)
9+
if (record["log"] == nil)
10+
then
11+
return 0, 0, 0
12+
end
13+
14+
local new_record = {}
15+
timeStr = os.date("!*t", timestamp["sec"])
16+
t = string.format("%4d-%02d-%02dT%02d:%02d:%02d.%sZ",
17+
timeStr["year"], timeStr["month"], timeStr["day"],
18+
timeStr["hour"], timeStr["min"], timeStr["sec"],
19+
timestamp["nsec"])
20+
kubernetes = {}
21+
kubernetes["pod_name"] = record["node_name"]
22+
kubernetes["container_name"] = "auditd"
23+
kubernetes["namespace_name"] = "kube-system"
24+
25+
new_record["time"] = t
26+
new_record["log"] = record["log"]
27+
new_record["kubernetes"] = kubernetes
28+
return 1, timestamp, new_record
29+
end
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: logging.kubesphere.io/v1alpha2
2+
kind: Filter
3+
metadata:
4+
name: filter-audit-logs
5+
namespace: kubesphere-logging-system
6+
labels:
7+
logging.kubesphere.io/enabled: "true"
8+
logging.kubesphere.io/component: logging
9+
spec:
10+
match: auditd
11+
filters:
12+
- recordModifier:
13+
records:
14+
- node_name ${NODE_NAME}
15+
- lua:
16+
script:
17+
key: auditd.lua
18+
name: fluent-bit-auditd-config
19+
call: cb_replace
20+
timeAsTable: true
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: logging.kubesphere.io/v1alpha2
2+
kind: Input
3+
metadata:
4+
name: auditd-input
5+
namespace: kubesphere-logging-system
6+
labels:
7+
logging.kubesphere.io/enabled: "true"
8+
logging.kubesphere.io/component: logging
9+
spec:
10+
tail:
11+
tag: auditd
12+
path: /var/log/audit/audit.log
13+
refreshIntervalSeconds: 10
14+
memBufLimit: 5MB
15+
db: /fluent-bit/tail/auditd.db
16+
dbSync: Normal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: logging.kubesphere.io/v1alpha2
2+
kind: Output
3+
metadata:
4+
name: auditd-to-es
5+
namespace: kubesphere-logging-system
6+
labels:
7+
logging.kubesphere.io/enabled: "true"
8+
logging.kubesphere.io/component: logging
9+
spec:
10+
matchRegex: auditd
11+
es:
12+
host: elasticsearch-logging-data.kubesphere-logging-system.svc
13+
port: 9200
14+
logstashPrefix: ks-logstash-log
15+
logstashFormat: true
16+
timeKey: "@timestamp"

pkg/operator/daemonset.go

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package operator
22

33
import (
44
"fmt"
5+
56
appsv1 "k8s.io/api/apps/v1"
67
corev1 "k8s.io/api/core/v1"
78
rbacv1 "k8s.io/api/rbac/v1"
@@ -116,6 +117,16 @@ func MakeDaemonSet(fb v1alpha2.FluentBit, logPath string) appsv1.DaemonSet {
116117
Protocol: "TCP",
117118
},
118119
},
120+
Env: []corev1.EnvVar{
121+
corev1.EnvVar{
122+
Name: "NODE_NAME",
123+
ValueFrom: &corev1.EnvVarSource{
124+
FieldRef: &corev1.ObjectFieldSelector{
125+
FieldPath: "spec.nodeName",
126+
},
127+
},
128+
},
129+
},
119130
VolumeMounts: []corev1.VolumeMount{
120131
{
121132
Name: "varlibcontainers",

0 commit comments

Comments
 (0)