tektoncd / pipeline

A cloud-native Pipeline resource.
https://tekton.dev
Apache License 2.0
8.44k stars 1.77k forks source link

Ability to add `serviceAccountName` per task in `pipeline` #8209

Open ElSamhaa opened 1 month ago

ElSamhaa commented 1 month ago

Feature request

Hello, thanks for the great project. First, after searching the issues, I believe many people can relate to this request.

IIUC, the pipeline behavior is dictated by the definition of the long-lived pipeline and the runtime pipelineruns resources. The dynamic parameters live in the pipelinerun while the more often usable config lives in the pipeline. That said, I see some limitations that seem counter-intuitive, to say the least:

The developers don't want to feed in meaningless strings each time they trigger a build. It's pointless because it's fixed for all pipelineruns and they're not relevant to them. Besides, "fixed" means they're not parameters => we should have the option to specify them once and forget about them.

Now, adding to the above, the fact that many of the tekton pipeline users are on Openshift, we hit another limitation which is Openshift doesn't prompt for serviceAccounts for a pipelinerun on its web GUI (at least until Openshift 4.12).

Use case

I want some tasks to interact with the Kubernetes API server. For this, I need to configure certain tasks or the whole pipeline to use a certain fixed serviceaccount for all its builds. Intuitively, I was expecting a serviceAccountName under the pipeline task (each task in the list resolves to a pod, so the implementation should be simple). IMO, I would even say that adding this capability shouldn't break anything as the omission of the serviceAccountName can still be treated the same way as it is currently (the same current behavior).

chengjoey commented 1 month ago

Currently, you can set a default serviceAccountName or pipelineRun for all pipelines and tasks, and taskRun can also set a separate serviceAccountName. you want to add a field serviceAccountName to taskSpec so that you can define serviceAccountName for a certain type of task, and when taskref references it, it will directly inherit the serviceAccountName of this taskSpec, rigth?

https://github.com/tektoncd/pipeline/blob/83996138ff2ff2032b984fc9afa9abe38aeea6cc/config/config-defaults.yaml#L44-L46

chengjoey commented 1 month ago

/assign

ElSamhaa commented 1 month ago

Hi @chengjoey, thank you for your quick response. I'd suggest one or all of the following:

vdemeester commented 4 weeks ago

Hey @ElSamhaa @chengjoey,

The dynamic parameters live in the pipelinerun while the more often usable config lives in the pipeline.

So the fact that it is not possible today is by design. Pipeline (and Task) are definition types, meant to be shareable, across different environment (cluster, teams, company, …). It's not really dynamic versus … but definition versus runtime. Any runtime specific information is on the PipelineRun. And the serviceAccount is a runtime information.

Adding serviceAccountName to a definition type make it less portable, because now, using this Pipeline (or Task) requires a specific serviceAccountName to be present — and the user has no context other than the name of the service account (what privileges or secrets the serviceAccount need, … he has to still figure it out).

How should tekton re-act if the serviceAccountName in the Pipeline is not present ? Do we fail when applying the Pipeline or do we fail when the PipelineRun is started ? Do we do a "fail to the default service account if the provided service account is not present" ?

In my opinion, there is a couple ways around this:

Now, adding to the above, the fact that many of the tekton pipeline users are on Openshift, we hit another limitation which is Openshift doesn't prompt for serviceAccounts for a pipelinerun on its web GUI (at least until Openshift 4.12).

This is a "client" limitation and should be reported here (SRVKP) (not that this is a known issue and a long-overdue one 😓 ).

ElSamhaa commented 4 weeks ago

Thanks @vdemeester for your comment. I understand this is by design as I could follow from former discussions. I hoped to provide some feedback and a different perspective nonetheless.

Thanks again for the active engagement from your side and for the great project :slightly_smiling_face: