Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the advanced audit backend #15657

Merged
merged 1 commit into from
Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package origin

import (
"fmt"
"io"
"net/http"
"net/url"
Expand All @@ -11,10 +12,13 @@ import (
"gopkg.in/natefinch/lumberjack.v2"

apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion"
auditinternal "k8s.io/apiserver/pkg/apis/audit"
auditpolicy "k8s.io/apiserver/pkg/audit/policy"
apifilters "k8s.io/apiserver/pkg/endpoints/filters"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
apiserver "k8s.io/apiserver/pkg/server"
apiserverfilters "k8s.io/apiserver/pkg/server/filters"
auditlog "k8s.io/apiserver/plugin/pkg/audit/log"
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
kubeapiserver "k8s.io/kubernetes/pkg/master"
kcorestorage "k8s.io/kubernetes/pkg/registry/core/rest"
Expand Down Expand Up @@ -225,6 +229,14 @@ func (c *MasterConfig) Run(kubeAPIServerConfig *kubeapiserver.Config, assetConfi
return err
}

// Start the audit backend before any request comes in. This means we cannot turn it into a
// post start hook because without calling Backend.Run the Backend.ProcessEvents call might block.
if c.AuditBackend != nil {
if err := c.AuditBackend.Run(stopCh); err != nil {
return fmt.Errorf("failed to run the audit backend: %v", err)
}
}

// add post-start hooks
aggregatedAPIServer.GenericAPIServer.AddPostStartHook("user.openshift.io-groupcache",
func(context apiserver.PostStartHookContext) error {
Expand Down Expand Up @@ -275,7 +287,13 @@ func (c *MasterConfig) buildHandlerChain(assetConfig *AssetConfig) (func(http.Ha
// backwards compatible writer to regular log
writer = cmdutil.NewGLogWriterV(0)
}
handler = apifilters.WithLegacyAudit(handler, contextMapper, writer)
c.AuditBackend = auditlog.NewBackend(writer)
auditPolicyChecker := auditpolicy.NewChecker(&auditinternal.Policy{
// This is for backwards compatibility maintaining the old visibility, ie. just
// raw overview of the requests comming in.
Rules: []auditinternal.PolicyRule{{Level: auditinternal.LevelMetadata}},
})
handler = apifilters.WithAudit(handler, contextMapper, c.AuditBackend, auditPolicyChecker, kc.LongRunningFunc)
}
handler = serverhandlers.AuthenticationHandlerFilter(handler, c.Authenticator, contextMapper)
handler = namespacingFilter(handler, contextMapper)
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/admission/initializer"
"k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle"
"k8s.io/apiserver/pkg/audit"
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authentication/group"
"k8s.io/apiserver/pkg/authentication/request/anonymous"
Expand Down Expand Up @@ -178,6 +179,8 @@ type MasterConfig struct {
// for that component.
PrivilegedLoopbackOpenShiftClient *osclient.Client

AuditBackend audit.Backend

// TODO inspect uses to eliminate them
InternalKubeInformers kinternalinformers.SharedInformerFactory
ExternalKubeInformers kinformers.SharedInformerFactory
Expand Down