尝试安装 PostgreSQL 免费版的「透明数据加密」

我尝试在PostgreSQL9.3上安装tdeforpg。

操作系统:CentOS 6.6(x64)
PostgreSQL:使用RPM进行新安装并进行SRPM编译。

我将在一个不同的环境中进行尝试。

RPM的安装

 

# 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

完了しました!

 

获取源代码

 


 # yumdownloader --source postgresql93
 # rpm -ivh postgresql93-9.3.9-1PGDG.rhel6.src.rpm
 # cd rpmbuild/SPECS/
 # rpmbuild -bp postgresql-9.3.spec

 

# 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

 


 # 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

 

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
成功しました。以下を使用してデータベースサーバを起動することができます。

    /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 行)