Skip to content
LF Cert Trainer

Lesson 80 · Section 7: Security

Lesson 80: Authorization: what an authenticated user may do

How the API server decides whether a request is allowed: the request attributes it looks at, the authorization modes (Node, RBAC, ABAC, Webhook, AlwaysAllow, AlwaysDeny), how the modes are chained, and how to check and debug access with kubectl auth can-i. · 18 min read · 5 min video

1/11Authorization
0:00 / 4:32

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

What authorization is

The Authentication lesson ended with the API server knowing who sent a request: a user name, and the groups that user belongs to. That is all authentication does. It gives no permissions at all. A perfectly valid certificate for the user jane lets Jane do nothing until something says she may.

Authorization is that something. For every request, the API server asks one question:

May this identity perform this action on this resource?

The answer is yes or no. There is no "partly". If it is no, the API server answers 403 Forbidden and the request goes no further.

Where authorization sits in a requestrequestjaneallowedwritekubectldelete pod webAuthenticationwho are you? else 401Authorizationmay you? else 403Admissionchange or rejectetcdchange is stored
Where authorization sits in a request. Every request passes the same three gates in the same order. Authorization is the second: it never asks who you are, only whether that identity may do this one action.

Parts:

  • kubectl (delete pod web)
  • Authentication (who are you? else 401)
  • Authorization (may you? else 403)
  • Admission (change or reject)
  • etcd (change is stored)

Connections:

  • kubectl to Authentication: request
  • Authentication to Authorization: jane
  • Authorization to Admission: allowed
  • Admission to etcd: write

Why does a cluster need this? Because very different identities use the same API:

  • Administrators may do everything, in every namespace.
  • Developers should deploy to their own namespace, and perhaps only read the others.
  • Applications (service accounts) usually need to read one or two kinds of object, nothing more.
  • Cluster components such as the kubelet, the scheduler and the controller manager each need a specific set of permissions to do their job.

Without authorization, every one of them could delete every Pod, read every Secret and change every node. With it, each identity gets the smallest set of permissions it needs. This is called least privilege, and it limits the damage of a mistake or of a stolen credential.

How it works

The request, reduced to attributes

An authorizer does not read the YAML you send. It gets a short description of the request, built from the URL and the HTTP method:

AttributeExampleWhere it comes from
UserjaneAuthentication
Groupsdevelopers, system:authenticatedAuthentication
Verbget, list, watch, create, update, patch, delete, deletecollectionHTTP method and URL
API group"" (core), apps, batchURL
Resourcepods, deployments, secretsURL
Subresourcelog, exec, status, scaleURL
NamespacedevURL, empty for cluster-scoped resources
NamewebURL, empty for list and create

A few requests are not about a resource at all, for example GET /healthz or GET /version. For these the authorizer sees a non-resource URL: the path and the HTTP method.

So kubectl delete pod web -n dev as Jane becomes: user jane, verb delete, API group "", resource pods, namespace dev, name web. Every permission rule in Kubernetes, in every mode, is a statement about these same attributes. This is why the API Groups lesson matters here: a rule for deployments must name the group apps, or it matches nothing.

The authorization modes

The API server has six built-in authorization modes. You choose them with the --authorization-mode flag.

ModeWho decidesWhere the rules liveTypical use
NodeA special-purpose authorizer for kubeletsBuilt in; follows which Pods are bound to which nodeEvery cluster
RBACRole-based access controlRole, ClusterRole, RoleBinding and ClusterRoleBinding objects in the APIEvery cluster
ABACAttribute-based access controlA JSON policy file on the control plane nodeLegacy clusters
WebhookAn external HTTP serviceIn that serviceManaged clouds, central policy engines
AlwaysAllowNobody: every request is allowedNowhereThrowaway test clusters only
AlwaysDenyNobody: every request is refusedNowhereTesting

Node authorizes requests made by kubelets. It gets its own section below.

RBAC is the mode you will use for people and applications. You describe a set of permissions once as a Role ("may get, list and watch Pods") and then give it to users, groups or service accounts with a RoleBinding. Rules are ordinary API objects, so you change them with kubectl and they take effect at once. The next two lessons, Role Based Access Controls and Cluster Roles, cover it in depth.

ABAC was the earlier approach. Each line of a policy file gives one user or group access to something:

