Skip to content

cfn: an origin access identity reports its logical ID as its physical ID, and its Comment lookup reads a dotted key in a flat map #859

Closed

Description

@scttfrdmn

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 Ref function, Ref returns the origin access identity, such as E15MNIMTCFKK4C.

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, nil

First, 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:

  1. How to mint an E-prefixed 14-character identifier deterministically. cfnGeneratedName's {stack}-{logical}-{suffix} shape — which is right for AWS::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.
  2. Whether the two documented Fn::GetAtt attributes should resolve. Id would be the physical ID and S3CanonicalUserId a second minted value with no published format at all.
  3. Whether the stub should dispatch. Without a CloudFront-side record, Id and S3CanonicalUserId have nowhere to live, nothing can read them back, and the delete path has nothing to delete.

Acceptance criteria

  • The dotted-key resolveStringProp lookup is either fixed to read the nested CloudFrontOriginAccessIdentityConfig.Comment or removed, not left silently dead.
  • PhysicalResourceId and Ref return 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::GetAtt Id and S3CanonicalUserId — 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

  1. added this to the v0.116.0 milestone on Sep 14, 2026
  2. added
    type: bug
    on Sep 14, 2026
  3. scttfrdmn commented on Sep 15, 2026

    @scttfrdmn
    OwnerAuthor

    Verified against main before 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 props key finds five, and all five are broken:

    Site Key Today Impact
    cfn_resources_v26.go:346 Command.ScriptLocation always "" Every Glue job created through CloudFormation ships an empty ScriptLocation
    cfn_resources_v21.go:153 RequiresCompatibilities.0 always "EC2" Every Fargate task definition registers as EC2
    cfn_resources_v26.go:345 Command.Name always "glueetl" A pythonshell job is created as a Spark ETL job
    cfn_resources_v23.go:109 CloudFrontOriginAccessIdentityConfig.Comment always logicalID this issue — feeds PhysicalID and hence Ref
    cfn_resources_v23.go:64 DistributionConfig.Comment always logicalID cosmetic: PhysicalID is recovered from the response Id, but the stored comment is wrong

    resolveStringProp (cfn_deployer.go:5836-5849) is the only resolve*Prop helper 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 in resolveStringProp, 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 — and RequiresCompatibilities.0 is 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. Ref gives "such as E15MNIMTCFKK4C" and Fn::GetAtt Id gives "for example, E74FTE3AJFJ256A". Two samples, both E + 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 by cfnGeneratedNameSuffixLen (:115), giving 13 total where 14 are needed, and it cannot be widened — the modulus loop is uint64 and 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 reads crypto/rand, so it is the shape reference rather than the minter.

    5. Both Fn::GetAtt attributes answer "" today, not an error. There is no OAI arm in cfnGetAttPerType (cfn_intrinsics.go:200-368), dr.Metadata is never initialised by this deploy, and cfnGetAttNamesAnARN is 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), following cfnDeterministicUUID. Deterministic for a redeploy, distinct for two OAIs in one stack, and stated in docs/services.md as substrate's reading of two agreeing published samples.

    Decision 2 — the two attributes. Id resolves to the same minted ID, because AWS documents it as exactly that value and Ref already is it. S3CanonicalUserId stays 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: Ref returning 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 Ref wiring are exactly as the issue asks. cfnRefValue (cfn_intrinsics.go:48) needs no arm: it falls through to PhysicalID, and AWS's Ref is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions