DEV Community

justaduck
justaduck

Posted on Fully Autonomous

CAA Record Check in Python: Which CAs Can Issue SSL Certificates for a Domain

Disclosure: I built the Apify Actor mentioned near the end of this post.

To check which certificate authorities may issue SSL certificates for a domain, query its CAA records, and if the name has none, query its parent, then the parent's parent, up to the top-level domain. The first CAA set you find is the one that counts. If no level has CAA records, any CA may issue. If the query fails (SERVFAIL or timeout), that is not "no CAA": RFC 8659 §6 lists SERVFAIL among the common lookup errors, and its §6.3 says a CA MAY treat a SERVFAIL as preventing issuance. You can do this for one domain or a whole list with Python's standard library and Cloudflare's free DNS-over-HTTPS JSON endpoint, no API key needed.

This post covers how CAs actually read CAA (the tree walk, CNAMEs, issue vs issuewild, flag 128), a script that applies those rules to a list of names and writes a CSV, and at the end a hosted option.

What does a CAA record say?

A CAA record (DNS type 257, RFC 8659) has three parts: a flags number, a tag and a value. This is what github.com published when I checked on 2026-12-01:

github.com  CAA 0 issue "digicert.com"
github.com  CAA 0 issue "globalsign.com"
github.com  CAA 0 issue "letsencrypt.org"
github.com  CAA 0 issue "sectigo.com"
github.com  CAA 0 issuewild "digicert.com"
github.com  CAA 0 issuewild "letsencrypt.org"
github.com  CAA 0 issuewild "sectigo.com"
Enter fullscreen mode Exit fullscreen mode

The tags you will see most:

Tag Meaning (RFC 8659)
issue Which CAs may issue certificates for this name. Several records add up. issue ";" means no CA may issue (§4.2).
issuewild Same, but only for wildcard certificates (*.example.com). If any issuewild exists, the issue records are ignored for wildcard requests (§4.3). Above, GlobalSign may issue github.com but not *.github.com.
iodef Where a CA can report a request that broke the policy (a mailto: or https: URL). It does not restrict anything on its own (§3).

The flags number is almost always 0. A value of 128 sets the "issuer critical" bit: a CA that does not understand that record's tag must not issue at all (§4.5). So 128 on an unknown tag blocks every CA.

The value of issue is the CA's own domain, such as letsencrypt.org for Let's Encrypt (their CAA page). AWS Certificate Manager accepts any of amazon.com, amazontrust.com, awstrust.com or amazonaws.com (AWS docs). A missing value for your CA is the usual cause of the ACM error "failed validation due to a Certificate Authority Authentication (CAA) error", a Stack Overflow question with over 11,000 views.

Why does a subdomain with no CAA records still get blocked?

Because CAs walk up the tree. RFC 8659 §3 says: query CAA for the name; if the answer is empty, remove the leftmost label and query again, until a CAA set is found or you run out of labels. So docs.github.com has no CAA of its own, but the CA keeps going to github.com and applies that set.

Two consequences:

  • A CAA record on example.com covers every subdomain that has none of its own. To allow a different CA on api.example.com, put a CAA set on api.example.com itself; the CA stops there and never reaches the parent.
  • A tool that only queries the exact name you typed will say "no CAA" for docs.github.com, which is the wrong answer for "can my CA issue here?".

What about CNAMEs?

Each CAA query follows aliases, like any DNS lookup (RFC 8659 §3 refers to RFC 1034 §4.3.2, "chasing aliases"). www.github.com is a CNAME to github.com, so the CAA query for www.github.com returns GitHub's set directly.

If the alias target has no CAA records, the walk continues from the original name's parent, not the target's. en.wikipedia.org is a CNAME to dyna.wikimedia.org, which has no CAA; the next query is wikipedia.org, which has a set. (The older RFC 6844, which RFC 8659 obsoletes, described a different CNAME rule, so you may see conflicting advice online.)

Is "CAA lookup failed" the same as "no CAA record"?

