Skip to content

How do I get CloudFront to comply with my organization’s requirement to use DNSSEC?

3 minute read
1

I have an Amazon CloudFront distribution, and I need to comply with my organization's regulatory mandate to use Domain Name System Security Extensions (DNSSEC).

Short description

The default CloudFront domain cloudfront.net doesn't allow DNSSEC. To activate DNSSEC for your domain, you must first create a DNSKEY resource record set. However, because AWS manages the DNS records for CloudFront domains, you can't configure a DNSKEY record. This means that you can't directly activate DNSSEC for a CloudFront domain. Instead, you must activate it through an alternate domain.

If your organization requires the use of DNSSEC, first block access to the distribution from the CloudFront domain. Then, activate DNSSEC on an alternate domain name or Canonical Name Record (CNAME) that's attached to the CloudFront distribution.

Resolution

Block access from CloudFront

To block any requests that have the cloudfront.net domain in the host header, use either AWS WAF or a function.

Use AWS WAF

Use an AWS WAF rule that blocks either of the following request types:

  • A host header that ends with cloudfront.net.
  • All requests that have the domain of the distribution (such as d123abc.cloudfront.net) inside a single header.

Use a function

Use a CloudFront function or AWS Lambda@Edge function to block any requests that have a value in the host header that ends with cloudfront.net. It's a best practice to use a CloudFront function because of lower cost and faster performance.

The following example CloudFront function blocks requests that have the CloudFront domain cloudfront.net in the host header:

function handler(event) {
  var request = event.request;

    // Extract the host header value
    var host = request.headers.host.value;

    // Check if the host header value ends with "cloudfront.net"
    if (host.endsWith('cloudfront.net')) {
      // Return a response to block the request
      return {
        statusCode: 403,
        statusDescription: 'Forbidden',
        headers: {
          'content-type': {
            value: 'text/plain'
          }
        },
        body: 'Access to this resource is forbidden.'
      };
    }

    // Allow the request to proceed
    return request;
  }

Activate DNSSEC on an alternate domain name

After you block access from the CloudFront domain, you can activate DNSSEC on an alternate domain name (CNAME). To do this, follow the steps in Activating DNSSEC signing and establishing a chain of trust.

Test your domain

To confirm that DNSSEC works correctly with your domain, use the DNSSEC analyzer on the Verisign website.

AWS OFFICIALUpdated a year ago