How To
Summary
Db2 は 10.5 フィックスパック 5 以降でネイティブ暗号化をサポートしています。
ネイティブ暗号化はデータベース全体を暗号化し、データベース・マネージャーによるユーザー・データの書き出しで暗号化を行い、読み取りで復号化を行います。
暗号化と復号化はアプリケーションから透過で行われますが、I/O パフォーマンスの遅延が予期されています。
データの暗号化はデータ暗号化キー (DEK) で行われ、DEK はマスター・キー (MK) で暗号化されています。MK の喪失はデータの喪失を意味するため管理に注意が必要です。
Objective
この文書ではネイティブ暗号化によるデータベースの暗号化とその管理方法およびマスター・キーの管理方法を概説します。
Environment
Db2 10.5 フィックスパック 5 以降
Steps
暗号化の設定:インスタンス・レベル
ネイティブ暗号化はデータベース・レベルで行われますが、ネイティブ暗号化が使用する鍵ストアの管理はインスタンス・レベルで行われます。ここではローカル鍵ストアの作成と構成例を示します。
- 鍵ストアの作成
GSKit C API コマンド (gsk8capicmd) で PKCS12 タイプの鍵ストアを作成します。
以下の例では、インスタンスのホーム・ディレクトリーに keystore.p12 として作成しています。$ gsk8capicmd_64 -keydb -create -db $HOME/keystore.p12 -pw Str0ngPassw0rd -strong -type pkcs12 -stash $ ls -al keystore* -rw------- 1 db2inst1 db2grp1 1392 Jul 21 19:20 keystore.p12 -rw------- 1 db2inst1 db2grp1 193 Jul 21 19:20 keystore.sth
- データベース・マネージャー構成で 1 で作成した鍵ストアを登録します。
$ db2 update dbm cfg using keystore_type pkcs12 keystore_location $HOME/keystore.p12 DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed successfully. SQL1362W One or more of the parameters submitted for immediate modification were not changed dynamically. Client changes will not be effective until the next time the application is started or the TERMINATE command has been issued. Server changes will not be effective until the next DB2START command. $ db2stop force $ db2start $ db2 get dbm cfg | grep KEYSTORE_ Keystore type (KEYSTORE_TYPE) = PKCS12 Keystore location (KEYSTORE_LOCATION) = /home/db2inst1/keystore.p12
KMIP または PKCS #11を使用してセントラル鍵ストアを構成するには鍵ストア構成を参照してください。
暗号化データベースの作成
CREATE DATABASE コマンドの ENCRYPT オプションで暗号化データベースを作成できます。このときデータ暗号化キーとマスター・キーは自動的に生成されます。デフォルト (AES 256) より弱い秘密鍵を使用したい場合、CIPHER オプションで弱い暗号化アルゴリズム (3DES) や、短いキーの長さを指定可能です。
- インスタンス・オーナーでデータベース・サーバーにログインします。
- CREATE DB で暗号化データベースを作成します。
$ db2 create db encdb encrypt DB20000I The CREATE DATABASE command completed successfully.
- 暗号化されていることと、暗号化の詳細を確認します。
$ db2 connect to encdb Database Connection Information Database server = DB2/LINUXX8664 11.5.8.0 SQL authorization ID = DB2INST1 Local database alias = ENCDB $ db2 get db cfg | grep -i encr Encryption Library for Backup (ENCRLIB) = libdb2encr.so Encryption Options for Backup (ENCROPTS) = CIPHER=AES:MODE=CBC:KEY LENGTH=256 Encrypted database = YES $ db2pd -db encdb -encrypt Database Member 0 -- Database ENCDB -- Active -- Up 0 days 00:00:09 -- Date 2023-07-21-19.23.47.493219 Encryption Info: Object Name: ENCDB Object Type: DATABASE Encyrption Key Info: Encryption Algorithm: AES Encryption Algorithm Mode: CBC Encryption Key Length: 256 Master Key Label: DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.20.32_C76E23B1 Master Key Rotation Timestamp: 2023-07-21-19.20.33.000000 Master Key Rotation Appl ID: *LOCAL.db2inst1.230722021908 Master Key Rotation Auth ID: DB2INST1 Previous Master Key Label: DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.20.32_C76E23B1 KeyStore Info: KeyStore Type: PKCS12 KeyStore Location: /home/db2inst1/keystore.p12 KeyStore Host Name: db2host.example.com KeyStore Port: 0 KeyStore IP Address: xx.xx.xx.xx KeyStore IP Address Type: IPV4 $ gsk8capicmd_64 -cert -list -db $HOME/keystore.p12 -stashed Certificates found * default, - personal, ! trusted, # secret key # DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.20.32_C76E23B1
既存のデータベースの暗号化
既存の暗号化されていないデータベースは、いったんバックアップを採取してリストアするときに暗号化できます。
- インスタンス・オーナーでデータベース・サーバーにログインします。
- 非暗号化データベースをバックアップします。
$ db2 get db cfg for testdb | grep -i encr Encryption Library for Backup (ENCRLIB) = Encryption Options for Backup (ENCROPTS) = Encrypted database = NO $ db2 backup db testdb to . Backup successful. The timestamp for this backup image is : 20230721202509
- データベースをドロップしてバックアップをリストアします。
$ db2 drop db testdb DB20000I The DROP DATABASE command completed successfully. $ db2 restore db testdb from . encrypt without rolling forward DB20000I The RESTORE DATABASE command completed successfully. $ db2 get db cfg for testdb | grep -i encr Encryption Library for Backup (ENCRLIB) = libdb2encr.so Encryption Options for Backup (ENCROPTS) = CIPHER=AES:MODE=CBC:KEY LENGTH=256 Encrypted database = YES
マスター・キーのローテーション
マスター・キー (MK) は DEK と違い外部からアクセス可能です。このため、組織のセキュリティ要件を満たすために定期的なローテーションを推奨します。MK は ADMIN_ROTATE_MASTER_KEY プロシージャーでローテーション可能です。
- セキュリティ管理者としてデータベースに接続します。
データベースのセキュリティ管理者は select grantee from syscat.dbauth where securityadmauth='Y' and granteetype='U' で確認できます。$ db2 connect to encdb user <secadm>
- MK をローテーションします。ローテーション前の MK と現在の MK は db2pd の -encrypt オプションで表示できます。
$ db2 "CALL SYSPROC.ADMIN_ROTATE_MASTER_KEY(NULL)" Value of output parameters -------------------------- Parameter Name : LABEL Parameter Value : DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.31.31_77929CEB Return Status = 0 $ db2pd -db encdb -encrypt Database Member 0 -- Database ENCDB -- Active -- Up 0 days 00:08:23 -- Date 2023-07-21-19.32.01.197139 Encryption Info: Object Name: ENCDB Object Type: DATABASE Encyrption Key Info: Encryption Algorithm: AES Encryption Algorithm Mode: CBC Encryption Key Length: 256 Master Key Label: DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.31.31_77929CEB Master Key Rotation Timestamp: 2023-07-21-19.31.31.000000 Master Key Rotation Appl ID: *LOCAL.db2inst1.230722022345 Master Key Rotation Auth ID: DB2INST1 Previous Master Key Label: DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.20.32_C76E23B1 KeyStore Info: KeyStore Type: PKCS12 KeyStore Location: /home/db2inst1/keystore.p12 KeyStore Host Name: db2host.example.com KeyStore Port: 0 KeyStore IP Address: xx.xx.xx.xx KeyStore IP Address Type: IPV4 $ gsk8capicmd_64 -cert -list -db $HOME/keystore.p12 -stashed Certificates found * default, - personal, ! trusted, # secret key # DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.31.31_77929CEB # DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.20.32_C76E23B1
注:MK をローテーションする前に生成されたトランザクション・ログやバックアップ・イメージを復号化するには、その時点の MK が必要です。このため、鍵ストアの不用意なコピーや、鍵ストアからの古い MK の削除はデータベースの破壊につながる可能性がある点に注意してください。
鍵ストアのベスト・プラクティス
バックアップ・イメージとログ・ファイルのマスター・キー
暗号化されたバックアップやトランザクション・ログ・ファイルの復号化に使用可能な MK は以下の手法で判別できます。
- バックアップ・イメージ
RESTORE DATABASE コマンドの encropts オプションに show master key details を指定すると、DIAGPATH に *masterKeyDetails ファイルが作成されます。
注:このオプションでリストアは実行されません。$ db2 "restore db ENCDB from /work taken at 20230721194059 encropts 'show master key details' without prompting" DB20000I The RESTORE DATABASE command completed successfully. $ cat $DIAGPATH/ENCDB.0.db2inst1.DBPART000.20230721194059.masterKeyDetails KeyStore Type: PKCS12 KeyStore Location: /home/db2inst1/keystore.p12 KeyStore Host Name: db2host.example.com KeyStore Port: 0 KeyStore IP Address: xx.xx.xx.xx KeyStore IP Address Type: IPV4 Encryption Algorithm: AES Encryption Algorithm Mode: CBC Encryption Key Length: 256 Master Key Label: DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.31.31_77929CEB
- ログ・ファイル
db2fmtlog コマンドで、ログ・ファイルの復号化に使用できる MK を表示できます。$ cd <path_to_log_files> $ db2fmtlog 3 Log File S0000003.LOG: Extent Number 3 Format Version 14 Architecture Level Version V:11 R:5 M:8 F:0 I:0 SB:0 Encrypted Yes Compression Mode OFF Number of Pages 1024 Partition 0 Log Stream 0 Database Seed 3976016818 Log File Chain ID Unset Master Key Label DB2_SYSGEN_db2inst1_ENCDB_2023-07-21-19.44.45_6C8C9A0B Previous Extent ID 2023-07-22-02.45.35.000000 GMT Current Extent ID 2023-07-22-02.45.36.000000 GMT Database log ID 2023-07-22-02.20.33.000000 GMT Topology Life ID 2023-07-22-02.20.33.000000 GMT First LFS/LSN Unset Last LFS/LSN Unset LSO range 65705121 to 69878944
暗号化データベースのバックアップ圧縮
暗号化データベースに対してバックアップ時に圧縮を指定しただけでは圧縮効果はほぼありません。
暗号化データベースの解除方法
暗号化データベースの暗号化を解除するには以下の Technote を参照してください。
[Db2] How to decrypt an encrypted database.
ハードウェア・アクセラレーターの使用
ネイティブ暗号化が使用する GSkit は暗号化に利用できるハードウェア・アクセラレーターを検出すると自動的にこれを使用します。
ハードウェア・アクセラレーターが使用されているかどうかは、暗号化データベースを活動化後に db2diag.log を確認してください。詳細は以下のページを参照してください。
なお、Db2 のモニター機能にハードウェア・アクセラレーターに関連するモニター・エレメントはありません。
関連情報
[Db2] ローカル鍵ストアを使用した暗号化データベースの HADR ペアを構築する方法
[Db2] HADR データベースでネイティブ暗号化のマスター鍵をローテーションする方法
パスポート・アドバンテージによく寄せられる質問
お問合せ先
技術的な内容に関して、パスポート・アドバンテージの契約のもと Db2 テクニカル・サポートへお問い合わせください。
Db2 テクニカル・サポート
[Db2] ローカル鍵ストアを使用した暗号化データベースの HADR ペアを構築する方法
[Db2] HADR データベースでネイティブ暗号化のマスター鍵をローテーションする方法
パスポート・アドバンテージによく寄せられる質問
お問合せ先
技術的な内容に関して、パスポート・アドバンテージの契約のもと Db2 テクニカル・サポートへお問い合わせください。
Db2 テクニカル・サポート
Document Location
Worldwide
[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"ARM Category":[{"code":"a8m500000008PmnAAE","label":"Security and Plug-Ins-\u003EEncryption"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"10.1.0;10.5.0;11.5.0"}]
Was this topic helpful?
Document Information
Modified date:
04 February 2024
UID
ibm17014075