Kubernetes Workload Permissions Guide
Overview
This guide discusses how Kubernetes' RBAC (Role-Based Access Control) interacts with cloud-specific IAM roles, focusing on the Zeet platform. Understanding these interactions is vital for ensuring security, optimizing access, and enhancing deployment processes.
1. Kubernetes RBAC System
Kubernetes uses RBAC to manage permissions for its resources. This system offers detailed control, setting specific permissions for different roles within a cluster.
1.1. Default RBAC Permissions
By default, Kubernetes has built-in roles with set permissions. For example, the cluster-admin
role has full administrative access. When developers access the cluster using kubectl
or lens
, they're using the cluster-admin
role. Zeet also uses this role to manage and orchestrate container deployments.
1.2. Container Permissions in Kubernetes
Typically, containers in Kubernetes don't have permissions. This means they can't access the Kubernetes API or change resources directly.
1.3. Customizing RBAC Permissions
To adjust RBAC permissions:
- Define Roles: Start by creating a
Role
(for specific namespace access) orClusterRole
(for cluster-wide access). These roles set permissions for different resources. - Bind Roles: After creating roles, link them to users or service accounts using
RoleBinding
(forRole
) orClusterRoleBinding
(forClusterRole
). - Limit Access: Only grant required permissions. Overly broad permissions can introduce security risks.
2. Container Networking Permissions
Kubernetes uses network policies to control how pods communicate within the cluster and with other network points.
2.1. Default Networking Behavior
Unless a network policy is applied, all pods can freely communicate within the cluster, which helps in smooth internal operations.
2.2. Customizing Network Permissions
To set a pod's networking permissions:
- Create Network Policies: Make a
NetworkPolicy
that lists the pod selectors and their allowed traffic rules. - Apply Policy: Implement the policy in the needed namespaces or throughout the cluster.
- Monitor & Adjust: Regularly check that the policies work as expected and make changes if needed.
3. Node Permissions & Cloud IAM
When Kubernetes nodes need to access cloud resources, cloud IAM roles dictate this access.
3.1. Default Node IAM Permissions
By default, nodes can read compute, network, and storage configurations. They don't have permissions to modify these configurations.
3.2. Interaction with Container Permissions
Containers typically inherit the IAM permissions of nodes. Adjusting this can enhance security.
3.3. Limiting Container Access to Node Permissions
To restrict containers from inheriting node IAM permissions:
- Limit at Metadata Service Level: For example, use AWS IMDSv2 Configuration.
- Control at Networking Level: Define a
NetworkPolicy
that restricts containers from accessing the metadata endpoint.
4. Assigning Custom IAM Permissions to Containers
When containers need specific cloud API access, grant custom IAM permissions through either direct methods or environment variable injection.
Direct Method: This method provides containers with auto-refreshed, short-lived tokens without needing explicit credentials.
- For AWS: See AWS EKS IAM Role with Zeet.
- For GCP: Check out the GCP GKE Workload Identity guide.
- For Azure: Refer to Azure Managed Identity.
Environment Variables: Obtain cloud credentials and set them as environment variables in your Zeet projects. Ensure you rotate these credentials regularly for security.