{"id":3495,"date":"2026-12-05T06:26:54","date_gmt":"2026-12-05T06:26:54","guid":{"rendered":"https:\/\/www.rajeshkumar.xyz\/blog\/?p=3495"},"modified":"2026-12-05T06:26:57","modified_gmt":"2026-12-05T06:26:57","slug":"kubernetes-rbac-explained-users-groups-roles-bindings-and-csrs","status":"publish","type":"post","link":"https:\/\/www.rajeshkumar.xyz\/blog\/kubernetes-rbac-explained-users-groups-roles-bindings-and-csrs\/","title":{"rendered":"Kubernetes RBAC Explained: Users, Groups, Roles, Bindings and CSRs"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Kubernetes cluster may run hundreds of applications, but not every person or application should have access to every resource.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Developers may need to view Pods. DevOps engineers may need to update Deployments. Monitoring tools may need to read selected metrics-related resources. Cluster administrators need broader permissions to manage infrastructure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Giving everyone administrator access creates unnecessary security risks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes solves this problem through <strong>Role-Based Access Control (RBAC)<\/strong>. RBAC decides who can perform which actions on which Kubernetes resources.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To understand Kubernetes RBAC, you need to understand five important concepts:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Users represent authenticated human or external identities.<\/li>\n\n\n\n<li>Groups collect identities with similar access requirements.<\/li>\n\n\n\n<li>Roles and ClusterRoles define permissions.<\/li>\n\n\n\n<li>RoleBindings and ClusterRoleBindings assign those permissions.<\/li>\n\n\n\n<li>CertificateSigningRequests (CSRs) can help provision client certificates for authentication.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how these parts work together. It includes YAML examples, practical commands, a ServiceAccount example, and a certificate-based user access workflow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The examples use the stable. <code>rbac.authorization.k8s.io\/v1<\/code> API and follow the current Kubernetes v1.37 documentation. Always check your own cluster version and authentication configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What Is Kubernetes RBAC?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">RBAC stands for Role-Based Access Control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a Kubernetes authorization mechanism. It determines whether an authenticated identity can perform a requested operation on a resource.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of RBAC through three questions:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Question<\/th><th>Meaning<\/th><th>Example<\/th><\/tr><tr><td>WHO?<\/td><td>Which identity needs access?<\/td><td><code>alice<\/code>, <code>team-dev<\/code>, <code>app-reader<\/code><\/td><\/tr><tr><td>WHAT?<\/td><td>Which action is allowed?<\/td><td><code>get<\/code>, <code>list<\/code>, <code>watch<\/code>, <code>create<\/code><\/td><\/tr><tr><td>WHERE?<\/td><td>Which resource and scope?<\/td><td>Pods in <code>development<\/code>, Deployments, ConfigMaps<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a developer may need permission to list Pods in the <code>development<\/code> namespace but should not read Secrets or modify cluster-wide resources.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RBAC lets an administrator define this permission without giving the developer full cluster access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How RBAC authorization works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A typical Kubernetes API request follows this process:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>A person or application sends a request to the Kubernetes API server.<\/li>\n\n\n\n<li>Kubernetes authenticates the request and identifies its username and groups.<\/li>\n\n\n\n<li>The API server determines which resource and operation the request involves.<\/li>\n\n\n\n<li>The configured authorization mechanisms evaluate the request.<\/li>\n\n\n\n<li>RBAC checks whether applicable permissions have been granted through Roles and bindings.<\/li>\n\n\n\n<li>The request is allowed or denied according to the authorization decision.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">A successful authentication does not automatically grant permission to operate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A user may authenticate successfully and still receive a <code>403 Forbidden<\/code> response because the required permission is missing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes also supports authentication and authorization mechanisms beyond client certificates and RBAC. The actual identity may come from an OIDC provider, an authentication webhook, a client certificate, or another configured authenticator.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Official documentation: <a href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/authentication\/\">Kubernetes Authentication<\/a> and <a href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/rbac\/\">Using RBAC Authorization<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Understand Users in Kubernetes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Kubernetes human user is an authenticated identity, not a normal Kubernetes API object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This distinction is important.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes does not provide a regular API resource called <code>User<\/code> for creating human accounts. Normal user identities are managed outside Kubernetes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An organisation may use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Client certificates.<\/li>\n\n\n\n<li>OpenID Connect (OIDC).<\/li>\n\n\n\n<li>An authentication proxy.<\/li>\n\n\n\n<li>An authentication webhook.<\/li>\n\n\n\n<li>Another supported identity integration.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The authenticator supplies an identity to the API server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That identity can contain a username, UID, groups, and additional attributes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example user identities<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>User identity<\/th><th>Possible purpose<\/th><\/tr><tr><td><code>alice<\/code><\/td><td>Developer<\/td><\/tr><tr><td><code>bob<\/code><\/td><td>Cluster operator<\/td><\/tr><tr><td><code>jane@example.com<\/code><\/td><td>Enterprise identity<\/td><\/tr><tr><td><code>ci-deployer<\/code><\/td><td>External automation identity<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">These are example identity strings. They are not automatically created Kubernetes users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an external OIDC provider may authenticate <code>alice@example.com<\/code>. Kubernetes can then use that username in RBAC bindings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can you create a Kubernetes user with kubectl?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No standard command such as this exists:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl create user alice<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Instead, you configure authentication using an appropriate identity provider or client certificate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then RBAC permissions can be assigned to the identity that the authenticator supplies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Understand Groups in Kubernetes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Groups allow administrators to assign permissions to several identities together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an organisation may have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>team-dev<\/code><\/li>\n\n\n\n<li><code>team-qa<\/code><\/li>\n\n\n\n<li><code>team-ops<\/code><\/li>\n\n\n\n<li><code>platform-admins<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Rather than creating separate RoleBindings for every developer, an administrator can grant a permission to the <code>team-dev<\/code> group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a developer authenticates, the authentication system supplies their group membership.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes then evaluates the group against the subjects in RBAC bindings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example group-based access<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose Alice and Bob belong to <code>team-dev<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The administrator creates a Role that allows reading Pods. A RoleBinding grants this permission to the group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both users receive the permission when their authenticated identities include <code>team-dev<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If another developer joins that group through the organisation&#8217;s identity system, they can receive the same access without a separate individual RoleBinding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The group&#8217;s membership must come from the configured authentication system. Creating a Group subject in a RoleBinding does not create an identity group or add users to it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Built-in Kubernetes groups<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes also uses special groups.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Group<\/th><th>Meaning<\/th><\/tr><tr><td><code>system:authenticated<\/code><\/td><td>Authenticated request identities<\/td><\/tr><tr><td><code>system:unauthenticated<\/code><\/td><td>Anonymous request identities, when enabled<\/td><\/tr><tr><td><code>system:serviceaccounts<\/code><\/td><td>ServiceAccounts across the cluster<\/td><\/tr><tr><td><code>system:serviceaccounts:development<\/code><\/td><td>ServiceAccounts in the <code>development<\/code> namespace<\/td><\/tr><tr><td><code>system:masters<\/code><\/td><td>Highly privileged group with unrestricted superuser access<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid assigning normal users to <code>system:masters<\/code>. Kubernetes documentation warns that members of this group bypass RBAC checks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Understand ServiceAccounts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ServiceAccounts are different from ordinary human users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A ServiceAccount is a Kubernetes API object. It represents an identity that an application or workload can use when communicating with the Kubernetes API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a monitoring application may need to read selected resources. Instead of using an administrator&#8217;s credentials, you create a dedicated ServiceAccount and assign the required permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The username format for a ServiceAccount is:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">system:serviceaccount:<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">namespace<\/span>&gt;<\/span>:<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">serviceaccount-name<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">system<\/span><span class=\"hljs-selector-pseudo\">:serviceaccount<\/span><span class=\"hljs-selector-pseudo\">:development<\/span><span class=\"hljs-selector-pseudo\">:app-reader<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">ServiceAccounts also belong to these groups:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">system<\/span><span class=\"hljs-selector-pseudo\">:serviceaccounts<\/span>\n<span class=\"hljs-selector-tag\">system<\/span><span class=\"hljs-selector-pseudo\">:serviceaccounts<\/span><span class=\"hljs-selector-pseudo\">:development<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Create a ServiceAccount<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl create <span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">development<\/span>\n\n<span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">create<\/span> <span class=\"hljs-title\">serviceaccount<\/span> <span class=\"hljs-title\">app<\/span>-<span class=\"hljs-title\">reader<\/span> \\\n  -<span class=\"hljs-title\">n<\/span> <span class=\"hljs-title\">development<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Verify it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> serviceaccounts -n development<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Creating a ServiceAccount does not automatically give it broad permissions. Grant only the access required by the application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Understand Kubernetes RBAC Objects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes RBAC uses four main API objects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Role<\/li>\n\n\n\n<li>ClusterRole<\/li>\n\n\n\n<li>RoleBinding<\/li>\n\n\n\n<li>ClusterRoleBinding<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The first two define permissions. The other two assign permissions to users, groups, or ServiceAccounts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Role<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A Role defines permissions within one namespace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you can create a Role that allows developers to list and read Pods in <code>development<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">apiVersion: rbac.authorization.k8s.io\/v1\n<span class=\"hljs-attr\">kind<\/span>: Role\n<span class=\"hljs-attr\">metadata<\/span>:\n  name: pod-reader\n  <span class=\"hljs-attr\">namespace<\/span>: development\n<span class=\"hljs-attr\">rules<\/span>:\n  - apiGroups: &#91;<span class=\"hljs-string\">\"\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"pods\"<\/span>]\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"get\"<\/span>, <span class=\"hljs-string\">\"list\"<\/span>, <span class=\"hljs-string\">\"watch\"<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">pod-reader-role<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Verify it:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe role pod-reader \\\n  -n development<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The Role does not grant access to anyone by itself. You need a RoleBinding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ClusterRole<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A ClusterRole defines permissions at cluster scope.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be used for several purposes:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Access to cluster-scoped resources.<\/li>\n\n\n\n<li>Reusable permissions for namespaced resources.<\/li>\n\n\n\n<li>Access to namespaced resources across all namespaces when bound cluster-wide.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For example, Nodes are cluster-scoped resources. A Role cannot grant cluster-wide access to them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a ClusterRole for reading Nodes:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">apiVersion: rbac.authorization.k8s.io\/v1\n<span class=\"hljs-attr\">kind<\/span>: ClusterRole\n<span class=\"hljs-attr\">metadata<\/span>:\n  name: node-reader\n<span class=\"hljs-attr\">rules<\/span>:\n  - apiGroups: &#91;<span class=\"hljs-string\">\"\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"nodes\"<\/span>]\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"get\"<\/span>, <span class=\"hljs-string\">\"list\"<\/span>, <span class=\"hljs-string\">\"watch\"<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">node-reader<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Verify it:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe clusterrole node-reader<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">A ClusterRole is reusable. It can also be referenced by a RoleBinding when you want its permissions to apply only within one namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">RoleBinding<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding assigns a Role or ClusterRole to one or more subjects within a namespace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, bind the <code>pod-reader<\/code> Role to Alice.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">apiVersion: rbac.authorization.k8s.io\/v1\nkind: RoleBinding\nmetadata:\n  name: alice-pod-reader\n  namespace: development\nsubjects:\n  - kind: User\n    name: alice\n    apiGroup: rbac.authorization.k8s.io\nroleRef:\n  kind: Role\n  name: pod-reader\n  apiGroup: rbac.authorization.k8s.io<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">alice-rolebinding<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Now the authenticated user <code>alice<\/code> can read Pods within <code>development<\/code>, assuming no other policies or authorization conditions are changing the result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding can also reference a ClusterRole. The permissions are then limited to the namespace containing that RoleBinding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is useful when you want to reuse one permission definition in several namespaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ClusterRoleBinding<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A ClusterRoleBinding assigns a ClusterRole to subjects across the cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, bind the <code>node-reader<\/code> ClusterRole to a group:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">apiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  name: team-ops-node-reader\nsubjects:\n  - kind: Group\n    name: team-ops\n    apiGroup: rbac.authorization.k8s.io\nroleRef:\n  kind: ClusterRole\n  name: node-reader\n  apiGroup: rbac.authorization.k8s.io<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">team-ops-node-reader<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Members of <code>team-ops<\/code> can now read Nodes across the cluster, subject to the configured authorization policy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The difference between the four objects<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Object<\/th><th>Scope<\/th><th>Purpose<\/th><\/tr><tr><td>Role<\/td><td>One namespace<\/td><td>Defines namespace permissions<\/td><\/tr><tr><td>ClusterRole<\/td><td>Cluster-level object<\/td><td>Defines reusable or cluster-level permissions<\/td><\/tr><tr><td>RoleBinding<\/td><td>One namespace<\/td><td>Assigns a Role or ClusterRole within that namespace<\/td><\/tr><tr><td>ClusterRoleBinding<\/td><td>Cluster-wide<\/td><td>Assigns a ClusterRole across the cluster<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Remember this rule:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A RoleBinding controls the namespace in which permissions apply. A ClusterRoleBinding grants the referenced ClusterRole&#8217;s permissions cluster-wide.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Official reference: <a href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/rbac\/\">Kubernetes RBAC API objects<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Understand RBAC Verbs, API Groups, and Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Role rule uses three important fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>apiGroups<\/code><\/li>\n\n\n\n<li><code>resources<\/code><\/li>\n\n\n\n<li><code>verbs<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These fields determine which API operations are permitted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Kubernetes verbs<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Verb<\/th><th>Meaning<\/th><\/tr><tr><td><code>get<\/code><\/td><td>Read an individual object<\/td><\/tr><tr><td><code>list<\/code><\/td><td>Read a collection of objects<\/td><\/tr><tr><td><code>watch<\/code><\/td><td>Receive updates as objects change<\/td><\/tr><tr><td><code>create<\/code><\/td><td>Create an object<\/td><\/tr><tr><td><code>update<\/code><\/td><td>Replace an existing object<\/td><\/tr><tr><td><code>patch<\/code><\/td><td>Partially modify an object<\/td><\/tr><tr><td><code>delete<\/code><\/td><td>Delete an object<\/td><\/tr><tr><td><code>deletecollection<\/code><\/td><td>Delete a collection of objects<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid granting <code>*<\/code> as a verb or resource wildcard unless there is a clearly justified need. Wildcards can include resources and actions introduced in the future.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Kubernetes API groups<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Resource<\/th><th>API group<\/th><\/tr><tr><td>Pods<\/td><td><code>\"\"<\/code><\/td><\/tr><tr><td>Services<\/td><td><code>\"\"<\/code><\/td><\/tr><tr><td>ConfigMaps<\/td><td><code>\"\"<\/code><\/td><\/tr><tr><td>Secrets<\/td><td><code>\"\"<\/code><\/td><\/tr><tr><td>Deployments<\/td><td><code>apps<\/code><\/td><\/tr><tr><td>ReplicaSets<\/td><td><code>apps<\/code><\/td><\/tr><tr><td>Jobs<\/td><td><code>batch<\/code><\/td><\/tr><tr><td>CronJobs<\/td><td><code>batch<\/code><\/td><\/tr><tr><td>Ingresses<\/td><td><code>networking.k8s.io<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The empty string represents the core Kubernetes API group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To inspect resources on your own cluster, run:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl api-resources -o wide<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To inspect RBAC API resources:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl api-resources \\\n  --api-group=rbac.authorization.k8s.io<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Example: Read Deployments<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">rules<\/span>:\n  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">apiGroups<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"apps\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">resources<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"deployments\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">verbs<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"get\"<\/span>, <span class=\"hljs-string\">\"list\"<\/span>, <span class=\"hljs-string\">\"watch\"<\/span>]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Example: Read Pod logs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pod logs are a subresource. Permission to read Pods does not automatically mean permission to read their logs.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">rules<\/span>:\n  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">apiGroups<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">resources<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"pods\/log\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">verbs<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"get\"<\/span>]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This distinction is important when designing access for developers and support teams.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Restrict access to one ConfigMap<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>resourceNames<\/code> field can restrict certain requests to a named object.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">rules<\/span>:\n  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">apiGroups<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">resources<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"configmaps\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">resourceNames<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"app-config\"<\/span>]<\/span>\n    <span class=\"hljs-selector-tag\">verbs<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"get\"<\/span>]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">There are limitations. For example, <code>resourceNames<\/code> cannot restrict top-level <code>create<\/code> or <code>deletecollection<\/code> requests by object name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Understand the Built-In Kubernetes Roles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes includes predefined ClusterRoles for common access requirements.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Built-in role<\/th><th>General purpose<\/th><th>Important consideration<\/th><\/tr><tr><td><code>cluster-admin<\/code><\/td><td>Full administrative access<\/td><td>Extremely powerful<\/td><\/tr><tr><td><code>admin<\/code><\/td><td>Namespace administration<\/td><td>Can manage most namespace resources and RBAC within its scope<\/td><\/tr><tr><td><code>edit<\/code><\/td><td>Read\/write access to most namespace resources<\/td><td>Can access Secrets and run Pods as ServiceAccounts in that namespace<\/td><\/tr><tr><td><code>view<\/code><\/td><td>Read-only access to most namespace resources<\/td><td>Does not allow reading Secrets<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">These built-in roles can be useful for basic access arrangements, but they are not always precise enough for production requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, <code>edit<\/code> may sound like a reasonable developer role. However, its ability to access Secrets and run Pods as namespace ServiceAccounts can expose additional API privileges.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a custom Role when the built-in permissions are broader than necessary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. How CertificateSigningRequests (CSRs) Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A CertificateSigningRequest is a Kubernetes API resource used to request an X.509 certificate from a configured signer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is useful when an organisation wants to issue client certificates for Kubernetes API access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The CSR process is important because a client certificate can establish an authenticated user identity. RBAC can then assign permissions to that identity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, a CSR does not directly create a Kubernetes user or grant RBAC permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are separate operations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Authentication establishes the identity.<\/li>\n\n\n\n<li>RBAC determines the permissions.<\/li>\n\n\n\n<li>Certificate issuance provides a credential that an authenticator may trust.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">CSR request lifecycle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A typical client certificate workflow looks like this:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Generate a private key.<\/li>\n\n\n\n<li>Create a certificate signing request.<\/li>\n\n\n\n<li>Submit a Kubernetes CertificateSigningRequest object.<\/li>\n\n\n\n<li>Inspect the requested identity and signer.<\/li>\n\n\n\n<li>Approve or reject the request.<\/li>\n\n\n\n<li>The configured signer issues the certificate if its requirements are satisfied.<\/li>\n\n\n\n<li>Configure the client certificate in kubeconfig.<\/li>\n\n\n\n<li>Create the required RBAC bindings.<\/li>\n\n\n\n<li>Test the authenticated identity and permissions.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The CSR API has been stable since Kubernetes v1.19. The <code>certificates.k8s.io\/v1<\/code> API requires <code>spec.signerName<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Official reference: <a href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/certificate-signing-requests\/\">Kubernetes Certificates and Certificate Signing Requests<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. Practical Lab: Give a Group Permission to Read Pods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This lab shows how a Role and RoleBinding work together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a disposable cluster and an administrator identity that is permitted to create namespaces and RBAC objects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create a namespace<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl create <span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">rbac<\/span>-<span class=\"hljs-title\">lab<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Verify it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> namespaces<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a Role<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file named <code>pod-reader.yaml<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">apiVersion: rbac.authorization.k8s.io\/v1\n<span class=\"hljs-attr\">kind<\/span>: Role\n<span class=\"hljs-attr\">metadata<\/span>:\n  name: pod-reader\n  <span class=\"hljs-attr\">namespace<\/span>: rbac-lab\n<span class=\"hljs-attr\">rules<\/span>:\n  - apiGroups: &#91;<span class=\"hljs-string\">\"\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"pods\"<\/span>]\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"get\"<\/span>, <span class=\"hljs-string\">\"list\"<\/span>, <span class=\"hljs-string\">\"watch\"<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">pod-reader<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 3: Bind the Role to a group<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>team-dev-binding.yaml<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">apiVersion: rbac.authorization.k8s.io\/v1\nkind: RoleBinding\nmetadata:\n  name: team-dev-pod-reader\n  namespace: rbac-lab\nsubjects:\n  - kind: Group\n    name: team-dev\n    apiGroup: rbac.authorization.k8s.io\nroleRef:\n  kind: Role\n  name: pod-reader\n  apiGroup: rbac.authorization.k8s.io<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">team-dev-binding<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The group receives permission to read Pods in <code>rbac-lab<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This does not create the group. Your authentication system must supply <code>team-dev<\/code> as part of the authenticated identity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Test the permissions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use impersonation to simulate an identity in the group:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl auth can-i <span class=\"hljs-keyword\">list<\/span> pods \\\n  -n rbac-lab \\\n  --<span class=\"hljs-keyword\">as<\/span>=alice \\\n  --<span class=\"hljs-keyword\">as<\/span>-group=team-dev<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Expected result in a clean lab: <code>yes<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test access to Secrets:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl auth can-i get secrets \\\n  -n rbac-lab \\\n  --<span class=\"hljs-keyword\">as<\/span>=alice \\\n  --<span class=\"hljs-keyword\">as<\/span>-group=team-dev<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Expected result in a clean lab: <code>no<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test access to Pods in another namespace:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl auth can-i <span class=\"hljs-keyword\">list<\/span> pods \\\n  -n <span class=\"hljs-keyword\">default<\/span> \\\n  --<span class=\"hljs-keyword\">as<\/span>=alice \\\n  --<span class=\"hljs-keyword\">as<\/span>-group=team-dev<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Expected result in a clean lab: <code>no<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These results assume no additional permissions have been granted to the test identity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> <code>--as<\/code> and <code>--as-group<\/code> use Kubernetes impersonation. The administrator running these commands must have the relevant impersonation permissions. These commands test authorization; they do not authenticate as a real user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">10. Practical Lab: Give a ServiceAccount Limited Access<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now create a ServiceAccount that can read ConfigMaps in <code>rbac-lab<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the ServiceAccount:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl create serviceaccount app-reader \\\n  -n rbac-lab<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Create a ConfigMap:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl create configmap app-config \\\n  --<span class=\"hljs-keyword\">from<\/span>-literal=mode=training \\\n  -n rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Create the Role:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl create role configmap-reader \\\n  --verb=<span class=\"hljs-keyword\">get<\/span>,list \\\n  --resource=configmaps \\\n  -n rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Bind the Role to the ServiceAccount:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl create rolebinding app-config-reader \\\n  --role=configmap-reader \\\n  --serviceaccount=rbac-lab:app-reader \\\n  -n rbac-lab<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Test access:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl auth can-i <span class=\"hljs-keyword\">get<\/span> configmaps \\\n  -n rbac-lab \\\n  --as=system:serviceaccount:rbac-lab:app-reader<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Expected result in a clean lab: <code>yes<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test access to Secrets:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-26\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl auth can-i <span class=\"hljs-keyword\">get<\/span> secrets \\\n  -n rbac-lab \\\n  --as=system:serviceaccount:rbac-lab:app-reader<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-26\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Expected result: <code>no<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Again, impersonation permissions are required for these tests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ServiceAccount does not need access to Pods, Secrets, Deployments, or other resources unless the application actually requires them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">11. Practical Lab: Create a Human User Certificate<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This lab shows how a client certificate can provide a username and group for Kubernetes authentication.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It requires:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>openssl<\/code><\/li>\n\n\n\n<li><code>kubectl<\/code><\/li>\n\n\n\n<li>A Kubernetes cluster with an appropriate client certificate signer.<\/li>\n\n\n\n<li>An API server configured to trust the issuing CA for client authentication.<\/li>\n\n\n\n<li>Administrator permissions to create and approve the required CSR.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Some managed clusters do not expose or configure the built-in client certificate signing workflow for customer use. Check your cluster provider&#8217;s documentation before starting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Generate a private key<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run these commands on a trusted workstation in a private directory.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-27\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">umask<\/span> 077\n\n<span class=\"hljs-selector-tag\">openssl<\/span> <span class=\"hljs-selector-tag\">genrsa<\/span> \\\n  <span class=\"hljs-selector-tag\">-out<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.key<\/span> \\\n  3072<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-27\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The private key must remain private. Do not upload it to GitHub, email it, or place it in a shared folder.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Generate a certificate request<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-28\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">openssl req -<span class=\"hljs-keyword\">new<\/span> \\\n  -key alice.key \\\n  -out alice.csr \\\n  -subj <span class=\"hljs-string\">\"\/CN=alice\/O=team-dev\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-28\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect the request:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-29\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">openssl<\/span> <span class=\"hljs-selector-tag\">req<\/span> \\\n  <span class=\"hljs-selector-tag\">-in<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.csr<\/span> \\\n  <span class=\"hljs-selector-tag\">-noout<\/span> \\\n  <span class=\"hljs-selector-tag\">-subject<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-29\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">For Kubernetes X.509 client certificate authentication:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>CN=alice<\/code> provides the username <code>alice<\/code>.<\/li>\n\n\n\n<li><code>O=team-dev<\/code> provides the group <code>team-dev<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This mapping applies to the X.509 authentication mechanism. Other authentication systems may provide usernames and groups differently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create the Kubernetes CSR object<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Encode the request:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-30\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">CSR_B64=<span class=\"hljs-string\">\"$(base64 &lt; alice.csr | tr -d '\\n')\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-30\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Create the Kubernetes CSR manifest:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">cat &gt; alice-csr.yaml &lt;&lt;EOF\napiVersion: certificates.k8s.io\/v1\nkind: CertificateSigningRequest\nmetadata:\n  name: alice-team-dev\nspec:\n  request: ${CSR_B64}\n  signerName: kubernetes.io\/kube-apiserver-client\n  expirationSeconds: 86400\n  usages:\n    - digital signature\n    - key encipherment\n    - client auth\nEOF<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Apply it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-31\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">alice-csr<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-31\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-32\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> csr<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-32\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe csr alice-team-dev<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The CSR is cluster-scoped. Do not add a namespace to its manifest.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Review and approve the CSR<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before approval, inspect the requested subject, signer, usages, and requested lifetime.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-33\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> csr alice-team-dev -o yaml<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-33\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Do not automatically approve every CSR.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An approved client certificate may allow its holder to authenticate as the requested identity. This can become a serious security issue if the requested username or group is privileged.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After an authorised administrator has reviewed the request:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl certificate approve alice-team-dev<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Approval does not guarantee a certificate will be issued. The configured signer must also be available and able to complete the signing process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Watch the CSR:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-34\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> csr alice-team-dev -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-34\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 5: Retrieve the issued certificate<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When the signer issues the certificate, it appears in <code>.status.certificate<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On Linux:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-35\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> csr alice-team-dev \\\n  -o jsonpath='{.status.certificate}<span class=\"hljs-string\">' \\\n  | base64 -d &gt; alice.crt<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-35\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect the certificate:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-36\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">openssl<\/span> <span class=\"hljs-selector-tag\">x509<\/span> <span class=\"hljs-selector-tag\">-in<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.crt<\/span> \\\n  <span class=\"hljs-selector-tag\">-noout<\/span> \\\n  <span class=\"hljs-selector-tag\">-subject<\/span> \\\n  <span class=\"hljs-selector-tag\">-issuer<\/span> \\\n  <span class=\"hljs-selector-tag\">-dates<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-36\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Confirm the username, group, issuer, and validity period.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the CSR is approved but <code>.status.certificate<\/code> remains empty, check the configured signer and controller-manager logs. Approval and signing are separate steps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Configure kubeconfig<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Get the current cluster entry:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-37\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">CLUSTER=<span class=\"hljs-string\">\"$(kubectl config view --minify \\\n  -o jsonpath='{.contexts&#91;0].context.cluster}')\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-37\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Add Alice&#8217;s credentials:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-38\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl config <span class=\"hljs-keyword\">set<\/span>-credentials alice \\\n  --client-certificate=alice.crt \\\n  --client-key=alice.key \\\n  --embed-certs=true<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-38\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Create a separate context:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-39\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl config set-context alice-rbac-lab \\\n  --cluster=<span class=\"hljs-string\">\"$CLUSTER\"<\/span> \\\n  --user=alice \\\n  --<span class=\"hljs-keyword\">namespace<\/span>=<span class=\"hljs-title\">rbac<\/span>-<span class=\"hljs-title\">lab<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-39\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This adds the new context without switching the active context.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the identity:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl --context=alice-rbac-lab auth whoami<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The expected identity should include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Username: <code>alice<\/code><\/li>\n\n\n\n<li>Group: <code>team-dev<\/code><\/li>\n\n\n\n<li>Group: <code>system:authenticated<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Bind the group and test access<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a RoleBinding for <code>team-dev<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl create rolebinding team-dev-read \\\n  --role=pod-reader \\\n  --group=team-dev \\\n  -n rbac-lab<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Test access using Alice&#8217;s actual certificate context:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-40\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl --context=alice-rbac-lab \\\n  <span class=\"hljs-keyword\">get<\/span> pods<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-40\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The request should be authorised within <code>rbac-lab<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now test access to Secrets:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-41\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl --context=alice-rbac-lab \\\n  <span class=\"hljs-keyword\">get<\/span> secrets<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-41\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In the clean lab, this should return <code>Forbidden<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the important relationship:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The certificate authenticates Alice and provides the group. The RoleBinding grants the group its Pod permissions.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A client certificate does not automatically grant those permissions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">12. Understand CSR Permissions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">CertificateSigningRequests have their own permission requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating or retrieving a CSR is different from approving it or signing it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Kubernetes documentation describes separate permissions for these operations.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Operation<\/th><th>Resource<\/th><th>Required verb<\/th><\/tr><tr><td>Create CSR<\/td><td><code>certificatesigningrequests<\/code><\/td><td><code>create<\/code><\/td><\/tr><tr><td>Inspect CSR<\/td><td><code>certificatesigningrequests<\/code><\/td><td><code>get<\/code>, <code>list<\/code>, <code>watch<\/code><\/td><\/tr><tr><td>Approve CSR<\/td><td><code>certificatesigningrequests\/approval<\/code><\/td><td><code>update<\/code><\/td><\/tr><tr><td>Authorise approval for a signer<\/td><td><code>signers<\/code><\/td><td><code>approve<\/code><\/td><\/tr><tr><td>Update signing result<\/td><td><code>certificatesigningrequests\/status<\/code><\/td><td><code>update<\/code><\/td><\/tr><tr><td>Authorise signing for a signer<\/td><td><code>signers<\/code><\/td><td><code>sign<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The signer permissions should be restricted by <code>resourceNames<\/code> where possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an approval role can be scoped to one signer:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-42\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">apiVersion: rbac.authorization.k8s.io\/v1\n<span class=\"hljs-attr\">kind<\/span>: ClusterRole\n<span class=\"hljs-attr\">metadata<\/span>:\n  name: client-csr-approver\n<span class=\"hljs-attr\">rules<\/span>:\n  - apiGroups: &#91;<span class=\"hljs-string\">\"certificates.k8s.io\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"certificatesigningrequests\"<\/span>]\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"get\"<\/span>, <span class=\"hljs-string\">\"list\"<\/span>, <span class=\"hljs-string\">\"watch\"<\/span>]\n\n  - apiGroups: &#91;<span class=\"hljs-string\">\"certificates.k8s.io\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"certificatesigningrequests\/approval\"<\/span>]\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"update\"<\/span>]\n\n  - apiGroups: &#91;<span class=\"hljs-string\">\"certificates.k8s.io\"<\/span>]\n    <span class=\"hljs-attr\">resources<\/span>: &#91;<span class=\"hljs-string\">\"signers\"<\/span>]\n    <span class=\"hljs-attr\">resourceNames<\/span>:\n      - kubernetes.io\/kube-apiserver-client\n    <span class=\"hljs-attr\">verbs<\/span>: &#91;<span class=\"hljs-string\">\"approve\"<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-42\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This is an example permission definition. You must still decide which trusted administrators or controllers should receive it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not grant CSR approval or signer permissions broadly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes explicitly warns that approving CSRs is a trust decision. The requested subject and signer must be checked before approval.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">References:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/certificate-signing-requests\/\">CSR signing authorization<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/kubernetes.io\/docs\/tasks\/tls\/certificate-issue-client-csr\/\">Issue a client certificate through a CSR<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">13. Important RBAC Security Risks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">RBAC is a security control, but incorrect permissions can create privilege escalation paths.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 1: Granting wildcard permissions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-43\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">verbs<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"*\"<\/span>]<\/span>\n<span class=\"hljs-selector-tag\">resources<\/span>: <span class=\"hljs-selector-attr\">&#91;<span class=\"hljs-string\">\"*\"<\/span>]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-43\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This can grant access to current and future API resources.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Define only the verbs and resources needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 2: Giving developers broad Secret access<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Secrets can contain credentials, tokens, certificates, and application configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reading a Secret may expose credentials that provide access to other Kubernetes resources.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Avoid granting Secret access unless the role genuinely requires it. Restrict access by namespace and, where practical, by resource name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 3: Giving <code>edit<\/code> to every developer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The built-in <code>edit<\/code> role can access Secrets and run Pods as ServiceAccounts in its namespace. This can expose permissions beyond the apparent scope of ordinary application editing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Use a custom Role when developers need narrower access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 4: Granting <code>cluster-admin<\/code> unnecessarily<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>cluster-admin<\/code> allows superuser operations across the cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Use scoped roles for everyday operations and reserve cluster-admin for trusted administrative tasks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 5: Granting <code>bind<\/code>, <code>escalate<\/code>, or <code>impersonate<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These verbs are especially sensitive:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>bind<\/code> can allow users to attach roles with permissions they do not already possess.<\/li>\n\n\n\n<li><code>escalate<\/code> can bypass built-in protections when creating or changing roles.<\/li>\n\n\n\n<li><code>impersonate<\/code> allows a user to act as another identity.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Grant these only to trusted operators with a defined need.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 6: Forgetting namespace boundaries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A ClusterRoleBinding gives the referenced ClusterRole access across the cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding using a ClusterRole applies that permission only in the RoleBinding&#8217;s namespace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Prefer RoleBindings when permissions only need to apply within one namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Risk 7: Treating a missing permission as a deny rule<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes RBAC rules are additive. They do not contain explicit deny rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding can add permissions. Removing a binding removes that grant, but another binding may still grant the same permission.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better approach:<\/strong> Review all applicable bindings and any other configured authorizers when investigating unexpected access.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">14. Useful Kubernetes RBAC Commands<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Purpose<\/th><th>Command<\/th><\/tr><tr><td>Show current context<\/td><td><code>kubectl config current-context<\/code><\/td><\/tr><tr><td>Show authenticated identity<\/td><td><code>kubectl auth whoami<\/code><\/td><\/tr><tr><td>List namespaces<\/td><td><code>kubectl get namespaces<\/code><\/td><\/tr><tr><td>List Roles<\/td><td><code>kubectl get roles -A<\/code><\/td><\/tr><tr><td>List RoleBindings<\/td><td><code>kubectl get rolebindings -A<\/code><\/td><\/tr><tr><td>List ClusterRoles<\/td><td><code>kubectl get clusterroles<\/code><\/td><\/tr><tr><td>List ClusterRoleBindings<\/td><td><code>kubectl get clusterrolebindings<\/code><\/td><\/tr><tr><td>Describe a Role<\/td><td><code>kubectl describe role pod-reader -n rbac-lab<\/code><\/td><\/tr><tr><td>Test permission<\/td><td><code>kubectl auth can-i list pods -n rbac-lab<\/code><\/td><\/tr><tr><td>Test as another user<\/td><td><code>kubectl auth can-i list pods -n rbac-lab --as=alice<\/code><\/td><\/tr><tr><td>List CSRs<\/td><td><code>kubectl get csr<\/code><\/td><\/tr><tr><td>Inspect a CSR<\/td><td><code>kubectl describe csr alice-team-dev<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The impersonation examples require the appropriate administrative permissions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">15. RBAC Troubleshooting Checklist<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a user receives an access error, investigate the identity and authorization separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Check authentication<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl auth whoami<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Confirm that the username and groups are correct.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If authentication fails, review the certificate, token, identity provider, kubeconfig, or authentication integration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Check the requested permission<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-44\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">kubectl auth can-i <span class=\"hljs-keyword\">list<\/span> pods -n rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-44\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Test the exact verb, resource, and namespace involved.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Inspect the Role<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-45\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> roles -n rbac-lab\nkubectl describe role pod-reader -n rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-45\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Confirm the API group, resource, and verbs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Inspect the binding<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-46\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> rolebindings -n rbac-lab\nkubectl describe rolebinding team-dev-pod-reader -n rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-46\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Check the subject name and subject type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A group name must match the authenticated group exactly. Names are case-sensitive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Check the namespace<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding grants access only within its own namespace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check whether the request uses the expected namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Check for other permissions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An unexpected <code>yes<\/code> result may come from another RoleBinding, ClusterRoleBinding, or configured authorization mechanism.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not assume that a single Role explains every permission.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">16. Clean Up the RBAC Lab<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After completing the exercises, remove the test namespace:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-47\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">delete<\/span> namespace rbac-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-47\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Remove the local training credentials and certificate files when they are no longer needed:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-48\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">rm<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.key<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.csr<\/span> <span class=\"hljs-selector-tag\">alice<\/span><span class=\"hljs-selector-class\">.crt<\/span>\n<span class=\"hljs-selector-tag\">rm<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">alice-csr<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-48\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Do not delete credentials that are used for another purpose. Confirm the files belong to the lab before removing them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Can I create a Kubernetes user using kubectl?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Kubernetes does not provide a normal User API resource. Human identities are supplied through authentication systems such as client certificates, OIDC, or authentication webhooks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a User and a ServiceAccount?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A normal User identity is managed outside Kubernetes. A ServiceAccount is a Kubernetes API object designed for workloads and applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a Role and a ClusterRole?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A Role defines permissions within one namespace. A ClusterRole is not namespaced and can define permissions for cluster-scoped resources or reusable permissions for namespaced resources.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a RoleBinding and a ClusterRoleBinding?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A RoleBinding grants permissions within one namespace. A ClusterRoleBinding grants the referenced ClusterRole permissions across the cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does a Role automatically give users access?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A Role defines permissions. A RoleBinding or ClusterRoleBinding must assign those permissions to a subject.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can a RoleBinding reference a ClusterRole?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The ClusterRole&#8217;s permissions then apply only within the RoleBinding&#8217;s namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a Kubernetes CSR?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A CertificateSigningRequest is a cluster-scoped API object used to request an X.509 certificate from a configured signer. It may require review and approval before signing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does approving a CSR automatically issue a certificate?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Approval and signing are separate stages. A configured signer must issue the certificate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does a CSR automatically create a Kubernetes user?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A signed client certificate can authenticate an identity. RBAC bindings then determine what that identity can do.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why is <code>kubectl auth can-i<\/code> useful?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It checks whether the current identity, or an impersonated identity when permitted, can perform a specified Kubernetes API operation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes RBAC helps organisations control access without giving every person or application administrator permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Users and groups identify who needs access. ServiceAccounts identify workloads. Roles and ClusterRoles define allowed actions. Bindings assign those permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CertificateSigningRequests provide a separate mechanism for requesting client certificates that can authenticate users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most important design principle is least privilege.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start with the minimum permissions required. Prefer namespace-scoped bindings when possible. Review Secret access carefully. Test permissions with <code>kubectl auth can-i<\/code>. Review certificate requests before approval.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When authentication and authorization are understood separately, Kubernetes access becomes easier to design, troubleshoot, and secure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction A Kubernetes cluster may run hundreds of applications, but not every person or application should have access to every&#8230; <\/p>\n","protected":false},"author":7,"featured_media":3496,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,736,734,735,713,712],"tags":[766,763,142,70,170,761,175,762,764,765],"series":[],"class_list":["post-3495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-career-growth","category-careers","category-devops","category-devops-careers","category-engineering-culture","tag-certificatesigningrequest","tag-clusterrole","tag-devops","tag-devopsschool","tag-kubernetes","tag-kubernetesrbac","tag-kubernetessecurity","tag-rolebasedaccesscontrol","tag-rolebinding","tag-serviceaccount"],"_links":{"self":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/comments?post=3495"}],"version-history":[{"count":1,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3495\/revisions"}],"predecessor-version":[{"id":3497,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3495\/revisions\/3497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/media\/3496"}],"wp:attachment":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/media?parent=3495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/categories?post=3495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/tags?post=3495"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/series?post=3495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}