@@ -16,6 +16,7 @@ import (
16
16
"github.com/go-openapi/spec"
17
17
"github.com/golang/glog"
18
18
"github.com/prometheus/client_golang/prometheus"
19
+ "gopkg.in/natefinch/lumberjack.v2"
19
20
20
21
kapi "k8s.io/kubernetes/pkg/api"
21
22
"k8s.io/kubernetes/pkg/api/meta"
@@ -25,6 +26,7 @@ import (
25
26
"k8s.io/kubernetes/pkg/apimachinery/registered"
26
27
v1beta1extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
27
28
"k8s.io/kubernetes/pkg/apiserver"
29
+ "k8s.io/kubernetes/pkg/apiserver/audit"
28
30
"k8s.io/kubernetes/pkg/client/restclient"
29
31
kclient "k8s.io/kubernetes/pkg/client/unversioned"
30
32
clientadapter "k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
@@ -177,7 +179,17 @@ func (c *MasterConfig) Run(protected []APIInstaller, unprotected []APIInstaller)
177
179
handler = c .authorizationFilter (handler )
178
180
handler = c .impersonationFilter (handler )
179
181
// audit handler must comes before the impersonationFilter to read the original user
180
- handler = c .auditHandler (handler )
182
+ if c .Options .AuditConfig .Enabled {
183
+ attributeGetter := apiserver .NewRequestAttributeGetter (c .getRequestContextMapper (), c .getRequestInfoResolver ())
184
+ writer := & lumberjack.Logger {
185
+ Filename : c .Options .AuditConfig .Path ,
186
+ MaxAge : c .Options .AuditConfig .MaxAge ,
187
+ MaxBackups : c .Options .AuditConfig .MaxBackups ,
188
+ MaxSize : c .Options .AuditConfig .MaxSize ,
189
+ }
190
+ handler = audit .WithAudit (handler , attributeGetter , writer )
191
+ defer writer .Close ()
192
+ }
181
193
handler = authenticationHandlerFilter (handler , c .Authenticator , c .getRequestContextMapper ())
182
194
handler = namespacingFilter (handler , c .getRequestContextMapper ())
183
195
handler = cacheControlFilter (handler , "no-store" ) // protected endpoints should not be cached
@@ -861,6 +873,23 @@ func (c *MasterConfig) getRequestContextMapper() kapi.RequestContextMapper {
861
873
return c .RequestContextMapper
862
874
}
863
875
876
+ // getRequestInfoResolver returns a request resolver.
877
+ func (c * MasterConfig ) getRequestInfoResolver () * apiserver.RequestInfoResolver {
878
+ if c .RequestInfoResolver == nil {
879
+ c .RequestInfoResolver = & apiserver.RequestInfoResolver {
880
+ APIPrefixes : sets .NewString (strings .Trim (LegacyOpenShiftAPIPrefix , "/" ),
881
+ strings .Trim (OpenShiftAPIPrefix , "/" ),
882
+ strings .Trim (KubernetesAPIPrefix , "/" ),
883
+ strings .Trim (KubernetesAPIGroupPrefix , "/" )), // all possible API prefixes
884
+ GrouplessAPIPrefixes : sets .NewString (strings .Trim (LegacyOpenShiftAPIPrefix , "/" ),
885
+ strings .Trim (OpenShiftAPIPrefix , "/" ),
886
+ strings .Trim (KubernetesAPIPrefix , "/" ),
887
+ ), // APIPrefixes that won't have groups (legacy)
888
+ }
889
+ }
890
+ return c .RequestInfoResolver
891
+ }
892
+
864
893
// RouteAllocator returns a route allocation controller.
865
894
func (c * MasterConfig ) RouteAllocator () * routeallocationcontroller.RouteAllocationController {
866
895
osclient , kclient := c .RouteAllocatorClients ()
0 commit comments