登录
首页 >  Golang >  Go问答

Firebase Admin Go SDK 仅在 Kubernetes 内运行时出现 x509 证书错误

来源:stackoverflow

时间:2024-04-20 10:12:38 352浏览 收藏

目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《Firebase Admin Go SDK 仅在 Kubernetes 内运行时出现 x509 证书错误》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~

问题内容

我目前正在开发一个项目,使用 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?


解决方案


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

今天关于《Firebase Admin Go SDK 仅在 Kubernetes 内运行时出现 x509 证书错误》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>