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

fix(query): Revise list of unsafe sysctls in cluster_allows_unsafe_sysctls k8s rule #4883

Merged

Conversation

Churro
Copy link
Contributor

@Churro Churro commented Feb 27, 2022

Problem

  • Many containers run as root so that they can bind on ports < 1024. As this poses a certain security risk, Kubernetes v1.22 introduced the possibility to specify net.ipv4.ip_unprivileged_port_start in the sysctls of the securityContext of a pod. This enables also unprivileged users to bind on privileged ports. The K8s documentation therefore includes this sysctl in the safe set (see here). The current rule is not aware of that.
  • Since Kubernetes v1.23, sysctl names may alternatively be spelled with a / as separator instead of a dot.
    This scheme is currently not supported.
  • The current rule is not immediately actionable, as it doesn't point to the specific line with the problematic sysctl name

Proposed Changes

  • Remediate false positive in case net.ipv4.ip_unprivileged_port_start is specified
  • Support sysctl names with /
  • Show targeted findings for each statement violating the rule
  • Extend rule to also cover Deployment, StatefulSet, etc. resource kinds

I submit this contribution under the Apache-2.0 license.

@kicsbot
Copy link
Contributor

kicsbot commented Feb 27, 2022

Scan submitted to Checkmarx

Copy link
Contributor

@rafaela-soares rafaela-soares left a comment

Choose a reason for hiding this comment

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

Another great observation and refactor, @Churro 🚀 Thank you!

I only have a suggestion. If you agree, can you also add a negative sample related to the positive2.yaml, please? (It is not extremely required, but the more samples, the better)

@Churro
Copy link
Contributor Author

Churro commented Mar 2, 2022

Thank you for the review, @rafaela-soares! As requested, I added a negative test sample.

Copy link
Contributor

@rafaela-soares rafaela-soares left a comment

Choose a reason for hiding this comment

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

LGTM

@joaoReigota1 joaoReigota1 merged commit a2dedba into Checkmarx:master Mar 4, 2022
@rafaela-soares rafaela-soares added the community Community contribution label Mar 16, 2022
@rafaela-soares rafaela-soares added the query New query feature label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution query New query feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants