Kubernetes: Using Default Service Accounts

Kubernetes
Medium
7/14/2023

Using Default Service Accounts

Default service accounts are automatically created with every new namespace, and they have broad access permissions, making them a potential security risk. These service accounts can be targeted by attackers to gain access to sensitive resources within the cluster.

To mitigate this risk, organizations should take the following steps:

  1. Disable the default service account token for namespaces where it is not needed. By default, Kubernetes allows all pods to use the default service account token, which can lead to unauthorized access to resources within the cluster. Organizations should disable the default service account token for namespaces where it is not needed.
  2. Create custom service accounts with specific permissions for each application or component. Organizations should create custom service accounts with specific permissions for each application or component running within the cluster. This helps to limit the blast radius of potential security breaches and makes it easier to manage access controls for each application or component.
  3. Use RBAC to restrict the access of custom service accounts. Role-based access control (RBAC) can be used to restrict the access of custom service accounts to only the resources they require. This helps to prevent unauthorized access to sensitive resources within the cluster.

In summary, to mitigate the risk of default service accounts, organizations should disable the default service account token for namespaces where it is not needed, create custom service accounts with specific permissions for each application or component, and use RBAC to restrict the access of custom service accounts. By following these best practices, organizations can reduce the attack surface and protect their Kubernetes infrastructure from potential security breaches.