Repository navigation
fix(github): match trusted owner lists without regard to case #629
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 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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package policies_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "sort" | ||
| "testing" | ||
|
|
||
| opaengine "github.com/getplumber/plumber/internal/engine/opa" | ||
| "github.com/getplumber/plumber/internal/ir" | ||
| "github.com/getplumber/plumber/policies" | ||
| ) | ||
|
|
||
| // TestTrustedOwnerLists_IgnoreCase pins that the trusted lists of the | ||
| // pin-by-SHA control (trustedOwners, ISSUE-701) and the authorized-source | ||
| // control (trustedGithubActions and the official owners, ISSUE-713) match | ||
| // the owner and repository of a reference without regard to case, as | ||
| // GitHub resolves them (#623). A path below the repository stays | ||
| // case-sensitive: `myorg/tools/sub` does not cover `myorg/tools/Sub/...`. | ||
| func TestTrustedOwnerLists_IgnoreCase(t *testing.T) { | ||
| engine := opaengine.New() | ||
| if err := engine.LoadFromFSFiltered(policies.FS, nil); err != nil { | ||
| t.Fatalf("load embedded policies: %v", err) | ||
| } | ||
| cfg := map[string]any{ | ||
| "githubActionMustComeFromAuthorizedSources": map[string]any{ | ||
| "trustGithubOfficialActions": true, | ||
| "trustSameOrgActions": false, | ||
| "minimumStars": 0, | ||
| "trustedGithubActions": []any{"someowner/*", "acme/deploy", "myorg/*"}, | ||
| }, | ||
| "actionsMustBePinnedByCommitSha": map[string]any{ | ||
| "trustedOwners": []any{"actions", "github", "someowner", "myorg/tools/sub"}, | ||
| }, | ||
| } | ||
| pipeline := &ir.NormalizedPipeline{ | ||
| Provider: ir.ProviderGitHub, | ||
| ProjectPath: "scanned/repo", | ||
| Jobs: []ir.Job{ | ||
| {Name: "ci/build", Uses: []ir.Action{ | ||
| {Uses: "SomeOwner/some-action@v1", Line: 10}, | ||
| {Uses: "someowner/other-action@v1", Line: 11}, | ||
| {Uses: "Actions/checkout@v4", Line: 12}, | ||
| {Uses: "GITHUB/codeql-action/init@v3", Line: 13}, | ||
| {Uses: "ACME/Deploy@v1", Line: 14}, | ||
| {Uses: "MYORG/Tools/sub/x@v1", Line: 15}, | ||
|
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. π΄ Test coverageLow: The Rego _is_trusted_owner owner/repo case-folding (lower(want)) is never tested against a mixed-case trustedOwners entry, unlike its Go counterpart. (Low)
The Go mirror is tested in both directions β Suggested test: extend the ISSUE-701 case in Control: |
||
| {Uses: "myorg/tools/Sub/x@v1", Line: 16}, | ||
| {Uses: "other/thing@v1", Line: 17}, | ||
| }}, | ||
| {Name: "ci/shared", ReusableWorkflowUses: "SomeOwner/repo/.github/workflows/x.yml@v1"}, | ||
| {Name: "ci/foreign", ReusableWorkflowUses: "other/repo/.github/workflows/x.yml@v1"}, | ||
| }, | ||
| } | ||
| findings, err := evaluateStrict(engine, context.Background(), pipeline, cfg) | ||
| if err != nil { | ||
| t.Fatalf("evaluate: %v", err) | ||
| } | ||
| hits := map[string][]string{} | ||
| for _, f := range findings { | ||
| if f.Code != "ISSUE-713" && f.Code != "ISSUE-701" { | ||
| continue | ||
| } | ||
| uses, _ := f.Data["uses"].(string) | ||
| hits[f.Code] = append(hits[f.Code], uses) | ||
| } | ||
| want := map[string][]string{ | ||
| "ISSUE-701": {"ACME/Deploy@v1", "myorg/tools/Sub/x@v1", "other/repo/.github/workflows/x.yml@v1", "other/thing@v1"}, | ||
| "ISSUE-713": {"other/repo/.github/workflows/x.yml@v1", "other/thing@v1"}, | ||
| } | ||
| for code, w := range want { | ||
| got := hits[code] | ||
| sort.Strings(got) | ||
| if !stringSlicesEqual(got, w) { | ||
| t.Errorf("%s: got %v, want %v", code, got, w) | ||
| } | ||
| } | ||
| } | ||
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.
π΄ Test coverage
Medium: No test exercises a mixed-case trustedGithubActions entry matching a differently-cased ref, so the lower(pattern) normalization that the default config now depends on is untested. (Medium)
_in_allowlistwas changed toglob.match(lower(pattern), ["/"], lower(_owner_repo_of(uses)))(policies/action_authorized_sources.rego:270), lowering both the pattern and the subject. In the same PR,defaultConfig/.plumber.yamldeletes every lowercase case-alias (azure/*,sonarsource/*,datadog/*,1password/*,pyo3/*, β¦) and keeps only the mixed-case canonical entries (Azure/*,SonarSource/*,DataDog/*,1Password/*,PyO3/*). That deletion is only correct becauselower(pattern)normalizes the pattern side so a lowercase workflow ref still matches a mixed-case entry.However, no test covers that direction. Every ISSUE-713 test uses already-lowercase
trustedGithubActionsentries:policies/trusted_owner_case_test.go:29β["someowner/*", "acme/deploy", "myorg/*"]policies/rules_test.go:6827β["mycompany/*", "jdx/mise-action"],:6861β["mycompany/*"]Because the patterns are already lowercase,
lower(pattern)is a no-op in all of them: if a future refactor droppedlower(pattern)(keeping onlylower(uses)), every existing test would still pass. The regression would be concrete and reachable: with the shipped default config, a workflow stepuses: azure/login@v1(lowercase owner, a common real-world form) would stop matching the mixed-case default entryAzure/*βglob.match("Azure/*", "azure/login")is false β and would be flagged ISSUE-713 "unauthorized source" even though Azure is trusted by default.Suggested test: add an ISSUE-713 case with a mixed-case allowlist entry and a lower/other-cased ref, e.g.
trustedGithubActions: ["Azure/*", "SonarSource/sonarcloud-github-action"]withuses: azure/login@v1anduses: sonarsource/sonarcloud-github-action@v2, asserting neither is flagged (and a same-owner non-member likeazure-foo/x@v1is flagged). This locks thelower(pattern)half that the default config relies on.Control:
.github/claude-prompts/test-coverage.mdΒ· resolve this conversation once addressed.