GCP 建议强制使用 SSL 连接数据库,所以我照做了。现在,当尝试连接时,我运行
#This cmd is the same with other options too -> gcloud sql generate-login-token
gcloud auth application-default print-access-token > token.txt
gcloud sql connect instanceid --user=postgres --access-token-file=token.txt
但随后,psql 需要证书(我的机器上有证书,但不确定如何提供)而失败。它失败并出现此错误
dean@Deans-MacBook-Pro database % ./connectMysql.sh
Allowlisting your IP for incoming connection for 5 minutes...done.
Connecting to database with SQL user [postgres].Password:
psql: error: connection to server at "xx.xxx.333.333", port 5432 failed: FATAL: connection requires a valid client certificate
connection to server at "22.222.222.222", port 5432 failed: FATAL: pg_hba.conf rejects connection for host "zz.yy.333.333, user "postgres", database "postgres", no encryption
我想使用 gcloud sql connect,这样它每次都会将我的 ip 列入白名单,因为我经常移动,而且我不想一直将 ip 列入白名单并删除它们。