Repository navigation
Description
Surfaced while researching #843, whose last acceptance criterion names this helper. Filed separately rather than folded into #843's PR, for the reasons at the bottom.
What AWS documents
aws-resource-cloudfront-cloudfrontoriginaccessidentity.html:
When you pass the logical ID of this resource to the intrinsic
Reffunction,Refreturns the origin access identity, such asE15MNIMTCFKK4C.
Fn::GetAtt publishes two attributes, Id and S3CanonicalUserId.
What substrate does — two defects, not one
deployCloudFrontOAI (emulator/cfn_resources_v23.go:101-114):
comment := resolveStringProp(props, "CloudFrontOriginAccessIdentityConfig.Comment", logicalID, cctx)
return DeployedResource{LogicalID: logicalID,
Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity", PhysicalID: comment}, 0, nilFirst, the physical ID is neither an OAI ID nor an E-prefixed identifier of any kind.
Second, and not what #843 assumed: it is not even the comment. resolveStringProp looks up a dotted key in a flat map, and CloudFrontOriginAccessIdentityConfig is a nested object, so the lookup never matches and the logicalID fallback always wins. Every OAI in every stack reports its own logical ID as its physical ID — which at least does not collide within a stack, but is still not an identifier AWS would return, and !Ref on the resource resolves to it.
Third: the helper dispatches nothing. It takes _ context.Context and a _ string stream ID and makes no request at all, so there is no CloudFront-side OAI record for a physical ID to come from.
Why this is its own issue
A correct fix needs three decisions #843's PR should not make in passing:
- How to mint an
E-prefixed 14-character identifier deterministically.cfnGeneratedName's{stack}-{logical}-{suffix}shape — which is right forAWS::ApiGateway::Method, because AWS's own example for that type is that shape — is wrong here. AWS publishes this format only by example, so any minter is substrate's reading of one sample. - Whether the two documented
Fn::GetAttattributes should resolve.Idwould be the physical ID andS3CanonicalUserIda second minted value with no published format at all. - Whether the stub should dispatch. Without a CloudFront-side record,
IdandS3CanonicalUserIdhave nowhere to live, nothing can read them back, and the delete path has nothing to delete.
Acceptance criteria
- The dotted-key
resolveStringProplookup is either fixed to read the nestedCloudFrontOriginAccessIdentityConfig.Commentor removed, not left silently dead. -
PhysicalResourceIdandRefreturn an OAI-shaped identifier, deterministic for a given (account, Region, stack, logical ID) so a redeploy does not change it. - The identifier's format is documented as substrate's reading of AWS's single published example,
E15MNIMTCFKK4C. - A decision is recorded on
Fn::GetAttIdandS3CanonicalUserId— resolved, or deliberately unresolved with the reason. - Two OAIs in one stack report distinct physical IDs.
Related: #843 (the same defect class, where the value is citable), #837 (whether PhysicalResourceId should be per-type at all).
Activity
scttfrdmn commentedon Sep 15, 2026
Verified against
mainbefore implementing. Both defects are exactly as described, and the diagnosis of the second one — a dotted key indexed into a flat map, so the fallback always wins — is right. Five corrections and one resolution of the issue's own open decisions.Corrections
1. The dotted-key defect is not the OAI's. It is a five-site class defect, and two of the other four are worse. An exhaustive search for a dotted literal passed as a
propskey finds five, and all five are broken:cfn_resources_v26.go:346Command.ScriptLocation""ScriptLocationcfn_resources_v21.go:153RequiresCompatibilities.0"EC2"EC2cfn_resources_v26.go:345Command.Name"glueetl"pythonshelljob is created as a Spark ETL jobcfn_resources_v23.go:109CloudFrontOriginAccessIdentityConfig.CommentlogicalIDPhysicalIDand henceRefcfn_resources_v23.go:64DistributionConfig.CommentlogicalIDPhysicalIDis recovered from the responseId, but the stored comment is wrongresolveStringProp(cfn_deployer.go:5836-5849) is the onlyresolve*Prophelper in the tree, so this is the complete set. One apparent sixth hit is a false positive:"IpPermissions.1."(cfn_delete.go:658,cfn_resources_v77.go:191) is a prefix for EC2 query-protocol output parameter names, not a props key, and is correct as written.2. AC 1's "fixed to read the nested
CloudFrontOriginAccessIdentityConfig.Comment" must not be done inresolveStringProp, and that is a decision rather than a preference. Teaching the shared helper to walk dotted paths would turn ECS's launch type and Glue's command name from effective constants into template-controlled values at all five sites at once, silently, in one commit — andRequiresCompatibilities.0is an index into a list, which a map walk does not give at all. So each site walks its own nested value. None of the five has a test today.3. AWS publishes the format twice, not once, so AC 3's "AWS's single published example" is off by one.
Refgives "such asE15MNIMTCFKK4C" andFn::GetAtt Idgives "for example,E74FTE3AJFJ256A". Two samples, bothE+ 13 uppercase alphanumerics. Still a format published only by example, so the minter is still substrate's reading — just of two samples that agree, which is worth stating because it is what makes the shape safe to commit to.4. Neither obvious deterministic helper can be reused, and the reason for the second one is arithmetic.
cfnGeneratedName(cfn_physical_name.go:134-170) returns a hyphenated{stack}-{logical}-{suffix}, which the issue already rules out.cfnNameSuffix(:176-190) looks like the right primitive and is not: it is pinned to 12 base-36 characters bycfnGeneratedNameSuffixLen(:115), giving 13 total where 14 are needed, and it cannot be widened — the modulus loop isuint64and 36¹³ ≈ 1.71×10²⁰ overflows 2⁶⁴ ≈ 1.84×10¹⁹ (36¹² ≈ 4.74×10¹⁸ fits). The constant is also shared and pinned to CloudFormation's own published example, so it is not free to change regardless.What does fit is
cfnDeterministicUUID(cloudformation_plugin.go:1518-1522), a SHA-256 over joined parts, whose rationale is already documented.generateCloudFrontID(cloudfront_plugin.go:586-597) already documents the exact shape — "E followed by 13 uppercase alphanumeric characters" — but readscrypto/rand, so it is the shape reference rather than the minter.5. Both
Fn::GetAttattributes answer""today, not an error. There is no OAI arm incfnGetAttPerType(cfn_intrinsics.go:200-368),dr.Metadatais never initialised by this deploy, andcfnGetAttNamesAnARNis false for both names. So AC 4 is a decision to record, not a bug to fix — the current behaviour is the honest-empty one #827 established.Resolving the issue's three stated decisions
Decision 1 — how to mint.
E+ 13 uppercase alphanumerics, derived by SHA-256 over (account, Region, stack, logical ID), followingcfnDeterministicUUID. Deterministic for a redeploy, distinct for two OAIs in one stack, and stated indocs/services.mdas substrate's reading of two agreeing published samples.Decision 2 — the two attributes.
Idresolves to the same minted ID, because AWS documents it as exactly that value andRefalready is it.S3CanonicalUserIdstays unresolved, and that is recorded rather than left to be rediscovered: AWS publishes no format for it, only a single 96-lowercase-hex sample, so minting one would be a second invented value on far thinner evidence than the ID — and an S3 bucket policy granting that canonical user is not something substrate evaluates, so a plausible-looking value would buy a template nothing and cost a reader a false signal.Decision 3 — dispatch. It stays non-dispatching, and the type stays in
cfnDeleteInertTypes(cfn_delete.go:558). Giving the OAI a CloudFront-side record is a separate decision with its own scope (a create operation, a read, and a delete path), and it is not what this issue is about:Refreturning a value AWS would never return is the defect, and an identity is what fixes it. The inert-types reason is updated, though — "the deploy records no state to remove" stays true, but the resource now has an identity, which is the thing a reader of that table would otherwise assume it lacks.Not changing
AC 2, AC 5 and the
Refwiring are exactly as the issue asks.cfnRefValue(cfn_intrinsics.go:48) needs no arm: it falls through toPhysicalID, and AWS'sRefis the OAI ID, so setting the physical ID is the whole of it.The five dotted-key sites are filed as their own issue, since four of them have nothing to do with CloudFront and two change what resource an existing template produces.
fix(cfn): read a dotted property key instead of defaulting (#877), an…
fix(cloudfront): a tagging ARN addresses the distribution it names (#918