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

[Security Hardened Kubernetes Cluster] Rule 2001 implementation #375

Merged

Conversation

AleksandarSavchev
Copy link
Member

What this PR does / why we need it:

Which issue(s) this PR fixes:
Part of #356

Special notes for your reviewer:

Release note:

Implementation for rule `2001` from the `security-hardened-k8s` ruleset for provider `managedk8s`.

@AleksandarSavchev AleksandarSavchev requested a review from a team as a code owner November 22, 2024 14:54
@gardener-robot gardener-robot added needs/review Needs review size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Nov 22, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 22, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 22, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! I have some really minor change requests. Other looks good.


> [!WARNING]
> `securityContext.allowPrivilegeEscalation` is set to `true` in the following exceptions:
> - container is running as `privileged`
> - `CAP_SYS_ADMIN` is added to the container
> - `CAP_SYS_ADMIN/SYS_ADMIN` is added to the container. More information can be found [here](https://github.com/kubernetes/kubernetes/issues/119568).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> - `CAP_SYS_ADMIN/SYS_ADMIN` is added to the container. More information can be found [here](https://github.com/kubernetes/kubernetes/issues/119568).
> - `CAP_SYS_ADMIN` or `SYS_ADMIN` is added to the container. More information can be found in [this issue](https://github.com/kubernetes/kubernetes/issues/119568).

var (
checkResults []rule.CheckResult
allowsPrivilegeEscalation = func(securityContext corev1.SecurityContext) bool {
var addsCapSysAdmin = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var addsCapSysAdmin = false
addsCapSysAdmin := false

Comment on lines 83 to 85
return securityContext.AllowPrivilegeEscalation == nil || *securityContext.AllowPrivilegeEscalation ||
(securityContext.Privileged != nil && *securityContext.Privileged) ||
addsCapSysAdmin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads better IMO.

Suggested change
return securityContext.AllowPrivilegeEscalation == nil || *securityContext.AllowPrivilegeEscalation ||
(securityContext.Privileged != nil && *securityContext.Privileged) ||
addsCapSysAdmin
var (
allowsPrivilegeEscalation = securityContext.AllowPrivilegeEscalation == nil || *securityContext.AllowPrivilegeEscalation
hasPrivilegedContext = securityContext.Privileged != nil && *securityContext.Privileged
)
return allowsPrivilegeEscalation || hasPrivilegedContext || addsCapSysAdmin

@gardener-robot gardener-robot added the needs/changes Needs (more) changes label Nov 25, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 25, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/changes Needs (more) changes needs/review Needs review labels Nov 25, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 25, 2024
@AleksandarSavchev AleksandarSavchev merged commit acaf802 into gardener:main Nov 25, 2024
9 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) status/closed Issue is closed (either delivered or triaged)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants