Access control in Kubernetes is essential to enforce security and prevent unauthorized access. It ensures that only authenticated and authorized users or entities can interact with the Kubernetes cluster's resources. Without access control, there is a higher risk of data breaches and malicious activities within the cluster. In Kubernetes, it is crucial to implement it for maintaining the confidentiality, integrity, and availability of containerized applications.
In short, you have to use a third-party authentication for your API server as it is a very important component in Kubernetes cluster and can be easily protected. You have to use and configure Role Based Access Control (RBAC) instead of using IAM roles because it gives a better granularity control for permissions given in your cluster. You also should use validating admission policy, a new Kubernetes feature which enables to control access inside the cluster between resources. Finally, you should follow best practices when configuring service accounts and managed clusters.
Our Recommendation: When securing your Kubernetes cluster, it's essential to use third-party authentication for the API Server. Instead of relying solely on Kubernetes native authentication mechanisms, consider integrating with a third-party auth provider (IdP) such as Google or GitHub. This enhances security by adding another layer of authentication before granting access to the Kubernetes API. It prevents administrators from reconfiguring the Kubernetes API to add or remove users.
Risks addressed by the recommendation:
Our Recommendation: Replace Identity and Access Management (IAM) with Kubernetes Role-Based Access Control (RBAC) for fine-grained access control.
RBAC is a method for regulating access to computer or network resources based on user roles. A RBAC Role or ClusterRole contains rules that represent a set of permissions. A role always defines permissions in a particular namespace while a ClusterRole is a namespaceless resource.
Follow best practices such as the principle of least privilege. For example, you should never use the admin role but give a set of permissions to groups that gather users who need the same rights on the resources. Define roles and role bindings that restrict permissions to only what is necessary for each user or service account. Minimize the distribution of privileged tokens by avoiding giving powerful permissions. Finally, make periodic review of the rights given and check if the permissions are adapted. However, you should not change the rights provided to system
.
Risks addressed by the recommendation:
Our Recommendation: Configure and manage service accounts diligently. Avoid using the default service account whenever possible, as it has broad permissions by default. Create specific service accounts for each application or workload, and associate them with appropriate RBAC roles and role bindings.
Risks addressed by the recommendation:
Our Recommendation: Using validating admission policies is a new Kubernetes feature that offers several benefits that enhance security and streamline management. Some of its features are the same as Kyverno which is a policy engine designed for Kubernetes. If you prefer using Kyverno, we wrote an article about best practices using this tool.
It restricts the access to resources and reduce the number of request a resource must handle, reducing the attack surface. It enables to restrict unnecessary communication between some resources. These policies make it simpler to manage configurations and govern the Kubernetes infrastructure, ensuring that resources adhere to predefined rules. It also can automate tasks like applying labels, adding annotations, and setting resource limits, streamlining the work of DevOps teams.
Risks addressed by the recommendation:
Our Recommendation: If you are using a managed Kubernetes service like Google Kubernetes Engine (GKE), Amazon EKS, or Azure Kubernetes Service (AKS), use the built-in features of the cloud provider that strenghten your security. For example, in GCP, use the library SQLConnector to use IAM service accounts to connect to databases. Alternatively, you can also deploy the sidecars Cloud-SQL Proxy in your cluster.
Risks addressed by the recommendation:
By following the best practices presented in this article, you can significantly reduce the risk of broken access control and improve the overall security of your infrastructure.
In the next article, we will address security best practices in policies, pods and nodes configurations.