@@ -27,20 +27,25 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
27
27
28
28
auditClient , err := libaudit .NewMulticastAuditClient (nil )
29
29
switch {
30
+ // syscall.EPROTONOSUPPORT or syscall.EAFNOSUPPORT is returned when calling attempting to connect to NETLINK_AUDIT
31
+ // on a kernel built without auditing support.
32
+ // https://github.com/elastic/go-libaudit/blob/ec298e53a6841a1f7715abbc7122635622f349bd/audit.go#L112-L115
30
33
case errors .Is (err , syscall .EPROTONOSUPPORT ), errors .Is (err , syscall .EAFNOSUPPORT ):
31
- // system doesn't support auditing, skip
32
- a .worthCheckingIPTables = true
33
- go a .kubernetesServiceWatcher .Start ()
34
- go a .fixSystemTimeSkew ()
35
- return a , nil
34
+ return startGuestAgentRoutines (a , false )
36
35
case ! errors .Is (err , nil ):
37
36
return nil , err
38
37
}
39
38
39
+ // syscall.EPERM is returned when using audit from a non-initial namespace
40
+ // https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
40
41
auditStatus , err := auditClient .GetStatus ()
41
- if err != nil {
42
+ switch {
43
+ case errors .Is (err , syscall .EPERM ):
44
+ return startGuestAgentRoutines (a , false )
45
+ case ! errors .Is (err , nil ):
42
46
return nil , err
43
47
}
48
+
44
49
if auditStatus .Enabled == 0 {
45
50
if err = auditClient .SetEnabled (true , libaudit .WaitForReply ); err != nil {
46
51
return nil , err
@@ -59,8 +64,21 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
59
64
} else {
60
65
a .worthCheckingIPTables = true
61
66
}
67
+ return startGuestAgentRoutines (a , true )
68
+ }
69
+
70
+ // startGuestAgentRoutines sets worthCheckingIPTables to true if auditing is not supported,
71
+ // instead of using setWorthCheckingIPTablesRoutine to dynamically set the value.
72
+ //
73
+ // Auditing is not supported in a kernels and is not currently supported outside of the initial namespace, so does not work
74
+ // from inside a container or WSL2 instance, for example.
75
+ func startGuestAgentRoutines (a * agent , supportsAuditing bool ) (* agent , error ) {
76
+ if ! supportsAuditing {
77
+ a .worthCheckingIPTables = true
78
+ }
62
79
go a .kubernetesServiceWatcher .Start ()
63
80
go a .fixSystemTimeSkew ()
81
+
64
82
return a , nil
65
83
}
66
84
0 commit comments