0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「Transparent Data Encryption for PostgreSQL Free Edition」をインストールしてみる。

Last updated at Posted at 2015-06-22

PostgreSQL9.3にtdeforpgをインストールしてみました。

OS:CentOS6.6(x64)
PostgreSQL:9.3.9-1PGDGをRPMで新規インストール&SRPM

な環境で試します。

RPMのインストール

pgcrypto.soが必要なので、postgresql93-contribもインストールします
# rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
# yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel postgresql93-test
~中略~
インストール:
postgresql93.x86_64 0:9.3.9-1PGDG.rhel6
postgresql93-contrib.x86_64 0:9.3.9-1PGDG.rhel6
postgresql93-devel.x86_64 0:9.3.9-1PGDG.rhel6
postgresql93-libs.x86_64 0:9.3.9-1PGDG.rhel6
postgresql93-server.x86_64 0:9.3.9-1PGDG.rhel6
postgresql93-test.x86_64 0:9.3.9-1PGDG.rhel6
完了しました!

ソースの取得

ビルドにソースが必要なのでSRPMを取得してPatchあて。

 # yumdownloader --source postgresql93
 # rpm -ivh postgresql93-9.3.9-1PGDG.rhel6.src.rpm
 # cd rpmbuild/SPECS/
 # rpmbuild -bp postgresql-9.3.spec
PostgreSQLを初期化しておきます。
# service postgresql-9.3 initdb

ビルド&インストール

 # cd /usr/local/src/
 # git clone https://github.com/nec-postgres/tdeforpg.git
環境変数を設定しておきます。

 # export PGSRC=~/rpmbuild/BUILD/postgresql-9.3.9
 # export PGHOME=/usr/pgsql-9.3
 # export TDEHOME=/usr/local/src/tdeforpg
 # export PATH=/usr/pgsql-9.3/bin/:$PATH
errcodes.hが読み込めないと怒られるのでシンボリックリンクで回避。

 # ln -s $PGHOME/lib/pgcrypto.so /usr/lib64/libpgcrypto.so
 # cd $PGSRC
 # ./configure
 # cd $TDEHOME/SOURCES/data_encryption
 # ln -s $PGSRC/src/backend/utils/errcodes.h $PGSRC/src/include/utils/errcodes.h
 # sh makedencryption.sh 93 $PGSRC

PostgreSQL設定


 # ln -s $TDEHOME/SOURCES/data_encryption/93/data_encryption93.so /usr/lib64/data_encryption.so
モジュールのロード設定を追記。
/var/lib/pgsql/9.3/data/postgresql.conf
shared_preload_libraries='/usr/lib64/data_encryption.so'

PostgreSQL起動

起動してモジュールの読み込みを確認。

 # /etc/init.d/postgresql-9.3 start
postgresql-9.3 サービスを開始中:                           [  OK  ]
cat /var/lib/pgsql/9.3/pgstartup.log
/var/lib/pgsql/9.3/pgstartup.log
成功しました。以下を使用してデータベースサーバを起動することができます。

    /usr/pgsql-9.3/bin/postmaster -D /var/lib/pgsql/9.3/data
または
    /usr/pgsql-9.3/bin/pg_ctl -D /var/lib/pgsql/9.3/data -l logfile start

< 2015-06-22 18:47:51.286 JST >LOG:  ライブラリ"/usr/lib64/data_encryption.so"をロードしました

TDE機能のインストール

ここでは
  • ユーザ:postgres
  • データベース:postgres

に設定します。(pg_hba.confは変更済み)

# cd $TDEHOME/SOURCES
# sh bin/cipher_setup.sh $PGHOME
Transparent data encryption feature setup script
Please select from the setup menu below
Transparent data encryption feature setup menu
1: activate  the transparent data encryption feature
2: inactivate the transparent data encryption feature
select menu [1 - 2] > 1
Please enter database server port to connect : 5432
Please enter database user name to connect : postgres
Please enter password for authentication :
Please enter database name to connect : postgres
CREATE LANGUAGE
INFO: Transparent data encryption feature has been activated

postgresユーザで接続してpgcryptoを有効化

# psql -U postgres

postgres=# create extension pgcrypto;
CREATE EXTENSION
 
postgres=# \d
                リレーションの一覧
 スキーマ |       名前       |    型    |  所有者
----------+------------------+----------+----------
 public   | cipher_key_table | テーブル | postgres
(1 行)
 
postgres=# \df
                                               関数一覧
 スキーマ |           名前            | 結果のデータ型 |        引数のデータ型        |       型
