0

I am trying to create a PipeLineRun/PipeLineRun from within a continer listening to a webhook and running tkn - but I need RBAC rights. I tried rolebinding role: tekton-pipelines-controller to default service account:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: webhook
  namespace: tekton-pipelines
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: tekton-pipelines-controller
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default

But I can still not do this:

kubectl auth can-i create taskrun -n default --as=system:serviceaccount:default:default

no

I also tried creating a role for the resource:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: webhook-create-taskrun
  namespace: tekton-pipelines
rules:
  - apiGroups: ["tekton.dev/v1beta1"]
    resources: ["taskrun"]
    verbs: ["get", "create", "list"]
# [ delete deletecollection get list patch create update watch ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: webhook-create-taskrun
  namespace: tekton-pipelines
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: webhook-create-taskrun
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default

Unfortunately still no access

I also looked for anything "taskrun" in all RoleBindings in tekton-pipelines, and found nothing

        ns := "tekton-pipelines"
    rbacClientSet := clientSet.RbacV1()
    rolebindings, _ := rbacClientSet.RoleBindings(ns).List(context.Background(), metav1.ListOptions{})

    for _, element := range rolebindings.Items {
        fmt.Println(element)
    }
Chris G.
  • 23,930
  • 48
  • 177
  • 302

1 Answers1

0

Your ServiceAccount should be granted with privileges similar to those of an EventListener (Tekton Triggers).

You can find a sample Role over there: https://github.com/tektoncd/triggers/blob/main/config/200-clusterrole.yaml#L64-L87 :

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tekton-triggers-eventlistener-roles
  labels:
    app.kubernetes.io/instance: default
    app.kubernetes.io/part-of: tekton-triggers
rules:
  - apiGroups: ["triggers.tekton.dev"]
    resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["tekton.dev"]
    resources: ["pipelineruns", "pipelineresources", "taskruns"]
    verbs: ["create"]
  - apiGroups: [""]
    resources: ["serviceaccounts"]
    verbs: ["impersonate"]
  - apiGroups: ["policy"]
    resources: ["podsecuritypolicies"]
    resourceNames: ["tekton-triggers"]
    verbs: ["use"]

The one you use (tekton-pipelines-controller) is not meant to create PipelineRuns.

The one you tried writing yourself allows creating TaskRuns, you're still missing PipelineRuns.

You probably don't need the full tekton-triggers-eventlistener-roles permissions, if you're implementing your own triggers. Creating pipelineruns may be enough.

SYN
  • 4,476
  • 1
  • 20
  • 22