# Security in DNS

Who may do what with hosted zones (IAM), what is recorded in the audit log, and who may claim a domain.

## IAM actions

Every request, through the API, the CLI, Terraform or the console, is checked against your IAM
policies. A zone's resource name has no region: `rn:ews::<organization id>:dns:zone/<zone id>`.
Every record action is checked against the zone, so a policy cannot grant one record set of a zone
without the others. Listing and creating zones are checked against `rn:ews::<organization id>:dns:*`.

(The table of IAM actions is generated on the web page.)
- `dns:ChangeRecords` covers adding, editing and deleting record sets; `dns:ImportZone` is
  separate.
- Exporting a zone file needs `dns:ListRecords`.
- Checking the DNSSEC chain of trust needs `dns:GetDnssec`.
- A key or an instance role that gets certificates through DNS-01 (see
  [Get wildcard certificates with Caddy](get-certificates-with-caddy.md)) needs `dns:ListZones` on
  `rn:ews::<organization id>:dns:*`, and `dns:ListRecords` and `dns:ChangeRecords` on the zone.

A policy for someone who may change the records of one zone only (replace _org-id_ and _zone-id_):

```json
{
  "Version": "2024-01-01",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["dns:GetZone", "dns:ListRecords", "dns:ChangeRecords"],
      "Resource": "rn:ews::org-id:dns:zone/zone-id"
    },
    {
      "Effect": "Allow",
      "Action": ["dns:ListZones"],
      "Resource": "rn:ews::org-id:dns:*"
    }
  ]
}
```

The zone's **Access** tab in the console shows who may act on the zone and, with
`iam:AttachUserPolicy`, grants access to it.

## Audit

Creating and deleting zones, adding, editing, deleting and importing records, turning query logging
on or off, and every DNSSEC change are recorded in the audit log, allowed or denied, once the
request has passed its validation: a request with a malformed body, or an id that is not a UUID,
is refused before the permission check and not recorded. Reads, including the delegation and
DNSSEC checks, are recorded only when they are denied, at most once a minute per user and action.

## Who may claim a domain

A hosted zone is answered on the internet as soon as the domain delegates to the platform
nameservers, and nothing checks that you own the domain before you create its zone. So each domain
is held by one organization:

| You claim              | Refused when                                                                                                         |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------- |
| A hosted zone          | It is the platform's own domain, under it, or above it (`400`)                                                       |
| A hosted zone          | Another organization holds the name, a name above it or a name below it, as a zone or an app's custom domain (`409`) |
| A hosted zone          | It is inside one of your own zones (`409`); delegate it from that zone with an `NS` set instead                      |
| An app's custom domain | Another organization holds a zone that contains it, or the same domain on their app (`409`)                          |

The refusals for a hosted zone read "<domain> is the platform's own domain, so a zone cannot be it,
sit under it, or enclose it", "<name> is already a hosted zone on this platform, held by another
organization" (or "a custom domain"), "<name> overlaps <other name>, a hosted zone held by another
organization" (or "a custom domain"), and "<name> is inside <zone>, your zone".

A zone holds its whole tree, so `example.com` and `shop.example.com` cannot belong to two
organizations. A name is available to whoever claims it first: if someone else holds your domain,
contact Deutsche Cloud support.

## Network exposure

The nameservers answer anyone on the internet over UDP and TCP port 53, for hosted zones only; they
never look up other names. See [How the nameservers answer](how-the-nameservers-answer.md).

## Related

- [Create a hosted zone](create-a-hosted-zone.md)
- [Log a zone's queries](log-queries.md)