{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "jane", "namespace": "dev", "resource": "pods", "readonly": true}}

The file is passed with --authorization-policy-file. Every change means editing a file on each control plane node and restarting the API server, and there is no way to group permissions into reusable roles. That is why RBAC replaced it. You need to recognise ABAC, not use it.

Webhook hands the decision to a service you run. The API server sends it a SubjectAccessReview object containing the request attributes, and the service answers allowed or not. Managed Kubernetes services use this to connect cluster access to their cloud's identity system, and policy engines can use it for rules RBAC cannot express.

AlwaysAllow switches authorization off, and AlwaysDeny blocks everyone except the built-in superuser group. AlwaysAllow is also what the kube-apiserver binary uses when you configure nothing, which is one more reason to check the flag on any cluster you inherit.

Several modes: the chain

You can list more than one mode, separated by commas. The API server then asks the authorizers in the order you wrote them:

--authorization-mode=Node,RBAC

Each authorizer gives one of three answers:

  • Allow. The request is authorized. No later authorizer is asked.
  • Deny. The request is refused at once. No later authorizer is asked.
  • No opinion. "I have no rule about this." The next authorizer is asked.

If every authorizer has no opinion, the request is refused. This is the deny-by-default rule in practice.

The authorizer chain: Node, then RBACfirstpass onallowallowno opinionRequestjane: delete podsNode authorizeronly for kubeletsRBACRoles and bindingsAllowedon to admission403 Forbiddennobody said yes
The authorizer chain: Node, then RBAC. Each authorizer answers allow, deny or no opinion. The first allow or deny ends the check. If every authorizer has no opinion, the request is refused with 403 Forbidden.

Parts:

  • Request (jane: delete pods)
  • Node authorizer (only for kubelets)
  • RBAC (Roles and bindings)
  • Allowed (on to admission)
  • 403 Forbidden (nobody said yes)

Connections:

  • Request to Node authorizer: first
  • Node authorizer to RBAC: pass on
  • Node authorizer to Allowed: allow
  • RBAC to Allowed: allow
  • RBAC to 403 Forbidden: no opinion

Follow Jane's delete pods through Node,RBAC. The Node authorizer only knows about kubelets; Jane is not one, so it has no opinion. RBAC then looks for a binding that gives Jane a role with delete on pods in dev. If it finds one, the request is allowed. If not, RBAC has no opinion either, the chain is exhausted, and Jane gets a 403.

Two consequences are worth remembering:

  • RBAC cannot deny. RBAC rules only ever add permissions. There is no "deny" rule, so you cannot write "everyone except Jane". To take a permission away you remove the binding that grants it. Of the built-in modes only a webhook (and AlwaysDeny) can return an explicit deny.
  • Order matters only when an authorizer can allow or deny. --authorization-mode=AlwaysAllow,RBAC behaves exactly like AlwaysAllow: the first authorizer allows everything, and RBAC is never asked.

The Node authorizer

A kubelet is an API client like any other. It needs to read the Pods assigned to its node, and the Secrets, ConfigMaps and volume claims those Pods use, and it needs to write its own Node status and its Pods' status.

Plain RBAC is a poor fit for this. A Role can say "may read Secrets", but not "may read only the Secrets used by Pods that are currently bound to this node". A rule that broad would let one compromised node read every Secret in the cluster.

What the Node authorizer gives a kubeletasksallowallowrefusedkubelet node01system:node:node01Node authorizerchecks Pod bindingsPods on node01and their SecretsNode node01status, lease, eventsOther Secretsnot used on node01
What the Node authorizer gives a kubelet. A kubelet authenticates as system:node:<name> in the group system:nodes. The Node authorizer lets it read only what the Pods bound to its own node need.

Parts:

  • kubelet node01 (system:node:node01)
  • Node authorizer (checks Pod bindings)
  • Pods on node01 (and their Secrets)
  • Node node01 (status, lease, events)
  • Other Secrets (not used on node01)

Connections:

  • kubelet node01 to Node authorizer: asks
  • Node authorizer to Pods on node01: allow
  • Node authorizer to Node node01: allow
  • Node authorizer to Other Secrets: refused

