Skip to content

Commit

Permalink
new features.enable_dynamic_audit_log
Browse files Browse the repository at this point in the history
  • Loading branch information
kron4eg committed Mar 13, 2019
1 parent 8d9a1d5 commit e81bbaf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
12 changes: 9 additions & 3 deletions config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ provider:
name: ''

# Set kubelet flag --cloud-provider=external, to be used with external
# Cloud Controller Managers (CCM)
# Cloud Controller Managers (CCM).
external: false

# path to file that will be uploaded and used as custom --cloud-config file
# Path to file that will be uploaded and used as custom --cloud-config file.
cloud_config: ''

features:
# enables PodSecurityPolicy admission plugin in API server, as well as creates
# Enables PodSecurityPolicy admission plugin in API server, as well as creates
# default `privileged` PodSecurityPolicy, plus RBAC rules to authorize
# `kube-system` namespace pods to `use` it.
enable_pod_security_policy: false

# Enables dynamic audit logs.
# After enablig this, operator should create auditregistration.k8s.io/v1alpha1
# AuditSink object.
# More info: https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#dynamic-backend
enable_dynamic_audit_log: false

backup:
# Ark supported provider, see https://heptio.github.io/ark/v0.10.0/support-matrix
provider: '' # currently only aws is supported, empty provider disable ark backups
Expand Down
1 change: 1 addition & 0 deletions pkg/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ func (m *BackupConfig) ApplyEnvironment() error {
// Features switches
type Features struct {
EnablePodSecurityPolicy bool `json:"enable_pod_security_policy"`
EnableDynamicAuditLog bool `json:"enable_dynamic_audit_log"`
}

// MachineControllerConfig controls
Expand Down
5 changes: 1 addition & 4 deletions pkg/features/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func Activate(ctx *util.Context) error {
// UpdateKubeadmClusterConfiguration update additional config options in the kubeadm's
// v1beta1.ClusterConfiguration according to enabled features
func UpdateKubeadmClusterConfiguration(featuresCfg config.Features, clusterConfig *kubeadmv1beta1.ClusterConfiguration) {
if clusterConfig.APIServer.ExtraArgs == nil {
clusterConfig.APIServer.ExtraArgs = make(map[string]string)
}

activateKubeadmPSP(featuresCfg.EnablePodSecurityPolicy, clusterConfig)
activateKubeadmDynamicAuditLogs(featuresCfg.EnableDynamicAuditLog, clusterConfig)
}
34 changes: 34 additions & 0 deletions pkg/features/dynamic_audit_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package features

import (
kubeadmv1beta1 "github.com/kubermatic/kubeone/pkg/apis/kubeadm/v1beta1"
)

const (
auditDynamicConfigurationFlag = "audit-dynamic-configuration"
runtimeConfigFlag = "runtime-config"
auditRegistrationAPI = "auditregistration.k8s.io/v1alpha1=true"
)

func activateKubeadmDynamicAuditLogs(activate bool, clusterConfig *kubeadmv1beta1.ClusterConfiguration) {
if !activate {
return
}

if clusterConfig.APIServer.ExtraArgs == nil {
clusterConfig.APIServer.ExtraArgs = make(map[string]string)
}

clusterConfig.APIServer.ExtraArgs[auditDynamicConfigurationFlag] = "true"

if _, ok := clusterConfig.APIServer.ExtraArgs[runtimeConfigFlag]; ok {
clusterConfig.APIServer.ExtraArgs[runtimeConfigFlag] += "," + auditRegistrationAPI
} else {
clusterConfig.APIServer.ExtraArgs[runtimeConfigFlag] = auditRegistrationAPI
}

if clusterConfig.FeatureGates == nil {
clusterConfig.FeatureGates = map[string]bool{}
}
clusterConfig.FeatureGates["DynamicAuditing"] = true
}
4 changes: 4 additions & 0 deletions pkg/features/psp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func activateKubeadmPSP(activate bool, clusterConfig *kubeadmv1beta1.ClusterConf
return
}

if clusterConfig.APIServer.ExtraArgs == nil {
clusterConfig.APIServer.ExtraArgs = make(map[string]string)
}

if _, ok := clusterConfig.APIServer.ExtraArgs[apiServerAdmissionPluginsFlag]; ok {
clusterConfig.APIServer.ExtraArgs[apiServerAdmissionPluginsFlag] += "," + pspAdmissionPlugin
} else {
Expand Down

0 comments on commit e81bbaf

Please sign in to comment.