概述
此实验关于Oracle Key Vault。
此实验申请地址在这里,时间为55分钟。
实验帮助在这里。
实验生成需要15分钟左右,最终会生成2个虚机,以下为我的专属配置:
- 129.146.74.138 DBSEC-LAB (数据库主机)
- 129.146.69.205 DBSEC-OKV (OKV服务器或OKV Console)
OKV Console的地址和登录凭证:
- 地址:https://<DBSEC-OKV公网地址>,本例为 https://129.146.69.205
- 用户名:KVRESTADMIN
- 口令:T06tron.
此实验比较容易超时,中途记得申请延时。
Introduction
本研讨会介绍了 Oracle Key Vault (OKV) 的各种特性和功能。 它使用户有机会学习如何配置此设备来管理密钥。
实验中Key Vault的版本为Oracle OKV 21.3。
本实验目标:
- 将 Oracle 数据库(由 TDE 加密)连接到 OKV
- 使用 OKV 管理现有的 DB 钱包
- 迁移 DB 钱包并通过 OKV 管理在线密钥
Task 1: (Mandatory) TDE Prerequisites
登录实例DBSEC-LAB。
sudo su - oracle
cd $DBSEC_LABS/tde
./tde_backup_db.sh
./tde_create_os_directory.sh
./tde_set_tde_parameters.sh
./tde_create_wallet.sh
./tde_create_mek_cdb.sh
./tde_create_mek_pdb.sh pdb1
./tde_create_autologin_wallet.sh
查看之前步骤创建的文件:
$ ./tde_view_wallet_on_os.sh
===================================================================================
Display the Wallet info on the OS...
===================================================================================
. Wallet location and files
/etc/ORACLE/WALLETS/cdb1
/etc/ORACLE/WALLETS/cdb1/tde
/etc/ORACLE/WALLETS/cdb1/tde/ewallet.p12
/etc/ORACLE/WALLETS/cdb1/tde/ewallet_2022051213483375.p12
/etc/ORACLE/WALLETS/cdb1/tde/ewallet_2022051213483989.p12
/etc/ORACLE/WALLETS/cdb1/tde/cwallet.sso
/etc/ORACLE/WALLETS/cdb1/tde_seps
/etc/ORACLE/WALLETS/cdb1/okv
. Display the keystore from the OS
-------------------------
Note:
To view it, run the following OS command:
$ orapki wallet display -wallet /etc/ORACLE/WALLETS/cdb1/tde -pwd Oracle123
-------------------------
Oracle PKI Tool Release 23.0.0.0.0 - Production
Version 23.0.0.0.0
Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
Requested Certificates:
Subject: CN=oracle
User Certificates:
Oracle Secret Store entries:
ORACLE.SECURITY.DB.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY.9623C50C30AD638EE0532C00000A4926
ORACLE.SECURITY.ID.ENCRYPTION.
ORACLE.SECURITY.KB.ENCRYPTION.
ORACLE.SECURITY.KM.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KM.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KT.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KT.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Trusted Certificates:
查看数据库中的Oracle Wallet:
$ ./tde_view_wallet_in_db.sh
===================================================================================
Display the Wallet info in the DB...
===================================================================================
. Display the keystore status
CON_ID NAME WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE
1 CDB$ROOT FILE /etc/ORACLE/WALLETS/cdb1/tde/ OPEN PASSWORD
2 PDB$SEED FILE OPEN PASSWORD
3 PDB1 FILE OPEN PASSWORD
4 PDB2 FILE OPEN_NO_MASTER_KEY PASSWORD
. Display the keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
1 12-MAY-22 01.48.33.897863 PM +00:00 TDE IN PDB CDB1: Initial Master Key
3 12-MAY-22 01.48.39.986914 PM +00:00 TDE IN PDB pdb1: Initial Master Key
现在,您的数据库已准备好用于 OKV 实验!
Task 2: Add an Endpoint
首先,我们需要让 Oracle Key Vault 知道我们的数据库服务器。 我们通过在 OKV 中将其创建为端点来做到这一点。
登录OKV Console(凭证在本文开始处,以下不再重复)。
在Endpoints标签页下,暂无对象。
回到实例DBSEC-LAB,我们将用 OKVdeploy.tgz 文件部署实用程序来自动化此过程。
sudo su - oracle
cd $DBSEC_LABS/okv
./okv_unpack_restservice.sh
./okv_crea_config_script.sh
生成的配置脚本okv-ep.sh会被下一个脚本调用:
$ cat /u01/app/okvrest/okv-ep.sh
mkdir -pv /etc/ORACLE/WALLETS/cdb1/okv
echo "Create Wallet CDB1 in OKV"
okv manage-access wallet create --wallet CDB1 --unique FALSE
echo "Create Endpoint for CDB1 in OKV"
okv admin endpoint create --endpoint CDB1_on_dbseclab --description "dbsec-lab, 10.0.0.150" --type ORACLE_DB --platform LINUX64 --subgroup "USE CREATOR SUBGROUP" --unique FALSE
echo "Make Wallet CDB1 the default Wallet for the Endpoint"
okv manage-access wallet set-default --wallet CDB1 --endpoint CDB1_on_dbseclab
echo "Download and install the OKV client software"
expect << _EOF
set timeout 120
spawn okv admin endpoint provision --endpoint CDB1_on_dbseclab --location /etc/ORACLE/WALLETS/cdb1/okv --auto-login FALSE
expect "Enter Oracle Key Vault endpoint password: "
send "change-on-install\r"
expect eof
_EOF
将你的数据库CDB1添加为端点:
./okv_add_endpoint.sh
修改端点的默认口令:
$ ./okv_change_endpoint_pwd.sh
==============================================================================
Change the Endpoint password...
==============================================================================
. Replace the current password 'change-on-install' to 'Oracle123'
Enter wallet password:change-on-install
Enter new wallet password:Oracle123
Confirm new wallet password:Oracle123
Wallet password changed successfully
回到OKV Console,此时可以看到新生成的端点。 点击端点名称CDB1_ON_DBSECLAB,在Default Wallet部分,确认在 OKV 中创建的 Wallet 是该 Endpoint 的默认 Wallet。
Task 3: View the Contents of the OKV Virtual Wallet
从操作系统,数据库和OKV分别查看Wallet的内容:
./okv_view_wallet_on_os.sh
./okv_view_wallet_in_db.sh
./okv_view_wallet_in_kv.sh
前面2个文件与tde目录下的tde_view_wallet_on_os.sh和tde_view_wallet_in_db.sh几乎一样,此处就不展示输出了。
最后一个命令的输出为:
$ ./okv_view_wallet_in_kv.sh
==============================================================================
View the virtual Wallet contents in Key Vault...
==============================================================================
. View the virtual Wallet contents in Key Vault
Enter Oracle Key Vault endpoint password:
Unique ID Type Identifier
1B19EC08-1308-40E1-B880-05DEAAD6BAC4 Template Template Object: Name ENDPOINT.vSrB6haYTs58xxKj.DEFWALLET
Task 4: Upload the TDE Wallet
通常,用户要做的第一件事是将他们现有的 Oracle 钱包(ewallet.p12 文件)上传到 Oracle Key Vault。 以下脚本,口令处输入Oracle123 。
$ ./okv_upload_wallet.sh
==============================================================================
Upload the Wallet to Oracle Key Vault...
==============================================================================
. Upload the Wallet (as reminder: Wallet and Endpoint password is 'Oracle123')
okvutil version 21.3.0.0.0
Endpoint type: Oracle Database
Configuration file: /etc/ORACLE/WALLETS/cdb1/okv/conf/okvclient.ora
Server: 10.0.0.153:5696
Standby Servers:
Uploading from /etc/ORACLE/WALLETS/cdb1/tde
Enter source wallet password:Oracle123
No auto-login wallet found, password needed
Enter Oracle Key Vault endpoint password:Oracle123
ORACLE.SECURITY.ID.ENCRYPTION.
Trying to connect to 10.0.0.153:5696 ...
Connected to 10.0.0.153:5696.
ORACLE.SECURITY.KB.ENCRYPTION.
ORACLE.SECURITY.KT.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KM.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.AeYvhQ57SU8Jv7FnMlOA7mIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KT.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.KM.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.AWCgf2HBO0/LvxT0NlOl3kYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY.9623C50C30AD638EE0532C00000A4926
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY
Uploaded 2 TDE keys
Uploaded 0 SEPS entries
Uploaded 0 other secrets
Uploaded 4 opaque objects
Uploading private persona
Uploading certificate request
Uploading trust points
Uploaded 1 private keys
Uploaded 1 certificate requests
Uploaded 0 user certificates
Uploaded 0 trust points
Upload succeeded
再次查看OKV中的虚拟钱包,有内容了:
$ ./okv_view_wallet_in_kv.sh
==============================================================================
View the virtual Wallet contents in Key Vault...
==============================================================================
. View the virtual Wallet contents in Key Vault
Enter Oracle Key Vault endpoint password:
Unique ID Type Identifier
1B19EC08-1308-40E1-B880-05DEAAD6BAC4 Template Template Object: Name ENDPOINT.vSrB6haYTs58xxKj.DEFWALLET
35C8FE16-D313-4F95-BF61-1CC1F7CB776F Opaque Object TDE Wallet Metadata
AE8A3F18-47B7-4F08-BF25-FB552D7643E5 Opaque Object TDE Wallet Metadata
D7E93A10-A269-555C-B8C0-9D1106EBA1FE Symmetric Key TDE Master Encryption Key: TAG CDB1: Initial Master Key
C31C6414-D71C-5627-8CE2-6BAA0E93F87F Symmetric Key TDE Master Encryption Key: TAG pdb1: Initial Master Key
B76AC522-4049-4FA3-BFFD-11C42EE45C09 Opaque Object TDE Wallet Metadata
5AB7B79B-39A1-4F3B-BFDF-FEF72AFA140C Opaque Object TDE Wallet Metadata
FE3C1261-8C5A-4F8A-BF6A-5E8DE7767B83 Private Key Private Key
FD983F6B-6039-4F56-BF2A-9E3BF9573297 Opaque Object Certificate Request
在OKV Console,Keys & Wallets选项卡,在Wallet Contents部分,单击Wallet名称(CDB1),可以看到所有上载的Wallet中的内容。 图中的内容与之前脚本的输出一致。
Task 5: Migrate to Online Master Key
将 Oracle Wallet 文件上传到 OKV Server 后,您可以从将主密钥存储在 Wallet 文件中的方式迁移为为从 Oracle Key Vault 查询它们。
在这一步中,我们将 TDE_CONFIGURATION 初始化参数从 KEYSTORE_CONFIGURATION=FILE 设置为 KEYSTORE_CONFIGURATION=OKV|FILE。 这是一个动态参数,所以我们不需要重新启动数据库。
$ ./okv_migrate_wallet_to_kv.sh
==============================================================================
Migrate the virtual Wallet to Key Vault...
==============================================================================
. Add secret for OKV connection
keystore altered.
. Change the tde_configuration initialization parameters to 'keystore_configuration=OKV|FILE'
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
tde_configuration string keystore_configuration=FILE
System altered.
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
tde_configuration string keystore_configuration=OKV|FIL
E
. Migrate the Keystore to KV
keystore altered.
keystore altered.
此时从数据库中可以查看到带OKV的行,WRL表示Wallet Resource Locator,由FILE变为了OKV:
$ ./okv_view_wallet_in_db.sh
===================================================================================
Display the Wallet info in the DB...
===================================================================================
. Display the keystore status
CON_ID NAME WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE
1 CDB$ROOT FILE /etc/ORACLE/WALLETS/cdb1/tde/ OPEN PASSWORD
2 PDB$SEED FILE CLOSED UNKNOWN
3 PDB1 FILE OPEN PASSWORD
4 PDB2 FILE OPEN_NO_MASTER_KEY PASSWORD
1 CDB$ROOT OKV OPEN OKV
2 PDB$SEED OKV CLOSED UNKNOWN
3 PDB1 OKV OPEN OKV
4 PDB2 OKV OPEN_NO_MASTER_KEY OKV
8 rows selected.
. Display the keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
1 12-MAY-22 02.41.10.401381 PM +00:00 TDE IN PDB
3 12-MAY-22 02.41.21.906827 PM +00:00 TDE IN PDB
在OKV中查看,增加了最后2行(即带MKID的2行):
$ ./okv_view_wallet_in_kv.sh
==============================================================================
View the virtual Wallet contents in Key Vault...
==============================================================================
. View the virtual Wallet contents in Key Vault
Enter Oracle Key Vault endpoint password:
Unique ID Type Identifier
1B19EC08-1308-40E1-B880-05DEAAD6BAC4 Template Template Object: Name ENDPOINT.vSrB6haYTs58xxKj.DEFWALLET
35C8FE16-D313-4F95-BF61-1CC1F7CB776F Opaque Object TDE Wallet Metadata
AE8A3F18-47B7-4F08-BF25-FB552D7643E5 Opaque Object TDE Wallet Metadata
D7E93A10-A269-555C-B8C0-9D1106EBA1FE Symmetric Key TDE Master Encryption Key: TAG CDB1: Initial Master Key
C31C6414-D71C-5627-8CE2-6BAA0E93F87F Symmetric Key TDE Master Encryption Key: TAG pdb1: Initial Master Key
B76AC522-4049-4FA3-BFFD-11C42EE45C09 Opaque Object TDE Wallet Metadata
5AB7B79B-39A1-4F3B-BFDF-FEF72AFA140C Opaque Object TDE Wallet Metadata
FE3C1261-8C5A-4F8A-BF6A-5E8DE7767B83 Private Key Private Key
FD983F6B-6039-4F56-BF2A-9E3BF9573297 Opaque Object Certificate Request
88EEF2DB-FE32-4F96-BF9A-731C4E31AC67 Symmetric Key TDE Master Encryption Key: MKID 06ACD3EAE387FD4FD0BFDBC312EE00756B
DE926BFB-28F6-4F8B-BF4F-47FA6D7B08E7 Symmetric Key TDE Master Encryption Key: MKID 067701C6050CD24F96BF27B6F5A19D53A2
现在,我们可以删除操作系统中Wallet了:
./okv_delete_wallet_files.sh
在OKV Console中也可以看到这新增的2行。
Task 6: Create the OKV SEPS Wallet
通常需要从文件系统上保存的 shell 脚本连接到数据库。 如果这些脚本包含数据库连接详细信息,这可能是一个主要的安全问题。 一种解决方案是使用操作系统身份验证,Oracle 为您提供了使用Secure External Password Store (SEPS) 的选项,其中 Oracle 登录凭据存储在客户端 Oracle 钱包中。 在这里,这将实现 DBA 和 OKV 管理员之间的职责分离,DBA不再需要知道 OKV的密码!
将 OKV Endpoint 密码放入 SEPS 钱包:
./okv_add_kv_pwd_to_seps.sh
现在,SEPS 钱包 (${SEPS_WALLET_DIR}/cwallet.sso) 已经存储了 OKV 密码。
通过在OKV 自动登录密钥库添加secret,完成在数据库中SEPS 钱包的设置:
$ ./okv_setup_external_store.sh
==============================================================================
Add the OKV password for the auto_login keystore...
==============================================================================
. Add secret for OKV autologin keystore
SQL> administer key management add secret 'Oracle123' for client 'OKV_PASSWORD' to local auto_login keystore '/etc/ORACLE/WALLETS/cdb1/tde'
keystore altered.
. View the new contents of Wallet directory
total 8
drwxr-xr-x. 3 oracle oinstall 51 May 12 14:56 .
drwx------. 5 oracle oinstall 60 May 12 13:44 ..
drwxr-xr-x. 2 oracle oinstall 4096 May 12 14:47 backup
-rw-------. 1 oracle oinstall 3541 May 12 14:56 cwallet.sso
现在您可以通过外部存储登录来管理密钥库,而无需透漏密码。
Task 7: Perform a Rekey Operation
在继续之前,您必须为容器数据库创建主密钥(MEK)。 每个可插拔数据库也必须有自己的主密钥(PDB$SEED 除外)。
为容器数据库执行TDE Master Key的Rekey操作:
$ ./okv_online_cdb_rekey.sh
==============================================================================
Perform an Online Master Key rekey for the container database...
==============================================================================
CON_NAME
------------------------------
CDB$ROOT
. Display the current keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
---------- ------------------------------------ ---------- --------------------------------------------------
1 12-MAY-22 02.41.10.401381 PM +00:00 TDE IN PDB
3 12-MAY-22 02.41.21.906827 PM +00:00 TDE IN PDB
. Rekey the Online Master Key
SQL> ADMINISTER KEY MANAGEMENT SET KEY USING TAG 'cdb1: OKV Online Master Key rekey on 20220512_1501' FORCE KEYSTORE IDENTIFIED BY EXTERNAL STORE WITH BACKUP container=current
keystore altered.
. Display the new keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
---------- ------------------------------------ ---------- --------------------------------------------------
1 12-MAY-22 03.01.13.099017 PM +00:00 TDE IN PDB cdb1: OKV Online Master Key rekey on 20220512_1501
1 12-MAY-22 02.41.10.401381 PM +00:00 TDE IN PDB
3 12-MAY-22 02.41.21.906827 PM +00:00 TDE IN PDB
在以上输出中:
- 由于创建了SEPS 钱包,现在您可以通过“IDENTIFIED BY EXTERNAL STORE”命令登录
- 不要忘记设置一个明确的标签(USING TAG)以更轻松地找到您的密钥
为可插拔数据库pdb1执行TDE Master Key的Rekey操作:
$ ./okv_online_pdb_rekey.sh pdb1
==============================================================================
Perform an Online Master Key rekey for the pluggable database pdb1...
==============================================================================
CON_NAME
------------------------------
PDB1
. Display the current keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
---------- ------------------------------------ ---------- --------------------------------------------------
3 13-MAY-22 12.32.15.579884 AM +00:00 TDE IN PDB
. Rekey the Online Master Key
SQL> ADMINISTER KEY MANAGEMENT SET KEY USING TAG 'pdb1: OKV Online Master Key rekey on 20220513_0035' FORCE KEYSTORE IDENTIFIED BY EXTERNAL STORE WITH BACKUP container=current
keystore altered.
. Display the new keys in the DB
CON_ID ACTIVATION_TIME KEY_USE TAG
---------- ------------------------------------ ---------- --------------------------------------------------
3 13-MAY-22 12.32.15.579884 AM +00:00 TDE IN PDB
3 13-MAY-22 12.35.13.335209 AM +00:00 TDE IN PDB pdb1: OKV Online Master Key rekey on 20220513_0035
注意输出中的最后一行。
现在,在Key Vault中查看虚拟钱包的新内容(带TAG的2行):
$ ./okv_view_wallet_in_kv.sh
==============================================================================
View the virtual Wallet contents in Key Vault...
==============================================================================
. View the virtual Wallet contents in Key Vault
Enter Oracle Key Vault endpoint password:
Unique ID Type Identifier
4397B064-0BEE-4794-9DE5-46F952DBD660 Template Template Object: Name ENDPOINT.RbCkjUl5jkPwGxsQ.DEFWALLET
D1D8E583-1F79-58F4-A991-6E8B9C3DA1E5 Symmetric Key TDE Master Encryption Key: TAG CDB1: Initial Master Key
1DD9B3BE-E93E-599C-8DB0-200BDF9E5637 Symmetric Key TDE Master Encryption Key: TAG pdb1: Initial Master Key
CA741954-795E-4F18-BFB9-4A08EB6CC895 Opaque Object TDE Wallet Metadata
8D90DD38-D0A2-4F55-BF59-816F91A76164 Opaque Object TDE Wallet Metadata
E94C8B5D-76D2-4FA0-BF01-21B8FA977798 Private Key Private Key
56C7CF32-C06A-4FA9-BF16-C57D10E187D2 Opaque Object Certificate Request
A6AE2563-25C8-4F6B-BF1D-3123A104A8F5 Symmetric Key TDE Master Encryption Key: MKID 06D5EE7062B3F74F85BF9FD44C2CD387B7
61CAC26E-4DF9-4FA9-BFA4-DCE9C530E678 Symmetric Key TDE Master Encryption Key: MKID 0682D068C9C0344FD0BF9A2B12F51927C3
60ECEA58-D0AB-4F4A-BF48-529869322B46 Symmetric Key TDE Master Encryption Key: TAG cdb1: OKV Online Master Key rekey on 20220513_0034
BC9C84A3-4D8D-4F36-BF94-1F370039212E Symmetric Key TDE Master Encryption Key: TAG pdb1: OKV Online Master Key rekey on 20220513_0035
08FF6D4E-65F6-4F77-BFFF-63ADB8E4DF8D Opaque Object TDE Wallet Metadata
3303BD55-2C14-4F00-BF6D-EA8777CCCF79 Opaque Object TDE Wallet Metadata
回到OKV Console,在Keys & Wallets选项卡,单击CDB1。在Wallet Contents部分,和之前的脚本一样,可以看到新增的内容:
Task 8: Secret Management with OKV - Fetching Database Account Password From OKV On-Demand
为secret管理创建一个新的Endpoint。
./okv_add_endpoint_secret.sh
- 我们为非数据库端点创建一个目录,此端点类型为数据库帐户(而非之前的数据库)。
- 我们配置的EndPoint是不需要密码的(autologin),并将 $OKV_RESTHOME/conf/okvrestcli.ini 中的客户端配置更改为指向此secret EndPoint 钱包目录
创建secret的密码并上传到 OKV:
$ ./okv_crea_secret_pwd.sh
==============================================================================
Create the secret password...
==============================================================================
. Create a temporary file on RAM disk
. Create a secret (a random password) into the temporary file
. Create the DB user 'REFRESH_DWH' with the secret generated
Grant succeeded.
. Generate the JSON file (sec-reg.json) to register the secret into OKV
. Upload the secret into OKV
. IMPORTANT: OKV will respond with the unique ID of the secret, please copy it for later!
Secret Unique ID (to copy): 78001895-8C43-4FFE-BFB4-69C51313E47E
. Delete the temporary file which contains the secret to avoid any risk of exposure
说明:
- 此脚本生成一个 JSON 文件 ($OKV_RESTHOME/sec-reg.json) 来注册密钥
生成后,会将secret的密码上传到 OKV - OKV 将回复secret密码的唯一 ID(78001895-8C43-4FFE-BFB4-69C51313E47E),请复制以备后用!
- 因为密码现在在 OKV 中,我们不再需要包含secret密码的临时文件,所以脚本将删除它
现在,为secret密码定义自定义属性:
./okv_add_secret_attributes.sh <SECRET_UNIQUE_ID>
输出为:
$ ./okv_add_secret_attributes.sh 78001895-8C43-4FFE-BFB4-69C51313E47E
==============================================================================
Add username and connect string as custom attributes to the password...
==============================================================================
. Add the username
... Generate the JSON file
... Execute the JSON file
{
"result" : "Success"
}
. Add the connect string
... Generate the JSON file
... Execute the JSON file
{
"result" : "Success"
}
. Confirm that all the custom attribute are correct
{
"result" : "Success",
"value" : {
"attributes" : {
"activationDate" : "2022-05-13 00:46:17",
"cryptoUsageMask" : [ "DERIVE_KEY" ],
"digest" : {
"algorithm" : "SHA-256",
"digestValue" : "DB7B77E51E13194EFDE9A339F2A5311D09CF4A1716DA8CEEAE3547102802C62D",
"keyFormatType" : "RAW"
},
"fresh" : "Yes",
"initialDate" : "2022-05-13 00:46:18",
"lastChangeDate" : "2022-05-13 00:50:53",
"objectType" : "Secret Data",
"state" : "Active"
},
"customAttributes" : [ {
"index" : "0",
"name" : "x-NAME",
"type" : "Text String",
"value" : "REFRESH_DWH"
}, {
"index" : "0",
"name" : "x-CONNECT-STRING",
"type" : "Text String",
"value" : "dbsec-lab:1521/pdb1"
} ]
}
}
说明:
- 我们添加了数据库用户的用户名(此处为 REFRESH_DWH)和数据库连接字符串(此处为“dbsec-lab:1521/pdb1”)
- 最终检查确认所有自定义属性均已正确设置
最后,通过使用secret密码登录到数据库来测试您的密码配置:
./okv_login_with_secret.sh REFRESH_DWH dbsec-lab:1521/pdb1
输出如下,可以看到连接成功了:
$ ./okv_login_with_secret.sh REFRESH_DWH dbsec-lab:1521/pdb1
==============================================================================
Log to the database with the secret password...
==============================================================================
. Generate the json file that contains the username and password to find the unique ID of the secret
Get it from OKV, pass through jq filter, write to file locate-pwd.json
. Execute the JSON file to find the unique ID of the secret
. Get the secret password by specifying the unique ID
. Login to the DB and exit after 3 seconds
SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 13 00:53:01 2022
Version 19.13.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
SYS> SYS> Connected.
这个脚本可以好好看一下,因为这是本实验的精髓(不解释了,看其中的注释吧):
$ cat ./okv_login_with_secret.sh
set +x
echo
echo "=============================================================================="
echo " Log to the database with the secret password..."
echo "=============================================================================="
cd $OKV_RESTHOME
dbuser="${1}"
export TWO_TASK="${2}"
echo
echo ". Generate the json file that contains the username and password to find the unique ID of the secret"
echo " Get it from OKV, pass through jq filter, write to file locate-pwd.json"
okv managed-object object locate --generate-json-input | jq --arg NAME $dbuser --arg twotask $TWO_TASK '.service.options |= (del(.max, .objectGroupMember, .attributes) | .customAttributes[0] |= (.name="x-NAME" | .value=$NAME | .type="TEXT") | .customAttributes[1] |= (.name="x-CONNECT-STRING" | .value=$twotask | .type="TEXT"))' > ./locate-pwd.json
echo
echo ". Execute the JSON file to find the unique ID of the secret"
KMIP_ID=$(okv managed-object object locate --from-json ./locate-pwd.json | jq -r '.value.uuids[0]')
echo
echo ". Get the secret password by specifying the unique ID"
pwd=$(okv managed-object secret get --uuid ${KMIP_ID} | jq '.value.object')
echo
echo ". Login to the DB and exit after 3 seconds"
sqlplus /nolog << _EOF
connect ${dbuser}/${pwd}
exec dbms_session.sleep(3);
_EOF
echo
说明:
- 如您所见,您可以在不知道密码或不输入密码的情况下登录到目标数据库,因为此密码现在在 OKV 中!
- 3 秒后,脚本中断 SQL 会话并自动退出
再在OKV Console中看一下此端点: 也可以看一下secret的属性,我们正式通过这些属性来定位secret的:
最后,重置secret配置:
./okv_clean_endpoint_secret.sh
Task 9: (Optional) Reset the OKV Lab Config
删除本实验期间在 OKV 中创建的 Endpoint 和 Wallet:
./okv_reset_config.sh
重置OKV的二进制文件:
rm -Rf $OKV_HOME
rm -Rf $OKV_RESTHOME/!(*.tgz)
ll $OKV_RESTHOME
现在,如果您愿意,您可以从 TASK 2 再次执行此实验!
当你想清理 TDE 时,可以将数据库恢复到TED之前。
cd $DBSEC_LABS/tde
./tde_restore_init_parameters.sh
./tde_restore_db.sh
./tde_delete_wallet_files.sh
./tde_start_db.sh
./tde_check_init_params.sh
$DBSEC_LABS/okv/okv_view_wallet_in_db.sh
只看最后2步的输出吧:
$ ./tde_check_init_params.sh
===================================================================================
View TDE-related init parameters...
===================================================================================
. View TDE-related init parameters
NAME VALUE
encrypt_new_tablespaces CLOUD_ONLY
one_step_plugin_for_pdb_with_tde FALSE
external_keystore_credential_location
wallet_root
tde_configuration
$ $DBSEC_LABS/okv/okv_view_wallet_in_db.sh
===================================================================================
Display the Wallet info in the DB...
===================================================================================
. Display the keystore status
CON_ID NAME WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE
1 CDB$ROOT FILE /u01/app/oracle/admin/cdb1/wallet NOT_AVAILABLE UNKNOWN
2 PDB$SEED FILE NOT_AVAILABLE UNKNOWN
3 PDB1 FILE NOT_AVAILABLE UNKNOWN
4 PDB2 FILE NOT_AVAILABLE UNKNOWN
. Display the keys in the DB
no rows selected
Appendix: About the Product
Overview
Oracle Key Vault 是一个全栈、安全强化的软件设备,旨在集中管理企业内的密钥和安全对象。
Oracle Key Vault 是一个健壮、安全且符合标准的密钥管理平台,您可以在其中存储、管理和共享您的安全对象。 您可以使用 Oracle Key Vault 管理的安全对象包括加密密钥、Oracle 钱包、Java 密钥库 (JKS)、Java 加密扩展密钥库 (JCEKS) 和凭证文件。
Oracle Key Vault 在您的组织中快速有效地集中加密密钥存储。 Oracle Key Vault 的集中式、高度可用和可扩展的安全解决方案基于 Oracle Linux、Oracle 数据库、Oracle 透明数据加密、Oracle Database Vault、Oracle 虚拟私有数据库和 Oracle GoldenGate 技术等 Oracle 数据库安全特性,有助于克服最大的关键问题 -当今组织面临的管理挑战。 使用 Oracle Key Vault,您可以保留、备份和恢复您的安全对象,防止其意外丢失,并在受保护的环境中管理其生命周期。
Oracle Key Vault 针对 Oracle 堆栈(数据库、中间件、系统)和高级安全透明数据加密 (TDE) 进行了优化。 此外,它还符合行业标准 OASIS 密钥管理互操作性协议 (KMIP),以便与基于 KMIP 的客户端兼容。
您可以使用 Oracle Key Vault 管理各种其他端点,例如 MySQL TDE 加密密钥。
从 Oracle Key Vault 版本 18.1 开始,可以使用新的多主集群操作模式来提供更高的可用性并支持地理分布。
多主集群节点为 Oracle Key Vault 环境提供高可用性、灾难恢复、负载分布和地理分布。
Oracle Key Vault 多主集群提供了一种创建 Oracle Key Vault 节点对的机制,以实现最大的可用性和可靠性。 Oracle Key Vault 支持集群节点的两种模式:只读受限模式或读写模式。
只读受限模式
在这种模式下,只有非关键数据可以更新或添加到节点。 在这种模式下,关键数据只能通过复制来更新或添加。 节点处于只读受限模式有两种情况:
- 节点是只读的,还没有读写对等点。
- 节点是读写对的一部分,但与其读写对等方的通信出现故障,或者节点出现故障。 当两个节点之一不可操作时,则将其余节点设置为只读受限模式。 当读写节点再次能够与其读写对等方通信时,该节点将从只读受限模式恢复到读写模式。
读写模式 此模式允许将关键信息和非关键信息写入节点。 读写节点应始终以读写模式运行。
您可以将只读 Oracle Key Vault 节点添加到集群,从而为需要 Oracle 钱包、加密密钥、Java 密钥库、证书、凭证文件和其他对象的端点提供更高的可用性。
Oracle Key Vault 多主集群是一组互连的 Oracle Key Vault 节点。集群中的每个节点都自动配置为在完全连接的网络中与所有其他节点连接。这些节点可以在地理上分布,并且 Oracle Key Vault 端点与集群中的任何节点进行交互。
此配置将数据复制到所有其他节点,从而降低了数据丢失的风险。为了防止数据丢失,您必须配置称为读写对的节点对来启用双向同步复制。此配置允许将一个节点的更新复制到另一个节点,并在认为更新成功之前在另一个节点上验证这一点。关键数据只能在读写对中添加或更新。所有添加或更新的数据都会异步复制到集群的其余部分。
完成升级过程后,Oracle Key Vault 集群中的每个节点都必须是 Oracle Key Vault 版本 18.1 或更高版本,并且在所有其他节点的一个版本更新中。 任何要加入集群的新 Oracle Key Vault 服务器必须与集群处于同一版本级别。
集群所有节点的时钟必须同步。 因此,集群的所有节点都必须启用网络时间协议 (NTP) 设置。
集群中的每个节点都可以主动独立地为端点提供服务,同时通过跨集群的连续复制来维护相同的数据集。 最小的可能配置是 2 节点集群,最大的配置可以有多达 16 个节点,其中多对节点分布在多个数据中心。
Benefits of Using Oracle Key Vault
Oracle Key Vault 可帮助您应对安全威胁、集中存储密钥和对密钥集中进行生命周期管理。
在您的组织中部署 Oracle Key Vault 将帮助您完成以下任务:
- 管理端点安全对象和密钥的生命周期,包括密钥创建、轮换、停用和删除 防止因忘记密码或意外删除而丢失钥匙和钱包
- 在整个组织的授权端点之间安全地共享密钥
- 使用包含所有必要二进制文件、配置文件和端点证书的单个软件包轻松注册和供应端点,以实现端点和Oracle Key Vault 之间的相互身份验证连接
- 除了透明数据加密 (TDE) 之外,还可以使用其他 Oracle产品和功能,例如 Oracle Real Application Clusters (Oracle RAC)、Oracle Data Guard、可插拔数据库和 Oracle GoldenGate。 Oracle Key Vault 使用 Oracle 数据泵和可传输表空间促进加密数据的移动,这是 Oracle 数据库的一个关键特性
Oracle Key Vault 多主集群提供了额外的好处,例如:
- 通过提供可以从中检索数据的多个 Oracle Key Vault 节点来最大程度地提高密钥可用性
- Oracle Key Vault 多主集群维护期间的零端点停机时间
Want to Learn More?
技术文档:
Acknowledgements
本实验的作者为Hakim Loumi,数据库安全产品经理。贡献者为Peter Wahl, Rene Fontcha。
|