The Node authorizer closes that gap. It recognises a kubelet by its identity: the user name system:node:<nodeName> in the group system:nodes. This is exactly what the kubelet's client certificate says (you saw those certificates in the TLS lessons). For such a user it follows the object graph: this node, the Pods bound to it, and the objects those Pods reference. Anything on that graph is allowed. Anything else is not.

It works together with the NodeRestriction admission plugin, which limits what a kubelet may write: only its own Node object and the Pods bound to it. The authorizer limits reads, the admission plugin limits writes. On a kubeadm cluster both are on by default.

Where the modes are configured

On a kubeadm cluster the API server runs as a static Pod, so the flag is in its manifest:

# /etc/kubernetes/manifests/kube-apiserver.yaml
spec:
  containers:
    - command:
        - kube-apiserver
        - --authorization-mode=Node,RBAC
        - --enable-admission-plugins=NodeRestriction

When you save a change to this file, the kubelet restarts the API server with the new flags. For a minute or so kubectl cannot connect. If the API server does not come back, the flag value is wrong: restore your backup of the file.

On a cluster built by hand, the same flag is in the systemd unit file of the kube-apiserver service.

Under the hood · The newer way: an authorization configuration file

Since Kubernetes 1.32 the chain can also be described in a file, passed with --authorization-config:

apiVersion: apiserver.config.k8s.io/v1
kind: AuthorizationConfiguration
authorizers:
  - type: Node
    name: node
  - type: RBAC
    name: rbac
  - type: Webhook
    name: policy-service
    webhook:
      timeout: 3s
      subjectAccessReviewVersion: v1
      matchConditionSubjectAccessReviewVersion: v1
      failurePolicy: NoOpinion
      authorizedTTL: 5m
      unauthorizedTTL: 30s
      connectionInfo:
        type: InClusterConfig

The file can do things the flag cannot: several webhooks, a failure policy for each one, and conditions that decide which requests a webhook sees at all. The API server also reloads the file when it changes. You must choose one approach: setting both --authorization-config and --authorization-mode makes the API server exit at startup. kubeadm still writes the --authorization-mode flag, and that is what you will meet in the exam.

Under the hood · system:masters skips authorization entirely

The group system:masters is hard-coded in the API server as a superuser group. A request from a member is allowed before any authorizer is asked, so no mode, no missing RBAC rule and no webhook can refuse it. It cannot be revoked either, except by letting the certificate expire.

For that reason kubeadm no longer puts everyday administrators in it. Since v1.29, /etc/kubernetes/admin.conf holds a certificate for the group kubeadm:cluster-admins, which is bound to the cluster-admin ClusterRole by ordinary RBAC and can be unbound. The break-glass credential in system:masters is kept separately in /etc/kubernetes/super-admin.conf. It still works if RBAC is broken or removed from the chain.

Under the hood · The kubelet has its own authorization

The kubelet serves an API too, on port 10250. kubectl logs and kubectl exec end there. It has its own setting in the kubelet configuration file:

# /var/lib/kubelet/config.yaml
authorization:
  mode: Webhook

With Webhook, the kubelet asks the API server (with a SubjectAccessReview) whether the caller may reach nodes/proxy, nodes/log and similar subresources. The other value, AlwaysAllow, lets any authenticated caller run commands in every container on the node. kubeadm sets Webhook.

Using it

Example · Find the authorization modes of a cluster

A common exam question is simply "which authorization modes are configured?". On the control plane node:

grep authorization-mode /etc/kubernetes/manifests/kube-apiserver.yaml
    - --authorization-mode=Node,RBAC

Without shell access to the node, read the flag from the running Pod:

kubectl -n kube-system get pod -l component=kube-apiserver \
  -o jsonpath='{.items[0].spec.containers[0].command}' | tr ',' '\n' | grep authorization

If neither --authorization-mode nor --authorization-config appears, the API server is running with its default, AlwaysAllow.

Example · Check your own access, and someone else's

kubectl auth can-i asks the API server to run the authorizer chain for a request without performing it:

kubectl auth can-i create deployments                 # in the current namespace
kubectl auth can-i delete nodes                       # a cluster-scoped resource
kubectl auth can-i get pods --subresource=log -n dev  # may I read logs?
kubectl auth can-i '*' '*' --all-namespaces           # am I a cluster admin?

Each prints yes or no. As an administrator, add --as to ask for another identity:

