Skip to content

Commit

Permalink
Improve privilage escalation remediation message (stackrox#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
janisz authored and abrad3 committed Sep 28, 2023
1 parent 97e1068 commit d2a39f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/generated/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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

0 comments on commit d2a39f0

Please sign in to comment.