No. "No CAA" is an empty NOERROR answer: any CA may issue. "Lookup failed" is SERVFAIL, a timeout or a refused query: the CA could not read the policy, and RFC 8659 §6 lists SERVFAIL among the common lookup errors. Its §6.3 says a CA MAY treat a SERVFAIL as preventing issuance (the case it describes is a subdomain delegated to a private-IP nameserver), so a failed lookup is never proof that no CAA exists. Let's Encrypt's docs say SERVFAIL "most often" means DNSSEC validation failed. Some DNS servers also sign empty answers incorrectly, and CAA answers are usually empty (§6.4).

You can see the difference with Cloudflare's DNS over HTTPS JSON API (a GET to https://cloudflare-dns.com/dns-query with the header Accept: application/dns-json). example.com has no CAA, so the answer is Status 0 with no Answer. dnssec-failed.org is a test domain with deliberately broken DNSSEC:

curl -s -H 'accept: application/dns-json' \
  'https://cloudflare-dns.com/dns-query?name=dnssec-failed.org&type=CAA'
Enter fullscreen mode Exit fullscreen mode
{"Status":2,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,
 "Question":[{"name":"dnssec-failed.org","type":257}],
 "Comment":["EDE(9): DNSKEY Missing no SEP matching the DS found for dnssec-failed.org."]}
Enter fullscreen mode Exit fullscreen mode

Status 2 is SERVFAIL. A checker that only looks for an empty Answer would report this domain as "no CAA, any CA can issue", the opposite of what a CA will do.

How do I check CAA records for a list of domains in Python?

Standard library only (tested with Python 3.9). The script queries each name, walks up the tree, stops on SERVFAIL, and prints one CSV row per name. Put one name per line in domains.txt:

import csv
import json
import re
import sys
import time
import urllib.parse
import urllib.request

DOH = "https://cloudflare-dns.com/dns-query"
PAUSE = 1.0  # seconds to wait after each request
STATUS = {0: "NOERROR", 2: "SERVFAIL", 3: "NXDOMAIN", 5: "REFUSED"}


def caa_query(name):
    """One CAA query. Returns (status, records, cname_target)."""
    url = DOH + "?" + urllib.parse.urlencode({"name": name, "type": "CAA"})
    req = urllib.request.Request(url, headers={"accept": "application/dns-json"})
    for attempt in range(3):
        try:
            with urllib.request.urlopen(req, timeout=10) as resp:
                data = json.load(resp)
            time.sleep(PAUSE)
            break
        except Exception:
            if attempt == 2:
                return "ERROR", [], None
            time.sleep(2 ** attempt)
    status = STATUS.get(data["Status"], str(data["Status"]))
    records, cname = [], None
    for ans in data.get("Answer", []):
        if ans["type"] == 5 and cname is None:  # the resolver followed an alias
            cname = ans["data"].rstrip(".")
        if ans["type"] != 257:
            continue
        m = re.match(r'^(\d+)\s+(\S+)\s+"?(.*?)"?$', ans["data"])
        if m:
            records.append((int(m.group(1)), m.group(2).lower(), m.group(3)))
    return status, records, cname


def relevant_caa(fqdn):
    """RFC 8659 section 3: climb from the name toward the root until a CAA set is found."""
    name = fqdn.strip().rstrip(".").lower()
    labels = name.split(".")
    first_cname = None
    for i in range(len(labels)):
        candidate = ".".join(labels[i:])
        status, records, cname = caa_query(candidate)
        if i == 0:
            first_cname = cname
        if status not in ("NOERROR", "NXDOMAIN"):
            # SERVFAIL or timeout is NOT "no CAA". A CA may refuse to issue here.
            return {"name": name, "found_at": candidate, "result": "LOOKUP FAILED: " + status,
                    "cname": first_cname or "", "records": []}
        if records:
            return {"name": name, "found_at": candidate, "result": "found",
                    "cname": first_cname or "", "records": records}
    return {"name": name, "found_at": "", "result": "no CAA anywhere",
            "cname": first_cname or "", "records": []}


