Once the account gained accessed to the cluster, the next thing to look at is what actions they can perform. This can be defined by the following authorization mechanisms
When you send requests to Kubernetes, you are first authenticated, and then Kubernetes determines if you are authorized to complete the request. Kubernetes supports several Authorization modules.
Node authorization controls API access for kubelets on worker nodes. This is normally used for access within the cluster
All API requests are handled by the Node Authorizer. It is responsible for making authorization decisions regarding kubelet (node) access to the Kubernetes API server.
Registration Process:
Authorization Policies:
ABAC is used for external access to the API. It uses a policy language to specify what actions are allowed based on attributes. ABAC is where you associate a user or a group of users with a set of permissions.
Every time you need to add or make a change, you need to manually edit the policy file and restart the kube-apiserver. This makes ABAC more difficult to manage.
Below is a sample ABAC policy file.
# Sample ABAC Policy File
# Define rules for access control
# Each rule specifies conditions for allowing or denying an action
# Allow all users to list pods in the 'default' namespace
{
"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "*",
"namespace": "default",
"resource": "pods",
"apiGroup": "",
"readonly": true
}
}
# Allow 'admin' user to perform any action across all namespaces
{
"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "admin",
"namespace": "*",
"resource": "*",
"apiGroup": "*",
"readonly": false
}
}
# Deny 'viewer' user the ability to delete pods in any namespace
{
"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "viewer",
"namespace": "*",
"resource": "pods",
"apiGroup": "",
"readonly": false,
"verbs": ["delete"]
}
}
# Allow 'editor' user to create and update deployments in the 'production' namespace
{
"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "editor",
"namespace": "production",
"resource": "deployments",
"apiGroup": "apps",
"readonly": false,
"verbs": ["create", "update"]
}
}
RBAC allows administrators to define roles with specific permissions and bind them to users or service accounts.
Role-based access controls provide a more standard approach to managing access within the Kubernetes cluster.
Apart from the available built-in authorization mechanism, we can also Webhook authorization. This allows the use of external admission controllers to make authorization decisions.
Open Policy Agent is a third-party tool that helps enforce best practices that are meant to be standards in Kubernetes environments.
To learn more, check out openpolicyagent.org.
This allows all request without performing any authorization checks.
This denies all request.
The modes are set on the kube-apiserver.
As an example, if the modes are specified in this order:
--authorization-mode=Node,RBAC,Webhook
Then any API requests will go through Node authorizer first, then RBAC, then Webhook.