【问题标题】:Firebase Admin Go SDK getting x509 certificate error ONLY when running inside KubernetesFirebase Admin Go SDK 仅在 Kubernetes 内运行时出现 x509 证书错误
【发布时间】:2019-03-30 20:38:11
【问题描述】:

我目前正在使用 Firebase Admin Go SDK 处理身份验证并使用实时数据库的项目。当我在本地运行该项目时(仅运行go run main.go),该项目可以正常工作。当我通过 docker 映像(或 GKE,我都测试过)在 Minikube 中运行它时,每当我尝试进行任何 Firestore 调用时都会收到此错误:

transport: authentication handshake failed: x509: certificate signed by unknown authority

这是我在服务器上用来调用数据库的代码:

// Initialize the app 
opt := option.WithCredentialsFile("./serviceAccountKey.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
// This is the first call I attempt to make, and where the error is thrown
// Create the client
client, err := app.Firestore(context.Background())
iter := client.Collection("remoteModels").Documents(context.Background())
snaps, err := iter.GetAll()
if err != nil {
    logger.Log.Warn("Error getting all remoteModels")
    fmt.Println(err)
    return err
}  

这是我的 Dockerfile,它添加了 Firebase 从控制台提供给我的服务帐户密钥:

FROM scratch

ADD main /
ADD serviceAccountKey.json /

EXPOSE 9090

ENTRYPOINT ["/main", "-grpc-port=9090", "-http-port=9089", "-env=prod"]

我在文档中找不到有关在 Kubernetes 中运行的任何内容。
我需要做些什么才能从 Kubernetes 连接到 Firestore?

【问题讨论】:

  • 您可以尝试将您的应用程序端口 8080 映射到其他端口吗...因为我怀疑 kubernetes api-server 使用该端口,因此请求可能会发送到可能正在验证证书。
  • @AmanJuneja 刚刚尝试过,得到了同样的错误
  • 你能告诉我你做了什么改变......只是好奇,因为在我看来,请求将发送到 apiserver
  • 当然!我刚刚更新了帖子,所以它更容易阅读。我只是仔细检查了端口在某些时候没有被硬编码。从我可以看出它应该在 9089 上运行的代码。
  • 只需将 9089 也添加到暴露行,然后尝试一下

标签: firebase go kubernetes google-cloud-firestore firebase-admin


【解决方案1】:

如果您使用的是基于 alpine 的图像,请尝试运行 apk add ca-certificates,它看起来像一个 tls 错误。
安装ca证书,应该可以解决问题

【讨论】:

  • 我的图像实际上是空的并且运行一个二进制文件,你可以在帖子中看到它。我需要基于 alpine 的图像来添加证书吗?
  • 啊,没关系!通过快速搜索,我找到了an example of a multi-stage build that injects CA certs。这是我的updated dockerfile
  • 刚下课回来测试了一下,效果很好!非常感谢,只是想确保它在我的生产环境(GKE)中也能正常工作
猜你喜欢
  • 2022-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-09
  • 2020-06-27
  • 1970-01-01
相关资源
最近更新 更多