Skip to content

Commit

Permalink
add default audit policy (Azure#2189)
Browse files Browse the repository at this point in the history
* add default audit policy

* apiserver audit log rotation is user-configurable
  • Loading branch information
pidah authored and Terje Torkelsen committed Mar 15, 2018
1 parent 7eaae6a commit 5e5bf4f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docs/clusterdefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,12 @@ Below is a list of apiserver options that acs-engine will configure by default:
|---|---|
|"--admission-control"|"NamespaceLifecycle, LimitRanger, ServiceAccount, DefaultStorageClass, ResourceQuota, DenyEscalatingExec, AlwaysPullImages, SecurityContextDeny"|
|"--authorization-mode"|"Node", "RBAC" (*the latter if enabledRbac is true*)|
|"--audit-log-maxage"|"30"|
|"--audit-log-maxbackup"|"10"|
|"--audit-log-maxsize"|"100"|
|"--feature-gates"|No default (can be a comma-separated list)|




Below is a list of apiserver options that are *not* currently user-configurable, either because a higher order configuration vector is available that enforces kubelet configuration, or because a static configuration is required to build a functional cluster:

|apiserver option|default value|
Expand All @@ -317,9 +320,6 @@ Below is a list of apiserver options that are *not* currently user-configurable,
|"--advertise-address"|*calculated value that represents listening URI for API server*|
|"--allow-privileged"|"true"|
|"--anonymous-auth"|"false|
|"--audit-log-maxage"|"30"|
|"--audit-log-maxbackup"|"10"|
|"--audit-log-maxsize"|"100"|
|"--audit-log-path"|"/var/log/apiserver/audit.log"|
|"--insecure-port"|"8080"|
|"--secure-port"|"443"|
Expand Down
62 changes: 62 additions & 0 deletions parts/k8s/manifests/kubernetesmaster-audit-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: audit.k8s.io/v1beta1 # This is required.
kind: Policy
# Don't generate audit events for all requests in RequestReceived stage.
omitStages:
- "RequestReceived"
rules:
# Log pod changes at RequestResponse level
- level: RequestResponse
resources:
- group: ""
# Resource "pods" doesn't match requests to any subresource of pods,
# which is consistent with the RBAC policy.
resources: ["pods"]

# Log "pods/log", "pods/status" at Metadata level
- level: Metadata
resources:
- group: ""
resources: ["pods/log", "pods/status"]

# Don't log watch requests by the "system:kube-proxy" on endpoints or services
- level: None
users: ["system:kube-proxy"]
verbs: ["watch"]
resources:
- group: "" # core API group
resources: ["endpoints", "services"]

# Don't log authenticated requests to certain non-resource URL paths.
- level: None
userGroups: ["system:authenticated"]
nonResourceURLs:
- "/api*" # Wildcard matching.
- "/version"

# Log the request body of configmap changes in kube-system.
- level: Request
resources:
- group: "" # core API group
resources: ["configmaps"]
# This rule only applies to resources in the "kube-system" namespace.
# The empty string "" can be used to select non-namespaced resources.
namespaces: ["kube-system"]

# Log the request body of secret changes.
- level: Request
resources:
- group: "" # core API group
resources: ["secrets"]

# Log all other resources in core and extensions at the Request level.
- level: Request
resources:
- group: "" # core API group
- group: "extensions" # Version of group should NOT be included.

# A catch-all rule to log all other requests at the Metadata level.
- level: Metadata
# Long-running requests like watches that fall under this rule will not
# generate an audit event in RequestReceived.
omitStages:
- "RequestReceived"
5 changes: 5 additions & 0 deletions pkg/acsengine/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func kubernetesManifestSettingsInit(profile *api.Properties) []kubernetesFeature
"pod-security-policy.yaml",
helpers.IsTrueBoolPointer(profile.OrchestratorProfile.KubernetesConfig.EnablePodSecurityPolicy),
},
{
"kubernetesmaster-audit-policy.yaml",
"audit-policy.yaml",
isKubernetesVersionGe(profile.OrchestratorProfile.OrchestratorVersion, "1.8.0"),
},
{
"kubernetesmaster-kube-apiserver.yaml",
"kube-apiserver.yaml",
Expand Down
17 changes: 11 additions & 6 deletions pkg/acsengine/defaults-apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ func setAPIServerConfig(cs *api.ContainerService) {
"--advertise-address": "<kubernetesAPIServerIP>",
"--allow-privileged": "true",
"--anonymous-auth": "false",
"--audit-log-maxage": "30",
"--audit-log-maxbackup": "10",
"--audit-log-maxsize": "100",
"--audit-log-path": "/var/log/apiserver/audit.log",
"--audit-log-path": "/var/log/audit.log",
"--insecure-port": "8080",
"--secure-port": "443",
"--service-account-lookup": "true",
Expand Down Expand Up @@ -73,6 +70,11 @@ func setAPIServerConfig(cs *api.ContainerService) {
staticLinuxAPIServerConfig["--oidc-issuer-url"] = "https://" + issuerHost + "/" + cs.Properties.AADProfile.TenantID + "/"
}

// Audit Policy configuration
if isKubernetesVersionGe(o.OrchestratorVersion, "1.8.0") {
staticLinuxAPIServerConfig["--audit-policy-file"] = "/etc/kubernetes/manifests/audit-policy.yaml"
}

staticWindowsAPIServerConfig := make(map[string]string)
for key, val := range staticLinuxAPIServerConfig {
staticWindowsAPIServerConfig[key] = val
Expand All @@ -82,8 +84,11 @@ func setAPIServerConfig(cs *api.ContainerService) {

// Default apiserver config
defaultAPIServerConfig := map[string]string{
"--admission-control": "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,DenyEscalatingExec,AlwaysPullImages",
"--authorization-mode": "Node",
"--admission-control": "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,DenyEscalatingExec,AlwaysPullImages",
"--authorization-mode": "Node",
"--audit-log-maxage": "30",
"--audit-log-maxbackup": "10",
"--audit-log-maxsize": "100",
}

// RBAC configuration
Expand Down

0 comments on commit 5e5bf4f

Please sign in to comment.