----------+---------------------------+----------------+------------------------------+----------------
 public   | armor                     | text           | bytea                        | normal(通常)
 public   | cipher_key_backup         | boolean        |                              | normal(通常)
 public   | cipher_key_disable_log    | boolean        |                              | normal(通常)
 public   | cipher_key_enable_log     | boolean        |                              | normal(通常)
 public   | cipher_key_reencrypt_data | boolean        | text, text, text             | normal(通常)
 public   | cipher_key_regist         | integer        | text, text, text             | normal(通常)
 public   | crypt                     | text           | text, text                   | normal(通常)
 public   | dearmor                   | bytea          | text                         | normal(通常)
 public   | decrypt                   | bytea          | bytea, bytea, text           | normal(通常)
 public   | decrypt_iv                | bytea          | bytea, bytea, bytea, text    | normal(通常)
 public   | digest                    | bytea          | bytea, text                  | normal(通常)
 public   | digest                    | bytea          | text, text                   | normal(通常)
 public   | enc_compeq_bytea_encbytea | boolean        | bytea, encrypt_bytea         | normal(通常)
 public   | enc_compeq_encbytea       | boolean        | encrypt_bytea, encrypt_bytea | normal(通常)
 public   | enc_compeq_encbytea_bytea | boolean        | encrypt_bytea, bytea         | normal(通常)
 public   | enc_compeq_enctext        | boolean        | encrypt_text, encrypt_text   | normal(通常)
 public   | enc_compeq_enctext_text   | boolean        | encrypt_text, text           | normal(通常)
 public   | enc_compeq_text_enctext   | boolean        | text, encrypt_text           | normal(通常)
 public   | enc_drop_key_info         | boolean        |                              | normal(通常)
 public   | enc_drop_old_key_info     | boolean        |                              | normal(通常)
 public   | enc_hash_encbytea         | integer        | encrypt_bytea                | normal(通常)
 public   | enc_hash_enctext          | integer        | encrypt_text                 | normal(通常)
 public   | enc_rename_backupfile     | boolean        | text, text                   | normal(通常)
 public   | enc_restore_logsetting    | boolean        |                              | normal(通常)
 public   | enc_save_logsetting       | boolean        |                              | normal(通常)
 public   | enc_store_key_info        | boolean        | text, text                   | normal(通常)
 public   | enc_store_old_key_info    | boolean        | text, text                   | normal(通常)
 public   | encbytea_in               | encrypt_bytea  | cstring                      | normal(通常)
 public   | encbytea_out              | cstring        | encrypt_bytea                | normal(通常)
 public   | encbytea_recv             | encrypt_bytea  | internal                     | normal(通常)
 public   | encbytea_send             | bytea          | encrypt_bytea                | normal(通常)
 public   | encrypt                   | bytea          | bytea, bytea, text           | normal(通常)
 public   | encrypt_iv                | bytea          | bytea, bytea, bytea, text    | normal(通常)
 public   | enctext_in                | encrypt_text   | cstring                      | normal(通常)
 public   | enctext_out               | cstring        | encrypt_text                 | normal(通常)
 public   | enctext_recv              | encrypt_text   | internal                     | normal(通常)
 public   | enctext_send              | bytea          | encrypt_text                 | normal(通常)
 public   | gen_random_bytes          | bytea          | integer                      | normal(通常)
 public   | gen_salt                  | text           | text                         | normal(通常)
 public   | gen_salt                  | text           | text, integer                | normal(通常)
 public   | hmac                      | bytea          | bytea, bytea, text           | normal(通常)
 public   | hmac                      | bytea          | text, text, text             | normal(通常)
 public   | pgp_key_id                | text           | bytea                        | normal(通常)
 public   | pgp_pub_decrypt           | text           | bytea, bytea                 | normal(通常)
 public   | pgp_pub_decrypt           | text           | bytea, bytea, text           | normal(通常)
 public   | pgp_pub_decrypt           | text           | bytea, bytea, text, text     | normal(通常)
 public   | pgp_pub_decrypt_bytea     | bytea          | bytea, bytea                 | normal(通常)
 public   | pgp_pub_decrypt_bytea     | bytea          | bytea, bytea, text           | normal(通常)
 public   | pgp_pub_decrypt_bytea     | bytea          | bytea, bytea, text, text     | normal(通常)
 public   | pgp_pub_encrypt           | bytea          | text, bytea                  | normal(通常)
 public   | pgp_pub_encrypt           | bytea          | text, bytea, text            | normal(通常)
 public   | pgp_pub_encrypt_bytea     | bytea          | bytea, bytea                 | normal(通常)
 public   | pgp_pub_encrypt_bytea     | bytea          | bytea, bytea, text           | normal(通常)
 public   | pgp_sym_decrypt           | text           | bytea, text                  | normal(通常)
 public   | pgp_sym_decrypt           | text           | bytea, text, text            | normal(通常)
 public   | pgp_sym_decrypt_bytea     | bytea          | bytea, text                  | normal(通常)
 public   | pgp_sym_decrypt_bytea     | bytea          | bytea, text, text            | normal(通常)
 public   | pgp_sym_encrypt           | bytea          | text, text                   | normal(通常)
 public   | pgp_sym_encrypt           | bytea          | text, text, text             | normal(通常)
 public   | pgp_sym_encrypt_bytea     | bytea          | bytea, text                  | normal(通常)
 public   | pgp_sym_encrypt_bytea     | bytea          | bytea, text, text            | normal(通常)
 public   | pgtde_begin_session       | boolean        | text                         | normal(通常)
 public   | pgtde_end_session         | boolean        |                              | normal(通常)
(63 行)

暗号化キーのテーブルと、暗号化の関数が作成されました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?