<!-- https://pkizerotohero.com/errors/go-x509-legacy-common-name/ | Markdown mirror of the HTML page | PKI Zero to Hero, by Duyutech BV -->

> Fix x509: certificate relies on legacy Common Name field in Go, kubectl and Terraform: Go reads the SAN only. See the SAN with OpenSSL and reissue.

Source: https://pkizerotohero.com/errors/go-x509-legacy-common-name/ · Last reviewed: 2026-10-24

- 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.

[Check yours: Hostname matcher](https://pkizerotohero.com/tools/hostname/)

## 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](https://pkg.go.dev/crypto/x509#HostnameError). 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:`).

```text
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:

```text
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](https://pkizerotohero.com/handbook/glossary/#x509) [certificate](https://pkizerotohero.com/handbook/glossary/#certificate) can carry a server’s name in two places. The [Subject Alternative Name](https://pkizerotohero.com/handbook/glossary/#subject-alternative-name) (SAN) extension holds typed entries, `DNS:` for host names and `IP Address:` for addresses. The [Common Name](https://pkizerotohero.com/handbook/glossary/#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](https://pkizerotohero.com/handbook/glossary/#certificate-authority) 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](https://pkizerotohero.com/handbook/glossary/#self-signed-certificate) made with a one-line `openssl req -x509 -subj "/CN=host"`, or a [private CA](https://pkizerotohero.com/handbook/glossary/#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](https://pkizerotohero.com/handbook/glossary/#leaf-certificate) and print its SAN block:

```bash
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:

```text
            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:

```bash
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](https://pkizerotohero.com/handbook/glossary/#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:

```bash
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](https://pkizerotohero.com/guides/openssl-test-ca/). 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`:

```text
[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](https://pkizerotohero.com/guides/create-csr-openssl/) walks through both paths.

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

```bash
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:

```json
{
  "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:

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

See the [step-ca guide](https://pkizerotohero.com/guides/private-ca-step-ca/) and the [cert-manager guide](https://pkizerotohero.com/guides/kubernetes-cert-manager/) 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.

Warning

Why InsecureSkipVerify and x509ignoreCN are traps

The suggestions that circulate are `InsecureSkipVerify: true` in Go code, `--insecure-skip-tls-verify` for kubectl, `VAULT_SKIP_VERIFY=1`, a custom `VerifyPeerCertificate` that returns nil, or `GODEBUG=x509ignoreCN=0`. The last does nothing on Go 1.17 or later (`go version "$(command -v kubectl)"` shows which toolchain built a binary). The others switch off the whole check, chain and name together, so a [man-in-the-middle](https://pkizerotohero.com/handbook/glossary/#man-in-the-middle) on the path receives your kubeconfig token, Vault token or registry password. Reissuing the certificate fixes every client at once.

## Check yours

*Interactive tool: Hostname matcher (runs in the browser at [/tools/hostname/](https://pkizerotohero.com/tools/hostname/))*

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

- [Names and jobs: SANs, wildcards, key usage and the CA flag](https://pkizerotohero.com/handbook/names-and-key-usage/)
- [X.509 certificate explained: anatomy of a certificate](https://pkizerotohero.com/handbook/x509-certificates/)
- Related: [x509: certificate signed by unknown authority](https://pkizerotohero.com/errors/go-x509-unknown-authority/) and [x509: certificate has expired or is not yet valid](https://pkizerotohero.com/errors/go-x509-certificate-expired/), Go’s other two checks; [No subject alternative names matching IP address … found](https://pkizerotohero.com/errors/java-no-subject-alternative-names/) in Java; [How to create a key and a CSR with OpenSSL (with SANs)](https://pkizerotohero.com/guides/create-csr-openssl/).
- Sources: the [Go 1.15](https://go.dev/doc/go1.15) and [Go 1.17](https://go.dev/doc/go1.17) release notes, [crypto/x509](https://pkg.go.dev/crypto/x509), [RFC 2818](https://www.rfc-editor.org/rfc/rfc2818), [RFC 6125](https://www.rfc-editor.org/rfc/rfc6125.html), [RFC 9525](https://www.rfc-editor.org/rfc/rfc9525.html), the [Baseline Requirements](https://cabforum.org/working-groups/server/baseline-requirements/requirements/), and the OpenSSL [req](https://docs.openssl.org/1.1.1/man1/req/) and [x509](https://docs.openssl.org/3.0/man1/openssl-x509/) manual pages.

**Early edition.** Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? [Tell us](https://pkizerotohero.com/contact/?topic=content-error&page=/errors/go-x509-legacy-common-name/).

Last reviewed 24 October 2026Edition 0.9

## Learn why it happens

- [Chapter 9: Names and jobs: SANs, wildcards, key usage and the CA flag](https://pkizerotohero.com/handbook/names-and-key-usage/)
- [Chapter 8: X.509 certificate explained: anatomy of a certificate](https://pkizerotohero.com/handbook/x509-certificates/)

## Everything on this topic

- [Certificates](https://pkizerotohero.com/topics/certificates/)
