Repository navigation
fix(iam): derive the AWS managed policy catalog per partition - #4742
Conversation
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
|
| 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)); |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
…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>
…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>
Summary
Part of #4272 (P8).
The bundled AWS managed policy catalog is the commercial one, so
arn:aws-cn:iam::aws:policy/AdministratorAccessdid 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):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);kms:ViaServicecondition names (s3.*.amazonaws.com) take the partition's DNS suffix;::aws:policy/owner slot. The commercial catalog is byte-identical to the bundled data.IamServiceresolves a managed policy under the partition its ARN names, so a China ARN resolves under any signing scope, andListPolicieslists the catalog of the caller's partition. The default deployer'sAdministratorAccessattachment follows the default partition. Whether AWS's China or GovCloud documents differ in content beyond these substitutions stays listed as an open question indocs/configuration/partitions.md.Partition literal baseline: 4 -> 3.
Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Incorrect behaviour: outside the commercial partition,
GetPolicy,AttachRolePolicyand policy evaluation could not resolvearn:<partition>:iam::aws:policy/...ARNs, andListPoliciesreturned commercialarn:aws:ARNs whose documents referenced commercial resources and hosts.Checklist
./mvnw testpasses locally: the focused suites for everything that resolves or lists managed policies pass (31 classes, 770 cases, includingIamServiceTest,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 shardsAwsManagedPoliciesTest,IamManagedPolicyPartitionIntegrationTest,IamManagedPolicyCatalogTest)