Repository navigation
fix(cfn): resolve intrinsics at any depth, and map ECS member names (#526, #527) - #533
Merged
Merged
Conversation
…526, #527) resolveValue resolves a value that *is* an intrinsic; nothing walked into a map or a list to resolve one nested within. A deploy path that forwarded a structured property whole therefore handed the plugin `{"Ref": "PK"}` as a literal object — DynamoDB's typed plugin rejected it with a SerializationException and the resource CREATE_FAILED, while an untyped plugin stored it and echoed it back. Which of a consumer's properties resolved depended on how each deploy path happened to have been written. resolveNested walks a property and returns a structurally identical value with every intrinsic resolved. Four rules a naive walk gets wrong: only a single-key map is an intrinsic (a multi-key map is user data even when one key is `Ref` — the same map-iteration nondeterminism #521 fixed a level up); a list-valued intrinsic in a list position splices its elements; an Fn::If yielding AWS::NoValue removes the property rather than leaving an empty string; and resolution never rewrites a key, which is what would mangle a logConfiguration.options whose keys are user data. Applied at the verbatim-forwarding sites, plus the three deploy paths that asserted a property was a literal string and dropped anything else — ACM's SubjectAlternativeNames, MSK's BrokerNodeGroupInfo and FSx's SubnetIds and Tags, so `Value: !Sub '${AWS::StackName}-data'` now reaches the API. For #527, CloudFormation spells a container's members in PascalCase where the ECS API spells them camelCase, and ContainerDefinitions is untyped both in RegisterTaskDefinition's request and in state, so nothing rejected them: the stack reached CREATE_COMPLETE, DescribeTaskDefinition answered 200, and `--query 'taskDefinition.containerDefinitions'` returned [{}]. The mapping is an explicit table of all 42 ContainerDefinition members plus the 11 nested types, verified against each type's own API reference page — a table rather than a first-letter-lowering function because only a table can tell "not mapped" from "mapped to itself", and per-service because DynamoDB, ACM and MSK are natively PascalCase and a generic converter is what would break them.
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.
What
Two
priority: highdefects with the same cause and the same symptom shape — substrate returns HTTP 200 while the observable a caller parses is wrong or empty.Closes #526
Closes #527
#526 — intrinsics never resolved below the top level
resolveValueresolves a value that is an intrinsic; nothing walked into a map or a list to resolve one nested within. So a deploy path that forwarded a structured property whole handed the plugin{"Ref": "PK"}as a literal object: DynamoDB's typed plugin rejected it —— and the resource
CREATE_FAILED, while an untyped plugin stored the object and echoed it back. Which of a consumer's properties resolved depended on how each deploy path happened to have been written:LaunchTemplateDataand security-group rules enumerate their members key by key,ContainerDefinitions/KeySchema/AttributeDefinitionswere forwarded verbatim.resolveNestedwalks a property and returns a structurally identical value with every intrinsic resolved. Four rules a naive walk gets wrong, each pinned by a test:Ref— and resolving one made the result depend on Go's map iteration order, which is the same nondeterminism CloudFormation: Fn::Split resolves to its first element only, so a split list silently loses everything after the first item #521 fixed one level up.Fn::Splitcontributes its elements rather than one rejoined string.Fn::IfyieldingAWS::NoValueremoves the property, as CloudFormation does, rather than leaving an empty string behind. That is what!If [HasCommand, !Split [...], !Ref 'AWS::NoValue']is written to say, and ECS rejects an emptycommand.logConfiguration.options— whose keys are user data — would get mangled.resolveNestedreturnsinterface{}rather thanresolveValue'sstring, so a member that is a list-valued intrinsic keeps its list instead of inheriting #521's scalar-context rejoin. A literal passes through untouched, so{"ContainerPort": 8080}stays the number 8080.Applied at the verbatim-forwarding sites, and at three more the audit found where a
.(string)assertion was silently dropping intrinsic-valued members — the same defect wearing a different plugin:ContainerDefinitionsKeySchema,AttributeDefinitions,ProvisionedThroughput,GlobalSecondaryIndexes,LocalSecondaryIndexes,StreamSpecificationCREATE_FAILEDSubjectAlternativeNames!Ref- or!Split-valued SANBrokerNodeGroupInfo.InstanceType,.ClientSubnets!Ref-valued subnet list — how a template names subnets far more often than as literalsSubnetIds,TagsValue: !Sub '${AWS::StackName}-data', the single most common way a template writes a tagMSK's
ClientSubnetsis overwritten only when it resolves to something, so an absent property keeps its[]default rather than becoming a JSONnull— different requests to a decoding consumer.#527 — ECS container definitions carried CloudFormation's casing onto the wire
CloudFormation spells a container's members in PascalCase where the ECS API spells them camelCase.
ContainerDefinitionsis untyped both inRegisterTaskDefinition's request and in state, so there was nothing to reject them: the stack reachedCREATE_COMPLETE,DescribeTaskDefinitionanswered 200, and--query 'taskDefinition.containerDefinitions'returned[{}]— every member present under a name no SDK reads. A directRegisterTaskDefinitioncall was never affected; the mismatch was introduced by the deploy path alone.The mapping is an explicit table of all 42
ContainerDefinitionmembers plus the 11 nested types (environment,secrets,portMappings,logConfiguration,mountPoints,volumesFrom,healthCheck,ulimits,dependsOn,extraHosts,systemControls), each verified member by member against its own API reference page. Two decisions worth stating:TestECSContainerDefinitionKeys_MatchAPICaseasserts the table against the rule, so the rule's safety is kept without its fragility.logConfiguration.optionsanddockerLabelsare named by their parent's table and then left whole, their keys being user data.Tests
Every new gate was confirmed to fail with the fix reverted. Assertions are on raw JSON bytes where the defect is a member's name — a Go round-trip cannot see a casing defect, since
encoding/jsonmatches a field case-insensitively absent an exact match, so DynamoDB's PascalCase struct reads"keySchema"perfectly well and a read-back agrees with the defect. The DynamoDB guard therefore reads the bytes the deploy path put on the wire, out of the event store.TestCFN_ECSContainerDefinitions_MemberNamesAndNesting— the member names an SDK reads, a loop asserting the seven PascalCase names are absent, andlogConfiguration.optionsverbatim with its values resolved.TestCFN_ECSContainerDefinitions_UnknownMemberSurvives— an unenumerated member is delivered unchanged.TestCFN_ECSContainerDefinitions_NoValueRemovesMember— both condition branches.TestCFN_DynamoDB_NestedRefInKeySchema— CloudFormation: an intrinsic nested inside a structured property is never resolved #526's own reproduction, read back throughDescribeTable, plus positive and negative assertions on the rawCreateTablebody: the guard against a generic converter.TestResolveNested_Conventions— 23 cases at the seam, most of them invisible through any deploy path.TestECSRewriteKeys_UserDataMembers—Options/DockerLabelsholding keys namedNameandImage, so the walk is proved to have stopped rather than merely missed them.TestCFN_ACMSubjectAlternativeNames_Resolved,TestCFN_MSKClientSubnets_Resolved,TestCFN_MSKClientSubnets_AbsentStaysEmptyList,TestCFN_FSxIntrinsicProperties_Resolved— the collateral paths, asserted on the dispatched body since none of the three echoes these members back.TestCFN_YAMLShortForm_ConsumerTemplateand a new…NoCommandsibling — the end-to-end gate on the checked-inecs_worker.yml, which is where CloudFormation: Fn::Split resolves to its first element only, so a split list silently loses everything after the first item #521/CloudFormation: an intrinsic nested inside a structured property is never resolved #526/ECS: a CloudFormation-deployed task definition's ContainerDefinitions keep CloudFormation's PascalCase keys #527 were all reported. All three fixes are exercised at once, and theCommand-unset case asserts the member is absent.Mutation testing
18 mutants, 16 CAUGHT. Both survivors are accounted for rather than left open:
M8b— first-letter-lowering applied to DynamoDB — is CAUGHT by the new raw-body assertions.ecsRewriteKeystouches keys only, through tables containing no intrinsic name, so it cannot change whether a map is an intrinsic;resolveNestedreplaces values only, so it cannot change which table is selected. The doc comment was corrected to say so rather than claim an ordering constraint that does not exist.One mutant found a real test-design defect and one found a redundant guard, both fixed rather than accepted:
ecsUserDataMemberswas a no-op — a member with no nested table is already never descended into, so the guard had no observable effect. Removed, and the reasoning moved toecsNestedContainerKeys, where membership is the actual decision:optionsanddockerLabelsmust never appear there.encoding/jsonreason above. It now asserts on the wire bytes.Verified over the wire
Against
substrate server, the three reproductions from the issues:Docs
docs/services.md§Templates gains the invariant a consumer needs to predict behaviour — intrinsics resolve at any depth — with the two rules that bound the walk (single-key maps only; keys are never rewritten by resolution) and the note that a resolved scalar is a string while a literal is never retyped. TheAWS::NoValueparagraph now covers the whole-property case, not only the list position.make docs-referenceproduces no diff; no plugin was added.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all green.