kubectl auth can-i list pods -n dev --as jane
kubectl auth can-i list pods -n dev --as jane --as-group developers
kubectl auth can-i get secrets -n dev --as system:serviceaccount:dev:builder

The user name of a service account is always system:serviceaccount:<namespace>:<name>. To see everything an identity may do in a namespace:

kubectl auth can-i --list -n dev --as jane
Resources                                       Non-Resource URLs   Resource Names   Verbs
selfsubjectaccessreviews.authorization.k8s.io   []                  []               [create]
selfsubjectrulesreviews.authorization.k8s.io    []                  []               [create]
pods                                            []                  []               [get list watch]
                                                [/healthz]          []               [get]
                                                [/version]          []               [get]

Example · Read a Forbidden error and turn it into a fix

Jane tries to delete a Pod:

kubectl delete pod web -n dev --as jane
Error from server (Forbidden): pods "web" is forbidden: User "jane" cannot delete resource "pods"
in API group "" in the namespace "dev"

Read the message as a list of attributes: user jane, verb delete, resource pods, API group "" (core), namespace dev. Those are exactly the values the missing rule needs. With RBAC, the fix is a Role and a RoleBinding carrying the same words:

kubectl create role pod-deleter -n dev --verb=delete --resource=pods
kubectl create rolebinding jane-pod-deleter -n dev --role=pod-deleter --user=jane
kubectl auth can-i delete pods -n dev --as jane        # yes

The next lesson explains these two objects properly. The point here is the method: the 403 message tells you what to grant.

Example · See the Node authorizer at work

Use a kubelet's own credentials to see what it may and may not do. On a kubeadm node:

export KUBECONFIG=/etc/kubernetes/kubelet.conf
kubectl auth whoami
ATTRIBUTE   VALUE
Username    system:node:node01
Groups      [system:nodes system:authenticated]
kubectl get node node01                  # allowed: its own Node object
kubectl get secrets -A                   # Forbidden: it may not list Secrets
kubectl get secret db-pass -n prod       # Forbidden, unless a Pod on node01 uses it
Error from server (Forbidden): secrets "db-pass" is forbidden: User "system:node:node01" cannot get resource
"secrets" in API group "" in the namespace "prod": no relationship found between node 'node01' and this object

"No relationship found" is the Node authorizer speaking: nothing on this node uses that Secret. Run unset KUBECONFIG when you are done.

Tricks

Common mistakes

  • Confusing authentication with authorization. A valid certificate proves who you are. It grants nothing. A new user can log in and still be forbidden everything.
  • Expecting a deny rule in RBAC. RBAC is purely additive. To restrict someone, remove the binding that gives them access; you cannot add a rule that takes it away.
  • Removing Node or RBAC from the chain. Without Node, kubelets depend on wider RBAC permissions or lose access. Without RBAC, almost every user, controller and service account is forbidden everything. Change the list only when a task explicitly asks for it.
  • Setting AlwaysAllow "to make it work". It turns every authenticated identity, including every service account in every Pod, into a cluster admin.
  • Forgetting the API group or the namespace. can-i list deployments checks the current namespace and the apps group. A rule in another namespace, or one written for the core group, does not match.
  • Assuming get pods covers logs and exec. Those are the separate subresources pods/log and pods/exec.
  • Using --as without the right to impersonate. Impersonation is itself a permission (the verb impersonate). Cluster admins have it; an ordinary user who tries --as gets a 403 of their own.

Recap

  • Authorization is the second gate in the API server: after authentication (401), before admission. It fails with 403 Forbidden.
  • The decision uses request attributes only: user, groups, verb, API group, resource, subresource, namespace, name.
  • Six modes: Node, RBAC, ABAC, Webhook, AlwaysAllow, AlwaysDeny, set with --authorization-mode in /etc/kubernetes/manifests/kube-apiserver.yaml. kubeadm uses Node,RBAC.
  • Modes are asked in order. Each answers allow, deny or no opinion; the first allow or deny wins, and no opinion from everyone means the request is refused.
  • The Node authorizer limits each kubelet (system:node:<name>, group system:nodes) to the objects its own Pods need. RBAC handles people and service accounts and can only add permissions.
  • kubectl auth can-i <verb> <resource> [--as <user>] [-n <ns>] tests a permission; --list shows them all, and the 403 message lists exactly what is missing.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.