Fix: Error from server (Forbidden): … is forbidden: User … cannot … in OpenShift
oc refuses a command with Error from server (Forbidden). The message names the user, verb, resource and project. Learn how to read it, check your rights with oc auth can-i and grant the right role.
Not checked by a trusted editor yet Last edited Outdated?
The API server rejected the request because the identity making it has no role that allows this action. Typical messages look like this:
Error from server (Forbidden): nodes is forbidden: User "developer" cannot list resource "nodes" in API group "" at the cluster scope
Error from server (Forbidden): namespaces "shop-dev" is forbidden: User "developer" cannot patch resource "namespaces" in API group "" in the namespace "shop-dev"
Error from server (Forbidden): templates.template.openshift.io is forbidden: User "system:serviceaccount:default:examplesa" cannot list resource "templates" in API group "template.openshift.io" in the namespace "example"
Read the message
- User: who made the request.
system:serviceaccount:PROJECT:NAMEmeans a pod or pipeline using a service account, not you. - Verb:
get,list,watch,create,update,patchordelete. - Resource and API group:
""is the core group (pods, secrets, namespaces); OpenShift types use groups such asroute.openshift.ioortemplate.openshift.io. - Scope: in the namespace “X” means a project-level permission is missing; at the cluster scope means the resource is cluster-wide (nodes, namespaces, storage classes, cluster Operators) and needs a cluster role.
Causes, most likely first
- Wrong project or cluster. You meant to work in a project where you have access but your current context points somewhere else.
- Missing role in the project. You have
viewbut the action needseditoradmin; for example,viewcannot read Secrets, andeditcannot change role bindings. - Cluster-scoped resource. Normal users cannot list nodes, change namespaces or read cluster Operators. Ask an administrator instead of asking for
cluster-admin. - A service account lacks a role. A pod, CI job or Operator calls the API with its own service account, which by default can do very little.
- Logged in as the wrong user, for example an old token saved in your kubeconfig.
Diagnose
oc whoami
oc project
oc auth can-i list pods -n shop-dev
oc auth can-i patch namespaces
oc auth can-i list templates.template.openshift.io -n example \
--as=system:serviceaccount:default:examplesa
oc auth can-i answers yes or no for the exact verb, resource and namespace from the error. Users allowed to impersonate (usually administrators) can check other identities with --as. To see who already has a permission in a project:
oc adm policy who-can list pods -n shop-dev
oc get rolebindings -n shop-dev
oc describe rolebinding.rbac -n shop-dev
Fix
- If you were in the wrong place, switch with
oc project NAMEor add-n NAME, then retry. - If you need more rights in a project, a project admin grants the smallest default role that covers the action:
oc adm policy add-role-to-user view alice -n shop-dev
oc adm policy add-role-to-user edit alice -n shop-dev
oc adm policy add-role-to-group edit dev-team -n shop-dev
- For a service account, bind the role to it with
-z. If no default role fits, create a narrow role with only the verbs and resources needed:
oc policy add-role-to-user view -z examplesa -n example
oc create role template-reader --verb=get,list --resource=templates.template.openshift.io -n example
oc create rolebinding examplesa-templates --role=template-reader \
--serviceaccount=default:examplesa -n example
- For cluster-scoped resources, a cluster administrator binds a cluster role, for example
cluster-readerfor read-only access across the cluster:oc adm policy add-cluster-role-to-user cluster-reader alice.
Avoid fixing this by granting cluster-admin or admin to service accounts. Also note that even project admins cannot grant access to Security Context Constraints; that needs a cluster administrator. Run oc auth can-i again to confirm before retrying the original command.
Official documentation
See also
- 0155 Security Context Constraints (SCC) and why root containers fail on OpenShift SCCs decide which user ID, capabilities and volumes a pod may use. Learn how restricted-v2 assigns random UIDs, how to see which… Advanced · Concept · Linux Article Cluster administration · Concepts 15 Oct 2026
- 0156 Operators, the software catalog (OperatorHub) and OLM on OpenShift Operators automate installing and running software on OpenShift. Learn the difference between cluster Operators and add-on Operators, and how OLM uses catalogs,… Intermediate · Concept · Linux Article Cluster administration · Concepts 15 Oct 2026
- 0157 oc cheat sheet: everyday OpenShift CLI commands The oc commands you use every day, grouped by task: login and projects, apps and builds, routes, config, debugging, permissions and admin… Intermediate · Reference · Any system Article Deploying applications · Troubleshooting 15 Oct 2026
- 0158 Collect an OpenShift project report with oc A read-only bash script that gathers a project's workloads, pods, routes, builds, storage and warning events, plus describe output and logs of… Intermediate · How-to · Linux, macOS Script Deploying applications · Troubleshooting 15 Oct 2026
- 0159 OpenShift cluster health snapshot: oc adm, nodes, MachineConfigPools and updates An admin overview of OpenShift day-2 checks (cluster version, update channels, cluster Operators, nodes, MachineConfigPools, must-gather) with a read-only bash script that… Advanced · Reference · Linux, macOS Script Cluster administration · Troubleshooting 15 Oct 2026
- 0160 Fix: Permission denied in a container on OpenShift because of the random UID A container that works under Docker or Kubernetes crashes on OpenShift with permission denied, because restricted-v2 runs it with a random non-root… Advanced · Fix · Linux Article Troubleshooting 15 Oct 2026
Repos in the wild
- openshift/oc: the OpenShift command line client openshift/oc Source code of oc, the OpenShift CLI. It is built on top of kubectl, so it can do everything kubectl does, and adds commands for projects, builds, routes, image streams and cluster administration. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +4,030 chars