Skip to content

fix(iam): derive the AWS managed policy catalog per partition - #4742

Merged
pgermosen merged 1 commit into
mainfrom
fix/partition-managed-policies
Sep 30, 2026
Merged

pgermosen merged 1 commit into
mainfrom
fix/partition-managed-policies

Conversation

@hectorvent

Copy link
Copy Markdown
Member

Summary

Part of #4272 (P8).

The bundled AWS managed policy catalog is the commercial one, so arn:aws-cn:iam::aws:policy/AdministratorAccess did not resolve and a China deployment listed commercial ARNs. Every other partition's catalog is now derived from the bundled data on first use and cached per partition (AwsManagedPolicies.forPartition):

  • every arn:aws: inside a document takes the partition, as AWS's SAM translator does for managed policy ARNs (samtranslator/translator/arn_generator.py, generate_aws_managed_policy_arn);
  • the region-bearing hostnames a kms:ViaService condition names (s3.*.amazonaws.com) take the partition's DNS suffix;
  • bare service principals and service-linked role paths are universal (fix(core): service principals are universal in every partition; accept the legacy forms #4633) and are left alone, as is the ::aws:policy/ owner slot. The commercial catalog is byte-identical to the bundled data.

IamService resolves a managed policy under the partition its ARN names, so a China ARN resolves under any signing scope, and ListPolicies lists the catalog of the caller's partition. The default deployer's AdministratorAccess attachment follows the default partition. Whether AWS's China or GovCloud documents differ in content beyond these substitutions stays listed as an open question in docs/configuration/partitions.md.

Partition literal baseline: 4 -> 3.

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

Incorrect behaviour: outside the commercial partition, GetPolicy, AttachRolePolicy and policy evaluation could not resolve arn:<partition>:iam::aws:policy/... ARNs, and ListPolicies returned commercial arn:aws: ARNs whose documents referenced commercial resources and hosts.

Checklist

  • ./mvnw test passes locally: the focused suites for everything that resolves or lists managed policies pass (31 classes, 770 cases, including IamServiceTest, IamIntegrationTest, the managed policy catalog, attachment-count and account-scope tests, CloudFormation IAM, Organizations, SSO Admin and SAM); the full suite runs in CI's four shards
  • New or updated integration test added (AwsManagedPoliciesTest, IamManagedPolicyPartitionIntegrationTest, IamManagedPolicyCatalogTest)
  • Commit messages follow Conventional Commits

The bundled managed policy catalog is the commercial one, so
arn:aws-cn:iam::aws:policy/AdministratorAccess did not resolve and a China
deployment listed commercial ARNs. Every other partition's catalog is now
derived from the bundled data on first use and cached per partition: every
arn:aws: inside a document takes the partition, as AWS's SAM translator does
for managed policy ARNs (arn_generator.py), and the region-bearing
kms:ViaService hosts (s3.*.amazonaws.com) take the partition's DNS suffix.
Bare service principals and service-linked role paths are universal (#4633)
and are left alone, as is the ::aws:policy/ owner slot.

IamService resolves a managed policy under the partition its ARN names, so a
China ARN resolves under any signing scope, and ListPolicies lists the catalog
of the caller's partition.

Partition literal baseline 4 -> 3.

Part of #4272
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Changes how AWS managed policies are looked up by partition.

The PR should not merge until IAM attachments reject managed policies from a different partition.

Findings

  1. P1 Foreign policies can be attached ▶
  2. P2 Test assumes a fixed version ▶
Summary

The PR derives partition-specific AWS managed-policy catalogs from bundled commercial data and uses them for IAM lookup and listing.

  • Policy documents receive partition-specific ARN prefixes and region-bearing DNS suffixes.
  • IAM catalog lookup, listing, default deployer attachment, tests, and documentation are updated.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  ARN[Managed policy ARN] --> Parse[Select catalog by ARN partition]
  Parse --> Lookup[Resolve managed policy]
  Lookup --> Read[GetPolicy]
  Lookup --> Attach[Attach policy or set boundary]
  Attach --> Auth[Authorization]
  Scope[Request partition] --> List[ListPolicies catalog]
  Scope -. missing compatibility check .-> Attach
Loading

Reviews (1) · Last reviewed commit: "fix(iam): derive the AWS managed policy ..."

@hectorvent hectorvent added bug Something isn't working iam AWS Identity and Access Management (IAM) labels Sep 30, 2026
Comment on lines +982 to +984
if (AwsManagedPolicies.isManagedPolicyArn(arn)) {
// Authorization and ListAttached* need policy documents or names, not attachment counts.
return Optional.ofNullable(awsManagedPolicies.get(arn));
return Optional.ofNullable(awsManagedPoliciesFor(arn).get(arn));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Foreign policies can be attached A caller in the commercial partition can now attach arn:aws-cn:iam::aws:policy/AdministratorAccess to a user or role. This lookup selects the catalog from the supplied ARN, while attachment checks only whether the policy resolves. The foreign policy is then used in authorization decisions, even though it should not be attachable to a principal in another partition. Keep cross-partition reads if intended, but check partition compatibility for attachments and permissions boundaries.

Knowledge Base Used: IAM and authentication

.header("Authorization", CHINA_IAM)
.formParam("Action", "GetPolicyVersion")
.formParam("PolicyArn", "arn:aws-cn:iam::aws:policy/AWSLambdaExecute")
.formParam("VersionId", "v1")

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 Test assumes a fixed version The catalog currently lists v1 as the default for AWSLambdaExecute, but it bundles only each policy’s current default version. If a catalog refresh advances that version, this test will fail with NoSuchEntity even when partition handling still works. Reading the default version from the catalog would keep the test focused on partition behavior.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The derivation looks right, and the rewrite tests cover the cases that could go wrong. Greptile's P1 is a real difference from AWS, where each account lives in one partition, but I don't see a clean place to check it yet. Role and user ARNs are still minted commercial until P9, and the CloudFormation path has no signing scope to compare against. Worth adding the attach and boundary check to P9, once principals carry their partition.

@pgermosen
pgermosen merged commit 99c1c41 into main Sep 30, 2026
34 checks passed
@hectorvent
hectorvent deleted the fix/partition-managed-policies branch September 30, 2026 15:24
omatheusmesmo pushed a commit to omatheusmesmo/floci that referenced this pull request Oct 12, 2026
…io#4742)

The bundled managed policy catalog is the commercial one, so
arn:aws-cn:iam::aws:policy/AdministratorAccess did not resolve and a China
deployment listed commercial ARNs. Every other partition's catalog is now
derived from the bundled data on first use and cached per partition: every
arn:aws: inside a document takes the partition, as AWS's SAM translator does
for managed policy ARNs (arn_generator.py), and the region-bearing
kms:ViaService hosts (s3.*.amazonaws.com) take the partition's DNS suffix.
Bare service principals and service-linked role paths are universal (floci-io#4633)
and are left alone, as is the ::aws:policy/ owner slot.

IamService resolves a managed policy under the partition its ARN names, so a
China ARN resolves under any signing scope, and ListPolicies lists the catalog
of the caller's partition.

Partition literal baseline 4 -> 3.

Part of floci-io#4272
Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
omatheusmesmo pushed a commit to omatheusmesmo/floci that referenced this pull request Oct 12, 2026
…io#4742)

The bundled managed policy catalog is the commercial one, so
arn:aws-cn:iam::aws:policy/AdministratorAccess did not resolve and a China
deployment listed commercial ARNs. Every other partition's catalog is now
derived from the bundled data on first use and cached per partition: every
arn:aws: inside a document takes the partition, as AWS's SAM translator does
for managed policy ARNs (arn_generator.py), and the region-bearing
kms:ViaService hosts (s3.*.amazonaws.com) take the partition's DNS suffix.
Bare service principals and service-linked role paths are universal (floci-io#4633)
and are left alone, as is the ::aws:policy/ owner slot.

IamService resolves a managed policy under the partition its ARN names, so a
China ARN resolves under any signing scope, and ListPolicies lists the catalog
of the caller's partition.

Partition literal baseline 4 -> 3.

Part of floci-io#4272
Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working iam AWS Identity and Access Management (IAM)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants