Skip to content

feat(bucketpolicy): add the bucket policy and its evaluation - #60

Draft
pyropy wants to merge 3 commits into
srdjan/feat/iam-principal-storefrom
srdjan/feat/iam-policy-package
Draft

pyropy wants to merge 3 commits into
srdjan/feat/iam-principal-storefrom
srdjan/feat/iam-policy-package

Conversation

@pyropy

@pyropy pyropy commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Adds pkg/bucketpolicy, the pure policy document package: validation, evaluation, and a canonical form whose lists are sets. The ETag is the CID of the document's DAG-CBOR encoding.

  • Decode, Validate, Canonical, ETag
  • Effective (allow minus deny), Named, Changed
  • Hand-written DAG-CBOR encoder; table tests

🤖 Generated with Claude Code

@pyropy
pyropy added this pull request to stack #62 September 10, 2026 16:30
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from d4024b1 to f797e0f Compare September 11, 2026 10:37
@pyropy
pyropy removed this pull request from stack #62 September 11, 2026 10:38
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from f797e0f to 75af1ea Compare September 11, 2026 10:59
@pyropy
pyropy added this pull request to stack #71 September 11, 2026 10:59
@pyropy
pyropy requested a lite review from Copilot September 11, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Exclude * from queried principals in Effective and add the corresponding test.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a pure bucket-policy package for validation, canonical ETags, permission evaluation, and change detection.

Changes:

  • Defines policy documents, statements, effects, and validation rules.
  • Implements canonical JSON, SHA-256 ETags, effective permissions, and change tracking.
  • Adds table-driven tests.
File summaries
File Summary
pkg/policy/policy.go Implements policy validation, canonicalization, evaluation, and change detection. Moderate issue (2 votes): Effective treats * as a queryable principal.
pkg/policy/policy_test.go Tests policy validation, canonicalization, ETags, evaluation, and change detection.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/bucketpolicy/bucketpolicy.go Outdated
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 75af1ea to 8c144d5 Compare September 11, 2026 12:46
@pyropy pyropy changed the title feat(policy): add the bucket policy document and its evaluation feat(bucketpolicy): add the bucket policy and its evaluation Sep 11, 2026
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch 2 times, most recently from 2821817 to 7ecf429 Compare September 16, 2026 14:11
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 7ecf429 to 1133cac Compare September 16, 2026 14:49
@pyropy
pyropy requested a lite review from Copilot September 16, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pyropy

pyropy commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T16:55:03.826051Z d2aa4d1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1133cac89e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/bucketpolicy/bucketpolicy.go
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 1133cac to 6c425fc Compare September 17, 2026 13:34
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch 2 times, most recently from a981176 to fac3ea6 Compare September 22, 2026 14:17
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from fac3ea6 to 6dc5b91 Compare September 23, 2026 10:29
@pyropy
pyropy marked this pull request as ready for review September 23, 2026 11:11
@pyropy
pyropy requested a review from a team September 23, 2026 11:14
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 6dc5b91 to fac3ea6 Compare September 23, 2026 11:55
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from fac3ea6 to 48cfce0 Compare September 23, 2026 11:55
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 48cfce0 to aa5a4df Compare September 24, 2026 11:34
@pyropy
pyropy removed this pull request from stack #71 September 24, 2026 11:48
@pyropy
pyropy added this pull request to stack #86 September 24, 2026 11:49
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch 2 times, most recently from 816e5d7 to 385868a Compare September 25, 2026 15:58
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from 385868a to a038ddb Compare September 25, 2026 16:31
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from a038ddb to d2aa4d1 Compare September 28, 2026 13:44
@pyropy

pyropy commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2aa4d164b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
var d Policy
if err := dec.Decode(&d); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject null statement IDs

When an otherwise valid policy contains "sid": null, encoding/json silently leaves the string field empty rather than reporting a type error. Validate does not inspect Sid, so Decode accepts this schema-invalid value and Canonical then omits it entirely instead of producing the documented 422 error; explicitly reject null for sid while still allowing the property to be absent.

Useful? React with 👍 / 👎.

@pyropy
pyropy marked this pull request as draft September 28, 2026 17:05
pyropy and others added 3 commits September 29, 2026 14:20
Adds pkg/bucketpolicy, a pure package with no store or transport
dependencies. Validate applies the RFC's 422 rules: at least one statement,
a recognized effect, non-empty principals and actions, actions from the
policy vocabulary (s3perm.PolicyAction), and named principals that exist for
the tenant. Canonical produces compact JSON in a fixed field order with
input order kept, and ETag is the quoted hex SHA-256 of that encoding, so
stored tags compare with If-Match values.

Effective computes a principal's actions on a bucket: the union of Allow
statements naming it or the wildcard, minus the union of Deny statements
naming it or the wildcard. Named lists the principals a policy names and
whether it uses the wildcard. Changed lists the principals whose effective
set differs between two policies, expanding the wildcard to the tenant's
principals, which is the set a policy write must invalidate. The wildcard is
not itself a principal: Effective is nil for "*", so only Changed expands it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A principal list naming an id twice decoded as given and was stored that
way. Decoding now keeps the first occurrence of each id, so every write path
that goes through Decode, the policy API and the CreateBucket header alike,
stores and tags the filtered document.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…r CID

The statement, principal and action lists are sets: Decode and Canonical
deduplicate and sort them, and Hilt stores and returns the sorted
document. The ETag is the CID (v1, dag-cbor, sha2-256) of the DAG-CBOR
encoding of that document, so two documents that differ only in order
or in duplicates carry the same tag.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@pyropy
pyropy force-pushed the srdjan/feat/iam-policy-package branch from d2aa4d1 to 98dde85 Compare September 29, 2026 15:22
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.

2 participants