Repository navigation
Allow explicit wildcard GitHub App repositories in strict mode #66039
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
Changes from 1 commit
d6a22f9
3803aa5
725a850
bf9baf3
bac8c5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,27 @@ import ( | |
| "github.com/github/gh-aw/pkg/console" | ||
| ) | ||
|
|
||
| type appTokenStepKey struct { | ||
| id, clientID, privateKey string | ||
| } | ||
|
|
||
| func (c *Compiler) hasGeneratedWildcardAppTokenStep(step, with map[string]any) bool { | ||
| id, ok := step["id"].(string) | ||
| if !ok { | ||
| return false | ||
| } | ||
| clientID, ok := with["client-id"].(string) | ||
| if !ok { | ||
| return false | ||
| } | ||
| privateKey, ok := with["private-key"].(string) | ||
| if !ok { | ||
| return false | ||
| } | ||
| return id != "" && clientID != "" && privateKey != "" && | ||
| c.wildcardAppTokenSteps[appTokenStepKey{id, clientID, privateKey}] | ||
|
Contributor
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. Confirmed: the wildcard exemption can be spoofed by an unrelated, custom step.
This defeats the stated safeguard: "Continue requiring explicit Suggested fix: track provenance via an identity that user-authored steps can't fabricate, e.g.:
@copilot please address this.
Contributor
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. Fixed in
Contributor
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. [/codebase-design] The existing Copilot review comment on this line is correct and worth confirming: 💡 Suggested fixScope the key to the job as well, e.g. @copilot please address this.
Contributor
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. Fixed in |
||
| } | ||
|
|
||
| func hasExplicitAppTokenPermission(with map[string]any) bool { | ||
| for key, value := range with { | ||
| if !strings.HasPrefix(strings.ToLower(key), "permission-") { | ||
|
|
@@ -68,7 +89,7 @@ func (c *Compiler) validateAppTokenPermissions(workflow map[string]any, strict b | |
| if !ok { | ||
| with = nil | ||
| } | ||
| if !hasExplicitAppTokenRepositories(with) { | ||
| if !hasExplicitAppTokenRepositories(with) && !c.hasGeneratedWildcardAppTokenStep(step, with) { | ||
| msg := fmt.Sprintf("actions/create-github-app-token in job %q has no explicit repositories input; add repositories: ${{ github.repository }} to scope the token to the current repository", jobName) | ||
| if strict { | ||
| return fmt.Errorf("strict mode: %s", msg) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,6 +426,16 @@ func appendGitHubAppTokenRepositoryInput(steps []string, app *GitHubAppConfig, f | |
|
|
||
| func (c *Compiler) buildGitHubAppTokenMintStepWithMeta(app *GitHubAppConfig, permissions *Permissions, fallbackRepoExpr string, ownerSourceRepository string, stepName string, stepID string) []string { | ||
| safeOutputsAppLog.Printf("Building GitHub App token mint step: owner=%s, repos=%d", app.Owner, len(app.Repositories)) | ||
| if len(app.Repositories) == 1 { | ||
|
Contributor
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. [/tdd] Side effect ( 💡 Suggested testAdd a case (or a table-driven loop) exercising at least one more caller path — e.g. @copilot please address this.
Contributor
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. Fixed in |
||
| for _, repository := range app.Repositories { | ||
| if repository == "*" { | ||
| if c.wildcardAppTokenSteps == nil { | ||
| c.wildcardAppTokenSteps = make(map[appTokenStepKey]bool) | ||
| } | ||
| c.wildcardAppTokenSteps[appTokenStepKey{stepID, app.AppID, app.PrivateKey}] = true | ||
| } | ||
| } | ||
| } | ||
| var steps []string | ||
|
|
||
| owner, ownerSteps := resolveGitHubAppOwner(app, ownerSourceRepository, stepName, stepID) | ||
|
|
||
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.
Fixed in
bac8c5f: wildcard exemptions are now scoped to the containing job and matched step metadata, with only one matching step allowed to consume the exemption. Regression tests cover same-job and cross-job spoofing.