Skip to content

fix: apply the run-level service account and security.service_account setting to task pods - #8414

Merged
pingsutw merged 2 commits into
flyteorg:mainfrom
jeffoodchain:fix/8241-run-service-account
Nov 16, 2026
Merged

pingsutw merged 2 commits into
flyteorg:mainfrom
jeffoodchain:fix/8241-run-service-account

Conversation

@jeffoodchain

Copy link
Copy Markdown
Contributor

Tracking issue

Closes #8241

Why are the changes needed?

A service account set on a run has no effect on task pods. The value is stored in
RunSpec.security_context.run_as.k8s_service_account, but every pod of the run uses the
default service account. On EKS the pod then has no IRSA role, and the task fails on its
first S3 access.

Three entry points are affected:

  • CLI: flyte run --service-account my-sa ...
  • SDK: flyte.with_runcontext(service_account="my-sa").run(...)
  • Setting: security.service_account at project or domain scope

The cause has three parts:

  • The executor reads the service account only from the task template. The actions service
    did not copy the run-level value into the task template.
  • A child action is created without a RunSpec. It inherits the run context from the
    TaskAction of its parent, and the CRD had no service account field.
  • applyRunSettings did not apply security.service_account.

What changes were proposed in this pull request?

The change follows the existing pattern of PodTemplateName.

  • CRD: add ServiceAccount to TaskActionSpec.
  • Root action: applyRunSpecToTaskAction copies the run-level service account from the
    RunSpec to the TaskAction.
  • Child action: inheritRunContextFromParentTaskAction copies it from the parent
    TaskAction.
  • Task template: the new applyServiceAccount writes it into the task template in
    embedTaskTemplate. A service account set on the task is kept. Other security context
    fields (IamRole, Secrets) are kept. The template is cloned before the write.
  • Setting: applyRunSettings uses security.service_account when the run sets no
    service account.

How was this patch tested?

Unit tests

  • actions/k8s: RunSpec to root TaskAction, parent to child, the rules of
    applyServiceAccount, and the serialized task template.
  • runs/service: four new cases in TestApplyRunSettings.
go test ./actions/k8s/ ./runs/service/ ./executor/pkg/plugin/

End to end on the devbox

I set up a testing flyte task:

import flyte

env = flyte.TaskEnvironment(name="sa_repro_d")

@env.task(service_account="task-sa")
async def child(n: int) -> int:
    return n + 1

@env.task
async def main(n: int) -> int:
    return await child(n)

I checked spec.serviceAccountName on each pod. The steps are in
"Setup process".

Case Task Run Setting main pod child pod
Baseline - - - default default
CLI --service-account - my-sa - my-sa my-sa
SDK with_runcontext - my-sa - my-sa my-sa
Setting only - - settings-sa settings-sa settings-sa
Run and setting - my-sa settings-sa my-sa my-sa
Task, run, and setting child: task-sa my-sa settings-sa my-sa task-sa
Task and setting child: task-sa - settings-sa settings-sa task-sa
Setting removed - - - default default

Labels

  • fixed

Setup process

  1. Build and start the devbox from this branch.

    make devbox-build
    make devbox-run
  2. Create the service accounts. Task pods run in the flyte namespace on the devbox.

    kubectl create sa my-sa -n flyte
    kubectl create sa settings-sa -n flyte
    kubectl create sa task-sa -n flyte
  3. Create wf.py.

    import flyte
    
    env = flyte.TaskEnvironment(name="sa_repro")
    
    @env.task
    async def child(n: int) -> int:
        return n + 1
    
    @env.task
    async def main(n: int) -> int:
        return await child(n)
  4. Start a run for each case.

    flyte create config --endpoint localhost:30080 --insecure --builder local \
      --project flytesnacks --domain development
    
    # Run-level service account
    flyte run --service-account my-sa wf.py main --n 1
    
    # Setting
    echo 'security.service_account: settings-sa' > settings.yaml
    flyte edit settings -p flytesnacks -d development --from-file settings.yaml
    flyte run wf.py main --n 1

    For the task-level cases, change child to @env.task(service_account="task-sa").

  5. Check the result.

    kubectl get taskactions -n flyte \
      -o custom-columns=NAME:.metadata.name,TASK:.spec.shortName,PARENT:.spec.parentActionName,SA:.spec.serviceAccount
    kubectl get pods -n flyte \
      -o custom-columns=NAME:.metadata.name,SA:.spec.serviceAccountName,STATUS:.status.phase

Screenshots

Not applicable. This PR has no UI change.

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Stack

If you do use git town to manage PR Stacks, the stack relevant to this PR
will show below. Otherwise, you can ignore this section.

Docs link

Not applicable. This PR does not change the documentation.

Signed-off-by: Jeff Chung <sh1001309@gmail.com>
Signed-off-by: Jeff Chung <sh1001309@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T12:11:50.357506Z c942b56 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jeffoodchain

Copy link
Copy Markdown
Contributor Author

This is not yet tested on IRSA and S3 access on EKS, might need some help cc @marrrcin @popojk Thanks a lot!

@pingsutw
pingsutw merged commit ecbacd3 into flyteorg:main Nov 16, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [V2] Run-level service account (--service-account / with_runcontext) and security.service_account setting are ignored for task pods

2 participants