@@ -14,34 +14,39 @@ import (
1414)
1515
1616type Audit struct {
17- options * options.AuditOptions
17+ opts * options.AuditOptions
1818 serverConfig * server.CompletedConfig
1919}
2020
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 ) {
2225 serverConfig := & server.Config {
2326 ExternalAddress : externalAddress ,
2427 SecureServing : secureServingInfo ,
2528
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.
2832 LongRunningFunc : genericfilters .BasicLongRunningRequestCheck (
2933 sets .NewString ("watch" ), sets .NewString ()),
3034 }
3135
3236 // 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 {
3438 return nil , err
3539 }
3640
3741 completed := serverConfig .Complete (nil )
3842
3943 return & Audit {
40- options : options ,
44+ opts : opts ,
4145 serverConfig : & completed ,
4246 }, nil
4347}
4448
49+ // Run will run the audit backend if configured.
4550func (a * Audit ) Run (stopCh <- chan struct {}) error {
4651 if a .serverConfig .AuditBackend != nil {
4752 if err := a .serverConfig .AuditBackend .Run (stopCh ); err != nil {
@@ -52,6 +57,7 @@ func (a *Audit) Run(stopCh <-chan struct{}) error {
5257 return nil
5358}
5459
60+ // Shutdown will shutdown the audit backend if configured.
5561func (a * Audit ) Shutdown () error {
5662 if a .serverConfig .AuditBackend != nil {
5763 a .serverConfig .AuditBackend .Shutdown ()
@@ -60,11 +66,16 @@ func (a *Audit) Shutdown() error {
6066 return nil
6167}
6268
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.
6371func (a * Audit ) WithRequest (handler http.Handler ) http.Handler {
6472 handler = genericapifilters .WithAudit (handler , a .serverConfig .AuditBackend , a .serverConfig .AuditPolicyChecker , a .serverConfig .LongRunningFunc )
6573 return genericapifilters .WithRequestInfo (handler , a .serverConfig .RequestInfoResolver )
6674}
6775
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.
6879func (a * Audit ) WithUnauthorized (handler http.Handler ) http.Handler {
6980 handler = genericapifilters .WithFailedAuthenticationAudit (handler , a .serverConfig .AuditBackend , a .serverConfig .AuditPolicyChecker )
7081 return genericapifilters .WithRequestInfo (handler , a .serverConfig .RequestInfoResolver )
0 commit comments