Kubernetes RBAC Generator

Build a Role or ClusterRole with its binding, and see what it actually grants. The output runs through our own RBAC analyzer as you type, so picking an escalating verb reports the escalation path here rather than in your cluster.

Role
What it grants

One per line. For apiGroups, an empty line means the core group: use "" for pods, services, secrets and configmaps.

Binding

rbac.yaml

updates as you type

    Common mistakes

    These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

    1. Using a ClusterRoleBinding where a RoleBinding was meant

      A ClusterRoleBinding grants the role in every namespace. The difference is one word and the blast radius is the whole cluster.

      Instead:RoleBinding for namespace scope.

    2. Granting list on secrets

      get on a named secret is narrow. list returns the contents of every secret in the response, which is a very different grant.

      Instead:Avoid list on secrets. Use get with resourceNames.

    3. Including a wildcard verb

      It covers delete, deletecollection, escalate, bind and impersonate. Impersonate in particular is privilege escalation.

      Instead:List the verbs you need.

    Reading an RBAC rule for what it actually grants

    RBAC is purely additive. There are no deny rules, no ordering and no precedence: a subject can do something if any binding says so. That makes each rule easy to read and the total effect hard to see, which is where the surprises live.

    The core group is the empty string, and "core" grants nothing

    Pods, Services, Secrets, ConfigMaps and Nodes are all in the group with no name. In YAML that is two quote characters. Writing core, or v1, or omitting the field is not an error: the API server stores the rule and it matches nothing, so the role grants no access and reports no problem. This is the most common reason a Role that looks right does not work.

    rules:
      - apiGroups: [""]              core: pods, services,
                                     secrets, configmaps
        resources: ["pods"]
        verbs: ["get", "list"]
    
      - apiGroups: ["apps"]          deployments, statefulsets
      - apiGroups: ["core"]          matches NOTHING
      - apiGroups: ["v1"]            also matches nothing

    A ClusterRole bound by a RoleBinding is namespaced

    The role's scope comes from the binding, not from the role. This is the intended way to define a permission set once and apply it in many namespaces, and because it reads like a mistake, people write near-identical Roles in every namespace instead. The reverse does not work: a Role cannot be referenced by a ClusterRoleBinding at all.

    ClusterRole + ClusterRoleBinding   everywhere
    ClusterRole + RoleBinding          one namespace
    Role        + RoleBinding          one namespace
    Role        + ClusterRoleBinding   rejected
    
    # and there is no way to narrow a ClusterRoleBinding
    # afterwards. It has no namespace field.

    Three verbs that are cluster-admin with extra steps

    escalate, bind and impersonate each let the holder end up with more than the role appears to grant, and none of them show up when you audit who is bound to cluster-admin. They exist for legitimate reasons, and a role carrying one should be a deliberate decision rather than something copied from a controller's manifest.

    escalate    on roles/clusterroles:
                  write yourself a cluster-admin role
    
    bind        on roles/clusterroles:
                  bind yourself to cluster-admin without
                  holding those permissions first
    
    impersonate on users/groups:
                  kubectl --as=... anyone, including
                  system:masters

    Reading Secrets is reading credentials

    A ServiceAccount's token is a Secret, or is obtainable through the TokenRequest API by anything that can create pods. So get or list on secrets in a namespace is the union of what every ServiceAccount in that namespace can do, and create on pods is at least the most privileged ServiceAccount there. Neither reads like an escalation in the rule.

    resources: ["secrets"]
    verbs: ["get", "list"]
      -> every ServiceAccount token in the namespace
      -> and therefore everything they can each do
    
    resources: ["pods"]
    verbs: ["create"]
      -> mount any ServiceAccount in the namespace
      -> without a policy engine, also hostPath the node

    resourceNames does not restrict list or watch

    It looks like the way to scope a rule to one object, and for get, update, patch and delete it is. For list and watch the name is not known until the response has already been assembled, so the API server cannot filter by it and grants the verb over everything of that type. The rule reads as restricted and is not.

    - apiGroups: [""]
      resources: ["configmaps"]
      resourceNames: ["my-config"]
      verbs: ["get", "list"]
    
      get   -> only my-config          restricted
      list  -> every configmap         NOT restricted
    
    # split them: resourceNames with get/update/delete in
    # one rule, and no list verb at all.

    More kubernetes tools

    Kubernetes YAML Generator Answer a few questions, get a manifest Kubernetes YAML Validator Is this YAML valid, and where is it wrong? Kubernetes Rollout & Probe Timing Restart loops, capacity dips and stuck drains Kubernetes Service Checker Will this Service have any endpoints? Kubernetes Network Policy Viewer What can reach what, and what just broke Kubernetes Manifest Diff What actually changed Kubernetes Resource Calculator What these manifests actually reserve Kubernetes RBAC Viewer Who can actually do what Kubernetes Deployment Generator See the capacity dip before you deploy Kubernetes Service Generator port, targetPort, and which one you meant Kubernetes StatefulSet Generator Stable names, and volumes that outlive you Kubernetes QoS Class Calculator And where you sit in the eviction order Kubernetes Node Capacity Planner Allocatable is not capacity Kubernetes Max Pods per Node Calculator The ENI limit, not the 110 default Kubernetes Label Selector Tester Which key failed, not just that one did Kubernetes Taint & Toleration Tester Tolerations permit, they do not attract Kubernetes Resource Name Validator RFC 1123 subdomain, label, or 1035 Kubernetes Label & Annotation Validator Why your image tag is not a legal label Kubernetes CrashLoopBackOff Guide The status is a timer, not a cause Kubernetes TLS Certificate Decoder When it expires, and what it covers Kubernetes ServiceAccount Token Decoder Bound or legacy, and when it dies Kubernetes imagePullSecret Generator The registry URL nobody gets right Kubernetes cert-manager Certificates Issuer scope, and the rate limit that costs a week Kubernetes Flux HelmRelease Generator With the source it cannot work without Kubernetes Helm Chart Generator Chart.yaml, values, and working templates Kubernetes Argo CD Application Generator The defaults that are off, turned on Kubernetes Ingress Generator pathType, and the TLS secret that fails quietly Kubernetes HPA Generator Why it says unknown and never scales Kubernetes SecurityContext Generator Pod level, container level, and which wins Kubernetes Probe Generator How long it gets to start before liveness kills it Kubernetes PVC Generator Access modes your storage can actually do Kubernetes ResourceQuota Generator And the LimitRange that stops it breaking deploys Kubernetes CronJob Generator The fields that decide whether it runs Kubernetes NetworkPolicy Generator With the DNS rule already in it Kubernetes PodDisruptionBudget Generator Can this budget ever be satisfied? Kubernetes API Deprecation Checker What breaks on the next upgrade Kubernetes Kubeconfig Viewer Read it without handing it to anyone Kubernetes Quantity Parser What 512Mi, 100m and 1e3 actually mean Kubernetes Multi-Document YAML Splitter One file per object, in apply order Kubernetes .env to ConfigMap & Secret Split the credentials out on the way Kubernetes Secret Decoder See what is actually in there Kubernetes Ingress to Gateway API Which annotations silently stop working Kubernetes Manifest Visualizer What points at what, and what points at nothing Kubernetes Patch Tester Which --type, and what it deletes Kubernetes kubectl JSONPath Tester kubectl's dialect, not generic JSONPath Kubernetes Node Affinity Tester Required excludes, preferred only scores Kubernetes Helm Values Diff A missing key is a third value Kubernetes Pod and Service CIDR Fixed at cluster creation Kubernetes Secret Encoder base64 is not encryption Kubernetes API Version Checker Will this apply on that cluster Kubernetes Go Template Tester Go truthiness is not JavaScript's Kubernetes Cluster Cost Estimator At your rates, not a price table Kubernetes Kustomize Build Transformers run in kustomize's order Kubernetes Helm Chart Validator version is SemVer, appVersion is not

    Elsewhere on the site