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

Improve privilage escalation remediation message #534

Merged
merged 1 commit into from
Apr 11, 2023
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
2 changes: 1 addition & 1 deletion docs/generated/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ strategyTypeRegex: ^(RollingUpdate|Rolling)$

**Description**: Alert on containers of allowing privilege escalation that could gain more privileges than its parent process.

**Remediation**: Ensure containers do not allow privilege escalation by setting allowPrivilegeEscalation=false." See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ for more details.
**Remediation**: Ensure containers do not allow privilege escalation by setting allowPrivilegeEscalation=false, privileged=false and removing CAP_SYS_ADMIN capability. See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ for more details.

**Template**: [privilege-escalation-container](templates.md#privilege-escalation-on-containers)
## privileged-container
Expand Down
3 changes: 2 additions & 1 deletion pkg/builtinchecks/yamls/privilege-escalation.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: "privilege-escalation-container"
description: "Alert on containers of allowing privilege escalation that could gain more privileges than its parent process."
remediation: >-
Ensure containers do not allow privilege escalation by setting allowPrivilegeEscalation=false."
Ensure containers do not allow privilege escalation by setting
allowPrivilegeEscalation=false, privileged=false and removing CAP_SYS_ADMIN capability.
See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ for more details.
scope:
objectKinds:
Expand Down
8 changes: 4 additions & 4 deletions pkg/templates/privilegeescalation/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func init() {
return []diagnostic.Diagnostic{{Message: fmt.Sprintf("container %q has AllowPrivilegeEscalation set to true.", container.Name)}}
}
if securityContext.Privileged != nil && *securityContext.Privileged {
return []diagnostic.Diagnostic{{Message: fmt.Sprintf("container %q is Privileged and allows privilege escalation.", container.Name)}}
return []diagnostic.Diagnostic{{Message: fmt.Sprintf("container %q is Privileged hence allows privilege escalation.", container.Name)}}
}
if securityContext.Capabilities != nil {
for _, cap := range securityContext.Capabilities.Add {
if cap == v1.Capability(sysAdminCapability) {
return []diagnostic.Diagnostic{{Message: fmt.Sprintf("container %q has SYS_ADMIN capability and allows privilege escalation.", container.Name)}}
for _, capability := range securityContext.Capabilities.Add {
if capability == sysAdminCapability {
return []diagnostic.Diagnostic{{Message: fmt.Sprintf("container %q has SYS_ADMIN capability hence allows privilege escalation.", container.Name)}}
}
}
}
Expand Down