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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

DnsValidatedCertificate: Tokens in the hostedZone property breaks cdk synth #6133

Closed
rhermes62 opened this issue Feb 5, 2020 · 1 comment 路 Fixed by #6685
Closed

DnsValidatedCertificate: Tokens in the hostedZone property breaks cdk synth #6133

rhermes62 opened this issue Feb 5, 2020 · 1 comment 路 Fixed by #6685
Assignees
Labels
@aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager bug This issue is a bug. effort/small Small work item 鈥撀爈ess than a day of effort in-progress This issue is being actively worked on. p1

Comments

@rhermes62
Copy link
Contributor

馃悰 Bug Report

For the DnsValidatedCertificate construct, tokens within the hostedZone property break the cdk synth with the following error:

DNS zone ${Token[Default.Parameter.Value.1234]} is not authoritative for certificate domain name mydomain.com

Ideally, the validation done in the construct should take into account tokens and not try to validate the string value of the token since, well, that is useless since it will always end up being something like ${Token[Default.Parameter.Value.1371]} opposed to the domain you would expect.

Background

We have our Route53 hosted zone deployed in us-east-1. However, we run a global service and need to be able to reference the hosted zone from any region to be able to do things like creating certificates, creating region-specific CNAMES, etc.

With that and to get past the inability to import values directly, we write the hosted zone id and name into SSM's parameter store using the StringParameter construct.

Then, whenever we need the IHostedZone reference, we leverage a custom resource (SSMParameterReader) that enables us to read parameters stored in whatever region we specify.

interface SSMParameterReaderProps {
  parameterName: string;
  region: string;
}

/**
 * A custom construct that is an AwsCustomResource that will use the provided parameterName and region
 * to make a call to SSM to retrieve the parameter's value in that region.
 *
 * This can be used alongside @aws-cdk/aws-ssm.StringParameter to reference values across regions
 */
export class SSMParameterReader extends AwsCustomResource {
  constructor(scope: Construct, name: string, props: SSMParameterReaderProps) {
    const { parameterName, region } = props;

    const ssmAwsSdkCall: AwsSdkCall = {
      service: 'SSM',
      action: 'getParameter',
      parameters: {
        Name: parameterName
      },
      region,
      physicalResourceId: Date.now().toString() // Update physical id to always fetch the latest version
    };

    super(scope, name, { onUpdate: ssmAwsSdkCall });
  }

  /**
   * Returns the string value of the parameter stored in the SSM parameter store
   */
  public getParameterValue(): string {
    return this.getData('Parameter.Value').toString();
  }
}

Using that custom resource, we can then read the hosted zone id/name and HostedZone.fromHostedZoneAttributes method.

const hostedZoneIdReader = new SSMParameterReader(this, 'Route53HostedZonedIdReader', {
  parameterName: 'ROUTE_53_HOSTED_ZONE_ID',
  region: 'us-east-1'
});
const hostedZoneId: string = hostedZoneIdReader.getParameterValue();

const hostedZoneNameReader = new SSMParameterReader(this, 'Route53HostedZoneNameReader', {
  parameterName: 'ROUTE_53_HOSTED_ZONE_NAME',
  region: 'us-east-1'
});
const hostedZoneName: string = hostedZoneNameReader.getParameterValue();

const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'Route53HostedZone', { hostedZoneId, zoneName: hostedZoneName });

With this, we can then use the hostedZone like it was deployed locally. We have used this extensively for creating CNAMES and aliases in the hosted zone from any region but we ran into issues whenever we tried to use the DnsValidatedCertificate since it's validation logic doesn't take into account tokens which are what the output of custom resources get referenced as.

Environment

  • CDK CLI Version: 1.20.0
  • Module Version: 1.20.0
  • OS: macOS Mojave
  • Language: TypeScript (but likely all languages)
@rhermes62 rhermes62 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2020
@SomayaB SomayaB added the @aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager label Feb 5, 2020
@skinny85 skinny85 added effort/small Small work item 鈥撀爈ess than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 7, 2020
@rhermes62
Copy link
Contributor Author

After looking into it, looks like the recommended way for checking for unresolved tokens like this is simply the isUnresolved method.

I'll work on getting a PR out for this so I can get unblocked.

@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Mar 12, 2020
@mergify mergify bot closed this as completed in #6685 Mar 19, 2020
mergify bot added a commit that referenced this issue Mar 19, 2020
This review adds a basic check to not try and validate unresolved tokens when performing validation for the `DnsValidatedCertificate` construct.

fixes #6133

Co-authored-by: Reed Hermes <hermesr@amazon.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager bug This issue is a bug. effort/small Small work item 鈥撀爈ess than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants