• Go

x509: certificate relies on legacy Common Name field, use SANs instead

Also seen in: kubectl, Helm, Terraform, Docker, Vault, Consul, Prometheus, any Go program

In one sentence

A Go program, such as kubectl or Terraform, rejected a certificate whose only name sits in the Common Name: Go matches names against the SAN extension and nothing else.

Where you see it

In any program written in Go: kubectl, Helm, Terraform, the Docker CLI, Vault, Consul, Prometheus and your own code. The text is the HostnameError of Go’s crypto/x509 package. Builds with Go 1.20 or later put tls: failed to verify certificate: in front, and each tool adds its own context (kubectl says Unable to connect to the server:).

x509: certificate relies on legacy Common Name field, use SANs instead

Go 1.15 and 1.16 builds printed a longer version ending use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0. Three siblings come from the same check, and the causes below cover all of them:

x509: certificate is not valid for any names, but wanted to match registry.internal
x509: certificate is valid for a.example, b.example, not registry.internal
x509: cannot validate certificate for 10.0.0.5 because it doesn't contain any IP SANs

Go prints a count instead of a long list, valid for 120 names, but none matched registry.internal, from Go 1.26, released in February 2026, when the certificate carries a hundred or more names.

What it means

An X.509 certificate can carry a server’s name in two places. The Subject Alternative Name (SAN) extension holds typed entries, DNS: for host names and IP Address: for addresses. The Common Name is one free-text field with no type: registry.internal, Registry Server and 10.0.0.5 are all legal values, and a client has to guess what it is holding. Go matches the name you dial against the SAN and nothing else, and prints the legacy message only when the Common Name would have matched: the name is right, it sits in the wrong place.

Go switched Common Name matching off by default in Go 1.15, released in August 2020, with GODEBUG=x509ignoreCN=0 as a stopgap, and removed the stopgap in Go 1.17, released in August 2021. No client-side setting brings it back; the VerifyHostname documentation says the legacy Common Name field is ignored.

Matching on the Common Name was deprecated in RFC 2818, published in May 2000, RFC 6125 kept it as a last resort, and its replacement is RFC 9525, published in November 2023, which allows a server identity only in the subjectAltName extension. Public certificate authorities have had to include a SAN since the first Baseline Requirements took effect in July 2012, and the current Baseline Requirements mark the Common Name as not recommended and say that, if present, it must be exactly one of the SAN values. Chrome dropped Common Name matching in Chrome 58 in 2017, so the message almost never involves a public certificate.

Likely causes

A private CA or self-signed certificate with no SAN

A self-signed certificate made with a one-line openssl req -x509 -subj "/CN=host", or a private CA whose template never copied the SAN from the request; it worked while older clients fell back to the Common Name. Pull the leaf certificate and print its SAN block:

openssl s_client -connect registry.internal:443 -servername registry.internal </dev/null 2>/dev/null \
  | openssl x509 -noout -text \
  | grep -A1 "Subject Alternative Name"

A healthy certificate prints the extension and its entries:

            X509v3 Subject Alternative Name:
                DNS:registry.internal, DNS:registry, IP Address:10.0.0.5

No output means no SAN extension (-subject instead of -text shows the Common Name; for a file on disk, drop the s_client stage and add -in server.crt).

Fix with OpenSSL 1.1.1 or later: reissue with a SAN listing every name and address clients dial; -addext has existed from OpenSSL 1.1.1, released in September 2018. Self-signed, with your existing key:

openssl req -x509 -key server.key -days 365 \
  -subj "/CN=registry.internal" \
  -addext "subjectAltName=DNS:registry.internal,DNS:registry,IP:10.0.0.5" \
  -out server.crt

For a certificate signing request to a private CA, use -new instead of -x509 -days 365 and write to server.csr. Then the next trap: openssl x509 -req ignores request extensions unless told to copy them, an option available from OpenSSL 3.0:

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -days 365 -copy_extensions copy -out server.crt

On any version, -extfile san.ext adds them from a file holding the line subjectAltName = DNS:registry.internal, DNS:registry, IP:10.0.0.5; openssl ca needs copy_extensions = copy, as in the OpenSSL test CA guide. Check the result with the grep above.

Fix with an older OpenSSL: without -addext, put the extension in a configuration file and pass -config san.cnf:

[req]
distinguished_name = dn
req_extensions = v3_req
x509_extensions = v3_req
prompt = no

[dn]
CN = registry.internal

[v3_req]
subjectAltName = DNS:registry.internal, DNS:registry, IP:10.0.0.5

The CSR guide walks through both paths.

Fix with step-ca, cfssl or cert-manager: each takes the names explicitly. With step, repeat --san:

step ca certificate registry.internal server.crt server.key \
  --san registry.internal --san registry --san 10.0.0.5

With cfssl, hosts becomes the SAN list; an empty array produces exactly this certificate:

{
  "CN": "registry.internal",
  "hosts": ["registry.internal", "registry", "10.0.0.5"],
  "key": { "algo": "ecdsa", "size": 256 }
}

With cert-manager, use dnsNames and ipAddresses and leave commonName out unless something else needs it:

spec:
  secretName: registry-tls
  dnsNames:
    - registry.internal
    - registry
  ipAddresses:
    - 10.0.0.5
  issuerRef:
    name: internal-ca
    kind: ClusterIssuer

See the step-ca guide and the cert-manager guide for the surrounding setup.

The name you dial is not in the SAN

For valid for a.example, b.example, not registry.internal, the certificate is modern but incomplete. Compare its entries with the name the client actually uses: the server: line in your kubeconfig, VAULT_ADDR, the Docker daemon address, a Terraform provider’s endpoint. Short name, fully qualified name and IP address are three different identifiers; each one in use has to be in the SAN, and a wildcard such as *.internal covers exactly one label. Reissue with the missing entry, or point the client at a name that is on the certificate.

An IP address without an IP SAN

For cannot validate certificate for 10.0.0.5 because it doesn't contain any IP SANs, you dialled an address. Go matches an IP address only against IP Address: entries, never against DNS entries or the Common Name, so DNS:registry.internal is no use when you dial https://10.0.0.5. Dial the DNS name, or reissue with IP:10.0.0.5 in the SAN as above.

Check yours

Try it: Hostname matcherOpen the full tool

Runs in your browser. Nothing you paste is sent anywhere.

What do you have?

Paste the certificate and type the name you dial. The matcher lists the SAN entries and shows why a certificate with only a Common Name matches nothing.

Learn why

Guided mission · free · no account · progress saves hereRepair the wrong-name certificate — 7 minutesTest SAN names, wildcards and permitted uses before deciding whether a certificate fits the service.

Does your team keep hitting this?

Everyone can use the lessons. Team seats add earned credentials, invitations and a completion report, so you see who has finished.

See team training

Early edition. Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? Tell us.

Last reviewed Edition 0.9