Tekton pipelines often fail because the PipelineRun can’t find the service account it’s supposed to use.
The PipelineRun needs a ServiceAccount to execute its tasks. This ServiceAccount needs specific RoleBindings to grant it permissions within the Kubernetes cluster, allowing it to create, read, and manage resources like Pods, Tasks, and Pipelines. Without these permissions, the PipelineRun will stall, often with an error indicating that the service account or its associated roles are not found or are insufficient.
Here’s a breakdown of common causes and how to fix them:
-
The Service Account Doesn’t Exist:
- Diagnosis: Check if the
ServiceAccountspecified in yourPipelineRunactually exists in the namespace where thePipelineRunis being created.kubectl get serviceaccount <service-account-name> -n <namespace> - Fix: If it doesn’t exist, create it.
Apply this withapiVersion: v1 kind: ServiceAccount metadata: name: <service-account-name> namespace: <namespace>kubectl apply -f <your-service-account-file.yaml>. - Why it works: This ensures the fundamental identity that the
PipelineRunwill attempt to use is present in the cluster.
- Diagnosis: Check if the
-
The Service Account is in the Wrong Namespace:
- Diagnosis:
PipelineRunscan only useServiceAccountsthat exist in the same namespace as thePipelineRunitself. Verify theServiceAccount’s namespace.
And check yourkubectl get serviceaccount <service-account-name> -n <namespace>PipelineRundefinition for the correct namespace. - Fix: Either move the
PipelineRunto the namespace where theServiceAccountexists, or create a newServiceAccountwith the same name in thePipelineRun’s namespace.# Example: Creating a new SA in the PipelineRun's namespace kubectl create serviceaccount <service-account-name> -n <pipeline-run-namespace> - Why it works: Kubernetes RBAC is namespace-scoped. A
ServiceAccountinnamespace-acannot be directly used by aPipelineRuninnamespace-bunless explicitly granted cross-namespace access (which is complex and usually not the intended pattern here).
- Diagnosis:
-
Missing
ClusterRoleBindingfor Tekton Controller:- Diagnosis: The Tekton controller (usually a
tekton-pipelines-controllerdeployment) needs permissions to manage Tekton resources. If this controller can’t see or managePipelines,Tasks, etc., your runs won’t start.
Look for akubectl get clusterrolebinding | grep tektonClusterRoleBindingthat grants thetekton-pipelines-controllerServiceAccount (in thetekton-pipelinesnamespace by default) thecluster-adminrole or a specific Tekton-relatedClusterRole. - Fix: Ensure the
tekton-pipelines-controllerhas the necessaryClusterRoleorClusterRoleBinding. If you installed Tekton using the operator or YAML, this should be present. If not, you might need to reapply the installation manifests or manually create a binding.
Apply with# Example of a common binding for the controller apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: tekton-pipelines-aggregate-edit subjects: - kind: ServiceAccount name: tekton-pipelines-controller namespace: tekton-pipelines # Adjust if your Tekton is in a different namespace roleRef: kind: ClusterRole name: tekton-pipelines-aggregate-edit # Or cluster-admin apiGroup: rbac.authorization.k8s.iokubectl apply -f <your-tekton-controller-binding.yaml>. - Why it works: This grants the Tekton controller itself the cluster-wide permissions it needs to create and manage
Podsand other resources on behalf of yourPipelineRuns.
- Diagnosis: The Tekton controller (usually a
-
PipelineRunService Account Lacks Permissions to Create Pods:- Diagnosis: The
ServiceAccountused by thePipelineRunneeds permission to createPodsin the namespace where thePipelineRunis executing.
You’re looking for a# First, find the SA used by your PipelineRun kubectl get pipelinerun <your-pipelinerun-name> -n <namespace> -o yaml # Look for spec.serviceAccountName # Then, check its RoleBindings in that namespace kubectl get rolebinding -n <namespace> | grep <service-account-name> # And check the Role it's bound to kubectl get role <role-name-from-binding> -n <namespace> -o yamlRolethat includespodsinresourcesandcreate,get,list,watch,update,patch,deleteinverbs. - Fix: Create or modify a
RoleandRoleBindingto grant the necessary permissions.
Apply withapiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: tekton-pod-creator namespace: <namespace> rules: - apiGroups: [""] resources: ["pods", "pods/log"] # pods/log is often needed for fetching logs verbs: ["create", "get", "list", "watch", "update", "patch", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: tekton-pod-creator-binding namespace: <namespace> subjects: - kind: ServiceAccount name: <service-account-name> # The SA from your PipelineRun namespace: <namespace> roleRef: kind: Role name: tekton-pod-creator apiGroup: rbac.authorization.k8s.iokubectl apply -f <your-tekton-permissions.yaml>. - Why it works: Each
Taskin aPipelineRunexecutes as aPod. TheServiceAccountassociated with thePipelineRunacts as the identity for creating theseTaskpods. Withoutcreatepermission onpods, thePipelineRuncannot launch its tasks.
- Diagnosis: The
-
PipelineRunService Account Lacks Permissions to Manage Tekton Resources:- Diagnosis: The
ServiceAccountmight also need permissions toget,list,watch,update,patch, ordeleteTekton-specific resources likeTasks,Pipelines,TaskRuns, andPipelineRunsthemselves, especially if thePipelineRunis trying to self-update its status or if custom controllers are involved.
You’re looking for rules covering# Check the same Role/RoleBinding as above, but for Tekton resources kubectl get rolebinding -n <namespace> | grep <service-account-name> # Look for roles granting access to tekton.dev kubectl get role <role-name-from-binding> -n <namespace> -o yamltasks,pipelines,taskruns,pipelinerunswith verbs likeget,list,watch,update,patch,delete. - Fix: Add these permissions to the
Roleor create a newRoleandRoleBinding.
Apply the updated YAML.# Add to the existing Role or create a new one - apiGroups: ["tekton.dev"] resources: ["tasks", "pipelines", "taskruns", "pipelineruns", "runs"] verbs: ["get", "list", "watch", "update", "patch", "delete"] - Why it works: This allows the
PipelineRunto interact with the Tekton control plane to report its status, fetch definitions, and manage its lifecycle.
- Diagnosis: The
-
Default Service Account Permissions (Less Common but Possible):
- Diagnosis: If your
PipelineRundoesn’t explicitly specify aserviceAccountName, it defaults todefaultin the namespace. Check the RBAC for thedefaultServiceAccount.kubectl get serviceaccount default -n <namespace> kubectl get rolebinding -n <namespace> | grep default - Fix: Grant the necessary permissions to the
defaultServiceAccount as described in points 4 and 5, or explicitly specify a dedicatedServiceAccountin yourPipelineRunwith its own granular permissions.# In your PipelineRun apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: my-pipeline-run namespace: <namespace> spec: pipelineRef: name: my-pipeline serviceAccountName: <dedicated-service-account-name> # <-- specify here - Why it works: Explicitly defining permissions for a dedicated service account is more secure and manageable than relying on the broad permissions often (and sometimes insecurely) assigned to the
defaultservice account.
- Diagnosis: If your
After fixing these, the next error you’ll likely encounter is a TaskRun failing because the ServiceAccount specified for the TaskRun itself (or inherited from the PipelineRun) doesn’t have permissions to pull container images or access other external resources.