Repository navigation
fix(cfn): read a dotted property key instead of defaulting (#877), and mint an OAI identity (#859) - #878
Merged
Conversation
…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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolveStringProp(emulator/cfn_deployer.go) does a single flat map index —v, ok := props[key], nostrings.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:cfn_resources_v26.goCommand.ScriptLocation""cfn_resources_v21.goRequiresCompatibilities.0EC2cfn_resources_v26.goCommand.Nameglueetlcfn_resources_v23.goCloudFrontOriginAccessIdentityConfig.Commentcfn_resources_v23.goDistributionConfig.CommentSo every Glue job created through CloudFormation shipped no script at all — the one property that says what the job runs — a
pythonshelljob was created as a Spark ETL job, and every Fargate task definition registered asEC2, 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. ADeployedResourceassertion 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.0is 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 throughresolveValue, so an intrinsic in the nested position still resolves;resolveStringPropnow 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-emptyCommand: {}and an emptyRequiresCompatibilities: []keep their documented defaults.The last of the five fed the OAI's
PhysicalID, which is #859:Refreturned 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
PhysicalIDis now a derived OAI ID —Efollowed 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 reasoncfnGeneratedNamerecords for its own suffix:UpdateStackre-deploys the whole template, so acrypto/randID would change on every update and every bucket policy naming the previous one would silently stop matching. Neither existing deterministic helper fits —cfnGeneratedNamereturns a hyphenated{stack}-{logical}-{suffix}, andcfnNameSuffixis pinned to twelve base-36 characters and cannot be widened to thirteen because its modulus loop isuint64and 36¹³ overflows it.Fn::GetAtt Idresolves to the same identifier, which is what makes the two intrinsics agree — they previously answeredRef→ logical ID andId→ empty, two answers about one resource.Fn::GetAtt S3CanonicalUserIdstays 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
Ref"returns the origin access identity, such asE15MNIMTCFKK4C" andFn::GetAtt Id"for example,E74FTE3AJFJ256A" — bothE+ 13 uppercase alphanumerics, which is also the shapegenerateCloudFrontID'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.cfnDeterministicUUID.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
ScriptLocationandCommand.Name, and every Fargate task definition registers asFARGATE, so an existing template produces a different — correct — resource. EveryAWS::CloudFront::CloudFrontOriginAccessIdentity'sPhysicalResourceIdandRefchange value, from the logical ID to a derivedE…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. GlueGetJobfor four command cases plus anFn::Subin the nested position; ECSDescribeTaskDefinitionfor fiveRequiresCompatibilitiescases including absent and empty; CloudFrontGetDistributionfor 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 outcrypto/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