fix: scope GitHub App token and deep-copy cached remote resources#2705
fix: scope GitHub App token and deep-copy cached remote resources#2705theakshaypant wants to merge 2 commits intotektoncd:mainfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2705 +/- ##
==========================================
- Coverage 59.00% 58.97% -0.03%
==========================================
Files 208 208
Lines 20436 20446 +10
==========================================
Hits 12059 12059
- Misses 7603 7612 +9
- Partials 774 775 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces resource deep-copying during remote resolution to prevent cache mutation when multiple PipelineRuns share the same remote pipeline or task. It also adds logic to scope GitHub App tokens to specific repositories when no explicit token is provided. Review feedback highlights a security concern where token scoping is bypassed for non-Pull Request events due to unpopulated repository IDs, and an inconsistency in the URL used for token generation that could affect GitHub Enterprise installations.
| // If Global and Repo level configurations are not provided then lets not override the provider token. | ||
| if token != "" { | ||
| event.Provider.Token = token | ||
| } else if len(v.RepositoryIDs) > 0 { |
There was a problem hiding this comment.
The scoping logic here relies on v.RepositoryIDs being populated, but this slice is currently only populated for Pull Request events (within populateRunEventFromPullRequest). For other event types, such as Push, v.RepositoryIDs remains empty. Consequently, the else if block is skipped, and the token remains unscoped (having access to all repositories in the installation). This defeats the security objective of the PR for non-PR event types.
| // Token is scoped to only the calling repo if no additional scoping repos are configured | ||
| // so that no unwanted remote tasks are executed. | ||
| ns := info.GetNS(ctx) | ||
| scopedToken, err := v.GetAppToken(ctx, run.Clients.Kube, event.Provider.URL, event.InstallationID, ns) |
There was a problem hiding this comment.
There is an inconsistency in the URL passed to GetAppToken. This call uses event.Provider.URL (the API URL, e.g., https://api.github.com/ or https://ghe.example.com/api/v3), whereas the initial token generation in InitAppClient (line 191) uses event.GHEURL (the base URL). For GitHub Enterprise installations, this discrepancy may lead to authentication failures or incorrect API endpoint resolution depending on how the underlying GetAppToken implementation handles the host/URL argument.
There was a problem hiding this comment.
@gemini-code-assist event.GHEURL and event.Provider.URL values are set to be same in
buildEventFromPipelineRunParsePayload
There was a problem hiding this comment.
Thank you for the clarification. While the values are currently set to be the same in those specific functions, using event.Provider.URL in GetAppToken introduces a dependency on the provider's API URL for token generation, whereas event.GHEURL is explicitly intended for base URL resolution. If event.Provider.URL is ever modified or configured differently (e.g., for specific API sub-paths), this could lead to authentication issues. Using event.GHEURL is safer and more consistent with the existing implementation in InitAppClient.
Reissue a scoped token in SetClient when no extra scope config is present. The initial token is created before RepositoryIDs are populated, so it has access to all repos in the installation. After ScopeTokenToListOfRepos returns empty, fall back to GetAppToken which now uses the populated RepositoryIDs. Signed-off-by: Akshay Pant <akpant@redhat.com>
Use DeepCopy when reusing cached Pipeline and Task objects across PipelineRuns. Without this, inlineTasks mutates the cached original, contaminating subsequent runs that reference the same remote pipeline. Assisted-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Akshay Pant <akpant@redhat.com>
9c0c99a to
bfb63c6
Compare
📝 Description of the Change
🔗 Linked GitHub Issue
N/A
🧪 Testing Strategy
Github App token scoping
akshay-pac-test-repoandjj-testakshay-pac-test-repopipelinerun references pipeline defined injj-test.jj-testwithout any extra config.Remote-pipeline Task Mutation
akshay-pac-test-repodefines 2 pipelineruns with the same remote pipeline def injj-testsecond-runuses a local definition ofmy-taskwhilefirst-runuses a remote definition.🤖 AI Assistance
AI assistance can be used for various tasks, such as code generation,
documentation, or testing.
Please indicate whether you have used AI assistance
for this PR and provide details if applicable.
Important
Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Claude noreply@anthropic.com
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.