@@ -28,27 +28,30 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
28
28
}
29
29
30
30
auditClient , err := libaudit .NewMulticastAuditClient (nil )
31
- switch {
32
- // syscall.EPROTONOSUPPORT or syscall.EAFNOSUPPORT is returned when calling attempting to connect to NETLINK_AUDIT
33
- // on a kernel built without auditing support.
34
- // https://github.com/elastic/go-libaudit/blob/ec298e53a6841a1f7715abbc7122635622f349bd/audit.go#L112-L115
35
- case errors .Is (err , syscall .EPROTONOSUPPORT ), errors .Is (err , syscall .EAFNOSUPPORT ):
36
- return startGuestAgentRoutines (a , false )
37
- case ! errors .Is (err , nil ):
38
- return nil , err
31
+ if err != nil {
32
+ // syscall.EPROTONOSUPPORT or syscall.EAFNOSUPPORT is returned when calling attempting to connect to NETLINK_AUDIT
33
+ // on a kernel built without auditing support.
34
+ // https://github.com/elastic/go-libaudit/blob/ec298e53a6841a1f7715abbc7122635622f349bd/audit.go#L112-L115
35
+ if ! errors .Is (err , syscall .EPROTONOSUPPORT ) && ! errors .Is (err , syscall .EAFNOSUPPORT ) {
36
+ return nil , err
37
+ }
38
+ logrus .Infof ("Auditing is not available: %s" , err )
39
+ return startGuestAgentRoutines (a , false ), nil
39
40
}
40
41
41
- // syscall.EPERM is returned when using audit from a non-initial namespace
42
- // https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
43
42
auditStatus , err := auditClient .GetStatus ()
44
- switch {
45
- case errors .Is (err , syscall .EPERM ):
46
- return startGuestAgentRoutines (a , false )
47
- case ! errors .Is (err , nil ):
48
- return nil , err
43
+ if err != nil {
44
+ // syscall.EPERM is returned when using audit from a non-initial namespace
45
+ // https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
46
+ if ! errors .Is (err , syscall .EPERM ) {
47
+ return nil , err
48
+ }
49
+ logrus .Infof ("Auditing is not permitted: %s" , err )
50
+ return startGuestAgentRoutines (a , false ), nil
49
51
}
50
52
51
53
if auditStatus .Enabled == 0 {
54
+ logrus .Info ("Enabling auditing" )
52
55
if err = auditClient .SetEnabled (true , libaudit .WaitForReply ); err != nil {
53
56
return nil , err
54
57
}
@@ -66,22 +69,23 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
66
69
} else {
67
70
a .worthCheckingIPTables = true
68
71
}
69
- return startGuestAgentRoutines (a , true )
72
+ logrus .Infof ("Auditing enabled (%d)" , auditStatus .Enabled )
73
+ return startGuestAgentRoutines (a , true ), nil
70
74
}
71
75
72
76
// startGuestAgentRoutines sets worthCheckingIPTables to true if auditing is not supported,
73
77
// instead of using setWorthCheckingIPTablesRoutine to dynamically set the value.
74
78
//
75
79
// Auditing is not supported in a kernels and is not currently supported outside of the initial namespace, so does not work
76
80
// from inside a container or WSL2 instance, for example.
77
- func startGuestAgentRoutines (a * agent , supportsAuditing bool ) ( * agent , error ) {
81
+ func startGuestAgentRoutines (a * agent , supportsAuditing bool ) * agent {
78
82
if ! supportsAuditing {
79
83
a .worthCheckingIPTables = true
80
84
}
81
85
go a .kubernetesServiceWatcher .Start ()
82
86
go a .fixSystemTimeSkew ()
83
87
84
- return a , nil
88
+ return a
85
89
}
86
90
87
91
type agent struct {
@@ -103,6 +107,7 @@ type agent struct {
103
107
// setWorthCheckingIPTablesRoutine sets worthCheckingIPTables to be false
104
108
// when no NETFILTER_CFG audit message was received for the iptablesIdle time.
105
109
func (a * agent ) setWorthCheckingIPTablesRoutine (auditClient * libaudit.AuditClient , iptablesIdle time.Duration ) {
110
+ logrus .Info ("setWorthCheckingIPTablesRoutine(): monitoring netfilter audit events" )
106
111
var latestTrue time.Time
107
112
go func () {
108
113
for {
@@ -323,6 +328,7 @@ func (a *agent) Info(ctx context.Context) (*api.Info, error) {
323
328
const deltaLimit = 2 * time .Second
324
329
325
330
func (a * agent ) fixSystemTimeSkew () {
331
+ logrus .Info ("fixSystemTimeSkew(): monitoring system time skew" )
326
332
for {
327
333
ok , err := timesync .HasRTC ()
328
334
if ! ok {
0 commit comments