From f0f749832a07539e42fdc7b4130a73df79d5cf84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Garc=C3=ADa=20Prado?= Date: Mon, 24 Apr 2023 11:24:14 +0200 Subject: [PATCH] fix(route53): delete old NS records on cross-account delegation renaming (#21249) --- .../integ.cross-account-zone-delegation.ts | 2 +- ...efaultTestDeployAssert2D0BD417.assets.json | 19 + ...aultTestDeployAssert2D0BD417.template.json | 36 ++ .../__entrypoint__.js | 147 +++++++ .../index.js | 102 +++++ .../cdk.out | 1 + .../child-stack.assets.json | 34 ++ .../child-stack.template.json | 158 ++++++++ .../integ.json | 14 + .../manifest.json | 156 +++++++ .../parent-stack.assets.json | 20 + .../parent-stack.template.json | 109 +++++ .../tree.json | 380 ++++++++++++++++++ ...eg.rename-cross-account-zone-delegation.ts | 102 +++++ .../index.ts | 20 +- .../index.test.ts | 104 ++++- 16 files changed, 1392 insertions(+), 12 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/__entrypoint__.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/index.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.cross-account-zone-delegation.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.cross-account-zone-delegation.ts index acc2563e9d74d..ab3043bcf2616 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.cross-account-zone-delegation.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.cross-account-zone-delegation.ts @@ -83,4 +83,4 @@ childOptInStack.addDependency(parentStack); new IntegTest(app, 'Route53CrossAccountInteg', { testCases: [childStack, childOptInStack], diffAssets: true, -}); \ No newline at end of file +}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.assets.json new file mode 100644 index 0000000000000..5d97c726756e0 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.assets.json @@ -0,0 +1,19 @@ +{ + "version": "34.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/__entrypoint__.js b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/__entrypoint__.js new file mode 100644 index 0000000000000..c83ecebaaadac --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/__entrypoint__.js @@ -0,0 +1,147 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.withRetries = exports.handler = exports.external = void 0; +const https = require("https"); +const url = require("url"); +// for unit tests +exports.external = { + sendHttpRequest: defaultSendHttpRequest, + log: defaultLog, + includeStackTraces: true, + userHandlerIndex: './index', +}; +const CREATE_FAILED_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED'; +const MISSING_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID'; +async function handler(event, context) { + const sanitizedEvent = { ...event, ResponseURL: '...' }; + exports.external.log(JSON.stringify(sanitizedEvent, undefined, 2)); + // ignore DELETE event when the physical resource ID is the marker that + // indicates that this DELETE is a subsequent DELETE to a failed CREATE + // operation. + if (event.RequestType === 'Delete' && event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) { + exports.external.log('ignoring DELETE event caused by a failed CREATE event'); + await submitResponse('SUCCESS', event); + return; + } + try { + // invoke the user handler. this is intentionally inside the try-catch to + // ensure that if there is an error it's reported as a failure to + // cloudformation (otherwise cfn waits). + // eslint-disable-next-line @typescript-eslint/no-require-imports + const userHandler = require(exports.external.userHandlerIndex).handler; + const result = await userHandler(sanitizedEvent, context); + // validate user response and create the combined event + const responseEvent = renderResponse(event, result); + // submit to cfn as success + await submitResponse('SUCCESS', responseEvent); + } + catch (e) { + const resp = { + ...event, + Reason: exports.external.includeStackTraces ? e.stack : e.message, + }; + if (!resp.PhysicalResourceId) { + // special case: if CREATE fails, which usually implies, we usually don't + // have a physical resource id. in this case, the subsequent DELETE + // operation does not have any meaning, and will likely fail as well. to + // address this, we use a marker so the provider framework can simply + // ignore the subsequent DELETE. + if (event.RequestType === 'Create') { + exports.external.log('CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored'); + resp.PhysicalResourceId = CREATE_FAILED_PHYSICAL_ID_MARKER; + } + else { + // otherwise, if PhysicalResourceId is not specified, something is + // terribly wrong because all other events should have an ID. + exports.external.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(event)}`); + } + } + // this is an actual error, fail the activity altogether and exist. + await submitResponse('FAILED', resp); + } +} +exports.handler = handler; +function renderResponse(cfnRequest, handlerResponse = {}) { + // if physical ID is not returned, we have some defaults for you based + // on the request type. + const physicalResourceId = handlerResponse.PhysicalResourceId ?? cfnRequest.PhysicalResourceId ?? cfnRequest.RequestId; + // if we are in DELETE and physical ID was changed, it's an error. + if (cfnRequest.RequestType === 'Delete' && physicalResourceId !== cfnRequest.PhysicalResourceId) { + throw new Error(`DELETE: cannot change the physical resource ID from "${cfnRequest.PhysicalResourceId}" to "${handlerResponse.PhysicalResourceId}" during deletion`); + } + // merge request event and result event (result prevails). + return { + ...cfnRequest, + ...handlerResponse, + PhysicalResourceId: physicalResourceId, + }; +} +async function submitResponse(status, event) { + const json = { + Status: status, + Reason: event.Reason ?? status, + StackId: event.StackId, + RequestId: event.RequestId, + PhysicalResourceId: event.PhysicalResourceId || MISSING_PHYSICAL_ID_MARKER, + LogicalResourceId: event.LogicalResourceId, + NoEcho: event.NoEcho, + Data: event.Data, + }; + exports.external.log('submit response to cloudformation', json); + const responseBody = JSON.stringify(json); + const parsedUrl = url.parse(event.ResponseURL); + const req = { + hostname: parsedUrl.hostname, + path: parsedUrl.path, + method: 'PUT', + headers: { + 'content-type': '', + 'content-length': Buffer.byteLength(responseBody, 'utf8'), + }, + }; + const retryOptions = { + attempts: 5, + sleep: 1000, + }; + await withRetries(retryOptions, exports.external.sendHttpRequest)(req, responseBody); +} +async function defaultSendHttpRequest(options, responseBody) { + return new Promise((resolve, reject) => { + try { + const request = https.request(options, _ => resolve()); + request.on('error', reject); + request.write(responseBody); + request.end(); + } + catch (e) { + reject(e); + } + }); +} +function defaultLog(fmt, ...params) { + // eslint-disable-next-line no-console + console.log(fmt, ...params); +} +function withRetries(options, fn) { + return async (...xs) => { + let attempts = options.attempts; + let ms = options.sleep; + while (true) { + try { + return await fn(...xs); + } + catch (e) { + if (attempts-- <= 0) { + throw e; + } + await sleep(Math.floor(Math.random() * ms)); + ms *= 2; + } + } + }; +} +exports.withRetries = withRetries; +async function sleep(ms) { + return new Promise((ok) => setTimeout(ok, ms)); +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZWpzLWVudHJ5cG9pbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJub2RlanMtZW50cnlwb2ludC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSwrQkFBK0I7QUFDL0IsMkJBQTJCO0FBRTNCLGlCQUFpQjtBQUNKLFFBQUEsUUFBUSxHQUFHO0lBQ3RCLGVBQWUsRUFBRSxzQkFBc0I7SUFDdkMsR0FBRyxFQUFFLFVBQVU7SUFDZixrQkFBa0IsRUFBRSxJQUFJO0lBQ3hCLGdCQUFnQixFQUFFLFNBQVM7Q0FDNUIsQ0FBQztBQUVGLE1BQU0sZ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Q+IHtcbiAgcmV0dXJuIG5ldyBQcm9taXNlKChvaykgPT4gc2V0VGltZW91dChvaywgbXMpKTtcbn1cbiJdfQ== \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/index.js new file mode 100644 index 0000000000000..6641aee6f2856 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697/index.js @@ -0,0 +1,102 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.handler = void 0; +// eslint-disable-next-line import/no-extraneous-dependencies +const client_route_53_1 = require("@aws-sdk/client-route-53"); +// eslint-disable-next-line import/no-extraneous-dependencies +const credential_providers_1 = require("@aws-sdk/credential-providers"); +async function handler(event) { + const resourceProps = event.ResourceProperties; + switch (event.RequestType) { + case 'Create': + return cfnEventHandler(resourceProps, false); + case 'Update': + return cfnUpdateEventHandler(resourceProps, event.OldResourceProperties); + case 'Delete': + return cfnEventHandler(resourceProps, true); + } +} +exports.handler = handler; +async function cfnUpdateEventHandler(props, oldProps) { + if (oldProps && props.DelegatedZoneName !== oldProps.DelegatedZoneName) { + await cfnEventHandler(oldProps, true); + } + await cfnEventHandler(props, false); +} +async function cfnEventHandler(props, isDeleteEvent) { + const { AssumeRoleArn, ParentZoneId, ParentZoneName, DelegatedZoneName, DelegatedZoneNameServers, TTL } = props; + if (!ParentZoneId && !ParentZoneName) { + throw Error('One of ParentZoneId or ParentZoneName must be specified'); + } + const timestamp = (new Date()).getTime(); + const route53 = new client_route_53_1.Route53({ + credentials: (0, credential_providers_1.fromTemporaryCredentials)({ + clientConfig: { + region: route53Region(process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION ?? ''), + }, + params: { + RoleArn: AssumeRoleArn, + RoleSessionName: `cross-account-zone-delegation-${timestamp}`, + }, + }), + }); + 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 })), + }, + }], + }, + }); +} +async function getHostedZoneIdByName(name, route53) { + const zones = await route53.listHostedZonesByName({ DNSName: name }); + const matchedZones = zones.HostedZones?.filter(zone => zone.Name === `${name}.`) ?? []; + if (matchedZones && matchedZones.length !== 1) { + throw Error(`Expected one hosted zone to match the given name but found ${matchedZones.length}`); + } + // will always be defined because we throw if length !==1 + return matchedZones[0].Id; +} +/** + * Return the region that hosts the Route53 endpoint + * + * Route53 is a partitional service: the control plane lives in one particular region, + * which is different for every partition. + * + * The SDK knows how to convert a "target region" to a "route53 endpoint", which + * equates to a (potentially different) region. However, when we use STS + * AssumeRole credentials, we must grab credentials that will work in that + * region. + * + * By default, STS AssumeRole will call the STS endpoint for the same region + * as the Lambda runs in. Normally, this is all good. However, when the AssumeRole + * is used to assume a role in a different account A, the AssumeRole will fail if the + * Lambda is executing in an an opt-in region R to which account A has not been opted in. + * + * To solve this, we will always AssumeRole in the same region as the Route53 call will + * resolve to. + */ +function route53Region(region) { + const partitions = { + 'cn': 'cn-northwest-1', + 'us-gov': 'us-gov-west-1', + 'us-iso': 'us-iso-east-1', + 'us-isob': 'us-isob-east-1', + }; + for (const [prefix, mainRegion] of Object.entries(partitions)) { + if (region.startsWith(`${prefix}-`)) { + return mainRegion; + } + } + // Default for commercial partition + return 'us-east-1'; +} +//# sourceM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XhlY3V0aW5nIGluIGFuIGFuIG9wdC1pbiByZWdpb24gUiB0byB3aGljaCBhY2NvdW50IEEgaGFzIG5vdCBiZWVuIG9wdGVkIGluLlxuICpcbiAqIFRvIHNvbHZlIHRoaXMsIHdlIHdpbGwgYWx3YXlzIEFzc3VtZVJvbGUgaW4gdGhlIHNhbWUgcmVnaW9uIGFzIHRoZSBSb3V0ZTUzIGNhbGwgd2lsbFxuICogcmVzb2x2ZSB0by5cbiAqL1xuZnVuY3Rpb24gcm91dGU1M1JlZ2lvbihyZWdpb246IHN0cmluZykge1xuICBjb25zdCBwYXJ0aXRpb25zID0ge1xuICAgICdjbic6ICdjbi1ub3J0aHdlc3QtMScsXG4gICAgJ3VzLWdvdic6ICd1cy1nb3Ytd2VzdC0xJyxcbiAgICAndXMtaXNvJzogJ3VzLWlzby1lYXN0LTEnLFxuICAgICd1cy1pc29iJzogJ3VzLWlzb2ItZWFzdC0xJyxcbiAgfTtcblxuICBmb3IgKGNvbnN0IFtwcmVmaXgsIG1haW5SZWdpb25dIG9mIE9iamVjdC5lbnRyaWVzKHBhcnRpdGlvbnMpKSB7XG4gICAgaWYgKHJlZ2lvbi5zdGFydHNXaXRoKGAke3ByZWZpeH0tYCkpIHtcbiAgICAgIHJldHVybiBtYWluUmVnaW9uO1xuICAgIH1cbiAgfVxuXG4gIC8vIERlZmF1bHQgZm9yIGNvbW1lcmNpYWwgcGFydGl0aW9uXG4gIHJldHVybiAndXMtZWFzdC0xJztcbn0iXX0= \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/cdk.out new file mode 100644 index 0000000000000..2313ab5436501 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.assets.json new file mode 100644 index 0000000000000..07e2b4edb7a24 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.assets.json @@ -0,0 +1,34 @@ +{ + "version": "34.0.0", + "files": { + "2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697": { + "source": { + "path": "asset.2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697", + "packaging": "zip" + }, + "destinations": { + "234567890123-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-234567890123-us-east-1", + "objectKey": "2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697.zip", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::234567890123:role/cdk-hnb659fds-file-publishing-role-234567890123-us-east-1" + } + } + }, + "e6a0e21d9a844ca6fc6c3aec1ebc784d5fe613ce2acddf77adff1e56b8bc004e": { + "source": { + "path": "child-stack.template.json", + "packaging": "file" + }, + "destinations": { + "234567890123-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-234567890123-us-east-1", + "objectKey": "e6a0e21d9a844ca6fc6c3aec1ebc784d5fe613ce2acddf77adff1e56b8bc004e.json", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::234567890123:role/cdk-hnb659fds-file-publishing-role-234567890123-us-east-1" + } + } + } + }, + "dockerImages": {} +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.template.json new file mode 100644 index 0000000000000..b2e1449eaac1b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/child-stack.template.json @@ -0,0 +1,158 @@ +{ + "Resources": { + "NewSubZone1DFF192F": { + "Type": "AWS::Route53::HostedZone", + "Properties": { + "Name": "new.uniqueexample.com." + } + }, + "delegatecrossaccountzonedelegationhandlerrolePolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E86169197": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Resource": "arn:aws:iam::12345678:role/MyUniqueDelegationRole" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E", + "Roles": [ + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "/", + { + "Fn::Select": [ + 5, + { + "Fn::Split": [ + ":", + { + "Fn::GetAtt": [ + "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B", + "Arn" + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + "delegateCrossAccountZoneDelegationCustomResource23BD590B": { + "Type": "Custom::CrossAccountZoneDelegation", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265", + "Arn" + ] + }, + "AssumeRoleArn": "arn:aws:iam::12345678:role/MyUniqueDelegationRole", + "ParentZoneName": "uniqueexample.com", + "DelegatedZoneName": "new.uniqueexample.com", + "DelegatedZoneNameServers": { + "Fn::GetAtt": [ + "NewSubZone1DFF192F", + "NameServers" + ] + }, + "TTL": 172800 + }, + "DependsOn": [ + "delegatecrossaccountzonedelegationhandlerrolePolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E86169197" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ] + } + }, + "CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-489995129089-us-east-1", + "S3Key": "2074c648c677a8b76908fd0d6e6e6bf13f1f69849146918f62cd91aee2b92697.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "__entrypoint__.handler", + "Role": { + "Fn::GetAtt": [ + "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B" + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/integ.json new file mode 100644 index 0000000000000..641a7aae7d528 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/integ.json @@ -0,0 +1,14 @@ +{ + "version": "34.0.0", + "testCases": { + "Route53RenameCrossAccountInteg/DefaultTest": { + "stacks": [ + "child-stack", + "child-stack" + ], + "diffAssets": true, + "assertionStack": "Route53RenameCrossAccountInteg/DefaultTest/DeployAssert", + "assertionStackName": "Route53RenameCrossAccountIntegDefaultTestDeployAssert2D0BD417" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/manifest.json new file mode 100644 index 0000000000000..2bf96b5053e19 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/manifest.json @@ -0,0 +1,156 @@ +{ + "version": "34.0.0", + "artifacts": { + "parent-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "parent-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "parent-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://${AWS::AccountId}/us-east-1", + "properties": { + "templateFile": "parent-stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/f3f95f41358a7bff65153b497abbfaf16d1174e64784789bed2c2cc13bc372c4.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "parent-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-us-east-1", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "parent-stack.assets" + ], + "metadata": { + "/parent-stack/HostedZone/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "HostedZoneDB99F866" + } + ], + "/parent-stack/CrossAccountRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CrossAccountRoleFACE29D1" + } + ], + "/parent-stack/CrossAccountRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CrossAccountRoleDefaultPolicy212A317F" + } + ], + "/parent-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/parent-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "parent-stack" + }, + "child-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "child-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "child-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://489995129089/us-east-1", + "properties": { + "templateFile": "child-stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::489995129089:role/cdk-hnb659fds-deploy-role-489995129089-us-east-1", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::489995129089:role/cdk-hnb659fds-cfn-exec-role-489995129089-us-east-1", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-489995129089-us-east-1/e6a0e21d9a844ca6fc6c3aec1ebc784d5fe613ce2acddf77adff1e56b8bc004e.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "child-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::489995129089:role/cdk-hnb659fds-lookup-role-489995129089-us-east-1", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "parent-stack", + "child-stack.assets" + ], + "metadata": { + "/child-stack/NewSubZone/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "NewSubZone1DFF192F" + } + ], + "/child-stack/delegate/cross-account-zone-delegation-handler-role/PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "delegatecrossaccountzonedelegationhandlerrolePolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E86169197" + } + ], + "/child-stack/delegate/CrossAccountZoneDelegationCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "delegateCrossAccountZoneDelegationCustomResource23BD590B" + } + ], + "/child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B" + } + ], + "/child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265" + } + ], + "/child-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/child-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "child-stack" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.assets.json new file mode 100644 index 0000000000000..8fd8dacf64ba1 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "34.0.0", + "files": { + "f3f95f41358a7bff65153b497abbfaf16d1174e64784789bed2c2cc13bc372c4": { + "source": { + "path": "parent-stack.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-12345678-us-east-1", + "objectKey": "f3f95f41358a7bff65153b497abbfaf16d1174e64784789bed2c2cc13bc372c4.json", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-us-east-1" + } + } + } + }, + "dockerImages": {} +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.template.json new file mode 100644 index 0000000000000..7c044adbcf035 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/parent-stack.template.json @@ -0,0 +1,109 @@ +{ + "Resources": { + "HostedZoneDB99F866": { + "Type": "AWS::Route53::HostedZone", + "Properties": { + "Name": "uniqueexample.com." + } + }, + "CrossAccountRoleFACE29D1": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "AWS": "arn:aws:iam::489995129089:root" + } + } + ], + "Version": "2012-10-17" + }, + "RoleName": "MyUniqueDelegationRole" + } + }, + "CrossAccountRoleDefaultPolicy212A317F": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "route53:ChangeResourceRecordSets", + "Condition": { + "ForAllValues:StringEquals": { + "route53:ChangeResourceRecordSetsRecordTypes": [ + "NS" + ], + "route53:ChangeResourceRecordSetsActions": [ + "UPSERT", + "DELETE" + ] + } + }, + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:route53:::hostedzone/", + { + "Ref": "HostedZoneDB99F866" + } + ] + ] + } + }, + { + "Action": "route53:ListHostedZonesByName", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "CrossAccountRoleDefaultPolicy212A317F", + "Roles": [ + { + "Ref": "CrossAccountRoleFACE29D1" + } + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/tree.json new file mode 100644 index 0000000000000..fecc549fc94e1 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.js.snapshot/tree.json @@ -0,0 +1,380 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "parent-stack": { + "id": "parent-stack", + "path": "parent-stack", + "children": { + "HostedZone": { + "id": "HostedZone", + "path": "parent-stack/HostedZone", + "children": { + "Resource": { + "id": "Resource", + "path": "parent-stack/HostedZone/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::HostedZone", + "aws:cdk:cloudformation:props": { + "name": "uniqueexample.com." + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "CrossAccountRole": { + "id": "CrossAccountRole", + "path": "parent-stack/CrossAccountRole", + "children": { + "ImportCrossAccountRole": { + "id": "ImportCrossAccountRole", + "path": "parent-stack/CrossAccountRole/ImportCrossAccountRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "Resource": { + "id": "Resource", + "path": "parent-stack/CrossAccountRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "AWS": "arn:aws:iam::489995129089:root" + } + } + ], + "Version": "2012-10-17" + }, + "roleName": "MyUniqueDelegationRole" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "parent-stack/CrossAccountRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "parent-stack/CrossAccountRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "route53:ChangeResourceRecordSets", + "Condition": { + "ForAllValues:StringEquals": { + "route53:ChangeResourceRecordSetsRecordTypes": [ + "NS" + ], + "route53:ChangeResourceRecordSetsActions": [ + "UPSERT", + "DELETE" + ] + } + }, + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:route53:::hostedzone/", + { + "Ref": "HostedZoneDB99F866" + } + ] + ] + } + }, + { + "Action": "route53:ListHostedZonesByName", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "policyName": "CrossAccountRoleDefaultPolicy212A317F", + "roles": [ + { + "Ref": "CrossAccountRoleFACE29D1" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "parent-stack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "parent-stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "child-stack": { + "id": "child-stack", + "path": "child-stack", + "children": { + "MutableRoleDelegationRole": { + "id": "MutableRoleDelegationRole", + "path": "child-stack/MutableRoleDelegationRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "DelegationRole": { + "id": "DelegationRole", + "path": "child-stack/DelegationRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "NewSubZone": { + "id": "NewSubZone", + "path": "child-stack/NewSubZone", + "children": { + "Resource": { + "id": "Resource", + "path": "child-stack/NewSubZone/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::HostedZone", + "aws:cdk:cloudformation:props": { + "name": "new.uniqueexample.com." + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "delegate": { + "id": "delegate", + "path": "child-stack/delegate", + "children": { + "cross-account-zone-delegation-handler-role": { + "id": "cross-account-zone-delegation-handler-role", + "path": "child-stack/delegate/cross-account-zone-delegation-handler-role", + "children": { + "PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E": { + "id": "PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E", + "path": "child-stack/delegate/cross-account-zone-delegation-handler-role/PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E", + "children": { + "Resource": { + "id": "Resource", + "path": "child-stack/delegate/cross-account-zone-delegation-handler-role/PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Resource": "arn:aws:iam::234567890123:role/MyUniqueDelegationRole" + } + ], + "Version": "2012-10-17" + }, + "policyName": "PolicychildstackdelegatecrossaccountzonedelegationhandlerroleCB13E48E", + "roles": [ + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "/", + { + "Fn::Select": [ + 5, + { + "Fn::Split": [ + ":", + { + "Fn::GetAtt": [ + "CustomCrossAccountZoneDelegationCustomResourceProviderRoleED64687B", + "Arn" + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "CrossAccountZoneDelegationCustomResource": { + "id": "CrossAccountZoneDelegationCustomResource", + "path": "child-stack/delegate/CrossAccountZoneDelegationCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "child-stack/delegate/CrossAccountZoneDelegationCustomResource/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "Custom::CrossAccountZoneDelegationCustomResourceProvider": { + "id": "Custom::CrossAccountZoneDelegationCustomResourceProvider", + "path": "child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "Role": { + "id": "Role", + "path": "child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider/Role", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "Handler": { + "id": "Handler", + "path": "child-stack/Custom::CrossAccountZoneDelegationCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "child-stack/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "child-stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.ts new file mode 100644 index 0000000000000..3af88597f84c7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.rename-cross-account-zone-delegation.ts @@ -0,0 +1,102 @@ +import * as iam from 'aws-cdk-lib/aws-iam'; +import * as cdk from 'aws-cdk-lib'; +import * as route53 from 'aws-cdk-lib/aws-route53'; +import { Construct } from 'constructs'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +interface ChildStacksProps extends cdk.StackProps { + subZoneName: string; +} + +const app = new cdk.App(); + +const account = process.env.CDK_INTEG_ACCOUNT || '123456789012'; // this account should NOT have af-south-1 enabled + +// As the integ-runner doesnt provide a default cross account, we make our own. +const crossAccount = process.env.CDK_INTEG_CROSS_ACCOUNT || '234567890123'; // this account MUST have af-south-1 enabled + +const delegationRoleName = 'MyUniqueDelegationRole'; + +const parentZoneName = 'uniqueexample.com'; + +class ParentStack extends cdk.Stack { + constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + const parentZone = new route53.PublicHostedZone(this, 'HostedZone', { + zoneName: parentZoneName, + }); + const crossAccountRole = new iam.Role(this, 'CrossAccountRole', { + roleName: delegationRoleName, + assumedBy: new iam.AccountPrincipal(crossAccount), + }); + parentZone.grantDelegation(crossAccountRole); + } +} + +class ChildStack extends cdk.Stack { + constructor(scope: Construct, id: string, props: ChildStacksProps) { + super(scope, id, props); + const delegationRoleArn = cdk.Stack.of(this).formatArn({ + region: '', + service: 'iam', + account: account, + resource: 'role', + resourceName: delegationRoleName, + }); + const delegationRole = iam.Role.fromRoleArn(this, 'DelegationRole', delegationRoleArn); + + const subZone = new route53.PublicHostedZone(this, 'NewSubZone', { + zoneName: props.subZoneName, + }); + + new route53.CrossAccountZoneDelegationRecord(this, 'delegate', { + delegatedZone: subZone, + parentHostedZoneName: parentZoneName, + delegationRole, + }); + } +} + +const oldApp = new cdk.App(); + +const oldParentStack = new ParentStack(oldApp, 'parent-stack', { + env: { + account: account, + region: 'us-east-1', + }, +}); + +const oldChildStack = new ChildStack(oldApp, 'child-stack', { + env: { + account: crossAccount, + region: 'us-east-1', + }, + subZoneName: 'old.uniqueexample.com', +}); + +oldChildStack.addDependency(oldParentStack); + +const newApp = new cdk.App(); + +const newParentStack = new ParentStack(newApp, 'parent-stack', { + env: { + account: account, + region: 'us-east-1', + }, +}); + +const newChildStack = new ChildStack(newApp, 'child-stack', { + env: { + account: crossAccount, + region: 'us-east-1', + }, + subZoneName: 'new.uniqueexample.com', +}); + +newChildStack.addDependency(newParentStack); + +new IntegTest(app, 'Route53RenameCrossAccountInteg', { + testCases: [oldChildStack, newChildStack], + diffAssets: true, +}); diff --git a/packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/index.ts b/packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/index.ts index 0be04017db9d9..c39fd03b0926f 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/index.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/index.ts @@ -3,6 +3,11 @@ import { Route53 } from '@aws-sdk/client-route-53'; // eslint-disable-next-line import/no-extraneous-dependencies import { fromTemporaryCredentials } from '@aws-sdk/credential-providers'; +export type CrossAccountZoneDelegationEvent = AWSLambda.CloudFormationCustomResourceEvent & { + ResourceProperties: ResourceProperties; + OldResourceProperties?: ResourceProperties; +} + interface ResourceProperties { AssumeRoleArn: string, ParentZoneName?: string, @@ -12,18 +17,25 @@ interface ResourceProperties { TTL: number, } -export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) { - const resourceProps = event.ResourceProperties as unknown as ResourceProperties; - +export async function handler(event: CrossAccountZoneDelegationEvent) { + const resourceProps = event.ResourceProperties; switch (event.RequestType) { case 'Create': - case 'Update': return cfnEventHandler(resourceProps, false); + case 'Update': + return cfnUpdateEventHandler(resourceProps, event.OldResourceProperties); case 'Delete': return cfnEventHandler(resourceProps, true); } } +async function cfnUpdateEventHandler(props: ResourceProperties, oldProps: ResourceProperties | undefined) { + if (oldProps && props.DelegatedZoneName !== oldProps.DelegatedZoneName) { + await cfnEventHandler(oldProps, true); + } + await cfnEventHandler(props, false); +} + async function cfnEventHandler(props: ResourceProperties, isDeleteEvent: boolean) { const { AssumeRoleArn, ParentZoneId, ParentZoneName, DelegatedZoneName, DelegatedZoneNameServers, TTL } = props; diff --git a/packages/aws-cdk-lib/aws-route53/test/cross-account-zone-delegation-handler/index.test.ts b/packages/aws-cdk-lib/aws-route53/test/cross-account-zone-delegation-handler/index.test.ts index 8696c93c62d3b..f9d073e82988b 100644 --- a/packages/aws-cdk-lib/aws-route53/test/cross-account-zone-delegation-handler/index.test.ts +++ b/packages/aws-cdk-lib/aws-route53/test/cross-account-zone-delegation-handler/index.test.ts @@ -1,4 +1,4 @@ -import { handler } from '../../lib/cross-account-zone-delegation-handler'; +import { handler, CrossAccountZoneDelegationEvent } from '../../lib/cross-account-zone-delegation-handler'; const mockAssumeRole = jest.fn(); const mockChangeResourceRecordSets = jest.fn(); @@ -77,6 +77,96 @@ test('calls create resource record set with Upsert for Create event', async () = }); }); +test('calls update resource record set with Upsert for Update event', async () => { + // GIVEN + mockStsClient.promise.mockResolvedValueOnce({ Credentials: { AccessKeyId: 'K', SecretAccessKey: 'S', SessionToken: 'T' } }); + mockRoute53Client.promise.mockResolvedValueOnce({}); + + // WHEN + const event= getCfnEvent({ + RequestType: 'Update', + OldResourceProperties: { + ServiceToken: 'Foo', + AssumeRoleArn: 'roleArn', + ParentZoneId: '1', + DelegatedZoneName: 'recordName', + DelegatedZoneNameServers: ['three', 'four'], + TTL: 172800, + }, + }); + await invokeHandler(event); + + // THEN + expect(mockRoute53Client.changeResourceRecordSets).toHaveBeenCalledTimes(1); + expect(mockRoute53Client.changeResourceRecordSets).toHaveBeenCalledWith({ + HostedZoneId: '1', + ChangeBatch: { + Changes: [{ + Action: 'UPSERT', + ResourceRecordSet: { + Name: 'recordName', + Type: 'NS', + TTL: 172800, + ResourceRecords: [{ Value: 'one' }, { Value: 'two' }], + }, + }], + }, + + }); +}); + +test('calls update resource record set with Upsert and Delete for Update event', async () => { + // GIVEN + mockStsClient.promise.mockResolvedValue({ Credentials: { AccessKeyId: 'K', SecretAccessKey: 'S', SessionToken: 'T' } }); + mockRoute53Client.promise.mockResolvedValue({}); + + // WHEN + const event= getCfnEvent({ + RequestType: 'Update', + OldResourceProperties: { + ServiceToken: 'Foo', + AssumeRoleArn: 'roleArn', + ParentZoneId: '1', + DelegatedZoneName: 'anotherRecordName', + DelegatedZoneNameServers: ['three', 'four'], + TTL: 172800, + }, + }); + await invokeHandler(event); + + // THEN + expect(mockStsClient.assumeRole).toHaveBeenCalledTimes(2); + expect(mockRoute53Client.changeResourceRecordSets).toHaveBeenCalledTimes(2); + expect(mockRoute53Client.changeResourceRecordSets).toHaveBeenCalledWith({ + HostedZoneId: '1', + ChangeBatch: { + Changes: [{ + Action: 'UPSERT', + ResourceRecordSet: { + Name: 'recordName', + Type: 'NS', + TTL: 172800, + ResourceRecords: [{ Value: 'one' }, { Value: 'two' }], + }, + }], + }, + }); + expect(mockRoute53Client.changeResourceRecordSets).toHaveBeenCalledWith({ + HostedZoneId: '1', + ChangeBatch: { + Changes: [{ + Action: 'DELETE', + ResourceRecordSet: { + Name: 'anotherRecordName', + Type: 'NS', + TTL: 172800, + ResourceRecords: [{ Value: 'three' }, { Value: 'four' }], + }, + }], + }, + }); +}); + test('calls create resource record set with DELETE for Delete event', async () => { // GIVEN mockStsClient.assumeRole.mockResolvedValueOnce({ Credentials: { AccessKeyId: 'K', SecretAccessKey: 'S', SessionToken: 'T' } }); @@ -141,7 +231,7 @@ test('calls listHostedZonesByName to get zoneId if ParentZoneId is not provided' }); }); -test('throws if more than one HostedZones are returnd for the provided ParentHostedZone', async () => { +test('throws if more than one HostedZones are returned for the provided ParentHostedZone', async () => { // GIVEN const parentZoneName = 'some.zone'; const parentZoneId = 'zone-id'; @@ -167,9 +257,9 @@ test('throws if more than one HostedZones are returnd for the provided ParentHos }); function getCfnEvent( - event?: Partial, + event?: Partial, resourceProps?: any, -): Partial { +): Partial { return { RequestType: 'Create', ResourceProperties: { @@ -187,6 +277,6 @@ function getCfnEvent( // helper function to get around TypeScript expecting a complete event object, // even though our tests only need some of the fields -async function invokeHandler(event: Partial) { - return handler(event as AWSLambda.CloudFormationCustomResourceEvent); -} \ No newline at end of file +async function invokeHandler(event: Partial) { + return handler(event as CrossAccountZoneDelegationEvent); +}