Skip to content

fix(policy): restore parsing of star-prefixed resources - #251

Merged
harshavardhana merged 2 commits into
minio:mainfrom
harshavardhana:fix/star-prefix-resource
Aug 1, 2026
Merged

fix(policy): restore parsing of star-prefixed resources#251
harshavardhana merged 2 commits into
minio:mainfrom
harshavardhana:fix/star-prefix-resource

Conversation

@harshavardhana

@harshavardhana harshavardhana commented Aug 1, 2026

Copy link
Copy Markdown
Member

Regression from #249.

Skipping the "*" entry while looping the ARN prefixes made every string that
merely starts with * fail to parse:

ParseResource("*"   ) -> type=* pattern="*" err=<nil>
ParseResource("**"  ) -> err=invalid resource '**'
ParseResource("*foo") -> err=invalid resource '*foo'

That breaks LoadPolicy for any stored policy using one. It surfaced in
aistor CI as an IAM authorization failure:

Error: invalid resource '**' (*grid.RemoteErr)
internal/grid/fanout.go:127:cmd.(*NotificationSys).LoadPolicy

The skip existed so a bare ARN prefix would stop parsing as the wildcard. That
property is unaffected: the exact string "*" is special-cased ahead of the
loop so its pattern stays "*" rather than the empty remainder, and a bare
prefix such as arn:aws:s3::: matches its own entry rather than the wildcard.

Verified by mutation — restoring the skip fails the new test on all three
inputs. make lint clean, full suite green.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of wildcard-prefixed resource patterns, including *, **, ***, and *foo.
    • Policies using wildcard resource patterns now validate correctly and permit the expected S3 access.

Skipping the "*" entry while looping the ARN prefixes made every string
that merely starts with "*" fail to parse. "**", "***" and "*foo" all
returned `invalid resource`, which broke LoadPolicy for any stored
policy using one and surfaced during IAM authorization as

    Error: invalid resource '**' (*grid.RemoteErr)
    internal/grid/fanout.go:127:cmd.(*NotificationSys).LoadPolicy

The skip was added so a bare ARN prefix would stop parsing as the
wildcard. That still holds without it: the exact string "*" is
special-cased ahead of the loop so its pattern stays "*" rather than the
empty remainder, and a bare prefix like "arn:aws:s3:::" matches its own
entry rather than the wildcard.

Regression test covers the parse and a whole policy carrying "**"
loading and matching.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@harshavardhana, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f174b323-e370-46ce-8593-a2eda20b788a

📥 Commits

Reviewing files that changed from the base of the PR and between 9e9d887 and 9ea5d37.

📒 Files selected for processing (5)
  • policy/condition/keyname.go
  • policy/memory-action.go
  • policy/memory-resource_test.go
  • policy/resource.go
  • policy/resource_corpus_test.go
📝 Walkthrough

Walkthrough

ParseResource now supports exact and prefixed wildcard resources. Regression tests cover parsing, validity, bare-ARN classification, policy validation, and S3 authorization.

Changes

Wildcard resource parsing

Layer / File(s) Summary
Resource parser and regression coverage
policy/resource.go, policy/memory-resource_test.go
ParseResource handles "*" directly and parses longer wildcard-prefixed strings with their suffix patterns. Tests verify parsing, validity, bare-ARN classification, policy loading, validation, and S3 authorization.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • minio/pkg#249: Both changes modify wildcard and bare-ARN parsing and validation in the same policy files.

Poem

A rabbit found stars in the policy night,
"*foo" and "**" parsed just right.
The ARN stayed bare, the patterns stayed clear,
S3 access hopped through without fear.
“Well tested,” I thumped, “the wildcards are here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the restored parsing behavior for resources that begin with "*".
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@policy/resource.go`:
- Around line 319-325: In policy/resource.go lines 319-325, replace the detailed
parsing-history comment with a brief explanation that the exact "*" branch is
handled separately so its pattern remains "*". In policy/memory-resource_test.go
lines 730-736, remove the failure-history comment or reduce it to a concise
regression rationale; make no other changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb43dcb4-2bd2-458f-b79e-8effab8e4d58

📥 Commits

Reviewing files that changed from the base of the PR and between 1083510 and 9e9d887.

📒 Files selected for processing (2)
  • policy/memory-resource_test.go
  • policy/resource.go

Comment thread policy/resource.go Outdated
A Memory list names a query, not a record, so the prefix cannot live in
the resource path. One ARN would mean a single record under
memory:GetAgent and every sibling sharing that prefix under
memory:ListAgents, and an operator writing both actions against one
resource would leak names with no cue that the string had changed
meaning.

Both keys are accepted only on the list actions. A read or a write has
no query to constrain, so accepting them there would let a policy look
scoped while constraining nothing -- the mistake now surfaces when the
policy is written rather than as a grant that silently does nothing.

Also add a corpus of every resource form the parser accepts. ParseResource
is shared by every ARN type, so a change made for one narrows what the
others take -- which is how the star-prefix regression reached main
through a green suite. Adding a form is a deliberate widening; removing
one breaks stored policies and now has to be argued rather than
discovered downstream.

The corpus found a pre-existing quirk on its first run: String() renders
the wildcard as its prefix plus its pattern, so "*" serializes to "**".
That is where the doubled form in stored policies comes from, and why
rejecting it broke real deployments rather than an exotic hand-written
value. The round-trip assertion checks stability rather than byte
identity and records the reason.
@harshavardhana
harshavardhana merged commit aa4efcb into minio:main Aug 1, 2026
11 checks passed
@harshavardhana
harshavardhana deleted the fix/star-prefix-resource branch August 1, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant