Skip to content

fix(cfn): read a dotted property key instead of defaulting (#877), and mint an OAI identity (#859) - #878

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/859-877-dotted-props-and-oai-id
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/859-877-dotted-props-and-oai-id

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

resolveStringProp (emulator/cfn_deployer.go) does a single flat map index — v, ok := props[key], no strings.Split, no walk — and five call sites passed it a key with a dot in it. None of them matched anything, so all five returned their fallback unconditionally. The result was not a missing value but a wrong one, because each fallback is a plausible default:

Site Key Was Now
cfn_resources_v26.go Command.ScriptLocation always "" the template's script
cfn_resources_v21.go RequiresCompatibilities.0 always EC2 the template's launch type
cfn_resources_v26.go Command.Name always glueetl the template's command name
cfn_resources_v23.go CloudFrontOriginAccessIdentityConfig.Comment always the logical ID the template's comment
cfn_resources_v23.go DistributionConfig.Comment always the logical ID the template's comment

So every Glue job created through CloudFormation shipped no script at all — the one property that says what the job runs — a pythonshell job was created as a Spark ETL job, and every Fargate task definition registered as EC2, a launch type a consumer asserts on and a real service refuses to run against the wrong one. Nothing reported the omission: the stack completed, the service answered 200, and the deploy result looked entirely correct. A DeployedResource assertion cannot see it, which is why none of the five had a test.

Each site reads its own nested member or list element; the shared helper was deliberately not taught to split a dotted key. A nested object read and a list-element read are different operations — RequiresCompatibilities.0 is a list index a map walk cannot reach at all — and a shared walk would have turned all five constants into template-controlled values simultaneously, as a side effect of a refactor rather than as a decision per site. Two small helpers (resolveNestedStringProp, resolveIndexedStringProp) route through resolveValue, so an intrinsic in the nested position still resolves; resolveStringProp now carries the warning in its own doc comment, and an AST tripwire parses every file in the package and fails on a sixth dotted literal, because the defect compiles, deploys and passes review exactly as the correct call does. The tripwire was mutation-verified against a temporary probe rather than trusted because it passes. A present-but-empty Command: {} and an empty RequiresCompatibilities: [] keep their documented defaults.

The last of the five fed the OAI's PhysicalID, which is #859: Ref returned the resource's own logical ID where AWS documents the identity's ID — a value AWS would never mint, handed to every S3 bucket policy and origin-access configuration that names an OAI by !Ref. It was not a stub left in place; the deploy asked for the comment through the broken lookup and the fallback happened to be the logical ID.

The PhysicalID is now a derived OAI ID — E followed by 13 uppercase alphanumerics, by SHA-256 over the account, the Region, the stack name and the logical ID. It is derived rather than random for the reason cfnGeneratedName records for its own suffix: UpdateStack re-deploys the whole template, so a crypto/rand ID would change on every update and every bucket policy naming the previous one would silently stop matching. Neither existing deterministic helper fits — cfnGeneratedName returns a hyphenated {stack}-{logical}-{suffix}, and cfnNameSuffix is pinned to twelve base-36 characters and cannot be widened to thirteen because its modulus loop is uint64 and 36¹³ overflows it.

Fn::GetAtt Id resolves to the same identifier, which is what makes the two intrinsics agree — they previously answered Ref → logical ID and Id → empty, two answers about one resource. Fn::GetAtt S3CanonicalUserId stays empty, by decision rather than by omission, and now has an arm saying so. The comment the broken lookup was reaching for is read and recorded in the resource's metadata. The type still dispatches nothing and still sweeps to a no-op on delete, with the reason updated: the identity is derived, not registered with CloudFront, so there remains nothing on the service side to remove.

Provenance

  • AWS's, published by example twice: the OAI ID shape. The Template Reference says Ref "returns the origin access identity, such as E15MNIMTCFKK4C" and Fn::GetAtt Id "for example, E74FTE3AJFJ256A" — both E + 13 uppercase alphanumerics, which is also the shape generateCloudFrontID's own doc comment already documented in-tree. It is a format published by two agreeing samples, not by a grammar, and the code says so.
  • Substrate's reading: the derivation from (account, Region, stack, logical ID), following cfnDeterministicUUID.
  • Unverified, and left unresolved because of it: S3CanonicalUserId. AWS publishes one 96-character lowercase-hex sample and no format. Minting one would be a second invented value on far thinner evidence than the two agreeing samples the ID rests on, so empty is the honest answer — the behaviour cfn: Ref returns the physical ID for every type, but AWS returns an ARN for an ELBv2 load balancer and target group #827 established.

Compatibility

Every CFN Glue job now ships the template's ScriptLocation and Command.Name, and every Fargate task definition registers as FARGATE, so an existing template produces a different — correct — resource. Every AWS::CloudFront::CloudFrontOriginAccessIdentity's PhysicalResourceId and Ref change value, from the logical ID to a derived E… ID; the ID is stable across redeploys of one stack, and distinct per resource, per stack, per account and per Region.

Tests

New emulator/cfn_dotted_props_test.go — every assertion goes through the owning service's own wire call, not the deploy result. Glue GetJob for four command cases plus an Fn::Sub in the nested position; ECS DescribeTaskDefinition for five RequiresCompatibilities cases including absent and empty; CloudFront GetDistribution for the comment. Each table includes the case that matches the old fallback, so it fails only if the other member is dropped. For the OAI, the two opposite halves of the contract are separate tests — stable across a redeploy (which rules out crypto/rand) and distinct between two resources in one stack (which rules out a constant) — with the ID asserted as a pattern rather than as one derivation's output.

Closes #877
Closes #859

…d mint an OAI identity (#859)

resolveStringProp does a single flat map index — no split, no walk — and five
call sites passed it a key containing a dot. Each returned its fallback
unconditionally, so the value substrate reported came from the deployer's own
default list rather than from the template: a Glue job's ScriptLocation was
always empty and its Name always glueetl, an ECS task definition's launch type
always EC2, and both CloudFront comments always the resource's logical ID.

Each site now reads its own nested member or list element. The shared helper was
deliberately not taught to split a dotted key: a nested object read and a list
index are different operations, and one shared walk would have flipped all five
constants at once as a side effect of a refactor rather than as a decision per
site. resolveStringProp carries the warning in its doc comment, and an AST
tripwire over the package refuses a sixth dotted literal.

The last of the five fed the OAI's PhysicalID, which is #859: Ref returned the
resource's logical ID where AWS documents the identity's ID. The PhysicalID is
now derived — E plus 13 uppercase alphanumerics, by SHA-256 over the account,
Region, stack name and logical ID. The shape is AWS's, published twice by
example; the derivation is substrate's reading. It is derived rather than random
because UpdateStack re-deploys the whole template, so a crypto/rand ID would
change on every update and every bucket policy naming the previous one would
stop matching. Fn::GetAtt Id resolves to the same identifier;
S3CanonicalUserId stays empty by decision, since AWS publishes no format for it.

Closes #877
Closes #859
@scttfrdmn scttfrdmn added this to the v0.116.0 milestone Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cfn_deployer.go 82.60% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit a17e12e into main Sep 15, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/859-877-dotted-props-and-oai-id branch September 15, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant