https://www.techtarget.com/searchitoperations/tutorial/How-to-secure-Kubernetes-clusters-in-7-steps
With the increase in container and container orchestrator adoption from enterprises to medium- and small-scale businesses, the requirement to protect any critical or sensitive infrastructure that runs container workloads has also increased.
As Kubernetes is the most popular container and container orchestration tool, let's discuss security best practices organizations should adopt to secure their Kubernetes clusters.
The most basic and neglected security best practice is to keep Kubernetes environments up to date. Take advantage of new updates and version releases of security features and bug fixes. In addition, use the latest stable version in the test environment before deploying to the production cluster.
Kubernetes APIs serve as the primary access point for a Kubernetes cluster. Admins or service accounts can access APIs through the command-line utility kubectl, REST API calls or other client SDKs.
The Kubernetes API server, also known as kube-apiserver, hosts the APIs and forms the core of a Kubernetes cluster. The server grants access and ensures a cluster is up and running.
As a best practice, all API calls in the cluster must use Transport Layer Security, which is encrypted. Adopt an API authentication mechanism for the API servers as per the access requirements.
Common authentication methods include simple certificates or a bearer token. Large-scale, enterprise-level clusters should integrate with third-party OpenID Connect providers or Lightweight Directory Access Protocol servers to segregate users into specific groups and control access. Refer to the official Kubernetes documentation for an overview on how to authenticate users and for authentication strategies.
Role-based access control (RBAC) is an access control mechanism that enables users and applications to perform specific actions based on the least-privilege model and enforce required permissions only. This might seem time-consuming -- it does require additional work to set up -- but it's impossible to secure large-scale Kubernetes clusters that run production workloads without implementing RBAC policies.
The following are some Kubernetes RBAC best practices administrators should follow:
The kubelet is an agent that runs on each node of the cluster. It interacts with users through a set of APIs that control the pods running on the nodes and performs specific operations. Unauthorized access to the kubelet gives attackers access to the APIs and can compromise node or cluster security.
Take the following steps to reduce this attack surface and prevent unauthorized access to the APIs through the kubelet:
To harden the node security that the pods run on, start with the following:
Configuration standards and benchmarks. Configure the host correctly as per the security recommendations. Validate clusters against Center for Internet Security benchmarks tied to specific Kubernetes releases.
Admin access minimization. Reduce the attack surface area by reducing the administrative access on Kubernetes nodes.
Node isolation and restrictions. Run specific pods on certain nodes or group of nodes. This ensures the pods run on nodes with specific isolation and security configurations.
To control which nodes a pod can access, add labels to node objects to enable pods to target specific nodes:
kubectl label nodes <node name> <label key>=<label value>
Once the node label is applied, add a nodeSelector to the pod deployments so the pod deploys to the selected node, like in the following YAML file:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: staging
spec:
containers:
- name: nginx-staging
image: nginx
Namespaces isolate sensitive workloads from nonsensitive ones. Even though managing multiple namespaces can be complex, it makes it easier to implement security controls like network policies on sensitive workloads to control the traffic flow to and from pods.
Enable audit logs for Kubernetes clusters, and monitor them for malicious activity and suspicious API calls. Kubernetes can keep granular records of actions performed in the cluster. Audit logs detect potential security issues in almost real time. For example, an attacker trying to brute force a password might generate authentication and authorization related logs. If they are repetitive, it could be a security issue.
Audit logs are disabled by default; to enable them, use the Kubernetes audit policy, which enables admins to define one of the four audit levels:
Follow the steps below to enable audit logs on Kubernetes clusters:
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
resources:
- group: ""
resources: ["pods/log", "pods/status"]
- level: RequestResponse
resources:
- group: ""
resources: ["pods"]
08 Apr 2022