Files
floci/src
Priamo Germosen b679fe2312 fix(s3): match a bucket policy's Principal the way IAM does in S3's own checks (#4961)
Follow-up from the reviews of #4838 and #4839.

S3 checks a bucket policy itself in two places, and neither matched its
Principal the way the IAM evaluator does since #4839:

- The signed-request check (s3.enforce-auth) passed the caller to the IAM
  evaluator as a bare ARN, so a role session was matched through a role ARN
  rebuilt from the session ARN, which drops the role's path. A bucket policy
  naming role/team/App never reached that role's sessions.
- The CopyObject/UploadPartCopy source check used S3's own matcher, which
  compared each AWS entry with the caller's ARN as a string. A grant to the
  caller's account, by id or root ARN, or to its role, never matched, so a
  cross-account caller allowed to read an object could not copy it.

Both now pass the typed caller to the IAM evaluator, a role session with the
ARN of the role it assumed, through a RequestPrincipal.caller factory the
enforcement filter now uses too. The copy check's own matcher is gone: its
direct-grant rules (an exact user ARN, or "*" with aws:PrincipalArn pinned to
it) are the IAM evaluator's, and the unit tests that pinned them there move to
IamPolicyEvaluatorTest. S3PublicAccessEvaluator keeps its principal matching
for CloudFront's origin access identity check.

A CanonicalUser entry matched nothing since #4839, and docs/services/iam.md
described that as AWS behaviour. The IAM User Guide ("AWS account principals")
lets an S3 bucket policy name an account by its canonical user ID, which the
S3 User Guide describes as an obfuscated form of the account ID. It now
matches the IAM identities of that account, as an account principal does.
Floci's canonical ID for an account is its account id, the owner ID its S3 ACL
responses report.

Integration tests (IAM and S3 enforcement, real SigV4) read and copy across
accounts under bucket policies naming the caller's account, a role under a
path, and the account's canonical ID; each fails on main. docs/services/iam.md
and docs/services/s3.md describe the matching.
2026-10-02 17:17:27 -05:00
..