『PostgreSQL 8.0 で OpenSSL を使うための設定』 2005-01-09 version 8.0 2001-05-10 version 7.1 桑村 潤 ここで説明している手順はPostgreSQLの文書に書いてあります。 http://www.postgresql.jp/document/pg800doc/html/ssl-tcp.html をご覧ください。 まず、OpenSSL-0.9.7e をインストールしてある環境で、PostgreSQL を --with-openssl で構成してインストールしてあることが前提となります。 openssl コマンドを使って自己証明書と鍵を作成する必要があります。 (OpenSSL の設定ファイルは OPENSSL_CONF 環境変数で指定できます。) 1. 自己署名用に証明書署名要求をつくります # 1. Create a quick self-signed certificate # the local host name as Common Name; # the challenge password can be left blank 以下のように質問に答えます。"Common Name" にマシンのホスト名、 "challenge password" には何も入れないでリターンします。 -- > openssl req -new -text -out server.req <= Generating a 1024 bit RSA private key .....++++++ ..++++++ writing new private key to 'privkey.pem' Enter PEM pass phrase: XXXXXXXXXXXXXXXXXXX <= パスフレーズ Verifying password - Enter PEM pass phrase: XXXXXXXXXXXXXXXXXXX <= 〃(もう一度) ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP <= State or Province Name (full name) [Some-State]:Yokohama <= Locality Name (eg, city) []:MinatoMirai <= Organization Name (eg, company) [Internet Widgits Pty Ltd]:JPUG <= Organizational Unit Name (eg, section) []:Plamo <= Common Name (eg, YOUR name) []:mygres <= ホスト名を Email Address []:juk@yokohama.email.ne <= Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: <= なし An optional company name []: <= -- この操作で、証明書(証明書署名要求)とデフォルトの名前のプライベート鍵 (privkey.pem)が生成されます。 2. プライベート鍵からパスフレーズを取り去ります # 2. Remove the passphrase # (as you must if you want automatic start-up of the postmaster) # enter the old passphrase (この操作は、postmasterを自動起動させたい場合に必要です) -- > openssl rsa -in privkey.pem -out server.key read RSA key Enter PEM pass phrase: <= 1.で使ったパスフレーズを入力 writing RSA key -- 3. 証明書署名要求を自己署名の証明書に変換します # 3. Turn the certificate into a self-signed certificate -- > openssl req -x509 -in server.req -text -key server.key -out server.crt -- ここまででつくられたファイルは: > ls -ltr ..... -rw-r--r-- 1 postgres pgsql 2166 1月 9日 19:55 server.req -rw-r--r-- 1 postgres pgsql 963 1月 9日 19:55 privkey.pem -rw-r--r-- 1 postgres pgsql 887 1月 9日 19:57 server.key -rw-r--r-- 1 postgres pgsql 3513 1月 9日 19:59 server.crt 4. 鍵と証明書を postmaster が探しにゆく場所にコピーします # 4. copy the key and certificate to where the postmaster will look for デフォルトでその場所は $PGDATA で参照されるディレクトリです。 プライベート鍵のパーミションはオーナーだけにします。 > cp server.key $PGDATA/server.key > cp server.crt $PGDATA/server.crt > chmod go-rwx $PGDATA/server.key 5. postgresql.conf に SSL を利用するための変更を加えます # 5. change postgresql.conf for using ssl このファイルは通常、 $PGDATA/postgresql.conf として存在します。 以下は、 postgresql.conf の変更内容の例です: -- #listen_addresses = 'localhost' #ssl = false listen_addresses = '*' ssl = true -- 6. pg_hba.conf に hostssl タイプの接続エントリを記載します # 6. add entry for hostssl type connection このファイルは通常、 $PGDATA/pg_hba.conf に存在します。 以下は pg_hba.conf への追加例です: -- hostssl sameuser all 192.168.1.0/24 md5 -- この設定は、 192.168.1.0/24のネットワーク(クラスC)にあるホストからの接 続を、md5ハッシュパスワードによる認証でユーザと同名のデータベースに対 するアクセスをすべてのユーザに許可するせって似なっています。 -- (c) 2001-2005 Jun Kuwamura