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

feat(controllermanager): add checks for Kubernetes Controller Manager #3291

Merged
merged 13 commits into from
Feb 22, 2024

Conversation

MrCloudSec
Copy link
Member

Description

Add all checks for Kubernetes Controller Manager:

[controllermanager_bind_address] Ensure that the --bind-address argument is set to 127.0.0.1 - controller-manager [medium]
[controllermanager_root_ca_file_set] Ensure that the --root-ca-file argument is set as appropriate - controller-manager [medium]
[controllermanager_rotate_kubelet_server_cert] Ensure that the RotateKubeletServerCertificate argument is set to true - controller-manager [medium]
[controllermanager_service_account_credentials] Ensure that the --use-service-account-credentials argument is set to true - controller-manager [medium]
[controllermanager_service_account_private_key_file] Ensure that the --service-account-private-key-file argument is set as appropriate - controller-manager [medium]

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@MrCloudSec MrCloudSec requested a review from a team January 16, 2024 16:52
@MrCloudSec MrCloudSec added prowler-4.0 provider/kubernetes Issues/PRs related with the Kubernetes provider labels Jan 16, 2024
Copy link
Member

@jfagoagas jfagoagas left a comment

Choose a reason for hiding this comment

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

More checks for Kubernetes!! Great job @sergargar 🚀

Please check my comments since there are broken links in the metadata and we need to control execution within loops not to loop over everything if it is not configured as expected.

"ResourceType": "KubernetesControllerManager",
"Description": "This check ensures that profiling is disabled in the Kubernetes Controller Manager, reducing the potential attack surface.",
"Risk": "Enabling profiling can expose detailed system and program information, which could be exploited if accessed by unauthorized users.",
"RelatedUrl": "https://github.com/kubernetes/community/blob/master/contributors/devel/profiling.md",
Copy link
Member

Choose a reason for hiding this comment

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

Broken link, if you use Github links please set the permalink.

},
"Recommendation": {
"Text": "Disable profiling in the Kubernetes Controller Manager for enhanced security.",
"Url": "https://kubernetes.io/docs/admin/kube-controller-manager/"
Copy link
Member

Choose a reason for hiding this comment

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

Broken link

f"Controller Manager has profiling enabled in pod {pod.name}."
)
for container in pod.containers.values():
if "--profiling=false" in str(container.command):
Copy link
Member

Choose a reason for hiding this comment

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

I think you have to check if this is not set and just break the loop if that happens.

f"Controller Manager has the root CA file set in pod {pod.name}."
)
for container in pod.containers.values():
if "--root-ca-file=" in str(container.command):
Copy link
Member

Choose a reason for hiding this comment

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

I think you have to check if this is not set and just break the loop if that happens.

},
"Recommendation": {
"Text": "Configure the Controller Manager with a root CA file to enhance security for pods communicating with the API server.",
"Url": "https://kubernetes.io/docs/admin/kube-controller-manager/"
Copy link
Member

Choose a reason for hiding this comment

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

Broken link.

"ResourceType": "KubernetesControllerManager",
"Description": "This check verifies that the Kubernetes Controller Manager is configured with the --root-ca-file argument set to a certificate bundle file, allowing pods to verify the API server's serving certificate.",
"Risk": "Not setting the root CA file can expose pods to man-in-the-middle attacks due to unverified TLS connections to the API server.",
"RelatedUrl": "https://github.com/kubernetes/kubernetes/issues/11000",
Copy link
Member

Choose a reason for hiding this comment

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

Is the only resource available?

"ResourceType": "KubernetesControllerManager",
"Description": "This check ensures that the Kubernetes Controller Manager is configured with the RotateKubeletServerCertificate argument set to true, enabling automated rotation of kubelet server certificates.",
"Risk": "Not enabling kubelet server certificate rotation could lead to downtime due to expired certificates.",
"RelatedUrl": "https://kubernetes.io/docs/admin/kubelet-tls-bootstrapping/#approval-controller",
Copy link
Member

Choose a reason for hiding this comment

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

Broken link.

"ResourceType": "KubernetesControllerManager",
"Description": "This check verifies that the Kubernetes Controller Manager is configured to use individual service account credentials for each controller, enhancing the security and role separation within the Kubernetes system.",
"Risk": "Not using individual service account credentials can lead to overly broad permissions and potential security risks.",
"RelatedUrl": "https://kubernetes.io/docs/admin/service-accounts-admin/",
Copy link
Member

Choose a reason for hiding this comment

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

Broken link.

"ResourceType": "KubernetesControllerManager",
"Description": "This check ensures that the Kubernetes Controller Manager is configured with the --service-account-private-key-file argument set to the private key file for service accounts.",
"Risk": "Not setting a private key file for service accounts can hinder the ability to securely rotate service account tokens.",
"RelatedUrl": "https://kubernetes.io/docs/admin/kube-controller-manager/",
Copy link
Member

Choose a reason for hiding this comment

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

Broken link.

@jfagoagas jfagoagas self-requested a review February 22, 2024 15:38
kubelete_server_cert = True
for command in container.command:
if command.startswith("--feature-gates"):
if "RotateKubeletServerCertificate=true" in (
Copy link
Member

Choose a reason for hiding this comment

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

Ar you sure of this logic? Wouldn't it be the other way around?

Copy link
Member

@jfagoagas jfagoagas left a comment

Choose a reason for hiding this comment

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

Please check the above comment and we'll merge. Thanks!

@jfagoagas jfagoagas merged commit 8b1e537 into prowler-4.0-dev Feb 22, 2024
3 of 6 checks passed
@jfagoagas jfagoagas deleted the controllermanager-checks branch February 22, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/kubernetes Issues/PRs related with the Kubernetes provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants