-
Notifications
You must be signed in to change notification settings - Fork 125
fix: scope GitHub App token and deep-copy cached remote resources #2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -363,6 +363,17 @@ func (v *Provider) SetClient(ctx context.Context, run *params.Run, event *info.E | |
| // 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 { | ||
| // We need to keep the token unscoped until ScopeTokenToListOfRepos so that CreateToken can | ||
| // look up the extra repos from the configmap. | ||
| // 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an inconsistency in the URL passed to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gemini-code-assist
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the clarification. While the values are currently set to be the same in those specific functions, using |
||
| if err != nil { | ||
| return fmt.Errorf("failed to scope token to triggering repository: %w", err) | ||
| } | ||
| event.Provider.Token = scopedToken | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scoping logic here relies on
v.RepositoryIDsbeing populated, but this slice is currently only populated for Pull Request events (withinpopulateRunEventFromPullRequest). For other event types, such as Push,v.RepositoryIDsremains empty. Consequently, theelse ifblock 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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 641eadc