mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
7dc514b52f2c96bdd1ea32ae64a02703f85be2aa
15
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1aabc8b4fe |
fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS (#5486)
* fix(efs): report the zone id EC2 reports for the same zone EFS derived its own availability-zone id (use1-az1) by splitting the region on hyphens, while EC2 publishes <region>-az<n> for subnets and zones, so a mount target and its subnet disagreed. The abbreviation also only worked for three-part regions: us-gov-west-1a and eusc-de-east-1a kept the whole region. EFS now takes the id from the helper EC2 and VPC flow logs use. Also drops an allowlist pattern for flow-log region abbreviations that matches no source line since flow logs moved to the same helper. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS EC2 published <region>-az<n> as a zone id and EFS its own abbreviation, so a mount target and its subnet disagreed and neither matched AWS in every region. AvailabilityZoneIds in core.common now derives the id for all three: AWS's short region prefix and -az<n> (use1-az1, apne1-az1, usgw1-az1, cnn1-az1). The prefix rule is attested for the commercial, China and GovCloud regions; AWS publishes no zone id for an ISO or EUSC region, so those keep the whole region as the prefix instead of a guessed one. Zone a is still az1, b az2, and so on: AWS maps names to ids per account, which Floci does not model. CreateSubnet resolves AvailabilityZoneId in the new shape and refuses the old one. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com> |
||
|
|
1b61945f28 |
fix(partition): hold escaped host regexes to the DNS suffix gate (#5232)
The partition literal gate's dns-suffix pattern matched amazonaws.com but not a Java regex that escapes its dots (amazonaws\\.com), so hand-written host patterns escaped it. With the dots allowed to be escaped, the gate found two on main: - ECR's pull-through cache recognised an ecr upstream only on the commercial and China suffixes, while Floci's own registry recognises an ECR image URI in every partition. The upstream host pattern is now built from AwsPartitions.dnsSuffixRegex() the same way. - The console sign-in host pattern in SigninService has no published non-commercial form, so it carries a partition-literal escape like the console literals beside it. |
||
|
|
ae216f22a0 |
chore(core): gate comparisons of a partition with the literal "aws" (#4892)
* chore(core): gate comparisons of a partition with the literal "aws" The five checks #4791 fixed compared a parsed ARN's partition with "aws", so RDS, ElastiCache and RAM broke silently outside the commercial partition, and make partition-check could not see them: a bare "aws" is not an arn:aws: prefix. partition_literals.py gains a gated aws-partition-compare category, scanned over the code with comments and text blocks blanked, that catches "aws".equals(...), .equals("aws"), their equalsIgnoreCase forms and Objects.equals with "aws". Run against main before #4791 it reports exactly those five sites. The three remaining uses compare an account, a command name and a reserved SSM name prefix, not a partition, and are escaped with a reason. AGENTS.md states the rule next to the other partition rules, so reviews flag it too. The audit table sizes its columns to the longest category name. Part of #4272. * chore(core): end the Objects.equals match at its call and gate switch labels on "aws" Greptile on #4892: the Objects.equals arm read past the call's closing parenthesis, so foo(Objects.equals(a, b), "aws") matched a comparison that is not there; each argument now allows one level of nested calls and the match ends at the call's own parenthesis. And a switch on a partition branched on "aws" without a match, so case labels naming "aws", alone or in a list, are caught too. main has none, so no new escapes and the baseline stays empty. |
||
|
|
27ddf0bb00 |
fix(core): mint every regionless ARN in its partition and gate blank-region Arn.of calls (#4787)
* fix(core): mint every regionless ARN in its partition and gate blank-region Arn.of calls Part of #4272 (P10a). Arn.of derives the partition from the region, so a blank region always minted arn:aws:, and the partition literal gate could not see it because it is a call shape, not a literal. Sixteen call sites did this, and three gated literals were left: - RdsSigV4Validator built the rds-db:connect resource as arn:aws:rds-db:, so a China IAM policy naming arn:aws-cn:rds-db: never matched and IAM auth to an RDS proxy was denied there. - CloudFront, Organizations, Cost Explorer anomaly monitors and the SSO portal role ARN now take the request's partition (RegionResolver injected). - S3 bucket ARNs (event notifications, AWS::S3::Bucket Arn, Cost Explorer S3 usage) take the bucket's or the stack region's partition; the Lambda CFN default role, the Kinesis ESM invokeIdentityArn, the EC2 launch template CreatedBy and the SQS AddPermission root principal take their own region's. - FlinkContainerManager's fallback key goes through Arn.of, and the CloudFormation S3 TemplateURL host check accepts every partition's DNS suffix. partition_literals.py gains a gated, code-scoped blank-region-arn category (Arn.of with a "" or null region, comments excluded). The baseline is now empty, so any new literal or blank-region mint fails Partition Literals. * fix(core): scan blank-region Arn.of calls across lines and skip text blocks Greptile on #4787: the blank-region-arn category ran per line, so a call whose region argument sits on the next line escaped it, and text-block contents were kept, so an example inside one would count as a call against the empty baseline. code_text now blanks comments and text blocks over the whole source and the code categories match across lines, reporting the line the call starts on. |
||
|
|
99c1c4129a |
fix(iam): derive the AWS managed policy catalog per partition (#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 (#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 |
||
|
|
43ed79d15b |
fix(core): service principals are universal in every partition; accept the legacy forms (#4633)
* fix(core): service principals are universal in every partition; accept the legacy forms A service principal is <service>.amazonaws.com in every partition, the rule the CDK applies (region-info.ts, principals.ts). Floci now emits it through ServicePrincipals.of: generated trust policies, SAM's Lambda permissions, CloudTrail's eventSource, service-linked role paths (Macie, GuardDuty, Connect, Application Auto Scaling, RAM, SSO) and the Redshift COPY trust check. Policies may still name a service in the per-partition form AWS accepted before (elasticmapreduce.amazonaws.com.cn, logs.cn-north-1.amazonaws.com.cn, config.c2s.ic.gov), and AWS still honours them. ServicePrincipals.canonical folds a published DNS suffix and a regional label away, and the trust-policy evaluator and CreateServiceLinkedRole compare in that form, so either spelling matches. DescribeVpcEndpointServices now lists China's S3 interface service, cn.com.amazonaws.<region>.s3, beside the com.amazonaws gateway one, each with its own type; where the names agree it stays one service carrying both types. Partition literal baseline 34 -> 4 occurrences. The web-identity and pod-identity audiences keep their commercial literals, escaped for the STS phase. Part of #4272 * fix(iam): put a legacy-named service-linked role under the universal principal CreateServiceLinkedRole derived the role name from the universal principal but kept the caller's legacy spelling (es.amazonaws.com.cn) in the path and the trust policy. All three now use the universal principal, so the role lists under /aws-service-role/es.amazonaws.com/ like one created from the universal name. ServicePrincipals.canonical no longer lower-cases: service-principal matching is exact and case-sensitive since #4555, and AWS matches principals case-sensitively, so only a suffix written the way AWS publishes it folds. |
||
|
|
833a43bfa7 |
feat(core): vendor the per-region hosted zones, SAML URLs and VPC endpoint prefixes (#4545)
* feat(core): vendor the per-region hosted zones, SAML URLs and VPC endpoint prefixes tools/aws/regen_region_facts.py transcribes the per-region and per-partition constants AWS publishes only as prose tables into src/main/resources/aws/region-facts.json: the Terraform provider's load balancer and S3 website hosted-zone maps, the CloudFront hosted zone per partition (cross-checked against the CDK), and the CDK's SAML sign-on URLs and VPC endpoint service-name exceptions. AwsRegionFacts serves them, as Optionals where a partition publishes nothing (the ISO and EUSC partitions have no hosted zones). make aws-data-check regenerates and compares where the local reference checkouts exist, and verifies the file's shape where they do not. Behaviour this changes: network load balancers report their own hosted zone per region instead of the Application one, Classic and Application load balancers report their region's zone, API Gateway EDGE domains carry the CloudFront zone of their partition, SAML assertions are checked against the sign-on URL of the provider's partition, and the AWS-managed S3 and DynamoDB prefix lists carry the partition's service-name prefix. Also carries the follow-ups from the #4494 review: bucketRegionForCreate cites the S3 model for the us-east-1 rules, docs/services/s3.md gains a Bucket Regions section, and the Marketplace files are gated per line with stated reasons instead of being allowlisted by path, so a new region literal there is caught. Part of #4272 * fix(core): harden the region facts against restarts, partitions without CloudFront, and CI without sources The source-free data check rejected real twelve-character hosted zone ids such as ap-southeast-1's NLB zone ZKVM4W9LS7TM, which failed the vendored-data job. It now accepts Route 53's id length range and checks substance: every partition has an entry whose VPC endpoint prefix is its reversed DNS suffix, every region is published in partitions.json, SAML URLs are https sign-on URLs, and unknown fields are refused. Load balancers restored from storage take the hosted zone of their region and type again, so balancers stored before the per-region lookup stop reporting the old fixed zone. An EDGE API Gateway custom domain is refused where the partition has no CloudFront, since it would have no distribution zone to alias to. A customer prefix list may not take the prefix of the AWS-managed lists its region carries, cn.com.amazonaws. in China. The partitions doc now says which ISO hosted zones exist. * fix(core): hold only a changed endpoint type to the partition, and name malformed region facts UpdateDomainName checked the partition for EDGE on every patch, so an EDGE custom domain stored in GovCloud before the rule could no longer take a certificate or security-policy update; only a patch that changes the endpoint type is held to the partition now. The source-free region-facts check reports a partition or region entry that is not an object by name instead of failing with a traceback, and its test asserts on computed results rather than on calls that write the fixture. * fix(core): keep gateway endpoint names on com.amazonaws, allow EDGE only in the commercial partition, and keep SAML working where no sign-on URL is published The AWS-managed prefix lists belong to the S3 and DynamoDB gateway endpoints, which the CDK names com.amazonaws.<region>.<service> in every partition (GatewayVpcEndpointAwsService); the reversed-suffix table applies to interface endpoints only. The managed lists are back to that name and the cn.com.amazonaws. reservation is gone; DescribeVpcEndpointServices now names the interface services through the table instead, keeping the S3 gateway entry on com.amazonaws. Edge-optimized API Gateway exists only in the commercial partition: China has CloudFront but no edge-optimized APIs or domains (its API Gateway documentation says so), so EDGE custom domains are refused everywhere else. Where the CDK publishes no SAML sign-on URL (aws-iso-e, aws-iso-f, aws-eusc) assertions keep being checked against the commercial URL, as every partition was before, instead of all being refused. applyEndpointType has its javadoc back. |
||
|
|
b8cae89a2d |
refactor(glue): extract shared Glue and Redshift role helpers (#4459)
* refactor(glue): move PartitionProjection from athena to glue package PartitionProjection resolves Glue table partition layout, not Athena-specific logic — Athena is only its current caller. Moving it into services/glue gives the upcoming GlueTableResolver (Redshift Spectrum Phase 2) a home for it without a glue-depends-on-athena layering inversion. readPath and assertInjectedColumnsFiltered become public (their callers stay in services/athena, a different package now); enabled/parameter stay package-private since nothing outside the class uses them. * refactor(glue): extract GlueTableResolver from GlueViewDdlBuilder GlueViewDdlBuilder now delegates table-to-read-plan resolution (read function inference, read expression, Iceberg detection, column projection) to a new public GlueTableResolver, so Redshift Spectrum's Glue-backed external tables can reuse the same logic Athena already proved correct. * refactor(redshift): extract RedshiftRoleAccess from S3CopySimulator COPY and UNLOAD's IAM role resolution and S3 authorization now live in a standalone RedshiftRoleAccess, matching the existing ManifestReader extraction pattern in this package, so Redshift Spectrum's Glue-backed external schemas (IAM_ROLE-authorized reads) can reuse it instead of duplicating role-session and policy-evaluation logic. Adds direct coverage for the enforced-policy-denial path, which only had implicit enforcement-off coverage before this extraction. * fix(redshift): follow RedshiftRoleAccess in native init list and partition baseline |
||
|
|
0cfb467cac |
fix(s3): apply AWS's CreateBucket region rules in every partition (#4494)
* fix(s3): apply AWS's CreateBucket region rules in every partition CreateBucket follows the rules moto verified against AWS: the us-east-1 endpoint takes any LocationConstraint but its own (InvalidLocationConstraint), and every other regional endpoint requires a constraint naming exactly its region, answering IllegalLocationConstraintException otherwise. The signing region alone no longer places a bucket, so a China or GovCloud client must send the constraint, which the AWS SDKs do. GetBucketLocation still answers an empty constraint only for us-east-1, in every partition. WAF's CLOUDFRONT scope lives in the partition's implicit global region and is refused with WAFInvalidParameterException where the partition has no CloudFront. Lightsail lists no regions outside the commercial partition. Region fallbacks read the configured default where a resolver or config is in scope, and PreSignedUrlGenerator gains an overload that signs for a given region. The region-literal category of the partition guardrail is now gated; every remaining literal carries a stated reason. Tests that created buckets under a regional signing scope with no constraint now send one, and S3IntegrationTest's case that pinned the old signing-region placement is replaced by the rejection and its positive twin. Part of #4272 * fix(s3,wafv2): answer a us-east-1 constraint off its endpoint as a mismatch, and gate the CLOUDFRONT scope on every operation A CreateBucket on a regional endpoint other than us-east-1 with LocationConstraint us-east-1 is just another mismatched region, IllegalLocationConstraintException, as moto's aws_verified test_create_bucket_with_wrong_location_constraint records; InvalidLocationConstraint belongs to the us-east-1 endpoint alone (test_bucket_create_force_us_east_1). The body parse no longer rejects us-east-1 early, and bucketRegionForCreate checks the endpoint mismatch first. WAF's CLOUDFRONT scope was refused in partitions without CloudFront only when creating a resource; validateScope, which every operation already calls, now applies the same check, so a List or Get for that scope answers the same WAFInvalidParameterException. * fix(wafv2): check the CLOUDFRONT scope against the region each call is about The previous change checked the scope in validateScope against the request region, but CloudFormation calls the service outside any request, where that region falls back to the deployment default: under a GovCloud default a commercial stack's CLOUDFRONT WebACL was refused on create, update and delete. WafV2Handler now checks Scope=CLOUDFRONT against the region the API request was sent to, before dispatch, so every operation still answers the same error; validateScope checks the enum only, and a create keeps its check against the region it is given where the ARN is built. |
||
|
|
2cccc73499 |
fix(core): build and recognise AWS hostnames in every partition (#4451)
* fix(core): build and recognise AWS hostnames in every partition AwsEndpoints builds the AWS-shaped hosts Floci returns from the region's partition DNS suffix: execute-api, the S3 bucket, regional, dual-stack and website hosts, Cognito and EKS OIDC issuers, APS, Bedrock AgentCore, AppSync and EC2 public DNS names. partitions.json records the regions whose S3 endpoint publishes a dual-stack variant, so DualStackDomainName is only returned there. The S3 virtual-host fallback, the execute-api host filter, the ECR image URI and the CloudFront S3-origin parsers recognise every published suffix, longest first. The CloudFront domain suffix Cognito and API Gateway mint comes from floci.services.cloudfront.domain-suffix. Two commercial bugs go with it: WebsiteURL uses the dash form (s3-website-<region>) in the nine regions that keep it and ends with a slash, and EMR's public DNS name is compute-1 only in us-east-1. Also carries the follow-ups from the #4444 review: accessDeniedResponse gets its Javadoc back in IamEnforcementFilter, IamAuthValidator's imports are in order, and the IAM test helper's pair loop cannot read past the array. Part of #4272 * fix(core): keep CloudTrail S3 hosts and CFN dual-stack attributes consistent with their region CloudTrail built an S3 data event's Host, TLS host header and resource ARNs from the request scope, but the log writer emits its own deliveries from the flush thread, where the request region falls back to the deployment default: a cn-north-1 trail's self-delivery record said awsRegion cn-north-1 with a .amazonaws.com host and an arn:aws: ARN. buildS3Record now takes the event region emitS3DataEvent already resolves and derives all of them from it. AWS::S3::Bucket drops a prior DualStackDomainName when an update lands in a region without an S3 dual-stack endpoint, since provision receives the previous attributes on update. * test(resourceexplorer2): check a regionless ARN's partition against the resource's region The cn-north-1 CloudTrail self-delivery test left its bucket behind in the shared emulator, and ResourceExplorer2's partition assertion then failed on arn:aws-cn:s3:::loop-logs-..., a correct ARN: S3 ARNs carry no region, so the expected partition fell back to aws. The assertion now takes a regionless ARN's partition from the Region the listing reports, and skips it when that is not a published region (global resources). The CloudTrail test deletes its trail, objects and bucket after each case through PartitionCleanup. |
||
|
|
0e8f965cb6 |
fix(core): mint every ARN in the request's partition (#4444)
* fix(core): mint every ARN in the request's partition
The build side of the multi-partition plan. 123 of the 126 gated arn:aws: literals in src/main now go through AwsArnUtils.Arn.of for regional resources, RegionResolver.buildGlobalArn for regionless ones minted under a request, and Arn.global with the region's partition where only a region is in scope, so a resource created in cn-north-1 or us-gov-west-1 carries arn:aws-cn: or arn:aws-us-gov:. CloudFormation's AWS::Partition and AWS::URLSuffix pseudo-parameters follow the stack region instead of a literal aws and amazonaws.com, and the SAM transform emits arn:${AWS::Partition}:... as the real translator does.
Seven literals are escaped with a stated reason: the stub-resource marker, the three Greengrass runtime ids from the Lambda Runtime enum, S3 Control's error text, and the two console client ids. The three still gated (the managed policy catalog, Flink and the RDS proxy validator) belong to later phases.
ResourceExplorer2IntegrationTest holds every listed ARN to its region's partition again; P0 had relaxed it to commercial regions while China-region resources were still minted arn:aws:.
Part of #4272
* fix(s3): evaluate a bucket policy against the bucket's own partition
A bucket policy names its bucket in the partition of the bucket's region. The authorization paths built the resource ARN from the request's partition instead, so with bucket names shared across regions a same-account request signed for cn-north-1 against a us-east-1 bucket was checked against arn:aws-cn:s3:::bucket/key, missed an explicit deny on arn:aws:s3:::bucket/*, and was allowed. The seven S3Service call sites now take the partition from the bucket's region, which also drops their dependency on a RegionResolver that the package-private test constructors leave null.
* fix(iam): match S3 resource ARNs against the bucket's own partition under IAM enforcement
IamEnforcementFilter built every S3 resource ARN through a regionless Arn.of, which always yields arn:aws:. Once AWS::Partition follows the stack region, a bucket created in cn-north-1 gets a policy naming arn:aws-cn:s3:::bucket/*, and under IAM enforcement its statements never matched, so an explicit deny was skipped.
ResourceArnBuilder now mints S3 ARNs in the request region's partition, which is right for a bucket that does not exist yet. ResourcePolicyProvider gains resolveResourceArn, a default no-op, and S3ResourcePolicyProvider re-mints an existing bucket's ARN in the partition of the bucket's region before any identity or resource policy is evaluated. S3Service.bucketPartition is the single rule for both layers and for the CopyObject source and presigned POST ARNs in S3Controller.
S3PartitionBucketPolicyIamEnforcementIntegrationTest runs with IAM enforcement alone, so S3's own policy check cannot deny first: the China-bucket deny fails without this change, and the cross-partition deny on a us-east-1 bucket fails if the re-minting step is skipped.
|
||
|
|
eb2872f578 |
fix(core): read ARNs and Step Functions integration ids in every partition (#4358)
P2 of the multi-partition initiative (#4272), the parse side. StatesIntegration replaces the literal arn:aws:states::: integration ids the ASL executor and the definition validator compared against: the CDK builds them as arn:${Aws.PARTITION}:states:::, so a China or GovCloud state machine never matched (aws-cdk task-utils.ts:36). Only AWS's three suffixes (.sync, .sync:2, .waitForTaskToken) parse, and a dispatch that does not read the suffix accepts none, so sqs:sendMessage.bogus stays unsupported as it was. AwsArnUtils .resourceIfArnFor replaces the 16 startsWith("arn:aws") probes, so bucket policies, S3 resource paths, assumed-role principals, SAML role pairs, EKS instance profiles, Security Hub, OAM and CloudTrail selectors recognise China, GovCloud and ISO ARNs, and an assumed role's underlying role is rebuilt in the session's own partition. Where a check used to pin arn:aws: and thereby the commercial partition, it now pins the partition explicitly: a root principal matches only a caller of the same partition and account, and a Security Hub resource ARN must carry the request's partition. The 25 hand-rolled partition alternations in regexes collapse onto AwsArnUtils.PARTITION_REGEX. The partition-literal baseline drops from 270 to 195 gated occurrences. Part of #4272 |
||
|
|
9331417bf2 |
fix(partition): drop baseline rows #4317 re-added after #4314 cleared them (#4333)
#4314 removed the partition literals in IamService, CostAnomalyService and EcrService and dropped their rows from tools/partition/baseline.tsv. #4317 was branched before that and its baseline carried the old rows, so the merge put them back and make partition-check now fails on main with four "dropped from 1 to 0" entries. Regenerated with make partition-baseline; no source change. |
||
|
|
0dd080a46f |
feat(core): partition foundation from botocore's published partition data (#4317)
P1 of the multi-partition initiative (#4272). tools/aws/regen_partitions.py vendors botocore's partitions.json and endpoints.json (8 partitions, 46 regions, the partition-wide endpoints with their signing regions) plus the CDK's opt-in and S3 website rules into src/main/resources/aws/partitions.json, checked by make aws-data-check. AwsPartition and AwsPartitions replace the hand-typed rules behind AwsRegions; RequestContext carries the request's partition from its SigV4 signing region; RegionResolver mints global ARNs in that partition and buildArn routes a blank region there; floci.partitions.id pins the deployment's partition behind a startup validator that refuses a contradiction with the default region. Behaviour a reviewer will see, all AWS-faithful: DescribeRegions follows the request's partition and the opt-in model (17 commercial regions by default, all 34 with AllRegions=true, RegionName.N filters, endpoints on the partition's DNS suffix); TLS SANs cover every published region; the EKS registry mirrors follow the deployment partition's regions. The partition-literal baseline drops by two. Part of #4272 |
||
|
|
0a601d54eb |
chore(tooling): gate partition literals in src/main against a per-file baseline (#4270)
P0 of the multi-partition plan. tools/partition/partition_literals.py inventories the arn:aws: prefixes, amazonaws.com hosts, hosted-zone ids and hand-rolled partition regexes in src/main/java per file against tools/partition/baseline.tsv. A literal in a new file fails, growth in an existing file fails, and a drop fails until the baseline is regenerated, so the remaining count only shrinks. Escapes are a `// partition-literal: <reason>` comment or an allowlist.yaml entry. Makefile targets (partition-check, partition-baseline, partition-audit, partition-test), a python-only workflow, AGENTS.md and CONTRIBUTING.md paragraphs, and the ResourceExplorer2 assertion now checks the partition against the ARN's region instead of a literal arn:aws:. |