This checklist aims to provide basic guidelines on securing applications running in Kubernetes from a developer's perspective. This list is not meant to be exhaustive and is intended to evolve over time.
On how to read and use this document:
developer is a Kubernetes cluster user who
interacts with namespaced scope objects.The following checklist provides base security hardening recommendations that would apply to most applications deploying to Kubernetes.
default ServiceAccount. Instead, create ServiceAccounts for
each workload or microservice.automountServiceAccountToken should be set to false unless the pod
specifically requires access to the Kubernetes API to operate.securityContext recommendationsrunAsNonRoot: true.runAsUser and runAsGroup), and configure appropriate
permissions on files or directories inside the container image.fsGroup to access persistent volumes.securityContext recommendationsallowPrivilegeEscalation: false.readOnlyRootFilesystem: true.privileged: false).system:unauthenticated group and remove them where
possible, as this gives access to anyone who can contact the API server at a network level.The create, update and delete verbs should be permitted judiciously. The patch verb if allowed on a Namespace can allow users to update labels on the namespace or deployments which can increase the attack surface.
For sensitive workloads, consider providing a recommended ValidatingAdmissionPolicy that further restricts the permitted write actions.
Make sure that your cluster provides and enforces NetworkPolicy. If you are writing an application that users will deploy to different clusters, consider whether you can assume that NetworkPolicy is available and enforced.
This section of this guide covers some advanced security hardening points which might be valuable based on different Kubernetes environment setup.
Configure Security Context for the pod-container.
Some containers may require a different isolation level from what is provided by
the default runtime of the cluster. runtimeClassName can be used in a podspec
to define a different runtime class.
For sensitive workloads consider using kernel emulation tools like gVisor, or virtualized isolation using a mechanism such as kata-containers.
In high trust environments, consider using confidential virtual machines to improve cluster security even further.
Items on this page refer to third party products or projects that provide functionality required by Kubernetes. The Kubernetes project authors aren't responsible for those third-party products or projects. See the CNCF website guidelines for more details.
You should read the content guide before proposing a change that adds an extra third-party link.