kube-linter icon indicating copy to clipboard operation
kube-linter copied to clipboard

[FEATURE_REQUEST] Explicit check for `securityContext.allowPrivilegeEscalation=false` on containers

Open AlanMasciangelo opened this issue 2 years ago • 1 comments

Description of the problem/feature request Add a check or option to check if containers explicitly set allowPrivilegeEscalation to false. Explicitly setting this to false is generally regarded as good security practice.

Description of the existing behavior vs. expected behavior

The existing privilege-escalation-container doesn't trigger on this condition, I imagine intentionally since allowPrivilegeEscalation is determined by a variety of factors and can be restricted in other ways.

AlanMasciangelo avatar Nov 30 '23 20:11 AlanMasciangelo

@AlanMasciangelo - CEL expression solution using the new template:

  • https://github.com/stackrox/kube-linter/pull/1012
customChecks:
  - name: explicit-privilege-escalation-false
    template: cel-expression
    params:
      check: |
        has(object.spec.containers) && 
        object.spec.containers.exists(c, 
          !has(c.securityContext.allowPrivilegeEscalation) || 
          c.securityContext.allowPrivilegeEscalation != false) ?
        "Container should explicitly set allowPrivilegeEscalation: false" : ""
    scope:
      objectKinds: [DeploymentLike]

This checks that all containers explicitly set allowPrivilegeEscalation to false.

janisz avatar Aug 29 '25 09:08 janisz