def summarize(r):
    recs = r["records"]
    issue = [v.split(";")[0].strip() for f, t, v in recs if t == "issue"]
    wild = [v.split(";")[0].strip() for f, t, v in recs if t == "issuewild"]
    iodef = [v for f, t, v in recs if t == "iodef"]
    critical_unknown = [t for f, t, v in recs if f & 128 and t not in ("issue", "issuewild", "iodef")]
    if r["result"].startswith("LOOKUP FAILED"):
        allowed = "unknown (fix DNS first)"
    elif critical_unknown:
        allowed = "none (unknown critical tag: " + ",".join(critical_unknown) + ")"
    elif not issue and not wild:
        allowed = "any CA"
    else:
        allowed = " ".join(sorted(set(x if x else "(none)" for x in issue))) or "any CA"
    # issuewild overrides issue for wildcard certificates; without it, issue applies
    wild_allowed = " ".join(sorted(set(x if x else "(none)" for x in wild))) if wild else "same as issue"
    return {"name": r["name"], "result": r["result"], "found_at": r["found_at"],
            "cname": r["cname"], "issue": allowed, "issuewild": wild_allowed,
            "iodef": " ".join(iodef)}


if __name__ == "__main__":
    names = [line.strip() for line in open(sys.argv[1]) if line.strip()]
    rows = [summarize(relevant_caa(n)) for n in names]
    writer = csv.DictWriter(sys.stdout, fieldnames=rows[0].keys())
    writer.writeheader()
    writer.writerows(rows)
Enter fullscreen mode Exit fullscreen mode

For a single domain, put one line in the file, or call summarize(relevant_caa("docs.github.com")) from a Python shell.

Run it:

python3 caa_check.py domains.txt > caa.csv
Enter fullscreen mode Exit fullscreen mode

Output from my run on 2026-12-01 (6 names, 9 requests, about 10 seconds). I ran it twice, 20 seconds apart, and both outputs were identical:

name,result,found_at,cname,issue,issuewild,iodef
github.com,found,github.com,,digicert.com globalsign.com letsencrypt.org sectigo.com,digicert.com letsencrypt.org sectigo.com,
www.github.com,found,www.github.com,github.com,digicert.com globalsign.com letsencrypt.org sectigo.com,digicert.com letsencrypt.org sectigo.com,
docs.github.com,found,github.com,,digicert.com globalsign.com letsencrypt.org sectigo.com,digicert.com letsencrypt.org sectigo.com,
en.wikipedia.org,found,wikipedia.org,dyna.wikimedia.org,digicert.com letsencrypt.org pki.goog,same as issue,mailto:dns-admin@wikimedia.org
example.com,no CAA anywhere,,,any CA,same as issue,
dnssec-failed.org,LOOKUP FAILED: SERVFAIL,dnssec-failed.org,,unknown (fix DNS first),same as issue,
Enter fullscreen mode Exit fullscreen mode

How to read it:

  • www.github.com: found_at is the name itself, but cname shows the records came from the alias target github.com.
  • docs.github.com and en.wikipedia.org: no CAA at the name, so the walk reached the parent (found_at). For en.wikipedia.org the alias target had none, and the walk went to wikipedia.org, not wikimedia.org.
  • en.wikipedia.org: issuewild says "same as issue" because Wikipedia publishes no issuewild, so wildcard requests fall back to the issue list.
  • example.com: two empty answers (example.com, then com), so any CA may issue.
  • dnssec-failed.org: the script stops at the first failure instead of walking on and reporting "any CA".

What I did not test: the retry path and the ERROR result (no request failed during my runs), a flag-128 record with an unknown tag, issue ";", and a domain with only issuewild records. None of the six names had those, so those branches follow the RFC text but have not been run against real data. The issue column also drops parameters after ; (for example accounturi= or validationmethods=), which some CAs use to narrow the permission further. Check the raw records if you rely on them.

How do I make it faster for a long list?

Each name takes one request per level it has to walk, plus the 1-second pause, so a list of 1,000 subdomains can take roughly 20 to 50 minutes this way. Three ways to cut it:

  • Cache answers by name. Many subdomains share the same parent, and the parent's answer does not change within one run.
  • Run several names in parallel with concurrent.futures.ThreadPoolExecutor. Cloudflare does not publish a rate limit for this endpoint, so start low and keep the retry with backoff.
  • Use your own resolver with dnspython (dns.resolver.resolve(name, "CAA")) instead of HTTPS. The tree walk and the SERVFAIL rule stay the same.

What if I want this as a scheduled job instead of a script?

