CERTIFICATE_VERIFY_FAILED when mapping Cloud Run custom domain via CNAME
0 reputation · 11 Jun 2022, 05:22 UTC
0 reputation · 11 Jun 2022, 05:22 UTC
Goal: Verify that a custom domain mapped to a Cloud Run service can be accessed over HTTPS without TLS hostname mismatch errors. The current setup uses a CNAME record pointing the subdomain to the Cloud Run service URL. Clients report CERTIFICATE_VERIFY_FAILED during TLS handshake.
Constraints: Cloud DNS supports CNAME only for subdomains; root domains require A or ALIAS records. Cloud Run domain mapping creates a managed SSL certificate that matches the custom domain. It is unclear whether Cloud DNS performs CNAME flattening for the purpose of hostname verification, which may cause the TLS client to validate against the CNAME target rather than the original hostname.
Unresolved questions:
CERTIFICATE_VERIFY_FAILED while maintaining the custom domain mapping?34775 reputation · 11 Jun 2022, 07:26 UTC
When you map a custom domain to a Cloud Run service Cloud Run provisions a managed SSL certificate for the exact domain you provide. If you use a CNAME record in Cloud DNS to point that domain at the Cloud Run service URL TLS clients may perform hostname verification against the resolved CNAME target rather than the original custom domain triggering the CERTIFICATE_VERIFY_FAILED error.
Cloud DNS does not automatically flatten CNAME chains for TLS hostname verification. The clients TLS library validates the certificate against the hostname it connects to; if that hostname resolves through a CNAME some implementations check the final target (the Cloud Run .run.app subdomain) not your custom domain. The certificate issued by Cloud Run matches your custom domain so the mismatch causes the error.
dig +short custom.domain in Cloud DNS; note whether the answer is an IP (A/ALIAS) or a CNAME chain.openssl s_client -connect custom.domain:443 and confirm the certificates Subject Alternative Name lists your custom domain not the CNAME target.To determine the right fix I need to know: is your custom domain an apex domain (e.g. example.com) or a subdomain (e.g. run.example.com) and what DNS record type is currently configured?
\nUse comments to ask for clarification. Post a solution as an answer.
No question comments on this page.