Tim*_*all 21 ssl ssl-certificate amazon-web-services amazon-rds
我和很多人一样,收到一封电子邮件,说要更新我的 RDS 实例以使用新的 rds-ca-2019 证书进行 SSL 连接(以前是 rds-ca-2015,将于 2020 年 3 月 5 日到期)。他们关于该过程的文档有点稀少,并且说诸如“更新您的数据库应用程序以使用新的 SSL/TLS 证书”之类的内容。和“将证书导入您的操作系统。” 没有关于客户端所需更改的更多详细信息。
当我最初设置时,我没有安装任何证书,而是使用了 vanilla Ubuntu 18.04 EC2 映像。RDS 实例设置为使用 rds-ca-2015,当我使用 psql 连接到 RDS 时,它报告说它正确使用了 TLSv1.2。如果我查看操作系统中安装的根证书,我会发现编号为 1 到 4 的 4 个“Amazon Root CA”证书。这些证书要到 2038 年和 2040 年才会过期。
所以,我的问题有两部分:
Tim*_*all 14
PostgreSQL的默认设置sslmode
是prefer
这意味着它将使用服务器提供的证书加密连接,但不会对其进行验证。如果我要将sslmode
设置更改为verify-ca
或verify-full
然后我需要在特定目录中安装中间证书,然后它会进行适当的验证。
由于我不担心对我的 VPC 的 MITM 攻击,我认为我不会费心切换到“验证”模式。
有问题的 RDS 证书是中间证书。您可能还知道它是 CA 证书。例如,当我使用 MySQL Workbench 时,我必须指定
如果我从未安装过 [证书],那么 SSL/TLS 最初是如何正常工作的?
取决于你的系统是如何设置的。CA 证书只是为所提供的证书提供受信任的权威。很可能会设置一些完全接受任何证书的东西,而无需尝试对其进行验证(即您使用自签名证书)。另一种选择是您的 CA 存储中已经存在一些隐式信任它的东西。这不太可能,但并非不可能。
如果您在本地执行此操作(例如您在与 RDS 实例相同的 VPC 中有一个 EC2 实例),您甚至可能不需要 SSL。
如果我将 RDS 数据库实例更改为使用 rds-ca-2019 并且它似乎“正常工作”,还有什么我需要做的吗?
不。这很令人困惑,但如果您正在连接并且没有收到任何证书错误,我不会担心。
在 ubuntu 中,按照此处所述添加 ca-cert:https : //askubuntu.com/questions/73287/how-do-i-install-a-root-certificate
wget https://s3.amazonaws.com/rds-downloads/rds-ca-2019-root.pem
sudo mkdir /usr/local/share/ca-certificates/aws
sudo mv rds-ca-2019-root.pem /usr/local/share/ca-certificates/aws
sudo openssl x509 \
-in /usr/local/share/ca-certificates/aws/rds-ca-2019-root.pem \
-inform PEM \
-out /usr/local/share/ca-certificates/aws/rds-ca-2019-root.crt
sudo update-ca-certificates
: sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
Adding debian:rds-ca-2019-root.pem
done.
done.
Run Code Online (Sandbox Code Playgroud)
此链接描述了如何为 django 应用程序设置 ssl 证书位置:https : //www.digitalocean.com/community/questions/how-to-connect-managed-database-postgres-with-ssl-mode-varify-full -in-django-app
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<name>',
'USER': '<user>',
'PASSWORD': '<password>',
'HOST' : '<host>',
'PORT' : '25060',
'OPTIONS':{
'sslmode':'verify-full',
'sslrootcert': os.path.join(BASE_DIR, 'ca-certificate.crt')
Run Code Online (Sandbox Code Playgroud)
}
Stackoverflow 中的这篇文章/sf/answers/4075044571/描述了如何使用 psql 的命令行参数进行连接。
psql "host={hostname} sslmode=prefer sslrootcert={ca-cert.pem} \
sslcert={client-cert.pem} sslkey={client-key.pem} port={port} user={user} \
dbname={db}"
Run Code Online (Sandbox Code Playgroud)
还
psqlrc and ~/.psqlrc
Unless it is passed an -X or -c option, psql attempts to read and execute commands
from the system-wide startup file (psqlrc) and then the user's personal startup
file (~/.psqlrc), after connecting to the database but before accepting normal
commands. These files can be used to set up the client and/or the server to taste,
typically with \set and SET commands.
Run Code Online (Sandbox Code Playgroud)
还有更多细节(在最后):https : //info.crunchydata.com/blog/ssl-certificate-authentication-postgresql-docker-containers
# the first parameter specifies which TLS mode to use to connect
export PGSSLMODE="verify-full"
# the following two parameters point to the client key/certificate
export PGSSLCERT="`pwd`/certs/client.crt"
export PGSSLKEY="`pwd`/keys/client.key"
# this parameter points to the trusted root CA certificate
export PGSSLROOTCERT="`pwd`/certs/ca.crt"
Run Code Online (Sandbox Code Playgroud)
环境变量的完整列表在这里:https : //www.postgresql.org/docs/9.2/libpq-envars.html
归档时间: |
|
查看次数: |
13099 次 |
最近记录: |