Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(route53): CrossAccountZoneDelegationRecord does not remove old NS records when the zoneName changes #21249

Closed
moltar opened this issue Jul 20, 2022 · 6 comments · Fixed by #27523
Assignees
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort management/tracking Issues that track a subject or multiple issues p0

Comments

@moltar
Copy link
Contributor

moltar commented Jul 20, 2022

Describe the bug

When changing the zoneName value of the PublicHostedZone the old NS entries in the delegated zone are not removed.

I think this is because when the logical ID did not change, the custom resource event type is still UPDATE and judging by the handler code, it does not handle this edge case.

async function cfnEventHandler(props: ResourceProperties, isDeleteEvent: boolean) {
const { AssumeRoleArn, ParentZoneId, ParentZoneName, DelegatedZoneName, DelegatedZoneNameServers, TTL } = props;
if (!ParentZoneId && !ParentZoneName) {
throw Error('One of ParentZoneId or ParentZoneName must be specified');
}
const credentials = await getCrossAccountCredentials(AssumeRoleArn);
const route53 = new Route53({ credentials });
const parentZoneId = ParentZoneId ?? await getHostedZoneIdByName(ParentZoneName!, route53);
await route53.changeResourceRecordSets({
HostedZoneId: parentZoneId,
ChangeBatch: {
Changes: [{
Action: isDeleteEvent ? 'DELETE' : 'UPSERT',
ResourceRecordSet: {
Name: DelegatedZoneName,
Type: 'NS',
TTL,
ResourceRecords: DelegatedZoneNameServers.map(ns => ({ Value: ns })),
},
}],
},
}).promise();
}

Expected Behavior

Old NS records to be removed.

Current Behavior

NS records remain in the delegated (parent) zone.

Reproduction Steps

Deploy:

    const hostedZone = new PublicHostedZone(this, 'PublicZone', {
      zoneName: 'abc.example.com',
    })

    new CrossAccountZoneDelegationRecord(this, 'Delegate', {
      delegationRole: 'arn...',
      delegatedZone: hostedZone,
      parentHostedZoneId: 'xyz',
    })

Then change zoneName value to abc2.example.com and deploy again.

Observe that NS records for abc.example.com remain.

Possible Solution

Compare zoneName values with the existing resource and delete it when the name chagnes.

Additional Information/Context

No response

CDK CLI Version

2.29.1 (build c42e961)

Framework Version

TS

Node.js Version

v14.19.3

OS

macOS

Language

Typescript

Language Version

TS 4.7.4

Other information

No response

@moltar moltar added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 20, 2022
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Jul 20, 2022
@moltar
Copy link
Contributor Author

moltar commented Jul 20, 2022

Ping @ayush987goyal, @phoefflin

@ayush987goyal
Copy link
Contributor

Yeah seems like a bug to me. We might need a separate handler for the UPDATE case perhaps and some corresponding refactoring. One callout is that the current implementation should technically work since it would still add the nameservers for the new hosted zone name.

@indrora indrora added p1 package/cfn Related to the CFN layer (L1) and removed needs-triage This issue or PR still needs to be triaged. labels Sep 9, 2022
@garciparedes
Copy link
Contributor

Hi! I would like to come this issue alive again as I'm also being affected by the same issue.

As @moltar described, if the zoneName changes the current implementation will insert the new NS record on the parent Hosted Zone but will keep the old one so it leaves a dangling NS record which MUST be removed manually. If it is not removed, it may allow an attacker to control the subdomain and serve content in your name.

garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Apr 25, 2023
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Apr 25, 2023
@peterwoodworth peterwoodworth removed the package/cfn Related to the CFN layer (L1) label Apr 28, 2023
@otaviomacedo otaviomacedo added the effort/small Small work item – less than a day of effort label May 19, 2023
@QwerTech
Copy link

Looks like the issue is still present, and it's currently reproducing for me with CDK 2.40.0 (build 56ba2ab).
Checked the PR #25285, and it seems it was closed without merging. I hope @garciparedes you can republish your PR to finally fix the issue.

@garciparedes
Copy link
Contributor

garciparedes commented Oct 12, 2023

I've just republished the #27523 pull request adding the missing integration tests from previous one.

garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Oct 12, 2023
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Oct 12, 2023
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Oct 12, 2023
…ing (aws#21249)

Signed-off-by: Sergio García Prado <sergio@garciparedes.me>
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Oct 12, 2023
@mergify mergify bot closed this as completed in #27523 Dec 6, 2023
mergify bot pushed a commit that referenced this issue Dec 6, 2023
…ing (#21249) (#27523)

…ing (#21249)

Improve the `CustomResource` implementation that manages the `Route53`'s `NS` Records on the Account that host the parent `HostedZone` to consider renaming cases in which updates and deletes are both required.

Closes #21249.

This is related to #25285

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

github-actions bot commented Dec 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

sumupitchayan pushed a commit that referenced this issue Dec 6, 2023
…ing (#21249) (#27523)

…ing (#21249)

Improve the `CustomResource` implementation that manages the `Route53`'s `NS` Records on the Account that host the parent `HostedZone` to consider renaming cases in which updates and deletes are both required.

Closes #21249.

This is related to #25285

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@sumupitchayan sumupitchayan added management/tracking Issues that track a subject or multiple issues p0 and removed p1 labels Dec 6, 2023
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
9 participants