使用 Hyper Protect Crypto Services PKCS #11 for Oracle 透通資料庫加密
透通資料加密 (Transparent Data Encryption,TDE) 是一種完善的技術,用來加密資料庫中的機密資料。 TDE 受各種熱門資料庫系統支援,包括雲端及內部部署,例如 Oracle® 資料庫。 使用 TDE,資料庫系統會加密資料庫儲存媒體 (例如表格空間和檔案) 及備份媒體上的資料。 當授權使用者及應用程式使用資料時,資料庫系統會自動且透通地加密及解密資料。 資料庫使用者不需要知道 TDE,資料庫應用程式也不需要特別針對 TDE 進行調整。
通常,TDE 使用兩層金鑰階層,由 TDE 主要加密金鑰及 TDE 資料加密金鑰組成。 TDE 資料加密金鑰用來加密及解密資料,而 TDE 主要加密金鑰用來加密及解密 TDE 資料加密金鑰。
因此,規劃 TDE 時的一個重要問題是: 您在何處保留 TDE 主要加密金鑰,以及如何保護它?
目標
本指導教學顯示如何將 TDE 主要加密金鑰儲存在 IBM Cloud® Hyper Protect Crypto Services中,以保持完整且唯一的控制。 基於此目的,您需要使用 Hyper Protect Crypto Services的 PKCS #11 整合特性。
使用本指導教學,您將實作下圖中所描述的設定。
在此設定中,Oracle Database 會呼叫作業來管理 Hyper Protect Crypto Services PKCS #11 程式庫上的 TDE 主要加密金鑰。 Hyper Protect Crypto Services PKCS #11 程式庫與 Hyper Protect Crypto Services 實例互動,它提供最佳類別技術來儲存及管理 TDE 主要加密金鑰。
開始之前
若要完成本指導教學,您需要符合下列必要條件:
作業流程
若要完成此解決方案,讓我們逐步執行下列步驟:
- 起始設定 Hyper Protect Crypto Services 實例。
- 在 Oracle Database 環境 中設定 Hyper Protect Crypto Services PKCS #11 程式庫。
- 設定 Oracle Database TDE 並加密資料。
讓我們從 Hyper Protect Crypto Services 實例起始設定程序開始。
起始設定 Hyper Protect Crypto Services 實例
-
對於本指導教學,您需要先 起始設定 Hyper Protect Crypto Services 實例。
記下 Hyper Protect Crypto Services 實例的 ID 及 EP11 端點位址。 後續步驟需要此資訊。
-
產生 API 金鑰以存取 Hyper Protect Crypto Services 實例。 執行下列指令,以建立 IBM Cloud 帳戶的 API 金鑰:
ibmcloud iam api-key-create apikeyhpcs -d "API key for Hyper Protect Crypto Services PKCS11" -
儲存 API 金鑰的值,以用於後續步驟。
在 Oracle Database 環境中設定 Hyper Protect Crypto Services PKCS #11 程式庫
1. 設定 Oracle Database
您需要具有 Oracle Advanced Security 的 Oracle Database Enterprise Edition 安裝。 本指導教學使用單一實例 Oracle Database 19.3 Enterprise Edition Docker 儲存器。 如需 Oracle Database 儲存器的相關資訊,以及建置個別儲存器的指示,請參閱 Docker 上的 Oracle Database。
-
啟動 Oracle Database 儲存器:
docker run --name oradb -p 1521:1521 -p 5500:5500 -e ORACLE_PWD=password oracle/database:19.3.0-ee請等待實例及資料庫建立完成。
-
從主機系統上的指令行執行下列指令:
docker exec -it --user root --workdir / oradb bash此 Shell 可用來在後續步驟中以
root身分執行指令。
2. 配置 Hyper Protect Crypto Services PKCS #11 程式庫
現在建立 Hyper Protect Crypto Services PKCS #11 特性的配置檔。 配置檔命名為 grep11client.yaml。
調整下列檔案範本,並將檔案命名為 grep11client.yaml:
- 將
<instance_ID>取代為 Hyper Protect Crypto Services 實例的 ID。 - 將
<EP11_endpoint_URL>和<EP11_endpoint_port_number>取代為 Hyper Protect Crypto Services 實例之 EP11 端點位址的個別參數。 - 將
<your_api_key>取代為您建立的 API 金鑰值。
iamcredentialtemplate: &defaultiamcredential
enabled: true
endpoint: "https://iam.cloud.ibm.com"
# Keep the 'apikey' empty. It will be overridden by the Anonymous user API key configured later.
apikey:
# The Universally Unique IDentifier (UUID) of your Hyper Protect Crypto Services instance.
instance: "<instance_ID>"
tokens:
0:
grep11connection:
# The EP11 endpoint address starting from 'ep11'.
# For example: "<instance_ID>.ep11.us-south.hs-crypto.appdomain.cloud"
address: "<EP11_endpoint_URL>"
# The EP11 endpoint port number
port: "<EP11_endpoint_port_number>"
tls:
# Grep11 requires TLS connection.
enabled: true
# Grep11 requires server only authentication, so 'mutual' needs to be set as 'false'.
mutual: false
# 'cacert' is a full-path certificate file.
# In Linux with the 'ca-ca-certificates' package installed, this is normally not needed.
cacert:
# Grep11 requires the server-only authentication, so 'certfile' and 'keyfile' need to be empty.
certfile:
keyfile:
storage:
filestore:
enabled: false
storagepath:
# 'remotestore' needs to be enabled if you want to generate keys with the attribute CKA_TOKEN.
remotestore:
enabled: true
users:
0: # The index of the Security Officer (SO) user MUST be 0.
# The name for the Security Officer (SO) user. For example: "Administrator".
# NEVER put the API key under the SO user for security reasons.
name: "Administrator"
iamauth:
<<: *defaultiamcredential
1: # The index of the normal user MUST be 1.
# The name for the normal user. For example: "Normal user".
# NEVER put the API key under the normal user for security reasons.
name: "Normal user"
# The Space ID is a 128-bit UUID and can be chosen freely.
# The UUID can be generated by third-party tools, such as 'https://www.uuidgenerator.net/'.
# For example: "f00db2f1-4421-4032-a505-465bedfa845b".
# 'tokenspaceID' under the normal user is to identify the private keystore.
tokenspaceID: "f00db2f1-4421-4032-a505-465bedfa845b"
iamauth:
<<: *defaultiamcredential
2: # The index of the anonymous user MUST be 2.
# The name for the anonymous user. For example: "Anonymous".
name: "Anonymous"
# The Space ID is a 128-bit UUID and can be chosen freely.
# The UUID can be generated by third-party tools, such as 'https://www.uuidgenerator.net/'.
# For example: "ca22be26-b798-4fdf-8c83-3e3a492dc215".
# 'tokenspaceID' under the anonymous user is to identify the public keystore.
tokenspaceID: "ca22be26-b798-4fdf-8c83-3e3a492dc215"
iamauth:
<<: *defaultiamcredential
# This API key for the Anonymous user must be provided.
# It will overide the 'apikey' in the previous defaultcredentials.iamauth.apikey field
apikey: "<your_api_key>"
logging:
# Set the logging level.
# The supported levels, in an increasing order of verboseness, are:
# 'panic', 'fatal', 'error', 'warning'/'warn', 'info', 'debug', 'trace'.
# The Default value is 'debug'.
loglevel: debug
# The full path of your logging file.
# For example: /tmp/grep11client.log
logpath: /tmp/grep11client.log
3. 安裝 Hyper Protect Crypto Services PKCS #11 程式庫
-
將建立的配置檔
grep11client.yaml及 PKCS #11 程式庫pkcs11-grep11-<platform>.so.<version>複製到 Oracle Database 儲存器中的起始資料夾。 -
以
root身分執行下列指令,以在 Oracle Database 設定中安裝 Hyper Protect Crypto Services PKCS #11 程式庫。mkdir /etc/ep11client chmod a+rx /etc/ep11client/ cp grep11client.yaml /etc/ep11client/grep11client.yaml chmod a+r /etc/ep11client/grep11client.yaml mkdir -p /opt/oracle/extapi/64/hsm/ibm cp pkcs11-grep11.so.1.1.3 /opt/oracle/extapi/64/hsm/ibm/pkcs11-grep11.so chown -R oracle:oinstall /opt/oracle/extapi touch /tmp/grep11client.log chmod a+rw /tmp/grep11client.log chown oracle:oinstall /tmp/grep11client.log
目錄 /opt/oracle/extapi/64/hsm 及子目錄只能包含一個檔案庫檔案。 移除存在於該目錄及子目錄中的任何其他檔案庫檔案。
4. 檢查磁帶庫設定
-
使用下列指令來安裝指令行公用程式 OpenSC (pkcs11-tool):
sudo yum install opensc -
以
root身分執行下列指令,以檢查磁帶庫設定:pkcs11-tool --module=/opt/oracle/extapi/64/hsm/ibm/pkcs11-grep11.so -I此指令會列印製造商及磁帶庫的相關資訊,例如:
Cryptoki version 2.40 Manufacturer IBM ... Library GREP11 PKCS11 client ...
5. 起始設定 Hyper Protect Crypto Services PKCS #11 程式庫
-
從主機系統上的指令行執行下列指令:
docker exec -it oradb bash此 Shell 可用來以使用者
oracle身分執行後續步驟的指令。 -
若要起始設定記號,請執行下列指令,並將
<your_api_key>取代為您所建立的 API 金鑰。pkcs11-tool --module /opt/oracle/extapi/64/hsm/ibm/pkcs11-grep11.so --init-token --label dbtoken --so-pin=<your_api_key>此指令會列印下列狀態訊息,例如:
Using slot 0 with a present token (0x0) Token successfully initialized
設定 Oracle Database TDE 並加密資料
現在讓我們擔任資料庫管理者的角色。
-
透過新增下列行,更新目錄 '$ORACLE_HOME/network/admin' 中的檔案 'sqlnet.ora':
encryption_wallet_location=(source=(method=hsm))若要這樣做,例如,您可以執行下列指令:
echo "encryption_wallet_location=(source=(method=hsm))" >> $ORACLE_HOME/network/admin/sqlnet.ora請確定檔案 'sqlnet.ora' 不包含
encryption_wallet_location的另一個設定。 -
使用下列指令開啟金鑰儲存庫。 將
<your_api_key>取代為您建立的 API 金鑰:export ORACLE_SID=<your SID, e.g. ORCLCDB> sqlplus / as sysdba SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "<your_api_key>" CONTAINER=ALL; -
使用下列指令建立主要金鑰。 將
<your_api_key>取代為您建立的 API 金鑰:SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "<your_api_key>" WITH BACKUP CONTAINER=ALL; -
使用下列指令建立加密表格空間:
SQL> CREATE TABLESPACE encrypted_ts DATAFILE 'tbs1_data.dbf' SIZE 128K AUTOEXTEND ON NEXT 64K ENCRYPTION USING 'AES256' DEFAULT STORAGE(ENCRYPT); -
如果要驗證設定,您可以在已加密的表格空間中建立表格,並插入一些測試資料:
SQL> CREATE TABLE tde_ts_test (id NUMBER(10), data VARCHAR2(50)) TABLESPACE encrypted_ts; SQL> INSERT INTO tde_ts_test VALUES (1, 'This is a secret!'); SQL> COMMIT; SQL> SELECT * FROM TDE_TS_TEST; -
您也可以建立含有已加密直欄的表格,並插入一些測試資料:
SQL> CREATE USER C##test IDENTIFIED BY test; SQL> GRANT UNLIMITED TABLESPACE TO C##test; SQL> CREATE TABLE C##test.tde_test (id NUMBER(10), data VARCHAR2(50) ENCRYPT); SQL> INSERT INTO C##test.tde_test VALUES (1, 'This is also a secret!'); SQL> COMMIT; SQL> SELECT * FROM C##test.tde_test; # Verify encrypted tablespace and encrypted column SQL> SELECT TABLESPACE_NAME, ENCRYPTED FROM DBA_TABLESPACES; SQL> SELECT * FROM dba_encrypted_columns ;
下一步
您的機密資料現在安全地儲存在已加密表格空間及已加密直欄中。 而且 TDE 主要加密金鑰以高度安全且防竄改的方式保留在 Hyper Protect Crypto Services 中。
在本指導教學中,您已學習如何使用 Hyper Protect Crypto Services來設定 Oracle Database TDE。
- 進一步瞭解 PKCS #11。
- 進一步瞭解 PKCS #11 API。
- 開始使用 PKCS #11 API。