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(apiserver): new 9 Kubernetes ApiServer checks #3288

Merged
merged 13 commits into from Feb 21, 2024

Conversation

sergargar
Copy link
Member

Description

Add new 9 Kubernetes ApiServer checks:

[apiserver_always_pull_images_plugin] Ensure that the admission control plugin AlwaysPullImages is set - apiserver [medium]
[apiserver_anonymous_requests] Ensure that the --anonymous-auth argument is set to false - apiserver [high]
[apiserver_audit_log_maxage_set] Ensure that the --audit-log-maxage argument is set to 30 or as appropriate - apiserver [medium]
[apiserver_audit_log_maxbackup_set] Ensure that the --audit-log-maxbackup argument is set to 10 or as appropriate - apiserver [medium]
[apiserver_audit_log_maxsize_set] Ensure that the --audit-log-maxsize argument is set to 100 or as appropriate - apiserver [medium]
[apiserver_audit_log_path_set] Ensure that the --audit-log-path argument is set - apiserver [high]
[apiserver_auth_mode_include_node] Ensure that the --authorization-mode argument includes Node - apiserver [medium]
[apiserver_auth_mode_include_rbac] Ensure that the --authorization-mode argument includes RBAC - apiserver [high]
[apiserver_auth_mode_not_always_allow] Ensure that the --authorization-mode argument is not set to AlwaysAllow - apiserver [high]

License

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

@sergargar sergargar requested a review from a team as a code owner January 16, 2024 15:34
@sergargar sergargar 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.

Impressive 👏

Please check my comments, there are some broken links and some parts of the code that can be improved not to check everything if something is not set.

"ResourceType": "KubernetesAPIServer",
"Description": "This check verifies that the AlwaysPullImages admission control plugin is enabled in the Kubernetes API server. This plugin ensures that every new pod always pulls the required images, enforcing image access control and preventing the use of possibly outdated or altered images.",
"Risk": "Without AlwaysPullImages, once an image is pulled to a node, any pod can use it without any authorization check, potentially leading to security risks.",
"RelatedUrl": "https://kubernetes.io/docs/admin/admission-controllers/#alwayspullimages",
Copy link
Member

Choose a reason for hiding this comment

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

Check link.

},
"Recommendation": {
"Text": "Configure the API server to use the AlwaysPullImages admission control plugin to ensure image security and integrity.",
"Url": "https://kubernetes.io/docs/admin/kube-apiserver/"
Copy link
Member

Choose a reason for hiding this comment

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

f"AlwaysPullImages admission control plugin is set in pod {pod.name}."
)
plugin_set = False
for container in pod.containers.values():
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to check if all the containers in the pod has the flag enabled.

},
"Recommendation": {
"Text": "Configure the API server audit log retention period to retain logs for at least 30 days or as per your organization's requirements.",
"Url": "https://kubernetes.io/docs/admin/kube-apiserver/"
Copy link
Member

Choose a reason for hiding this comment

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

Please check this link.

audit_log_maxage_set = False
for container in pod.containers.values():
# Check if "--audit-log-maxage" is set to 30 or as appropriate
for command in 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.

Maybe we need to check if all the containers in the pod has the flag enabled.

},
"Recommendation": {
"Text": "Enable audit logging in the API server by specifying a valid path for --audit-log-path to ensure comprehensive activity logging within the cluster.",
"Url": "https://kubernetes.io/docs/admin/kube-apiserver/"
Copy link
Member

Choose a reason for hiding this comment

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

Check link.

# Check if "--audit-log-maxsize" is set to 100 MB or as appropriate
for command in container.command:
if command.startswith("--audit-log-maxsize"):
if int(command.split("=")[1]) >= 100:
Copy link
Member

Choose a reason for hiding this comment

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

Check if value is more or less than that.

},
"Recommendation": {
"Text": "Configure the API server audit log file size limit to 100 MB or as per your organization's requirements.",
"Url": "https://kubernetes.io/docs/admin/kube-apiserver/"
Copy link
Member

Choose a reason for hiding this comment

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

Check this link please.

# Check if "--audit-log-maxbackup" is set to 10 or as appropriate
for command in container.command:
if command.startswith("--audit-log-maxbackup"):
if int(command.split("=")[1]) >= 10:
Copy link
Member

Choose a reason for hiding this comment

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

Here we should check if the value is different. What if we create a config variables for all the checks here, thus it will be customizable.

},
"Recommendation": {
"Text": "Configure the API server audit log backup retention to 10 or as per your organization's requirements.",
"Url": "https://kubernetes.io/docs/admin/kube-apiserver/"
Copy link
Member

Choose a reason for hiding this comment

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

Check link.

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.

@jfagoagas jfagoagas merged commit b40f32a into prowler-4.0-dev Feb 21, 2024
3 of 6 checks passed
@jfagoagas jfagoagas deleted the apiserver-checks-1 branch February 21, 2024 08:19
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.

None yet

2 participants