阅读背景:

在没有网络授权的情况下使用Google Cloud SQL

来源:互联网 

I am using Google Cloud PostgreSQL with my django rest api developed locally and to be able to connect to the database, you are required to enter an IP address of where do you want to connect from. My team and I are using dynamic IP addresses and we should change the IP address everytime in the cloud interface in order to connect. Is there any other way? I wanted to try the SSL thing but it's too complicated. Any thoughts? Thanks

我正在使用Google Cloud PostgreSQL和本地开发的django rest api,并且能够连接到数据库,您需要输入要从哪里连接的IP地址。我和我的团队正在使用动态IP地址,我们应该每次都在云端口更改IP地址以进行连接。还有别的办法吗?我想尝试SSL的东西,但它太复杂了。有什么想法吗?谢谢

Edit: I am trying to use SSL and this is what I added to my settings.py but I am getting an error:

编辑:我正在尝试使用SSL,这是我添加到我的settings.py,但我收到一个错误:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'HOST': '00.000.00.000',
    'NAME': 'dbname',
    'USER': 'username',
    'PASSWORD': 'mypassword',
    'OPTIONS': {
        'sslmode': 'require',
        'ssl': {
            'ca': 'certs/server-ca.pem',
            'cert': 'certs/client-cert.pem',
            'key': 'certs/client-key.pem'
            }
    },
}

}

}

The ssl files are located in a folder called certs and this folder is in the same directory as the settings.py file.

ssl文件位于名为certs的文件夹中,此文件夹与settings.py文件位于同一目录中。

This is the error I get when running the server:

这是我在运行服务器时遇到的错误:

django.db.utils.ProgrammingError: invalid dsn: invalid connection option "ssl"

1 个解决方案

#1


0  

Try using cloud proxy This will enable the use of an authenticated connection, however you will not need to worry about the IP or authentication aspect.

尝试使用云代理这将允许使用经过身份验证的连接,但您无需担心IP或身份验证方面。

Using cloud proxy - allows a dedicated connection to your Cloud SQL instance (this is an authenticated connection). Once this is correctly set up, simply point your application to the proxy and all traffic will be sent to the back-end Cloud SQL instance.

使用云代理 - 允许与您的Cloud SQL实例建立专用连接(这是经过身份验证的连接)。正确设置后,只需将应用程序指向代理,所有流量都将发送到后端Cloud SQL实例。

For bonus points, cloud proxy can be configured dynamically using the VM metadata to setup the environment. I have used it like this previously with Terraform where it used to point to a specific cloud sql instance and it saves a lot of effort.

对于奖励积分,可以使用VM元数据动态配置云代理以设置环境。我之前使用它像Terraform一样用于指向特定的云sql实例,它节省了很多精力。


分享到: