A CI pipeline fails with `deployments.apps "api" is forbidden: User "system:serviceaccount:ci:deployer" cannot patch resource "deployments" in API group "apps" in the namespace "prod"`.
BeginnerTroubleshootingControl plane, RBAC, webhooks and autoscaling
Answer
Likely causes → The ServiceAccount has a Role in ci or staging but not in prod; or the binding's subjects[].namespace is wrong (a ServiceAccount subject must name the SA's own namespace, here ci).
Diagnose →
kubectl auth can-i patch deployments.apps -n prod --as system:serviceaccount:ci:deployer
kubectl get rolebinding -n prod -o yaml | yq '.items[] | select(.subjects[]?.name=="deployer")'
Fix →
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: {name: deployer, namespace: prod}
subjects:
- {kind: ServiceAccount, name: deployer, namespace: ci}
roleRef: {kind: ClusterRole, name: app-deployer, apiGroup: rbac.authorization.k8s.io}
Prevent → Test pipeline permissions with kubectl auth can-i --list --as ... in a pre-flight step.
More on Control plane, RBAC, webhooks and autoscaling
A developer gets `Error from server (Forbidden): pods is forbidden: User "[email protected]" cannot list resource "pods" in API group "" in the namespace "payments"`.BeginnerA user can `get pods` but `kubectl logs` fails with `cannot get resource "pods/log"` and `kubectl exec` fails with `cannot create resource "pods/exec"`.BeginnerCreating a RoleBinding fails with `is attempting to grant RBAC permissions not currently held`.IntermediateEvery `kubectl apply` fails with `Internal error occurred: failed calling webhook "validate.kyverno.svc-fail": failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/validate/fail?timeout=10s": context deadline exceeded`.AdvancedCreating a Certificate fails with `failed calling webhook "webhook.cert-manager.io": ... no endpoints available for service "cert-manager-webhook"`.IntermediateA webhook fails with `failed calling webhook ... tls: failed to verify certificate: x509: certificate signed by unknown authority`.Intermediate