Skip to content

Keep the Step SecurityContext when the StepAction has none - #10657

Open
arpitjain099 wants to merge 1 commit into
tektoncd:mainfrom
arpitjain099:fix/stepaction-security-context-guard
Open

Keep the Step SecurityContext when the StepAction has none#10657
arpitjain099 wants to merge 1 commit into
tektoncd:mainfrom
arpitjain099:fix/stepaction-security-context-guard

Conversation

@arpitjain099

Copy link
Copy Markdown

Changes

resolveStepRef merges a resolved StepAction into the Step that referenced it, and every field is guarded so the StepAction only wins where it actually set something. SecurityContext is the exception:

resolvedStep.SecurityContext = stepFromStepAction.SecurityContext

A StepAction that leaves securityContext unset therefore overwrites the Step's with nil. StepActionSpec.SetDefaults only walks Params and Results, so nothing fills it in before the merge and the nil really does reach the assignment.

This guards it the same way Command, Args, Script, Env, VolumeMounts and Results already are.

Fixes #10634

/kind bug
/area api

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Existing coverage kept the "StepAction sets a securityContext" direction (step-action-with-security-context-overwritten); the new case is its sibling for the unset direction, with runAsUser, runAsNonRoot and readOnlyRootFilesystem on the Step. Without the guard it fails:

- SecurityContext: s"&SecurityContext{...RunAsUser:*1001,RunAsNonRoot:*true,ReadOnlyRootFilesystem:*true,...}"
+ SecurityContext: nil

go build ./..., go vet and go test ./pkg/reconciler/taskrun/... are clean.

Release Notes

Fixed a bug where referencing a StepAction that does not set `securityContext` cleared the `securityContext` set on the Step.

resolveStepRef guards every merged field so that a StepAction only overrides
the referencing Step where it actually sets a value, except SecurityContext,
which is assigned unconditionally. A StepAction that leaves SecurityContext
unset therefore replaces the Step's with nil, dropping settings such as
runAsNonRoot and readOnlyRootFilesystem without any indication.

StepActionSpec.SetDefaults only walks Params and Results, so nothing fills
SecurityContext in before the merge.

Guard the assignment the same way Command, Args, Script, Env, VolumeMounts
and Results are already guarded, and add a case to TestGetStepActionsData
covering a StepAction with no SecurityContext.

Fixes tektoncd#10634

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. area/api Indicates an issue or PR that deals with the API. labels Aug 25, 2026
@tekton-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign abayer after the PR has been reviewed.
You can assign the PR to them by writing /assign @abayer in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api Indicates an issue or PR that deals with the API. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guard SecurityContext assignment in StepAction merge (resolveStepRef) to prevent silent nil-overwrite

2 participants