Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
add default audit policy (#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 jackfrancis committed Feb 7, 2018
1 parent a138e69 commit 4649183
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/clusterdefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ 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)|


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 4649183

Please sign in to comment.