# Sign a zone with DNSSEC

Turn on DNSSEC signing for a hosted zone, put its DS record at the registrar, and check the chain of trust.

Replace _zone-id_ with the id of your hosted zone and _example.com_ with its domain. A signed zone
lets validating resolvers reject answers for it that were not signed with its keys. The keys use
ECDSA P-256 with SHA-256 (algorithm 13).

**Important:**
Once the DS record is at the registrar, validating resolvers reject any answer for the zone that
its keys did not sign. To turn signing off again, remove the DS first (see
[Turn off DNSSEC](turn-off-dnssec.md)).

## Prerequisites

- Permission for `dns:EnableDnssec` on the zone; to see the keys and the DS record and to check the
  chain of trust, `dns:GetDnssec`. Without `dns:GetDnssec` the console's **DNSSEC** tab says
  "Seeing this zone’s DNSSEC keys needs dns:GetDnssec on it. Ask an administrator."; without
  `dns:EnableDnssec`, **Enable DNSSEC** is unavailable and the tab says "Enabling DNSSEC needs
  dns:EnableDnssec on this zone."
- In the console, also `dns:ListZones` to open **Hosted zones** (without it the page shows an
  access-denied notice) and `dns:GetZone` to open the zone (without it the zone's page is not
  found).
- A registrar that accepts DS records for the domain.
- DNSSEC available on the platform. Where it is not, the console says "Signing zones is not
  available in this region yet. It is on the way; your zone keeps working unsigned until then.",
  and the API refuses with `409` "DNSSEC is not available on this installation: …".

## Step 1: Turn on signing

**Console**
1. Open the zone, then choose the **DNSSEC** tab.
2. Under **DNSSEC is off**, choose **Enable DNSSEC**.

The console says "Signing. Add the DS record below at the registrar." The header's **DNSSEC** fact
reads **Signed**.

**CLI**
```sh
dcloud dns dnssec enable zone-id
```

**API**
```http
POST /dns/api/zones/zone-id/dnssec/enable
```

The answer has `status` `signing` and, in `ds`, the record for the registrar.

**Terraform**
```hcl
resource "dcloud_dns_zone_dnssec" "main" {
  zone_id = dcloud_dns_zone.main.id
}

output "ds" {
  value = dcloud_dns_zone_dnssec.main.ds
}
```

The platform creates a key-signing key and a zone-signing key, and the nameservers sign every
answer from their next pull. Enabling a zone that is already signed changes nothing.

## Step 2: Put the DS record at the registrar

Copy the DS record. In the console it is under **DS record for the registrar**, written as
`<example.com>. IN DS <key tag> 13 2 <digest>`. In the API, CLI and Terraform, `ds` is a list with
one entry `<key tag> 13 2 <digest>` per active key-signing key. Some registrars ask for the fields
one by one: the key tag, algorithm 13 (ECDSAP256SHA256), digest type 2 (SHA-256) and the digest.

## Step 3: Check the chain of trust

The check asks two public resolvers (1.1.1.1 and 8.8.8.8) which DS records the parent zone serves,
and keeps the records both return.

**Console**
1. On the **DNSSEC** tab, under **Chain of trust**, choose **Check now**.

It reads "Secure: the parent serves the DS" once the parent serves the DS of an active key-signing
key, and "Signed, not yet validated: the parent serves no DS for this zone" before.
"The parent serves:" lists what the resolvers returned. The platform also repeats the check by
itself while the zone is signed, so the status changes without **Check now** too.

**CLI**
```sh
dcloud dns dnssec check zone-id
```

**API**
```http
POST /dns/api/zones/zone-id/dnssec/check
```

`secure` is `true` once the parent serves the DS. `502` "Public resolvers did not answer; try
again" when either resolver did not answer; nothing is stored then.

**Terraform**
`secure` of `dcloud_dns_zone_dnssec` shows the result of the last check.

From any machine, a validating resolver then sets the `ad` flag:

```sh
dig +dnssec example.com A @1.1.1.1
```

## Result

The zone is signed and validated. The zone-signing key rolls by itself every 90 days; the
key-signing key rolls when you ask (see [Roll the DNSSEC keys](roll-dnssec-keys.md)). If you enable
DNSSEC again after turning it off completely, the zone gets new keys and a new DS.

## Related

- [Roll the DNSSEC keys](roll-dnssec-keys.md)
- [Turn off DNSSEC](turn-off-dnssec.md)
- [How the nameservers answer](how-the-nameservers-answer.md)
- `dns.dnssec.enable` · `dcloud dns dnssec enable` · `dcloud_dns_zone_dnssec`