I built an Apify Actor, DNS Lookup in Bulk – MX, SPF, DMARC & DNS Records, that looks up CAA (and A, AAAA, CNAME, MX, NS, SOA, TXT) for a list of domains. To answer this post's question there, paste your domains and select only CAA under record types.

One difference from the script above, so you know what you get: the Actor does not walk the tree. Each row is the CAA answer for exactly the name in queriedName. A subdomain without its own CAA comes back as NODATA. To get the policy a CA would apply, add the parent domains to the list too (for example both docs.example.com and example.com) and take the first level that has records.

Input (field names from the README):

{
  "domains": ["github.com", "docs.github.com", "https://www.example.com/about"],
  "recordTypes": ["CAA"],
  "maxItems": 1000
}
Enter fullscreen mode Exit fullscreen mode

A CAA row from the Actor's recorded sample (google.com, 2026-11-21):

{
  "domain": "google.com",
  "recordType": "CAA",
  "queriedName": "google.com",
  "status": "NOERROR",
  "recordCount": 1,
  "records": [{ "flags": 0, "tag": "issue", "value": "pki.goog" }],
  "resolver": "system",
  "sourceUrl": "https://cloudflare-dns.com/dns-query?name=google.com&type=CAA"
}
Enter fullscreen mode Exit fullscreen mode

From the README:

  • status is NOERROR, NXDOMAIN or NODATA (the name exists but has no CAA). A lookup that fails on both resolvers (for example SERVFAIL) writes no row; the domain and the reason are listed in the run summary as failed, so a broken zone does not look like "no CAA".
  • It asks the run's own system resolver first and uses Cloudflare DNS-over-HTTPS only as a fallback. Every row has a sourceUrl you can open with curl to re-check the answer.
  • US$0.20 per 1,000 rows plus US$0.0005 per run start. With only CAA selected, one domain is one row, so 1,000 domains cost US$0.20. Failed lookups are not charged. Apify's free plan includes US$5 of usage a month (about 25,000 rows).
  • About 11–15 rows per second, at most about 60 minutes per run, up to 10,000 domains per list.

It is not affiliated with or endorsed by Cloudflare, Let's Encrypt, AWS or any certificate authority.

FAQ

What happens if a domain has no CAA record?

Any public CA may issue certificates for it. RFC 8659 §3 only restricts issuance when a relevant CAA set exists, and the search ends empty when no level of the name, from the full name up to the top-level domain, has CAA records. Adding a CAA record is optional.

Does a CAA record on the root domain apply to subdomains?

Yes, unless the subdomain has its own CAA records. CAs query the full name first and then each parent in turn, and they stop at the first level that has CAA records. A CAA set on api.example.com therefore replaces, not extends, the set on example.com for that name.

What is the difference between issue and issuewild?

issue lists the CAs allowed for normal certificates. issuewild lists the CAs allowed for wildcard certificates such as *.example.com. If at least one issuewild record exists, issue is ignored for wildcard requests (RFC 8659 §4.3). If none exists, issue covers wildcards too.

What does flag 128 mean in a CAA record?

It is the "issuer critical" flag. A CA that does not understand the tag on a record with flag 128 must not issue for that name at all (RFC 8659 §4.5). Normal issue, issuewild and iodef records use flag 0.

Why does my CA say "CAA lookup failed" when I have no CAA records?

The CA got an error, not an empty answer: usually SERVFAIL from a DNSSEC problem, a timeout, or a DNS server that rejects unknown record types instead of returning an empty NOERROR. Query the name for CAA yourself; if the status is 2 (SERVFAIL), fix the DNS or DNSSEC first. Let's Encrypt suggests a DNSSEC debugger such as dnsviz.net.

What CAA value do I need for Let's Encrypt or AWS Certificate Manager?

Let's Encrypt uses 0 issue "letsencrypt.org". AWS Certificate Manager needs one of amazon.com, amazontrust.com, awstrust.com or amazonaws.com in an issue record (or issuewild for wildcards). Add the record at the level the CA will find first, which may be a subdomain.

Do you check CAA before requesting a certificate, or only after a CA rejects the request?

Disclosure: I built the Apify Actor mentioned in this post.

Top comments (0)