@@ -14,34 +14,39 @@ import (
14
14
)
15
15
16
16
type Audit struct {
17
- options * options.AuditOptions
17
+ opts * options.AuditOptions
18
18
serverConfig * server.CompletedConfig
19
19
}
20
20
21
- func New (options * options.AuditOptions , externalAddress string , secureServingInfo * server.SecureServingInfo ) (* Audit , error ) {
21
+ // New creates a new Audit struct to handle auditing for proxy requests. This
22
+ // is mostly a wrapper for the apiserver auditing handlers to combine them with
23
+ // the proxy.
24
+ func New (opts * options.AuditOptions , externalAddress string , secureServingInfo * server.SecureServingInfo ) (* Audit , error ) {
22
25
serverConfig := & server.Config {
23
26
ExternalAddress : externalAddress ,
24
27
SecureServing : secureServingInfo ,
25
28
26
- // Default to treating watch as a long-running operation
27
- // Generic API servers have no inherent long-running subresources
29
+ // Default to treating watch as a long-running operation.
30
+ // Generic API servers have no inherent long-running subresources.
31
+ // This is so watch requests are handled correctly in the audit log.
28
32
LongRunningFunc : genericfilters .BasicLongRunningRequestCheck (
29
33
sets .NewString ("watch" ), sets .NewString ()),
30
34
}
31
35
32
36
// We do not support dynamic auditing, so leave nil
33
- if err := options .ApplyTo (serverConfig , nil , nil , nil , nil ); err != nil {
37
+ if err := opts .ApplyTo (serverConfig , nil , nil , nil , nil ); err != nil {
34
38
return nil , err
35
39
}
36
40
37
41
completed := serverConfig .Complete (nil )
38
42
39
43
return & Audit {
40
- options : options ,
44
+ opts : opts ,
41
45
serverConfig : & completed ,
42
46
}, nil
43
47
}
44
48
49
+ // Run will run the audit backend if configured.
45
50
func (a * Audit ) Run (stopCh <- chan struct {}) error {
46
51
if a .serverConfig .AuditBackend != nil {
47
52
if err := a .serverConfig .AuditBackend .Run (stopCh ); err != nil {
@@ -52,6 +57,7 @@ func (a *Audit) Run(stopCh <-chan struct{}) error {
52
57
return nil
53
58
}
54
59
60
+ // Shutdown will shutdown the audit backend if configured.
55
61
func (a * Audit ) Shutdown () error {
56
62
if a .serverConfig .AuditBackend != nil {
57
63
a .serverConfig .AuditBackend .Shutdown ()
@@ -60,11 +66,16 @@ func (a *Audit) Shutdown() error {
60
66
return nil
61
67
}
62
68
69
+ // WithRequest will wrap the given handler to inject the request information
70
+ // into the context which is then used by the wrapped audit handler.
63
71
func (a * Audit ) WithRequest (handler http.Handler ) http.Handler {
64
72
handler = genericapifilters .WithAudit (handler , a .serverConfig .AuditBackend , a .serverConfig .AuditPolicyChecker , a .serverConfig .LongRunningFunc )
65
73
return genericapifilters .WithRequestInfo (handler , a .serverConfig .RequestInfoResolver )
66
74
}
67
75
76
+ // WithUnauthorized will wrap the given handler to inject the request
77
+ // information into the context which is then used by the wrapped audit
78
+ // handler.
68
79
func (a * Audit ) WithUnauthorized (handler http.Handler ) http.Handler {
69
80
handler = genericapifilters .WithFailedAuthenticationAudit (handler , a .serverConfig .AuditBackend , a .serverConfig .AuditPolicyChecker )
70
81
return genericapifilters .WithRequestInfo (handler , a .serverConfig .RequestInfoResolver )
0 commit comments