Hands-on AWS knowledge base for developers Managed Ops
Talk to Us

Go: x509: certificate signed by unknown authority

Export PDF Print-friendly layout with a copyright watermark; choose Save as PDF in the print dialog
Go: x509: certificate signed by unknown authority — Go: x509: certificate signed by unknown authority

原因

Go 程序用系统信任库验证失败:证书链不完整、私有 CA,或容器镜像缺 ca-certificates(Go 不会自动用浏览器信任库)。

解决

  1. Alpine 镜像:apk add --no-cache ca-certificates && update-ca-certificates;
  2. 私有 CA:设置 SSL_CERT_FILE=/path/root.pem 或代码中 RootCAs 指定池;
  3. 服务端补全中间证书;
  4. 调试可用 openssl s_client -showcerts 对照 Go 报的证书指纹。