PostgreSQL 17 : PostgreSQL over SSL/TLS2025/11/25 |
|
PostgreSQL で SSL/TLS による暗号化通信の設定を有効にします。 |
|
| [1] |
事前に SSL/TLS を取得 または 自己署名の証明書を作成しておきます。 |
| [2] | 作成した証明書をコピーして SSL/TLS の設定をします。 |
|
www:~ # cp /etc/ssl/private/server.{crt,key} /var/lib/pgsql/data/ www:~ # chown postgres:postgres /var/lib/pgsql/data/server.{crt,key} www:~ # chmod 600 /var/lib/pgsql/data/server.{crt,key}
www:~ #
vi /var/lib/pgsql/data/postgresql.conf # 107行目 : コメント解除して変更 ssl = on
# 109, 112行目 : コメント解除して作成した証明書に変更 ssl_cert_file = ' server.crt 'ssl_key_file = ' server.key '
www:~ #
vi /var/lib/pgsql/data/pg_hba.conf # 112行目以降でアクセス元や認証方式の設定 local all all peer # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer host replication all 127.0.0.1/32 ident host replication all ::1/128 ident # 最終行に追記 # [hostssl] ⇒ SSL/TLS 使用時のみ TCP/IP ネットワークを使用する # [10.0.0.0/24] ⇒ アクセス許可するネットワーク # [scram-sha-256] ⇒ SCRAM-SHA-256 パスワード認証を使用する hostssl all all 10.0.0.0/24 scram-sha-256www:~ # systemctl restart postgresql
|
| [3] | 設定が完了したら、PostgreSQL でアクセス許可を設定したネットワーク内の任意のホストから接続確認をしておきます。 |
|
# Unix ドメインソケット接続は通常通り suse@www:~> psql testdb
sql (17.6)
Type "help" for help.
testdb=> \q
# 宛先ホストを指定した TCP/IP 接続は設定通り SSL/TLS 接続 # SSL/TLS 接続時は以下のように [SSL connection ***] と表示される suse@www:~> psql -h www.srv.world testdb
Password for user cent:
psql (17.6)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql)
Type "help" for help.
testdb=> \q
# 他ホストからの TCP/IP 接続も SSL/TLS 接続 node01:~ # psql -h www.srv.world -d testdb -U suse Password for user suse: psql (17.6) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Type "help" for help. testdb=> |
| Sponsored Link |
|
|