Make audit writer accessible from Config
... such that it can be used for a custom handler chain.
This commit is contained in:
@@ -19,6 +19,7 @@ package genericapiserver
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -53,10 +54,8 @@ import (
|
|||||||
|
|
||||||
// Config is a structure used to configure a GenericAPIServer.
|
// Config is a structure used to configure a GenericAPIServer.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AuditLogPath string
|
// Destination for audit logs
|
||||||
AuditLogMaxAge int
|
AuditWriter io.Writer
|
||||||
AuditLogMaxBackups int
|
|
||||||
AuditLogMaxSize int
|
|
||||||
// Allow downstream consumers to disable swagger.
|
// Allow downstream consumers to disable swagger.
|
||||||
// This includes returning the generated swagger spec at /swaggerapi and swagger ui at /swagger-ui.
|
// This includes returning the generated swagger spec at /swaggerapi and swagger ui at /swagger-ui.
|
||||||
EnableSwaggerSupport bool
|
EnableSwaggerSupport bool
|
||||||
@@ -165,14 +164,21 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(options *options.ServerRunOptions) *Config {
|
func NewConfig(options *options.ServerRunOptions) *Config {
|
||||||
|
var auditWriter io.Writer
|
||||||
|
if len(options.AuditLogPath) != 0 {
|
||||||
|
auditWriter = &lumberjack.Logger{
|
||||||
|
Filename: options.AuditLogPath,
|
||||||
|
MaxAge: options.AuditLogMaxAge,
|
||||||
|
MaxBackups: options.AuditLogMaxBackups,
|
||||||
|
MaxSize: options.AuditLogMaxSize,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &Config{
|
return &Config{
|
||||||
APIGroupPrefix: options.APIGroupPrefix,
|
APIGroupPrefix: options.APIGroupPrefix,
|
||||||
APIPrefix: options.APIPrefix,
|
APIPrefix: options.APIPrefix,
|
||||||
CorsAllowedOriginList: options.CorsAllowedOriginList,
|
CorsAllowedOriginList: options.CorsAllowedOriginList,
|
||||||
AuditLogPath: options.AuditLogPath,
|
AuditWriter: auditWriter,
|
||||||
AuditLogMaxAge: options.AuditLogMaxAge,
|
|
||||||
AuditLogMaxBackups: options.AuditLogMaxBackups,
|
|
||||||
AuditLogMaxSize: options.AuditLogMaxSize,
|
|
||||||
EnableGarbageCollection: options.EnableGarbageCollection,
|
EnableGarbageCollection: options.EnableGarbageCollection,
|
||||||
EnableIndex: true,
|
EnableIndex: true,
|
||||||
EnableProfiling: options.EnableProfiling,
|
EnableProfiling: options.EnableProfiling,
|
||||||
@@ -332,15 +338,6 @@ func (c Config) New() (*GenericAPIServer, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.AuditLogPath) != 0 {
|
|
||||||
s.auditWriter = &lumberjack.Logger{
|
|
||||||
Filename: c.AuditLogPath,
|
|
||||||
MaxAge: c.AuditLogMaxAge,
|
|
||||||
MaxBackups: c.AuditLogMaxBackups,
|
|
||||||
MaxSize: c.AuditLogMaxSize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send correct mime type for .svg files.
|
// Send correct mime type for .svg files.
|
||||||
// TODO: remove when https://github.com/golang/go/commit/21e47d831bafb59f22b1ea8098f709677ec8ce33
|
// TODO: remove when https://github.com/golang/go/commit/21e47d831bafb59f22b1ea8098f709677ec8ce33
|
||||||
// makes it into all of our supported go versions (only in v1.7.1 now).
|
// makes it into all of our supported go versions (only in v1.7.1 now).
|
||||||
@@ -371,7 +368,7 @@ func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (
|
|||||||
secure = handler
|
secure = handler
|
||||||
secure = apiserverfilters.WithAuthorization(secure, attributeGetter, c.Authorizer)
|
secure = apiserverfilters.WithAuthorization(secure, attributeGetter, c.Authorizer)
|
||||||
secure = apiserverfilters.WithImpersonation(secure, c.RequestContextMapper, c.Authorizer)
|
secure = apiserverfilters.WithImpersonation(secure, c.RequestContextMapper, c.Authorizer)
|
||||||
secure = apiserverfilters.WithAudit(secure, attributeGetter, s.auditWriter) // before impersonation to read original user
|
secure = apiserverfilters.WithAudit(secure, attributeGetter, c.AuditWriter) // before impersonation to read original user
|
||||||
secure = authhandlers.WithAuthentication(secure, c.RequestContextMapper, c.Authenticator, authhandlers.Unauthorized(c.SupportsBasicAuth))
|
secure = authhandlers.WithAuthentication(secure, c.RequestContextMapper, c.Authenticator, authhandlers.Unauthorized(c.SupportsBasicAuth))
|
||||||
secure = genericfilters.WithPanicRecovery(secure, s.NewRequestInfoResolver())
|
secure = genericfilters.WithPanicRecovery(secure, s.NewRequestInfoResolver())
|
||||||
secure = genericfilters.WithTimeoutForNonLongRunningRequests(secure, longRunningFunc)
|
secure = genericfilters.WithTimeoutForNonLongRunningRequests(secure, longRunningFunc)
|
||||||
|
@@ -19,7 +19,6 @@ package genericapiserver
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
@@ -166,9 +165,6 @@ type GenericAPIServer struct {
|
|||||||
postStartHooks map[string]PostStartHookFunc
|
postStartHooks map[string]PostStartHookFunc
|
||||||
postStartHookLock sync.Mutex
|
postStartHookLock sync.Mutex
|
||||||
postStartHooksCalled bool
|
postStartHooksCalled bool
|
||||||
|
|
||||||
// Writer to write the audit log to.
|
|
||||||
auditWriter io.Writer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestContextMapper is exposed so that third party resource storage can be build in a different location.
|
// RequestContextMapper is exposed so that third party resource storage can be build in a different location.
|
||||||
|
Reference in New Issue
Block a user