@@ -244,6 +244,11 @@ type options struct {
244244 openAPIDefinitions common.GetOpenAPIDefinitions
245245 addToScheme func (* runtime.Scheme ) error
246246 admissionPlugins []admissionPlugin
247+ auditPolicyFile string
248+ auditLogPath string
249+ auditLogMaxAge int // days
250+ auditLogMaxBackups int
251+ auditLogMaxSizeMB int // megabytes
247252}
248253
249254type admissionPlugin struct {
@@ -464,6 +469,26 @@ func WithAdmissionPlugin(name string, factory admission.Factory) Option {
464469 }
465470}
466471
472+ // WithAuditPolicyFile sets the path to an audit policy YAML file.
473+ // When set, the apiserver will emit audit events filtered by the policy.
474+ func WithAuditPolicyFile (path string ) Option {
475+ return func (o * options ) { o .auditPolicyFile = path }
476+ }
477+
478+ // WithAuditLogPath sets the file path for audit log output.
479+ func WithAuditLogPath (path string ) Option {
480+ return func (o * options ) { o .auditLogPath = path }
481+ }
482+
483+ // WithAuditLogRotation configures lumberjack-based rotation for the audit log.
484+ func WithAuditLogRotation (maxAgeDays , maxBackups , maxSizeMB int ) Option {
485+ return func (o * options ) {
486+ o .auditLogMaxAge = maxAgeDays
487+ o .auditLogMaxBackups = maxBackups
488+ o .auditLogMaxSizeMB = maxSizeMB
489+ }
490+ }
491+
467492func defaultResources () []resource.Object {
468493 // Higher versions need to be registered first as storage resources.
469494 return []resource.Object {
@@ -974,6 +999,22 @@ func start(
974999 o .RecommendedOptions .Authorization = nil
9751000 }
9761001
1002+ if opts .auditPolicyFile != "" {
1003+ o .RecommendedOptions .Audit = apiserveropts .NewAuditOptions ()
1004+ o .RecommendedOptions .Audit .PolicyFile = opts .auditPolicyFile
1005+ o .RecommendedOptions .Audit .LogOptions .Path = opts .auditLogPath
1006+ o .RecommendedOptions .Audit .LogOptions .Format = "json"
1007+ if opts .auditLogMaxAge > 0 {
1008+ o .RecommendedOptions .Audit .LogOptions .MaxAge = opts .auditLogMaxAge
1009+ }
1010+ if opts .auditLogMaxBackups > 0 {
1011+ o .RecommendedOptions .Audit .LogOptions .MaxBackups = opts .auditLogMaxBackups
1012+ }
1013+ if opts .auditLogMaxSizeMB > 0 {
1014+ o .RecommendedOptions .Audit .LogOptions .MaxSize = opts .auditLogMaxSizeMB
1015+ }
1016+ }
1017+
9771018 return o
9781019 }).
9791020 WithConfigFns (func (c * apiserver.RecommendedConfig ) * apiserver.RecommendedConfig {
0 commit comments