无法使用Google App Engine中的SSL + Golang连接到Google Cloud SQL [英] Cannot connect to Google Cloud SQL using SSL + Golang from Google App Engine

查看:117
本文介绍了无法使用Google App Engine中的SSL + Golang连接到Google Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌表示,你可以使用Golang和 go-sql-driver 连接到Google Cloud SQL,如下所示:

  importdatabase / sql
import _github.com/go-sql-driver/mysql
$ b $ db,err:= sql .Open(mysql,user @ cloudsql(project-id:instance-name)/ dbname)

ref: https://cloud.google.com/appengine/ docs / go / cloud-sql / reference

...然而,这(对我来说)会产生一个x509证书错误:


$ b


x509:证书适用于projectName:instanceName,而不是
projectName

我无法弄清楚如何解决这个问题。根据Google自己的文档,在连接字符串中再次添加实例名称(即使它已经在那里)并没有帮助,也不是正确的。



有没有人设法做到这一点工作?什么是错的?

解决方案

您是否使用SSL连接?此错误消息表明,当您使用mysql驱动程序注册自定义TLSConfig时,必须设置 ServerName 属性,除 之外指定 project-id:instance-name 内部 sql.Open()



如从文档使用TLS设置,但添加 ServerName RegisterTLSConfig 的调用中:

  mysql.RegisterTLSConfig(custom,& tls.Config {
RootCAs:rootCertPool,
证书:clientCert,
ServerName:projectName:instanceName,$ b $然后追加?tls = nameOfYourCustomTLSConfig >

>

  db,err:= sql.Open(mysql,user @ cloudsql(project-id:instance-name )/ dbname?tls = custom)


Google says you can connect to Google Cloud SQL using Golang and the go-sql-driver like so:

import "database/sql"
import _ "github.com/go-sql-driver/mysql"

db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname")

ref: https://cloud.google.com/appengine/docs/go/cloud-sql/reference

... However, this (for me) generates a x509 certificate error:

x509: certificate is valid for projectName:instanceName, not projectName

I cannot figure out how to solve this. Adding the instance name again (even though it's already there) in the connection string does not help, nor is correct according to Google's own docs.

Has anyone managed to make this work? What is wrong?

解决方案

Are you connecting with SSL? This error message indicates that must set the ServerName property when you register your custom TLSConfig with the mysql driver, in addition to specifying the project-id:instance-name inside sql.Open().

e.g. Use the TLS setup from the docs, but add a ServerName in your call to RegisterTLSConfig:

mysql.RegisterTLSConfig("custom", &tls.Config{
            RootCAs:      rootCertPool,
            Certificates: clientCert,
            ServerName:   "projectName:instanceName",
        })

Then append ?tls=nameOfYourCustomTLSConfig

db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname?tls=custom")

这篇关于无法使用Google App Engine中的SSL + Golang连接到Google Cloud SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