Kubernetes security
Security model and best practices
-
The K8s security model is based on the CNCF guidelines for securing cloud infrastructure and applications.
-
The framework of security related best practices and tools is split along the 4 phases of the cloud application lifecycle :
phase description DevelopEnforce security best practices during application development DistributeSecure supply chain and images registries, keep dependencies up-to-date DeploySecure cluster and nodes configuration, restrict access to the K8s API RuntimeRestrict workloads access to cluster resources and node resources -
It is assumed that security measures relevant to
DevelopandDistributephases are enforced outside of K8s :- Candidate workloads are compliant to security best practices (OWASP top 10, etc).
- Container images are built on top of a secure supply chain (socket.dev, base image scanning, etc).
- Nodes are provisioned with strict security measures (VLAN / VPC, firewall, hardened SSH config, etc).
-
Past that stage, K8s offers native security mechanisms for the
DeployandRuntimephases :phase tier security feature description DeployaccessPKI Authenticate components and users to kube-apiserverDeployaccessServiceAccountAuthenticate pods to kube-apiserverDeployaccessmTLS Encrypt control plane traffic DeployaccessRBACAuthorize / deny requests to kube-apiserverDeploystorageSecretBuilt-in encryption for confidential workload data DeploystorageEncryption at rest On-disk encryption for persistent data RuntimecomputesecurityContextFine tune pods privileges and capabilities RuntimecomputeOS level security Support OS-level restrictions for pods
- Integrity : protection of cluster state
- Only cluster components and admins have to have the ability to update the cluster state.
- As a result, access to the components APIs must be restricted by authentication and authorization policies.
- Otherwise, outsiders may deploy unauthorized workloads to the cluster or tamper with existing workloads.
- Authenticity : authentication of cluster components and admins
- Components and admins have to prove their respective identities when interacting with one another.
- It means that for each interaction, components and admins identities have to be verified :
- Each component / admin must be identified (is it
etcd,kubelet, an admin, etc ...). - Each component / admin must be part of the same cluster.
- Each component / admin must be identified (is it
- Otherwise, outsiders may impersonate components or admins, which could lead to unauthorized cluster state updates.
- Confidentiality : securing control plane traffic
- All traffic between cluster components have to be encrypted, and not exposed to public internet.
- The go-to options to that effect are to use TLS for encryption and VLAN / VPC for network isolation.
- Admins communications with the control plane can also be secured through SSH tunneling.
- Otherwise, outsiders may spy on traffic and gain unauthorized access to confidential cluster data (
Secrets, etc ...)
Notes :
- Authentication, authorization and traffic encryption for workloads themselves is out of scope (
Developphase). - A service mesh can be used to encrypt all internal cluster traffic as well (
Pods,Service, etc ...)
- Security for the
Deploy/accessphase is provided by state update requests validation. - Each incoming request to
kube-apiservergoes through a sequence of security checks :
- Authentication
- The request is evaluated against
kube-apiserverconfigured authentication strategies. - If a single authentication strategy validates the request, it is considered authenticated and identified.
- Authorization
- The request is evaluated against
kube-apiserverconfigured authorization policies. - If all authorization policies validate the request, the requested state update is considered authorized.
- Admission control
-
The request is processed by
kube-apiserverconfigured admission controllers. -
At this stage, the request can be modified (set default values, etc) and rejected in some cases.
-
If none of the admission controllers reject the request, it is considered validated.
-
Once the request is validated, it is written into
etcdto update the cluster's desired state. -
Then,
kube-controller-managerandkube-schedulerpropagate the update to the cluster's current state.