Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/testdata/catalog_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"name": "trustedOwners",
"type": "array",
"optional": true,
"description": "List of action-owner prefixes exempt from the pin-by-SHA requirement; only owners already inside the workflow's trust boundary should be listed.",
"description": "List of action-owner prefixes exempt from the pin-by-SHA requirement, the owner and repository matched case-insensitively; only owners already inside the workflow's trust boundary should be listed.",
"elem": {
"type": "string",
"optional": false
Expand Down Expand Up @@ -826,7 +826,7 @@
"name": "trustedGithubActions",
"type": "array",
"optional": true,
"description": "Lists action sources that are always allowed; each entry is an exact owner/repo or an owner/* wildcard.",
"description": "Lists action sources that are always allowed; each entry is an exact owner/repo or an owner/* wildcard, matched case-insensitively.",
"elem": {
"type": "string",
"optional": false
Expand Down
4 changes: 2 additions & 2 deletions configuration/schema_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var controlFieldDocs = map[string]FieldDoc{
Description: "Turns the control on; when false or absent the control is skipped.",
},
"actionsMustBePinnedByCommitSha.trustedOwners": {
Description: "List of action-owner prefixes exempt from the pin-by-SHA requirement; only owners already inside the workflow's trust boundary should be listed.",
Description: "List of action-owner prefixes exempt from the pin-by-SHA requirement, the owner and repository matched case-insensitively; only owners already inside the workflow's trust boundary should be listed.",
},
"componentMustComeFromAuthorizedSources.enabled": {
Description: "Turns the control on; when false or absent the control is skipped.",
Expand Down Expand Up @@ -293,7 +293,7 @@ var controlFieldDocs = map[string]FieldDoc{
Default: "0",
},
"githubActionMustComeFromAuthorizedSources.trustedGithubActions": {
Description: "Lists action sources that are always allowed; each entry is an exact owner/repo or an owner/* wildcard.",
Description: "Lists action sources that are always allowed; each entry is an exact owner/repo or an owner/* wildcard, matched case-insensitively.",
},
"githubActionMustComeFromAuthorizedSources.includePlumberDefaults": {
Description: "In overlay mode, unions Plumber's curated default trusted list with trustedGithubActions; set false to trust only the listed entries; ignored in legacy mode.",
Expand Down
23 changes: 21 additions & 2 deletions control/github_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,35 @@ func ownerOf(ref string) string {
return ""
}

// isTrustedOwner mirrors _is_trusted_owner in action_unpinned.rego:
// the reference sits below an entry (`owner`, `owner/repo` or a deeper
// path). Owner and repository compare without regard to case, as GitHub
// resolves them; a path below them compares exactly. strings.ToLower
// matches Rego's lower().
func isTrustedOwner(ref string, trustedOwners []string) bool {
owner := ownerOf(ref)
head := strings.Split(strings.SplitN(ref, "@", 2)[0], "/")
for _, t := range trustedOwners {
if owner == t {
prefix := strings.Split(t, "/")
if len(head) > len(prefix) && segmentsMatch(prefix, head) {
return true
}
}
return false
}

func segmentsMatch(prefix, head []string) bool {
for i, want := range prefix {
got := head[i]
if i < 2 {
want, got = strings.ToLower(want), strings.ToLower(got)
}
if want != got {
return false
}
}
return true
}

func isShaPinned(ref string) bool {
return shaRefRegex.MatchString(ref)
}
Expand Down
60 changes: 60 additions & 0 deletions control/github_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,66 @@ func TestAggregate_UppercaseShaCountsAsPinned(t *testing.T) {
}
}

// TestAggregate_TrustedOwnersIgnoreCase locks the action-pinning counter
// to _is_trusted_owner in action_unpinned.rego, which compares the owner
// without regard to case (#623): `Actions/checkout@v4` is a trusted
// owner's reference and stays out of the counted refs.
func TestAggregate_TrustedOwnersIgnoreCase(t *testing.T) {
pipeline := &ir.NormalizedPipeline{
Jobs: []ir.Job{
{
Name: "build",
Uses: []ir.Action{
{Uses: "Actions/checkout@v4"},
{Uses: "someowner/somerepo@v4"}, // the only third-party ref
},
},
},
}
pc := &configuration.PlumberConfig{GitHub: &configuration.ProviderConfig{}}
stats := AggregateGitHubStats(pipeline, pc)

if stats.ActionRefsTotal != 1 || stats.ActionRefsUnpinned != 1 {
t.Fatalf("ActionRefsTotal = %d, ActionRefsUnpinned = %d, want 1 and 1 (Actions/ is the trusted owner actions)", stats.ActionRefsTotal, stats.ActionRefsUnpinned)
}
}

// TestAggregate_TrustedOwnersMatchLikeRego locks the counter to the
// entry forms _is_trusted_owner accepts: an owner, `owner/repo` or a
// deeper path, the owner and repository compared without regard to
// case, a path below them exactly (#623).
func TestAggregate_TrustedOwnersMatchLikeRego(t *testing.T) {
pipeline := &ir.NormalizedPipeline{
Jobs: []ir.Job{
{
Name: "build",
Uses: []ir.Action{
{Uses: "myorg/x@v1"}, // under MyOrg
{Uses: "ACME/Deploy/sub@v1"}, // under acme/deploy
{Uses: "acme/deploy@v1"}, // the entry itself: nothing below it
{Uses: "Tools/Kit/lib/a@v1"}, // under tools/kit/lib
{Uses: "tools/kit/Lib/a@v1"}, // path differs in case
{Uses: "other/thing@v1"}, // not trusted
},
},
},
}
pc := &configuration.PlumberConfig{
GitHub: &configuration.ProviderConfig{
Controls: configuration.ControlsConfig{
ActionsMustBePinnedByCommitSha: &configuration.ActionsPinnedByShaControlConfig{
TrustedOwners: []string{"MyOrg", "acme/deploy", "tools/kit/lib"},
},
},
},
}
stats := AggregateGitHubStats(pipeline, pc)

if stats.ActionRefsTotal != 3 {
t.Fatalf("ActionRefsTotal = %d, want 3 (acme/deploy@v1, tools/kit/Lib/a@v1, other/thing@v1)", stats.ActionRefsTotal)
}
}

// TestAggregate_ActionRefsAbsentUpstreamCounter locks the ISSUE-707
// "Impostor Refs Found" metric to what the rego actually flags. The
// counter is deliberately guarded by isShaPinned β€” unlike its sibling
Expand Down
21 changes: 1 addition & 20 deletions defaultConfig/.plumber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ github:
trustGithubOfficialActions: true # actions/* and github/*
trustSameOrgActions: true # action owner == scanned repo owner
minimumStars: 20000 # popular-by-adoption floor (requires API access)
# Owner matching is literal and CASE-SENSITIVE, so mixed-case orgs are
# listed in both their canonical and lowercase forms.
# Owner and repository match without regard to case, as on GitHub.
trustedGithubActions:
# ── Cloud providers ──────────────────────────────────────────
- aws-actions/* # Amazon Web Services
Expand Down Expand Up @@ -977,24 +976,6 @@ github:
- qltysh/* # Qlty Software
- flatpak/* # Flatpak project
- peter-evans/* # Peter Evans (widely-adopted PR/comment actions; pin by SHA)
# ── Lowercase case-aliases (literal matcher is case-sensitive) ──
- azure/* # = Azure/*
- sonarsource/* # = SonarSource/*
- datadog/* # = DataDog/*
- jetbrains/* # = JetBrains/*
- shopify/* # = Shopify/*
- gitguardian/* # = GitGuardian/*
- checkmarx/* # = Checkmarx/*
- qualys/* # = Qualys/*
- circleci-public/* # = CircleCI-Public/*
- virtuslab/* # = VirtusLab/*
- nuget/* # = NuGet/*
- determinatesystems/* # = DeterminateSystems/*
- 1password/* # = 1Password/*
- apple-Actions/* # mixed-case form of apple-actions/*
- embarkstudios/* # = EmbarkStudios/*
- pyo3/* # = PyO3/*
- homebrew/* # = Homebrew/*

# ===========================================
# Container images must not use forbidden reference
Expand Down
10 changes: 7 additions & 3 deletions docs/GITHUB_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ so they are reported as they would be without any lockfile.
**Config.** Enabled by default in the generated `.plumber.yaml`.
`trustedOwners: [actions, github]` exempts first-party GitHub-owned
actions so the initial signal stays focused on the third-party
surface. Pair with Dependabot
surface. Owner and repository match without regard to case, as GitHub
resolves them: `actions` covers `Actions/checkout`. An entry with a
path below the repository matches that path exactly. Pair with Dependabot
(`version-update-strategy: sha-and-version`) to keep pins fresh, or
set `enabled: false` on projects that are not yet ready to migrate.

Expand Down Expand Up @@ -477,13 +479,15 @@ surface.
An action is **trusted** when any of these hold:

- `trustGithubOfficialActions` (default `true`) covers `actions/*` and
`github/*`, the first-party owners every workflow already trusts.
`github/*`, the first-party owners every workflow already trusts,
whatever the case of the owner.
- `trustSameOrgActions` (default `true`) covers actions whose owner is
the same org/user as the scanned repository β€” an org's own actions are
inside its trust boundary. Owner match is case-insensitive; it abstains
when the scanned repo's owner is unknown.
- its `owner/repo` matches an entry in `trustedGithubActions` β€” either
an exact `owner/repo` or an `owner/*` whole-org wildcard.
an exact `owner/repo` or an `owner/*` whole-org wildcard, matched
case-insensitively.
- `minimumStars` is set and the action's upstream repository has at
least that many stars. This catches the rename/re-creation squat
where a once-trusted name is re-registered with no history. It needs
Expand Down
14 changes: 9 additions & 5 deletions policies/action_authorized_sources.rego
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# org/user as the scanned repository (input.pipeline.projectPath).
# An org's own actions are already inside its trust boundary.
# input.config.githubActionMustComeFromAuthorizedSources.trustedGithubActions
# Allowlist of `owner/repo` (exact) or `owner/*` (whole-org wildcard).
# Allowlist of `owner/repo` (exact) or `owner/*` (whole-org wildcard),
# matched case-insensitively like the official owners.
# input.config.githubActionMustComeFromAuthorizedSources.minimumStars
# When > 0, trust any action whose upstream repo has >= this many
# stars. Driven by collect-time API metadata; when the star count is
Expand Down Expand Up @@ -101,11 +102,12 @@ _authorized(action) if _in_allowlist(action.uses)

_authorized(action) if _has_enough_stars(action)

# First-party GitHub-owned actions, when the user trusts them.
# First-party GitHub-owned actions, when the user trusts them. Owner
# comparison is case-insensitive, as GitHub resolves it.
_is_official(uses) if {
input.config.githubActionMustComeFromAuthorizedSources.trustGithubOfficialActions == true
owner := _owner_of(uses)
owner in {"actions", "github"}
lower(owner) in {"actions", "github"}
}

# Same-org actions: trust an action whose owner is the org/user that
Expand All @@ -124,10 +126,12 @@ _is_same_org(uses) if {
# Allowlist match. Patterns are matched against `owner/repo` with `/` as
# a glob delimiter, so `owner/*` trusts a whole org and `owner/repo`
# matches exactly. Path-scoped composite refs (`owner/repo/path@ref`)
# collapse to `owner/repo` before matching.
# collapse to `owner/repo` before matching. Both sides are lowered:
# GitHub resolves the owner and repository without regard to case, and
# the subject never carries a path or a ref (#623).
_in_allowlist(uses) if {
some pattern in input.config.githubActionMustComeFromAuthorizedSources.trustedGithubActions
glob.match(pattern, ["/"], _owner_repo_of(uses))
glob.match(lower(pattern), ["/"], lower(_owner_repo_of(uses)))
}

# Minimum-stars floor. Abstains when the threshold is 0 (disabled) or
Expand Down
22 changes: 21 additions & 1 deletion policies/action_unpinned.rego
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,27 @@ _is_local(uses) if {
startswith(uses, "docker://")
}

# _is_trusted_owner: the reference sits below a trustedOwners entry
# (`owner`, `owner/repo` or a deeper path). GitHub resolves the owner
# and repository without regard to case, so those two segments compare
# case-insensitively; a path below them compares exactly. The ref is cut
# off first: an entry never names one (#623).
_is_trusted_owner(uses) if {
some trusted in input.config.actionsMustBePinnedByCommitSha.trustedOwners
startswith(uses, sprintf("%s/", [trusted]))
prefix := split(trusted, "/")
head := split(split(uses, "@")[0], "/")
count(head) > count(prefix)
every i, want in prefix {
_segment_matches(i, want, head[i])
}
}

_segment_matches(i, want, got) if {
i < 2
lower(want) == lower(got)
}

_segment_matches(i, want, got) if {
i >= 2
want == got
}
76 changes: 76 additions & 0 deletions policies/trusted_owner_case_test.go
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/*"},

Copy link
Copy Markdown

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_allowlist was changed to glob.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.yaml deletes 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 because lower(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 trustedGithubActions entries:

  • 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 dropped lower(pattern) (keeping only lower(uses)), every existing test would still pass. The regression would be concrete and reachable: with the shipped default config, a workflow step uses: azure/login@v1 (lowercase owner, a common real-world form) would stop matching the mixed-case default entry Azure/* β€” 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"] with uses: azure/login@v1 and uses: sonarsource/sonarcloud-github-action@v2, asserting neither is flagged (and a same-owner non-member like azure-foo/x@v1 is flagged). This locks the lower(pattern) half that the default config relies on.

Control: .github/claude-prompts/test-coverage.md Β· resolve this conversation once addressed.

},
"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},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ”΄ Test coverage

Low: 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)

_segment_matches for i<2 compares lower(want) == lower(got) (policies/action_unpinned.rego:216-219), where want is a trustedOwners entry segment. The only Rego test for this (policies/trusted_owner_case_test.go:45) configures trustedOwners: ["actions", "github", "someowner", "myorg/tools/sub"] β€” all lowercase. Matching those against mixed-case refs (SomeOwner/..., MYORG/Tools/...) only exercises lowering the ref side (lower(got)); the entry side is already lowercase, so lower(want) is a no-op here. A regression that changed the comparison to want == lower(got) would pass every Rego test.

The Go mirror is tested in both directions β€” TestAggregate_TrustedOwnersMatchLikeRego (control/github_stats_test.go:143) uses mixed-case entries ["MyOrg", "acme/deploy", "tools/kit/lib"] β€” so the Go segmentsMatch entry-lowering is covered but the Rego one is not, leaving the two implementations' coverage asymmetric for a user who configures a mixed-case trustedOwners entry (e.g. MyOrg).

Suggested test: extend the ISSUE-701 case in trusted_owner_case_test.go with a mixed-case entry such as "MyOrg" and a ref myorg/x@v1 (lowercase owner), asserting it is exempt/not flagged, mirroring the Go test.

Control: .github/claude-prompts/test-coverage.md Β· resolve this conversation once addressed.

{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)
}
}
}