All technological notes.
Authorization
authentication within the API serverBy default:
The Kubernetes API server may authorize a request using one of several authorization modes:
AlwaysAllow
AlwaysDeny
ABAC (attribute-based access control)
RBAC (role-based access control)
rbac.authorization.k8s.io API group to drive authorization decisions, allowing you to dynamically configure permission policies through the Kubernetes API.Node
kubelets based on the pods they are scheduled to run.Webhook
remote HTTP service responds to the query.Node authorizerkubelet access to api serversystem:nodesystem:nodesAttribute-based access control(ABAC){"kind": "Policy", "spec": {"user": "dev-user", "namespace": "*", "resource":"pods","apiGroup":"*"}}Role-based access control(RBAC)Webhook authorization(Webhook)Open Policy Agent, a 3-rd party tools helps with admission control and authorization.ExecStart=/usr/local/bin/kube-apiserver \\
--advertise-address=${INTERNAL_IP} \\
--allow-privileged=true \\
--apiserver-count=3 \\
--authorization-mode=AlwaysAllow \\ # default mode; can be multiple modes with order: --authorization-mode=Node,RBAC,Webhook
--bind-address=0.0.0.0 \\
--enable-swagger-ui=true \\
--etcd-cafile=/var/lib/kubernetes/ca.pem \\
--etcd-certfile=/var/lib/kubernetes/apiserver-etcd-client.crt \\
--etcd-keyfile=/var/lib/kubernetes/apiserver-etcd-client.key \\
--etcd-servers=https://127.0.0.1:2379 \\
--event-ttl=1h \\
--kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \\
--kubelet-client-certificate=/var/lib/kubernetes/apiserver-etcd-client.crt \\
--kubelet-client-key=/var/lib/kubernetes/apiserver-etcd-client.key \\
--service-node-port-range=30000-32767 \\
--client-ca-file=/var/lib/kubernetes/ca.pem \\
--tls-cert-file=/var/lib/kubernetes/apiserver.crt \\
--tls-private-key-file=/var/lib/kubernetes/apiserver.key \\
--v=2
--authorization-mode=Node,RBAC,Webhook,
Role-based access control(RBAC)role is created by defining a role oject.each role has 3 sections:
# developer-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: developer
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["list", "get", "create", "update", "dalete"]
resourceNames: ["blue", "orange"] # optional; can specific a typical resource with the name
- apiGroups: [""]
resource: ["ConfigMap"]
verb: ["create"]
kubectl create -f developer-role.yaml
Link the created role with a user
RoleBinding ObjectExample
# devuser-developer-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: devuser-developer-binding
namespace: default
# user details
subjects:
- kind: User
name: dev-user
apiGroup: rbac.authorization.k8s.io
# role details
roleRef:
kind: Role #this must be Role or ClusterRole
name: developer # this must match the name of the Role or ClusterRole you wish to bind to
apiGroup: rbac.authorization.k8s.io
kubectl create -f devuser-developer-binding.yaml
kubectl get roles
kubectl get rolebindings
kubectl describe role developer
kubectl describe rolebindings devuser-developer-binding
# check whether the current user has the access to a specific resources.
kubectl auth can-i create deployment
# test a specific user's access
kubectl auth can-i create deployment --as dev-user
kubectl auth can-i create deployment --as dev-user -n test
# get the api server authorization mode
cat kube-apiserver.yaml | grep authorization
# --authorization-mode=Node,RBAC
# get the authorization mode by process
ps -aux | grep kube-apiserver
# list role
kubectl get role
# get a role
kubectl get role kube-proxy -n kube-system
# NAME CREATED AT
# kube-proxy 2025-11-28T02:05:01Z
# get detail
kubectl describe role kube-proxy -n kube-system
# Name: kube-proxy
# Labels: <none>
# Annotations: <none>
# PolicyRule:
# Resources Non-Resource URLs Resource Names Verbs
# --------- ----------------- -------------- -----
# configmaps [] [kube-proxy] [get]
# get the related rolebinding
kubectl get rolebinding -n kube-system| grep kube-proxy
# NAMESPACE NAME ROLE AGE
# proxy kube-proxy Role/kube-proxy 27m
# get the related group
kubectl describe rolebinding kube-proxy -n kube-system
# stem
# Name: kube-proxy
# Labels: <none>
# Annotations: <none>
# Role:
# Kind: Role
# Name: kube-proxy
# Subjects:
# Kind Name Namespace
# ---- ---- ---------
# Group system:bootstrappers:kubeadm:default-node-token
# check a user's access
kubectl auth can-i list pod --as dev-user
kubectl list pod --as dev-user
# create a role in default ns for dev-user to list pod
kubectl create role developer --verb=list --verb=create --verb=delete --resource=pod --dry-run=client -o yaml > role.yaml
cat role.yaml
# apiVersion: rbac.authorization.k8s.io/v1
# kind: Role
# metadata:
# name: developer
# rules:
# - apiGroups:
# - ""
# resources:
# - pods
# verbs:
# - list
# - create
# - delete
# create role
kubectl apply -f role.yaml
# role.rbac.authorization.k8s.io/developer created
# create role binding
kubectl create rolebinding dev-user-binding --role=developer --user=dev-user --dry-run=client -o yaml > rbd.yaml
cat rbd.yaml
# apiVersion: rbac.authorization.k8s.io/v1
# kind: RoleBinding
# metadata:
# name: dev-user-binding
# roleRef:
# apiGroup: rbac.authorization.k8s.io
# kind: Role
# name: developer
# subjects:
# - apiGroup: rbac.authorization.k8s.io
# kind: User
# name: dev-user
# create rolebinding
kubectl apply -f rbd.yaml
# rolebinding.rbac.authorization.k8s.io/dev-user-binding created
kubectl edit role developer -n blue
# confirm
kubectl auth can-i list pod --as dev-user