Key Protect CLI 參考資料
最新版本的 IBM® Key Protect for IBM Cloud® CLI 外掛程式提供安全且有效率的方式來管理 Key Protect實例中的金鑰。
當您登入 IBM Cloud CLI 時,當有更新可用時,您會收到通知。 請務必將 CLI 保持最新,以便您可以使用適用於 Key Protect CLI 外掛程式的指令及旗標。
附註
若要安裝並配置 Key Protect CLI 外掛程式,請參閱 設定 CLI 主題。
顯示如何使用 region-set
的範例概述配置中的重要步驟。
舊版
0.8 版的本文件不包含已淘汰的指令。
所有已淘汰的指令都在 0.4.0 和 0.5.2版中運作。 也就是說,0.5.2 版與舊版 0.3.9 和 0.4.0相容。
範例
所有指令都有一個 Example
區段,其中顯示如何在工作流程的環境定義中使用指令。
許多範例利用針對階段作業所設定的環境變數 (與 Key Protect 實例 ID 相關),而非 -i
參數。 以這種方式設定的變數將由外掛程式在適當且必要時自動使用。
# export the Key Protect instance id in the command line
$ export KP_INSTANCE_ID=<INSTANCE_ID>
ibmcloud kp 指令摘要
ibmcloud kp
支援這裡列出的指令。
kp import-token 指令
kp import-token
指令會準備根金鑰以進行安全匯入。
次指令 | 狀態 v0.8 | 說明 |
---|---|---|
create | 建立匯入記號 | |
金鑰加密 | 加密您匯入至服務的金鑰 | |
nonce-encrypt | 加密 kp import-token create 所產生的暫時性要求 |
|
show | 擷取匯入記號 |
kp 實例指令
kp instance
指令會管理 Key Protect 實例。
次指令 | 狀態 v0.8 | 說明 |
---|---|---|
原則 | 列出與實例相關聯的原則 | |
policy-update allowed-network | 更新「容許的網路」的實例原則 | |
policy-update dual-auth-delete | 更新「雙重鑑別刪除」的實例原則 | |
policy-update rotation | 更新 "rotation" 的實例原則 |
kp key 指令
kp key
指令會管理個別金鑰。
次指令 | 狀態 v0.8 | 說明 |
---|---|---|
alias-create | 建立金鑰的唯一且方便參照的別名 | |
cancel-delete | 取消先前排定的刪除金鑰要求 | |
create | 建立金鑰或匯入您自己的金鑰 | |
刪除 | 刪除金鑰 | |
停用 | 停用金鑰 | |
啟用 | 啟用金鑰 | |
原則 | 擷取政策清單 | |
policy-update dual-auth-delete | 更新「雙重鑑別刪除」的金鑰原則 | |
policy-update rotation | 更新「替換」的金鑰原則 | |
還原 | 還原先前已刪除的根金鑰 | |
旋轉 | 替換根金鑰 | |
schedule-delete | 使用 dual-auth-delete 原則來授權要刪除的金鑰 | |
show | 擷取金鑰 | |
同步 | 同步化金鑰的相關聯資源 | |
不換行 | 開啟資料加密金鑰 | |
更新 | 更新金鑰,將它傳送至新的金鑰環 | |
版本 | 列出所有金鑰版本 | |
換行 | 包裝資料加密金鑰 |
kp key-ring 指令
「金鑰環」支援容許使用 kp key-ring
來管理金鑰群組,以取得最佳作法。
次指令 | 狀態 v0.8 | 說明 |
---|---|---|
create | 在 kp 實例內建立金鑰環 | |
刪除 | 刪除 kp 實例內的金鑰環 |
其他 kp 指令
更多用於管理的指令 Key Protect 資源可以支援最佳作法。
指令 | 狀態 v0.8 | 說明 |
---|---|---|
kp 鍵 | 列出 Key Protect 範例中可用的金鑰 | |
kp 金鑰環 | 列出與 kp 實例相關聯的金鑰環 | |
kp 地區集 | 針對不同的區域端點 | |
kp 登錄 | 列出根金鑰與其他雲端資源之間的關聯 | |
kp kmip | 建立及管理 KMIP 配接卡及相關聯的資源。 |
金鑰別名 可以用作方法的 ID,如 金鑰建立、金鑰停用 的範例中所示,以及您在這裡看到「金鑰 ID 或別名」支援的任何位置。
檢視說明
這些是 kp
說明資訊的範例。
ibmcloud kp -h
ibmcloud kp import-token -h
ibmcloud kp key -h
ibmcloud kp keys -h
kp import-token
及 kp key
指令具有次指令。 這些範例顯示部分次指令的說明。
ibmcloud kp import-token create -h
ibmcloud kp key delete -h
kp import-token create
建立匯入記號,可用來將根金鑰加密及匯入至 Key Protect 實例。 依預設,匯入記號會在 10 分鐘 (600 秒) 之後到期。
ibmcloud kp import-token create
-i, --instance-id INSTANCE_ID
[-e, --expiration EXPIRATION_TIME_SECONDS]
[-m, --max-retrievals MAX_RETRIEVALS]
範例
此範例會建立匯入記號。 匯入記號由 nonce
和 public key
組成。
Nonce 是在加密通訊中只能使用一次的任意數字。
# create an import token that expires in 5 minutes and allows 3 retrievals
$ ibmcloud kp import-token create --expiration 300 --max-retrievals 3
Created Expires Max Retrievals Remaining Retrievals
2020-05-04 19:12:07 +0000 UTC 2020-05-04 19:17:07 +0000 UTC 3 3
# show the created token
$ ibmcloud kp import-token show
{
"nonce": "8rf2ldP/zWm1Tjrb",
"payload":
"LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t ...<redacted>... QyBLRVktLS0tLQo="
}
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-e, --expiration
指定匯入記號的有效期限 (以秒為單位)。 此值決定匯入記號及其相關聯公開金鑰在作業中保持有效的時間長度。
最小值為
300
秒(5 分鐘),最大值為86400
秒(24 小時)。 預設值為600
秒 (10 分鐘)。 -
-m, --max-retrievals
設定匯入記號的使用計數。 此值決定匯入標記在過期時間內可擷取的次數,之後就無法再存取。 預設值為
1
。
kp import-token key-encrypt
加密您匯入至的金鑰資料 Key Protect,方法是使用與 Key Protect 實例相關聯的公開金鑰。
然後,在您執行 ibmcloud kp key create
時提供擷取的加密金鑰 以將金鑰匯入至服務。
ibmcloud kp import-token key-encrypt
-i, --instance-id INSTANCE_ID
-k, --key KEY_MATERIAL
-p, --pubkey PUBLIC_KEY
[-a, --hash HASH_ALGORITHM]
範例
此範例會使用所建立的公開金鑰來加密 key material
kp import-token create
.
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
# extract the public key that was created by the "kp import-token create" command
$ PUBLIC_KEY=$(ibmcloud kp import-token show | jq -r '.["payload"]')
# encrypt the key material using the public key
$ ibmcloud kp import-token key-encrypt -k $KEY_MATERIAL -p $PUBLIC_KEY
Encrypted Key
Ela33aTdDiKVUNryLeM/xwUEaKWvzY+u ...<redacted>... Asv7bZxvyZn9KNU=
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。 -
-k, --key
您在服務中儲存及管理的 base64-encoded 金鑰資料。
-p, --pubkey
由 Key Protect配送的 base64-encoded 公開加密金鑰。 若要建立新的公開金鑰,請使用
ibmcloud kp import-token create
。 若要擷取公開金鑰,請使用ibmcloud kp import-token show
。
選用參數
-
-a, --hash
用來包裝金鑰的雜湊演算法。 支援 SHA1 和 SHA256。 預設為 SHA256。 只有 HPCS 才支援 SHA1。
此選項用於產生加密金鑰,該金鑰只能在具有 HPCS API 的要求中使用。 請勿使用此選項來建立 Key Protect 根金鑰。
Hyper Protect Crypto Services (HPCS) 是專用金鑰管理服務及硬體安全模組 (HSM)。 HPCS 與 Key Protect 整合,以產生和加密金鑰。 HPCS 也啟用「保留自己的金鑰 (KYOK)」功能。
附註
如需 HPCS 的相關資訊,請參閱 開始使用 IBM Cloud Hyper Protect Crypto Services。
kp import-token nonce-encrypt
加密由所配送的 Nonce Key Protect (含您匯入至服務的金鑰資料)。
然後,當您執行下列指令時,請提供擷取的加密 Nonce 和 IV 值:
ibmcloud kp key create
以匯入金鑰。
ibmcloud kp import-token nonce-encrypt
-i, --instance-id INSTANCE_ID
-k, --key KEY_MATERIAL
-n, --nonce NONCE
[-c, --cbc]
範例
此範例使用 key material
來加密 nonce
。
Nonce 是在加密通訊中只能使用一次的任意數字。
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
# extract the nonce that was created by the "kp import-token create" command
$ NONCE=$(ibmcloud kp import-token show | jq -r '.["nonce"]')
# encrypt the nonce
$ ibmcloud kp import-token nonce-encrypt -k $KEY_MATERIAL -n $NONCE
Encrypted Nonce IV
mWQad1RHdWoFXFw/D9h8z43t/+0vIZc55VBBQg== 6nvOwUvQdowoD+3v
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。 -
-k, --key
您在服務中儲存及管理的 base64-encoded 金鑰資料。
-n, --nonce
用來驗證匯入金鑰之要求的暫時性要求。 值為 base64-encoded。 若要擷取暫時性要求,請使用
ibmcloud kp import-token show
。
選用參數
-
-c, --cbc
使用 AES-CBC 加密演算法來加密暫時性要求。 只有 HPCS 才支援此演算法方法。 預設加密演算法是 AES-GCM。
此選項用於產生加密的 Nonce,只能在具有 HPCS API 的要求中使用。 請勿使用此選項來建立 Key Protect 根金鑰。
Hyper Protect Crypto Services (HPCS) 是專用金鑰管理服務及硬體安全模組 (HSM)。 HPCS 與 Key Protect 整合,以產生和加密金鑰。 HPCS 也啟用「保留自己的金鑰 (KYOK)」功能。
附註
如需 HPCS 的相關資訊,請參閱 開始使用 IBM Cloud Hyper Protect Crypto Services。
kp import-token show
匯入記號包含公開加密金鑰和暫時性要求。 提供擷取的公開金鑰和 Nonce 作為的引數
ibmcloud kp import-token nonce-encrypt
以及
ibmcloud kp import-token key-encrypt
.
ibmcloud kp import-token show
-i, --instance-id INSTANCE_ID
範例
此範例會建立匯入記號並顯示結果。
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
# show the created token
$ ibmcloud kp import-token show
{
"nonce": "8rf2ldP/zWm1Tjrb",
"payload":
"LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t ...<redacted>... QyBLRVktLS0tLQo="
}
# extract the nonce that was created by the "kp import-token create" command
$ ibmcloud kp import-token show | jq -r '.["nonce"]'
8rf2ldP/zWm1Tjrb
# extract the public key that was created by the "kp import-token create" command
$ ibmcloud kp import-token show | jq -r '.["payload"]'
LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t ...<redacted>... QyBLRVktLS0tLQo=
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
kp 實例原則
擷取實例原則的相關詳細資料,例如 allowed networks
(public-and-private
或 private-only
)、allowed IP
原則、key create import
存取權、度量值及雙重授權刪除 (刪除金鑰需要兩個使用者的授權)。
ibmcloud kp instance policies
[-i, --instance-id INSTANCE_ID]
[-p, --allowed-ip]
[-a, --allowed-network]
[-d, --dual-auth-delete]
[-k, --key-create-import-access]
[-m, --metrics]
[-o, --output OUTPUT]
[-r, --rotation]
範例
此範例顯示如何使用指令及結果。 如果服務沒有查詢的結果,則會傳回空陣列 ([]
)。
# update the instance policy and set the allowed network to public-and-private
$ ibmcloud kp instance policy-update allowed-network --enable --network-type public-and-private
Updating instance policy...
OK
# list the instance policies
$ ibmcloud kp instance policies
Retrieving policy details for instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
OK
Created By user id ...<redacted>...
Creation Date 2020-06-22T16:17:52Z
Last Updated 2020-06-22T16:17:52Z
Updated By user id ...<redacted>...
Policy Type allowedNetwork
Enabled true
Network Allowed public-and-private
# disable the instance allowed-network policy
$ ibmcloud kp instance policy-update allowed-network --disable
Updating instance policy...
OK
# list the instance policies - the policy exists and it's disabled
$ ibmcloud kp instance policies
Retrieving policy details for instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
OK
Created By user id ...<redacted>...
Creation Date 2020-06-22T16:17:52Z
Last Updated 2020-06-22T16:20:08Z
Updated By user id ...<redacted>...
Policy Type allowedNetwork
Enabled false
Network Allowed public-and-private
# list the instance policies and show the output as JSON
$ ibmcloud kp instance policies --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T16:17:52Z",
"lastUpdated": "2020-06-22T16:20:08Z",
"updatedBy": "user id ...<redacted>...",
"policy_type": "allowedNetwork",
"policy_data": { "enabled": false, "attributes": { "allowed_network": "public-and-private" }
}
}
]
必要參數
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-p, --allowed-ip
顯示 "allowed ip" 的實例原則。
-
-a, --allowed-network
顯示「容許的網路」的實例原則。
-
-d, --dual-auth-delete
顯示「雙重授權刪除」的實例原則。
-
-k, --key-create-import-access
擷取實例的金鑰建立匯入存取原則詳細資料。
-
-m, --metrics
擷取實例的度量原則詳細資料。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-r, --rotation
擷取實例的輪替原則詳細資料。
kp instance policy-update allowed-network
更新實例的原則,並將容許的網路設為
public-and-private
或 private-only
。
allowed-network
原則會封鎖實例,使其無法從公用或專用網路取得要求。
對於現有實例,在設定網路存取原則之後會強制執行網路存取原則。
如需相關資訊,請參閱 管理網路存取原則。
ibmcloud kp instance policy-update allowed-network
-i, --instance-id INSTANCE_ID
-d, --disable OR
-e, --enable
-t, --network-type NETWORK_TYPE
範例
此範例將 "allowed network" 原則設為 "public-and-private"。
# update the instance policy and set the allowed network to public-and-private
$ ibmcloud kp instance policy-update allowed-network --enable --network-type public-and-private
Updating instance policy...
OK
# list the instance policies
$ ibmcloud kp instance policies
Retrieving policy details for instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
OK
Created By user id ...<redacted>...
Creation Date 2020-06-22T16:17:52Z
Last Updated 2020-06-22T18:17:32Z
Updated By user id ...<redacted>...
Policy Type allowedNetwork
Enabled true
Network Allowed public-and-private
必要參數
-
-d, --disable
-
-e, --enable
停用或啟用網路存取原則。 需要一個選項。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。 -
-t, --network-type
指定容許的網路存取類型。 選項為
public-and-private
或private-only
。
kp 實例原則-更新 dual-auth-delete
使用 dual-auth-delete
原則來安全地刪除加密金鑰。 當您 刪除金鑰時,您會刪除其內容和相關資料。 金鑰所加密的任何資料都會變成無法存取。
刪除具有雙重授權原則的金鑰需要來自兩個使用者的授權。
有關詳細信息,請參閱 使用雙重授權策略刪除密鑰。
附註
實例的雙重授權刪除不同於金鑰的雙重授權刪除。
針對金鑰啟用 dual-auth-delete
之後,您就無法停用或移除它。 您必須等待 7 天,原則才會到期。
可以隨時啟用或停用實例的雙重授權刪除。
如果金鑰具有 dual-auth-delete
原則,則變更實例原則不會變更任何現有的金鑰原則。
當您變更實例原則時,會使用實例原則來施行新的金鑰。
ibmcloud kp instance policy-update dual-auth-delete
-i, --instance-id INSTANCE_ID
-d, --disable OR
-e, --enable
範例
這些是 kp instance policy-update dual-auth-delete
的範例。
範例 1
此範例會啟用雙重授權刪除原則。
# enable the instance dual authorization policy
$ ibmcloud kp instance policy-update dual-auth-delete --enable
Updating instance policy...
OK
# list the instance policies
$ ibmcloud kp instance policies --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T18:45:14Z",
"lastUpdated": "2020-06-22T18:45:14Z",
"updatedBy": "user id ...<redacted>...",
"policy_type": "dualAuthDelete",
"policy_data": { "enabled": true
}
}
]
# disable the instance dual authorization policy
$ ibmcloud kp instance policy-update dual-auth-delete --disable
Updating instance policy...
OK
# list the instance policies
$ ibmcloud kp instance policies --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T18:45:14Z",
"lastUpdated": "2020-06-22T18:51:33Z",
"updatedBy": "user id ...<redacted>...",
"policy_type": "dualAuthDelete",
"policy_data": { "enabled": false
}
}
]
範例 2
此範例會啟用雙重授權刪除原則並建立新金鑰,以顯示新金鑰如何繼承實例原則。
停用實例的雙重授權原則不會變更現有金鑰的原則。 實例原則會套用至在更新原則之後所建立的新金鑰。
# enable the instance dual authorization policy
$ ibmcloud kp instance policy-update dual-auth-delete --enable
Updating instance policy...
OK
# create a new key
$ ibmcloud kp key create my-protected-key
Creating key: 'my-protected-key', in instance: 'a192d603-0b8d-452f-aac3-f9e1f95e7411'...
OK
Key ID Key Name
6a8a129b-0cd4-4667-ba57-b355a125a7ca my-protected-key
# list the policies for the key - dual-auth-delete is
# enabled because the key inherits the instance policy
$ ibmcloud kp key policies 6a8a129b-0cd4-4667-ba57-b355a125a7ca --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T19:13:00Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:2427dbde-6cff-41eb-8b5a-ff26b038cafc",
"lastUpdateDate": "2020-06-22T19:13:00Z",
"updatedBy": "user id ...<redacted>...",
"dualAuthDelete": { "enabled": true
}
}
]
# attempt to delete the key - this fails
$ ibmcloud kp key delete 6a8a129b-0cd4-4667-ba57-b355a125a7ca
Deleting key: 6a8a129b-0cd4-4667-ba57-b355a125a7ca, from instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
FAILED
kp.Error:
correlation_id='8ad33eb2-7bbf-4b7a-a02e-221959920342',
msg='Conflict: 1 prior authorization(s) are required for deletion: Key could not be deleted. Please see "reasons" for more details.',
reasons='[AUTHORIZATIONS_NOT_MET: Number of authorizations required to delete is not met -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/apidocs/key-protect]'
# disable the instance dual authorization policy
$ ibmcloud kp instance policy-update dual-auth-delete --disable
Updating instance policy...
OK
# attempt to delete the key - this fails because the key policy
# does not change when the instance policy is updated
$ ibmcloud kp key delete 6a8a129b-0cd4-4667-ba57-b355a125a7ca
Deleting key: 6a8a129b-0cd4-4667-ba57-b355a125a7ca, from instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
FAILED
kp.Error:
correlation_id='cbc0d18b-a816-45ab-af6a-b8e18dc3e628',
msg='Conflict: 1 prior authorization(s) are required for deletion: Key could not be deleted. Please see "reasons" for more details.',
reasons='[AUTHORIZATIONS_NOT_MET: Number of authorizations required to delete is not met -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/apidocs/key-protect]'
必要參數
-
-d, --disable
-
-e, --enable
停用或啟用雙重授權原則。 需要一個選項。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
kp 金鑰別名-建立
建立金鑰的別名,並以 JSON 格式顯示輸出。 別名可以在接受索引鍵 ID
的方法中作為參照。 每一個別名僅在給定的實例內是唯一的,且不會在 Key Protect 服務中保留。 每個按鍵最多可以有五個別名。 每個實例的別名數目沒有限制。 別名的長度可以介於 2-90 個字元 (含) 之間。
別名必須是英數字元,且不能包含空格或 '-' 或 '_' 以外的特殊字元。此外,別名不能是第 4 版 UUID,也不能是 Key Protect 保留名稱: allowed_ip
、key
、keys
、metadata
、policy
、policies
、registration
、registrations
、ring
、rings
、rotate
、wrap
、unwrap
、rewrap
、version
、versions
。
ibmcloud kp key alias-create KEY_ID -a KEY_ALIAS
-i, --instance-id INSTANCE_ID
-a, --alias KEY_ALIAS
[-o, --output OUTPUT]
範例
這是 kp key alias-create
的範例。
範例
建立金鑰別名。
# create a key alias
$ ibmcloud kp key alias-create 24203f96-b134-440e-981a-a24f2d432256 my-alias
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Alias
24203f96-b134-440e-981a-a24f2d432256 my-alias
必要參數
-
KEY_ID
您要修改的金鑰 ID。 若要擷取 執行 kp keys 指令。
-
KEY_ALIAS
您要修改之金鑰的別名或替代 ID。 ID 必須是英數,且沒有空格或 '-' 或 '_' 以外的特殊字元,且不能是第 4 版 UUID。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。
kp key cancel-delete
具有 dual-auth-delete
原則的金鑰需要兩個管理使用者的授權,才能刪除金鑰。
此指令 (kp key cancel-delete
) 會取消或移除先前的授權。
The kp key schedule-delete 指令是刪除金鑰的「授權」。
請遵循此處理程序,以使用 dual-auth-delete
原則來刪除金鑰。
-
建立金鑰並啟用
dual-auth-delete
原則 -
使用者 1 使用來排程 (授權) 金鑰刪除
kp key schedule-delete
指令 -
使用者 2 排程 (授權) 金鑰刪除
-
在執行使用者介面、API 及 CLI 中支援的第二個
schedule-delete
之後,會刪除金鑰 -
如果在 7 天內未進行第二次授權,則金鑰會回到其預設狀態
有兩種方式可啟用 dual-auth-delete
原則:
- 使用
kp key policy-update dual-auth-delete
來設定單一金鑰的原則 - 使用來設定實例的原則
kp instance policy-update dual-auth-delete
; 在啟用實例原則之後建立的所有金鑰都會繼承實例原則設定
ibmcloud kp key cancel-delete KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
範例
這是取消先前排定的金鑰刪除的範例。
# this key has a dual-auth-delete policy
$ ibmcloud kp key policies $KEY_ID --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T19:13:00Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:2427dbde-6cff-41eb-8b5a-ff26b038cafc",
"lastUpdateDate": "2020-06-22T21:29:10Z",
"updatedBy": "user id ...<redacted>...",
"dualAuthDelete": { "enabled": true
}
}
]
# cancel a previously scheduled key delete
$ ibmcloud kp key cancel-delete $KEY_ID
Cancelling key for deletion...
OK
必要參數
-
KEY_ID_OR_ALIAS
您要刪除之金鑰的 v4 UUID 或別名。 若要擷取可用金鑰清單,請執行 kp keys 指令。
kp key create
在您指定的 Key Protect 實例中 建立根金鑰,或 匯入您自己的金鑰
根金鑰長度必須為 16、24 或 32 個位元組; 對應於 128、192 或 256 位元。
ibmcloud kp key create KEY_NAME
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-k, --key-material KEY_MATERIAL]
[-n, --encrypted-nonce NONCE]
[-o, --output OUTPUT]
[-s, --standard-key]
[-v, --iv IV]
[-D, --description DESCRIPTION]
範例
這些是 kp key create
的範例。
範例 1
建立根金鑰。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
24203f96-b134-440e-981a-a24f2d432256 my-root-key
範例 2
建立根金鑰並顯示 JSON 輸出。
# create a root key
$ ibmcloud kp key create my-root-key --output json
{
"id": "24203f96-b134-440e-981a-a24f2d432256",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:24203f96-b134-440e-981a-a24f2d432256"
}
範例 3
從 base64-encoded 值建立根金鑰。
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
# create a root key from a base64-encoded value
$ ibmcloud kp key create my-base64-root-key -k $KEY_MATERIAL
Creating key: 'my-base64-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
5f9eef2d-53b4-42e8-8b56-c2970255210a my-base64-root-key
範例 4
使用匯入記號建立根金鑰。
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
# extract the nonce that was created by the "kp import-token create" command
$ NONCE=$(ibmcloud kp import-token show | jq -r '.["nonce"]')
# extract the public key that was created by the "kp import-token create" command
$ PUBLIC_KEY=$(ibmcloud kp import-token show | jq -r '.["payload"]')
# encrypt the key material using the public key
$ ibmcloud kp import-token key-encrypt -k $KEY_MATERIAL -p $PUBLIC_KEY
Encrypted Key
qT1pyiS1Sivbmmt4doTtfZC4XuLazk7u ...<redacted>... +a/6EqeAamo/9vo=
# capture the encrypted key material
$ ENCRYPTED_KEY=qT1pyiS1Sivbmmt4doTtfZC4XuLazk7u ...<redacted>... +a/6EqeAamo/9vo=
# encrypt the nonce
$ ibmcloud kp import-token nonce-encrypt -k $KEY_MATERIAL -n $NONCE
Encrypted Nonce IV
fR8uRvbrKIm9y/LCq9p6pwFBXbF864q/bw5meQ== efQgA8xBeyuBy39D
# capture the encrypted nonce and the initialization vector (IV)
$ ENCRYPTED_NONCE=fR8uRvbrKIm9y/LCq9p6pwFBXbF864q/bw5meQ==
$ IV=efQgA8xBeyuBy39D
# create a root key using an import token, provide an encrypted key, nonce, and initialization vector (IV)
$ ibmcloud kp key create my-imported-root-key -k $ENCRYPTED_KEY -n $ENCRYPTED_NONCE -v $IV
Creating key: 'my-imported-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
4241a9b3-0ee0-4cfd-b0f3-fd80505fb675 my-imported-root-key
範例 5
建立標準金鑰。
# create a standard key
$ ibmcloud kp key create my-standard-key -s
Creating key: 'my-standard-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
12d3f3a4-aea5-4832-8339-fa14dbffd935 my-standard-key
範例 6
建立標準金鑰,以作為認證的儲存庫。
任何 base64-encoded 字串都可以匯入為標準金鑰。 此範例顯示如何在中儲存認證,而不只是加密金鑰 Key Protect.
在 base64-encoding之前,標準金鑰最多可以有 7,500 個位元組的大小。
# create a file with your credentials
$ cat credentials.json
{
"host": "localhost",
"database": "dev-backup",
"username": "my-username",
"password": "my-password"
}
# encode the credentials (or any string) to a base64 string
$ ENCODED=$(base64 -i credentials.json)
$ echo $ENCODED
ewoJImhvc3QiOiAibG9jYWxob3N0IiwK...<redacted>...cGFzc3dvcmQiCn0K
# create a new key that contains the base64-encoded credentials
$ ibmcloud kp key create credentials-key -i $KP_INSTANCE_ID --key-material $ENCODED --standard-key --output json
# OR... CAPTURE THE KEY_ID
$ KEY_ID=$(ibmcloud kp key create credentials-key -i $KP_INSTANCE_ID --key-material $ENCODED --standard-key --output json | jq -r '.["id"]')
{
"id": "8480e26f-3add-4fff-bca7-8cf908894b7c",
"name": "credentials-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": true,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:8480e26f-3add-4fff-bca7-8cf908894b7c",
"deleted": false
}
# retrieve the base64-encoded payload
$ ibmcloud kp key show $KEY_ID --output json
# OR... CAPTURE THE PAYLOAD
$ PAYLOAD=$(ibmcloud kp key show $KEY_ID --output json | jq -r '.["payload"]')
{
"id": "8480e26f-3add-4fff-bca7-8cf908894b7c",
"name": "credentials-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-08-18T16:13:08Z",
"lastUpdateDate": "2020-08-18T16:13:08Z",
"extractable": true,
"payload": "ewoJImhvc3QiOiAibG9jYWxob3N0IiwKCSJkYXRhYmFzZSI6ICJkZXYtYmFja3VwIiwKCSJ1c2VybmFtZSI6ICJteS11c2VybmFtZSIsCgkicGFzc3dvcmQiOiAibXktcGFzc3dvcmQiCn0=",
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:8480e26f-3add-4fff-bca7-8cf908894b7c",
"deleted": false,
"dualAuthDelete": {
"enabled": false
}
}
# decode the payload to get the original string (credentials)
$ echo $PAYLOAD | base64 -d
{
"host": "localhost",
"database": "dev-backup",
"username": "my-username",
"password": "my-password"
}
範例 7
建立具有別名的根金鑰,然後使用該別名來識別金鑰以顯示金鑰詳細資料。
# create a root key with an alias
$ ibmcloud kp key create root-key-with-alias -a example-alias --output json
{
"id": "b3660416-4186-4587-b528-484886a4731b",
"name": "root-key-with-alias",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"aliases": [
"example-alias"
],
"keyRingID": "default",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:b3660416-4186-4587-b528-484886a4731b",
"deleted": false
}
# show key details using the alias as identifier
$ ibmcloud kp key show example-alias --output json
{
"id": "b3660416-4186-4587-b528-484886a4731b",
"name": "root-key-with-alias",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-06-09T21:21:55Z",
"lastUpdateDate": "2022-06-09T21:21:55Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2022-06-09T21:21:55Z"
},
"aliases": [
"example-alias"
],
"keyRingID": "default",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:b3660416-4186-4587-b528-484886a4731b",
"deleted": false,
"dualAuthDelete": {
"enabled": false
}
}
範例 8
將說明新增至金鑰。 例如,用來說明索引鍵預期用途的簡短詞組。
ibmcloud kp key create KEY_NAME -i 40f2a13c-780e-4641-bea5-e166e5bb5a9f -D ""description of the key""
必要參數
-
KEY_NAME
指定給鑰匙的唯一、人類可讀的識別碼。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-k, --key-material
如果您已產生金鑰,則這是您在服務中儲存及管理的 base64-encoded 金鑰資料。
根金鑰長度必須為 16、24 或 32 個位元組; 對應於 128、192 或 256 位元。 金鑰必須以 base64-encoded。
標準金鑰的大小最多可以為 7,500 個位元組。 金鑰必須以 base64-encoded。
如果您使用匯入記號來建立金鑰,則這是來自
kp import-token key-encrypt
處理程序的加密金鑰。若要產生新金鑰,請省略
-k, --key-material
參數。 -
-n, --encrypted-nonce
與匯入記號搭配使用。 加密的 Nonce 值會驗證您將金鑰匯入至 Key Protect的要求。 必須使用您匯入至服務的金鑰資料來加密此值。 請參閱
ibmcloud kp import-token --help
。若要擷取暫時性要求,請使用
ibmcloud kp import-token show
。 然後,執行ibmcloud kp import-token nonce-encrypt
來加密值。 -
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-s, --standard-key
僅在要建立 標準鑰匙 時才設定此參數。 若要建立根金鑰,請省略
--standard-key
參數。 -
-v, --iv
與匯入記號搭配使用。 當您加密 Nonce 時所產生的起始設定向量 (IV)。 當您對服務提出金鑰匯入要求時,需要 IV 值才能解密您提供的已加密 Nonce 值。
若要產生 IV,請執行
ibmcloud kp import-token nonce-encrypt
來加密 Nonce。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
-
-D, --description
容許將說明新增至金鑰。 例如,用來說明索引鍵預期用途的簡短詞組。
kp key create-key-with-policy-overrides
僅針對將置換任何適用實例原則的具名金鑰建立具有原則的金鑰。
ibmcloud kp key create-key-with-policy-overrides KEY_NAME
-i, --instance-id INSTANCE_ID
[-a, --aliases ALIAS]
[-d, --dual-auth-delete-policy-enabled KEY_RING_ID]
[--key-ring KEY_RING_ID]
[-k, --key-material KEY_MATERIAL]
[-m, --rotation-interval-month VALUE]
[-n, --encrypted-nonce NONCE]
[-o, --output OUTPUT]
[-s, --standard-key]
[-v, --iv IV]
範例
建立啟用輪替原則的根金鑰,其間隔為 2 個月 (每個「月」的值為 30 天,產生 60 天輪替間隔)。
% ibmcloud kp key create-key-with-policy-overrides test-key -m 2 -r
Creating key with policy overrides: 'test-key', in instance: '47377f07-8721-2O47-f396-ef1982c1e96e'...
OK
Key ID Key Name
076df396-4c90-e008-bf20-f1bb672d465b test-key
# List policies
% ibmcloud kp key policies 076df396-4c90-e008-bf20-f1bb672d465b
Retrieving policy details for key ID: 076df396-4c90-e008-bf20-f1bb672d465b...
OK
Created By IBMid-xxxxnnnnnxxx
Creation Date 2022-10-27T17:48:20Z
Last Updated 2022-10-27T17:48:20Z
Updated By IBMid-xxxxnnnnnxxx
Policy Type Rotation
Interval 2
Enabled true
必要參數
-
KEY_NAME
指定給鑰匙的唯一、人類可讀的識別碼。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-a, --aliases
指派給您金鑰的英數人類可讀別名,範圍為 2-90 個字元。 別名不能包含底線及橫線以外的空格或特殊字元。 每個金鑰最多容許 5 個別名。
-
-d, --dual-auth-delete-policy-enabled
啟用金鑰的雙重鑑別刪除原則。
-
-k, --key-material
如果您已產生金鑰,則這是您在服務中儲存及管理的 base64-encoded 金鑰資料。
根金鑰長度必須為 16、24 或 32 個位元組; 對應於 128、192 或 256 位元。 金鑰必須以 base64-encoded。
標準金鑰的大小最多可以為 7,500 個位元組。 金鑰必須以 base64-encoded。
如果您使用匯入記號來建立金鑰,則這是來自
kp import-token key-encrypt
處理程序的加密金鑰。若要產生新金鑰,請省略
-k, --key-material
參數。 -
-n, --encrypted-nonce
與匯入記號搭配使用。 加密的 Nonce 值會驗證您將金鑰匯入至 Key Protect的要求。 必須使用您匯入至服務的金鑰資料來加密此值。 請參閱
ibmcloud kp import-token --help
。若要擷取暫時性要求,請使用
ibmcloud kp import-token show
。 然後,執行ibmcloud kp import-token nonce-encrypt
來加密值。 -
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-m, --rotation-interval-month
指定金鑰的替換時間間隔(以月為單位)。 預設值為 -1
。
-
-s, --standard-key
僅在要建立 標準鑰匙 時才設定此參數。 若要建立根金鑰,請省略
--standard-key
參數。 -
-v, --iv
與匯入記號搭配使用。 當您加密 Nonce 時所產生的起始設定向量 (IV)。 當您對服務提出金鑰匯入要求時,需要 IV 值才能解密您提供的已加密 Nonce 值。
若要產生 IV,請執行
ibmcloud kp import-token nonce-encrypt
來加密 Nonce。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 鍵刪除
刪除金鑰(儲存在您的 Key Protect 服務中)。
ibmcloud kp key delete KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-f, --force]
[-o, --output OUTPUT]
範例
這些是 kp key delete
的範例。
範例 1
刪除根金鑰。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
8635b804-9966-4918-a16b-d561fdbf181f my-root-key
# show key details
$ ibmcloud kp key show 8635b804-9966-4918-a16b-d561fdbf181f
Grabbing info for key id: 8635b804-9966-4918-a16b-d561fdbf181f...
OK
Key ID Key Name Description Creation Date Expiration Date
8635b804-9966-4918-a16b-d561fdbf181f my-root-key 2020-05-05 19:58:02 +0000 UTC Key does not expire
# delete the key
$ ibmcloud kp key delete 8635b804-9966-4918-a16b-d561fdbf181f
Deleting key: 8635b804-9966-4918-a16b-d561fdbf181f, from instance: 390086ac-76fa-4094-8cf3-c0829bd69526...
OK
Deleted Key
8635b804-9966-4918-a16b-d561fdbf181f
範例 2
刪除根金鑰並顯示 JSON 輸出。
# create a root key
$ ibmcloud kp key create my-root-key --output json
{
"id": "9cca88c9-019e-4f0a-9e76-8e657c6b9720",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb145:390086ac-76fa-4094-8cf3-c0829bd69526:key:9cca88c9-019e-4f0a-9e76-8e657c6b9720"
}
# show key details
$ ibmcloud kp key show 9cca88c9-019e-4f0a-9e76-8e657c6b9720 --output json
{
"id": "9cca88c9-019e-4f0a-9e76-8e657c6b9720",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-05-05T20:03:00Z",
"lastUpdateDate": "2020-05-05T20:03:00Z",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb145:390086ac-76fa-4094-8cf3-c0829bd69526:key:9cca88c9-019e-4f0a-9e76-8e657c6b9720"
}
# delete the key
$ ibmcloud kp key delete 9cca88c9-019e-4f0a-9e76-8e657c6b9720 --output json
{
"id": "9cca88c9-019e-4f0a-9e76-8e657c6b9720"
}
範例 3
刪除向另一個雲端資源登錄的根金鑰。
# create a Cloud Object Storage (COS) instance
# "lite" is the pricing plan and "global" is the region
$ COS_NAME=my-cos-1
$ ibmcloud resource service-instance-create $COS_NAME cloud-object-storage lite global
# capture the COS instance id (GUID)
$ COS_INSTANCE_ID=9d4353d8-6b85-4689-90dd-1ccfb4a275ab
# create a Key Management Service (KMS) instance
# "tiered-pricing" is the pricing plan and "us-south" is the region
$ KMS_NAME=my-kms-1
$ ibmcloud resource service-instance-create $KMS_NAME kms tiered-pricing us-south
# capture the Key Protect (KP) instance id (GUID)
$ KP_INSTANCE_ID=b0d84b32-09d0-4314-8049-da78e3b9ab6f
# create a policy for COS to read KMS; source is COS, target is KMS (Key Protect)
$ ibmcloud iam authorization-policy-create cloud-object-storage kms Reader \
--source-service-instance-id $COS_INSTANCE_ID \
--target-service-instance-id $KP_INSTANCE_ID
# capture the COS-to-KMS authorization policy id
$ COS_KMS_AUTHORIZATION=79375168-2d74-49df-98aa-3e727410fa71
# create a KP root key that COS uses to encrypt data
$ ibmcloud kp key create my-cos-key --output json
{
"id": "52a9d772-8982-4620-bfb4-b070dd812a0c",
"name": "my-cos-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:b0d84b32-09d0-4314-8049-da78e3b9ab6f:key:52a9d772-8982-4620-bfb4-b070dd812a0c"
}
# capture the KP root key id
$ MY_COS_KEY_ID=52a9d772-8982-4620-bfb4-b070dd812a0c
# create a COS bucket and set KP encryption
# must be done in the console user interface (UI) because
# there is no API or CLI support at this time
# capture the name of the COS bucket that was created
$ COS_BUCKET=my-cos-kms-bucket
# view the KP registration; it's a result of creating the COS bucket
$ ibmcloud kp registrations --output json
[
{
"keyId": "52a9d772-8982-4620-bfb4-b070dd812a0c",
"resourceCrn": "crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:9d4353d8-6b85-4689-90dd-1ccfb4a275ab:bucket:my-cos-kms-bucket",
"createdBy": "crn-crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:9d4353d8-6b85-4689-90dd-1ccfb4a275ab::",
"creationDate": "2020-06-15T20:41:23Z",
"lastUpdated": "2020-06-15T20:41:23Z",
"keyVersion": { "id": "52a9d772-8982-4620-bfb4-b070dd812a0c", "creationDate": "2020-06-15T20:36:46Z"
}
}
]
# delete the authorization policy between COS AND KMS - this breaks everything
$ ibmcloud iam authorization-policy-delete $COS_KMS_AUTHORIZATION --force
# delete the KP root key - this fails because the registration was not deleted
$ ibmcloud kp key delete $MY_COS_KEY_ID
Deleting key: 52a9d772-8982-4620-bfb4-b070dd812a0c, from instance: b0d84b32-09d0-4314-8049-da78e3b9ab6f...
FAILED
kp.Error:
correlation_id='c27b7948-4a1f-4cbd-8770-cb3616888e27',
msg='Conflict: Key could not be deleted. Please see "reasons" for more details.',
reasons='[PROTECTED_RESOURCE_ERR: Key is protecting one or more cloud resources -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/docs/key-protect?topic=key-protect-troubleshooting#unable-to-delete-keys]'
# delete the KP root key; use --force because the registration between COS and KMS still exists
$ ibmcloud kp key delete $MY_COS_KEY_ID --force --output json
{
"id": "52a9d772-8982-4620-bfb4-b070dd812a0c"
}
# delete the KMS instance
$ ibmcloud resource service-instance-delete $KMS_NAME --force
# delete the COS instance
$ ibmcloud resource service-instance-delete $COS_NAME --force
# view resources (COS and KMS should no longer exist)
$ ibmcloud resource service-instances
Retrieving instances with type service_instance in resource group Default in all locations under account <account name> as <email address>...
OK
No service instance found.
必要參數
-
KEY_ID_OR_ALIAS
您要刪除之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-f, --force
強制刪除金鑰,用來刪除具有「登錄」的金鑰。 登錄是根金鑰與其他雲端資源 (例如 Cloud Object Storage (COS) 儲存區或 Cloud Databases 部署) 之間的關聯。
如需相關資訊,請參閱 kp 登錄
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp key disable
kp key disable
指令會停用根金鑰,並暫時撤銷對雲端中金鑰相關聯資料的存取權。
身為管理者,您可能需要暫時 如果您懷疑資料可能暴露、危害或外洩,請 停用主要金鑰。
停用根金鑰會暫停其加密及解密作業。 確認安全風險不再處於作用中之後,您可以透過 啟用 已停用的根金鑰來還原對資料的存取權。
當您停用先前已啟用的根金鑰時,金鑰會從 作用中 (值為 1) 轉移至 已暫停 (值為 2) 金鑰狀態。
若要停用根金鑰,您必須獲指派實例或金鑰的 管理員 服務存取角色。 瞭解 IAM 角色如何對映至 Key Protect 服務動作,請查看 服務存取角色。
如果您使用支援撤銷已停用之根金鑰的存取權的整合式雲端服務,則在撤銷對根金鑰相關聯資料的存取權之前,該服務最多可能需要 4 小時。
撤銷對相關聯資料的存取權之後,對應的 disable event
會顯示在 IBM Cloud Logs Web UI 中。 disable event
指出金鑰已撤銷 (現在已停用),且金鑰 不能 用於加密及解密作業。
ibmcloud kp key disable KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
範例
這些是 kp key disable
的範例。
範例 1
建立根金鑰,停用它,驗證金鑰狀態 (已暫停),啟用根金鑰,並驗證金鑰狀態 (作用中)。
# create a root key
$ ibmcloud kp key create my-root-key --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# show key details - a state of "1" is "active"
$ ibmcloud kp key show 264fadc3-7667-4b25-916e-5825fe70de0b --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:21:55Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# disable the root key
$ ibmcloud kp key disable 264fadc3-7667-4b25-916e-5825fe70de0b
Disabling key: '264fadc3-7667-4b25-916e-5825fe70de0b', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
# show key details - a state of "2" is "suspended"
$ ibmcloud kp key show 264fadc3-7667-4b25-916e-5825fe70de0b --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:23:26Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 2,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
範例 2
建立根金鑰,停用它,並嘗試使用根金鑰來包裝另一個金鑰。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
63d044d9-b38b-4803-85ef-ed9a1e5087c2
# disable the root key
$ ibmcloud kp key disable $KEY_ID
Disabling key: '63d044d9-b38b-4803-85ef-ed9a1e5087c2', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
# create a random, base64-encoded, 32-byte data encryption key (DEK)
$ PLAINTEXT=$(openssl rand -base64 32)
$ echo $PLAINTEXT
BNxtU9B4kXOZA45Cnyz3wOh4J77TakTXI1n2rj0ZiMc=
# wrap the plaintext key with the root key, creating a DEK (this is the ciphertext)
# this should fail (the root key is disables)
$ ibmcloud kp key wrap $KEY_ID -p $PLAINTEXT --output json
FAILED
kp.Error:
correlation_id='c2edbdad-7e62-4690-8fcc-10515ade9913',
msg='Conflict: Action could not be performed on key. Please see "reasons" for more details.',
reasons='[KEY_ACTION_INVALID_STATE_ERR: Key is not in a valid state -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/apidocs/key-protect]'
範例 3
建立具有別名的根金鑰,使用該別名來識別要停用的金鑰,驗證金鑰狀態 (已暫停),然後啟用根金鑰並驗證新的金鑰狀態 (作用中)。
# create a root key
$ ibmcloud kp key create root-key-with-alias -a example-alias-1 --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "root-key-with-alias",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"aliases": [
"example-alias"
],
"deleted": false,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# show key details using the alias as identifier - a state of "1" is "active"
$ ibmcloud kp key show example-alias-1 --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "root-key-with-alias",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:21:55Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 1,
...
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# disable the root key identified by alias
$ ibmcloud kp key disable example-alias-1
Disabling key: '264fadc3-7667-4b25-916e-5825fe70de0b', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
# show key details - a state of "2" is "suspended"
$ ibmcloud kp key show example-alias-1 --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "root-key-with-alias",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:23:26Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 2,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
必要參數
-
KEY_ID_OR_ALIAS
您要刪除之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp key enable
當您啟用先前已停用的根金鑰時,金鑰會從 已暫停 (值為 2) 轉移至 作用中 (值為 1) 金鑰狀態。 此動作會還原金鑰的加密及解密作業。
如果您使用的整合式雲端服務支援還原對已停用的根金鑰的存取權,則在還原對根金鑰相關聯資料的存取權之前,該服務最多可能需要 4 小時。
在還原對相關聯資料的存取權之後,對應的 enable event
會顯示在 IBM Cloud Logs Web UI 中。 enable event
指出金鑰已還原 (且現在已啟用),且金鑰可用於加密及解密作業,例如包裝、解除包裝及重新包裝。
ibmcloud kp key enable <KEY_ID_OR_ALIAS> -i <INSTANCE_ID> [ --key-ring KEY_RING_ID]
範例
這是 kp key enable
的範例。
# create a root key
$ ibmcloud kp key create my-root-key --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# show key details - a state of "1" is "active"
$ ibmcloud kp key show 264fadc3-7667-4b25-916e-5825fe70de0b --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:21:55Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# disable the root key
$ ibmcloud kp key disable 264fadc3-7667-4b25-916e-5825fe70de0b
Disabling key: '264fadc3-7667-4b25-916e-5825fe70de0b', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
# show key details - a state of "2" is "suspended"
$ ibmcloud kp key show 264fadc3-7667-4b25-916e-5825fe70de0b --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:23:26Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 2,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
# enable the key
$ ibmcloud kp key enable 264fadc3-7667-4b25-916e-5825fe70de0b
Enabling key: '264fadc3-7667-4b25-916e-5825fe70de0b', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
# show key details - a state of "1" is "active"
$ ibmcloud kp key show 264fadc3-7667-4b25-916e-5825fe70de0b --output json
{
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-09T21:21:55Z",
"lastUpdateDate": "2020-06-09T21:31:44Z",
"keyVersion": {
"id": "264fadc3-7667-4b25-916e-5825fe70de0b",
"creationDate": "2020-06-09T21:21:55Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:264fadc3-7667-4b25-916e-5825fe70de0b"
}
必要參數
-
KEY_ID_OR_ALIAS
您要刪除之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰原則
擷取金鑰原則的詳細資料,例如,金鑰的自動替換間隔。
ibmcloud kp key policies KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-d, --dual-auth]
[-o, --output OUTPUT]
[-r, --rotation]
範例
此範例列出根金鑰的原則。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
c024c2b3-2093-46e5-aabb-fdf8cbc14e44
# show key details
$ ibmcloud kp key show $KEY_ID --output json
{
"id": "c024c2b3-2093-46e5-aabb-fdf8cbc14e44",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-18T20:34:39Z",
"lastUpdateDate": "2020-06-18T20:34:39Z",
"keyVersion": {
"id": "c024c2b3-2093-46e5-aabb-fdf8cbc14e44",
"creationDate": "2020-06-18T20:34:39Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:c024c2b3-2093-46e5-aabb-fdf8cbc14e44"
}
# update the policy and rotate the key every 2 months
$ ibmcloud kp key policy-update rotation $KEY_ID -m 2 --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-18T20:35:41Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:06a40fd6-6fd7-460a-87d7-8388fc1be057",
"lastUpdateDate": "2020-06-18T20:35:41Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"interval_month": 2
}
}
# list the policies
$ ibmcloud kp key policies $KEY_ID --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-18T20:35:41Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:06a40fd6-6fd7-460a-87d7-8388fc1be057",
"lastUpdateDate": "2020-06-18T20:35:41Z",
"updatedBy": "user id ...<redacted>...",
"rotation": { "interval_month": 2
}
}
]
必要參數
-
KEY_ID_OR_ALIAS
您要查詢之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-d, --dual-auth
顯示具有
dual-auth-delete
原則的原則。 -
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-r, --rotation
顯示具有
rotation
原則的原則。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰原則-更新 dual-auth-delete
您可以使用 Key Protect,利用雙重授權程序來安全地刪除加密金鑰。 刪除鑰匙時、您會刪除其內容和相關資料。 金鑰所加密的任何資料都會變成無法存取。
刪除具有的金鑰 雙重授權原則 需要兩個使用者的授權。 使用 Key Protect API,您可以提供 第一次授權 設定刪除的金鑰。 然後,不同的使用者使用 圖形使用者介面 或 API 刪除金鑰。
ibmcloud kp key policy-update dual-auth-delete KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
-e, --enable
[--key-ring KEY_RING_ID]
[-o, --output OUTPUT]
範例
此範例會啟用雙重授權刪除原則。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
d887bfe8-5166-4dad-af32-7e3055ca1873
# show key details
$ ibmcloud kp key show $KEY_ID --output json
{
"id": "d887bfe8-5166-4dad-af32-7e3055ca1873",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-19T16:07:50Z",
"lastUpdateDate": "2020-06-19T16:07:50Z",
"keyVersion": {
"id": "d887bfe8-5166-4dad-af32-7e3055ca1873",
"creationDate": "2020-06-19T16:07:50Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:d887bfe8-5166-4dad-af32-7e3055ca1873"
}
# enable the dual authorization policy
$ ibmcloud kp key policy-update dual-auth-delete $KEY_ID --enable --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-19T16:08:59Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:0aab763d-b650-43a2-86ad-bdfe2c35c94c",
"lastUpdateDate": "2020-06-19T16:08:59Z",
"updatedBy": "user id ...<redacted>...",
"dualAuthDelete": {
"enabled": true
}
}
# list the policies
$ ibmcloud kp key policies $KEY_ID --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-19T16:08:59Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:0aab763d-b650-43a2-86ad-bdfe2c35c94c",
"lastUpdateDate": "2020-06-19T16:08:59Z",
"updatedBy": "user id ...<redacted>...",
"dualAuthDelete": { "enabled": true
}
}
]
# this should fail (the key has a dual authorization policy)
$ ibmcloud kp key delete $KEY_ID_OR_ALIAS
Deleting key: d887bfe8-5166-4dad-af32-7e3055ca1873, from instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
FAILED
kp.Error:
correlation_id='fe0db627-1726-4827-a9d2-c21d728e1c92',
msg='Conflict: 1 prior authorization(s) are required for deletion: Key could not be deleted.
Please see "reasons" for more details.',
reasons='[AUTHORIZATIONS_NOT_MET: Number of authorizations required to delete is not met -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/apidocs/key-protect]'
必要參數
-
KEY_ID_OR_ALIAS
您要查詢之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
-
-e, --enable
一旦啟用 dual-auth-delete 原則,就無法停用它。 如果沒有兩個 (雙重) 授權,您 無法 刪除金鑰。 此處理程序必須在 7 天內完成,否則會自動取消雙重授權原則,這表示具有授權的任何人都可以刪除金鑰 (不需要兩個授權)。
如果您意外啟用雙重授權原則,且想要刪除金鑰,則可以
disable
金鑰 (使用kp key disable
指令),並等待 7 天,讓雙重授權原則到期。 此時您可以刪除金鑰。您 無法 刪除 Key Protect 實例 (只要它們的作用中金鑰)。 具有雙重授權原則的金鑰是作用中金鑰。
選用參數
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰原則-更新循環
當您為根金鑰設定自動替換原則時,會定期縮短金鑰的生命期限,並且會限制該金鑰所保護的資訊量。 使用者也可以在金鑰上啟用或停用金鑰輪替原則。
您只能針對在下列項目中產生的根金鑰建立旋轉政策 Key Protect. 如果您最初匯入的是根密鑰 最初,您必須提供新的 base64-encoded 金鑰素材來旋轉金鑰。 如需相關資訊,請參閱 隨需應變替換根金鑰。
ibmcloud kp key policy-update rotation KEY_ID|KEY_ALIAS
[--enable | --disable] [-m MONTHLY_INTERVAL] [-o FORMAT]
[--key-ring KEY_RING_ID]
範例
輪替原則可以在建立金鑰時或建立金鑰之後套用。 在第一個範例中,我們只是建立不含替換原則的金鑰:
# create a root key
ibmcloud kp key create rotateKeyEnableDisableDemo
Creating key: 'rotateKeyEnableDisableDemo', in instance: '5ecfe306-d4at-48c0-ab07-b5c5bc751534'...
OK
Key ID Key Name
4d5540bd-3235-4a46-a8af-974f7ed6558a rotateKeyEnableDisableDemo
---------------------------------------------------------------------------------------------------------------------------------------------------
# set a rotation policy of three months
ibmcloud kp key policy-update rotation 4d5540bd-3235-4a46-a8af-974f7ed6558a -m 3 -e --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-12-02T00:50:11Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/e3e8fd14a61a49cda102faad15b06c09:5ecfe306-d4af-48c0-ab07-b5c5bc751534:policy:0ec7ad62-982d-45bb-895f-986d95015f5b",
"lastUpdateDate": "2022-12-02T00:51:38Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"enabled": true,
"interval_month": 3
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
# show the rotation policy for this key
ibmcloud kp key policies 4d5540bd-3235-4a46-a8af-974f7ed6558a -r --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-12-02T00:50:11Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/e3e8fd14a61a49cda102faad15b06c09:5ecfe306-d4af-48c0-ab07-b5c5bc751534:policy:0ec7ad62-982d-45bb-895f-986d95015f5b",
"lastUpdateDate": "2022-12-02T00:51:38Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"enabled": true,
"interval_month": 2
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
# update the policy to three months
ibmcloud kp key policy-update rotation 4d5540bd-3235-4a46-a8af-974f7ed6558a -m 3 -e --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-12-02T00:50:11Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/e3e8fd14a61a49cda102faad15b06c09:5ecfe306-d4af-48c0-ab07-b5c5bc751534:policy:0ec7ad62-982d-45bb-895f-986d95015f5b",
"lastUpdateDate": "2022-12-02T00:51:38Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"enabled": true,
"interval_month": 3
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
# disable the policy for this key
ibmcloud kp key policy-update rotation 4d5540bd-3235-4a46-a8af-974f7ed6558a -d --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-12-02T00:50:11Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/e3e8fd14a61a49cda102faad15b06c09:5ecfe306-d4af-48c0-ab07-b5c5bc751534:policy:0ec7ad62-982d-45bb-895f-986d95015f5b",
"lastUpdateDate": "2022-12-02T00:52:52Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"enabled": false,
"interval_month": 3
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
# show that the policy has been disabled
ibmcloud kp key policies 4d5540bd-3235-4a46-a8af-974f7ed6558a -r --output json
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2022-12-02T00:50:11Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/e3e8fd14a61a49cda102faad15b06c09:5ecfe306-d4af-48c0-ab07-b5c5bc751534:policy:0ec7ad62-982d-45bb-895f-986d95015f5b",
"lastUpdateDate": "2022-12-02T00:52:52Z",
"updatedBy": "user id ...<redacted>...",
"rotation": {
"enabled": false,
"interval_month": 3
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
必要參數
-
KEY_ID_OR_ALIAS
您要查詢之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
選用參數
-
-m, --monthly-interval
設定金鑰輪替間隔 (以月為單位)。 旋轉間隔必須為 1 到 12 個月。
-
-e, --enable
或-d, --disable
依預設,會啟用金鑰輪替原則。 如果使用者想要停用或啟用該策略,他們可以使用-d (--禁用) 或-e (--啟用) 分別。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰還原
Key Protect 可以還原先前刪除的根金鑰,這會還原其雲端中相關聯資料的存取權。
作為管理者,您可能需要還原已匯入至的主要金鑰 Key Protect,以存取先前受保護的金鑰資料。
當您還原金鑰時,會將金鑰從 已毀損 (值為 5) 移至 作用中 (值為 1) 金鑰狀態,並還原先前使用金鑰加密之任何資料的存取權。
您可以在刪除金鑰的 30 天內還原已刪除的金鑰。 此功能僅適用於使用 key material
建立的根金鑰。
您只能使用下列指令來還原使用 key material
建立的根金鑰:
kp key create
搭配 -k, --key-material
選項。 如果 未 指定 --key-material
選項,則您 無法 還原根金鑰。
如果您想要還原已刪除的根金鑰,則 必須 儲存 用來建立根金鑰的 key material
。 如果沒有提供原始 key material
,您 無法 還原已刪除的金鑰。
ibmcloud kp key restore KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
-k, --key-material KEY_MATERIAL
[--key-ring KEY_RING_ID]
[-n, --encrypted-nonce ENCRYPTED_NONCE]
[-v, --iv IV]
範例
這些是 kp key restore
的範例。
範例 1
此範例會使用金鑰資料建立根金鑰,刪除金鑰,然後還原金鑰。
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
$ echo $KEY_MATERIAL
4EZBMBMkZ87z4nvYsQH21DC5+wslgWhHRiU8bmqJ4CY=
# create a root key from a base64-encoded value
$ KEY_ID=$(ibmcloud kp key create my-base64-root-key -k $KEY_MATERIAL --output json | jq -r '.["id"]')
$ echo $KEY_ID
62ad0cd5-70a4-4c4d-9d87-5f4db620b120
# delete the root key
$ ibmcloud kp key delete $KEY_ID
Deleting key: 62ad0cd5-70a4-4c4d-9d87-5f4db620b120, from instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
OK
Deleted Key
62ad0cd5-70a4-4c4d-9d87-5f4db620b120
# list keys - verify the key was deleted
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
# restore the deleted key
$ ibmcloud kp key restore $KEY_ID -k $KEY_MATERIAL --output json
{
"id": "62ad0cd5-70a4-4c4d-9d87-5f4db620b120",
"name": "my-base64-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:62ad0cd5-70a4-4c4d-9d87-5f4db620b120"
}
# list keys - verify the key was restored
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
62ad0cd5-70a4-4c4d-9d87-5f4db620b120 my-base64-root-key
範例 2
此工作流程會使用匯入記號建立根金鑰,刪除金鑰,然後還原金鑰。
這是一個兩步驟的過程。
-
使用匯入記號建立根金鑰,然後刪除金鑰
-
建立還原金鑰及還原金鑰所需的匯入記號
使用匯入記號建立根金鑰有時間限制 (
-e, --expiration
選項)。 當您還原金鑰時,需要匯入記號。 這就是為何您需要透過匯入記號處理程序來還原金鑰的原因。
步驟 1-使用匯入記號建立根金鑰,然後刪除金鑰
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
Created Expires Max Retrievals Remaining Retrievals
2020-06-18 12:21:59 +0000 UTC 2020-06-18 12:26:59 +0000 UTC 10 10
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
$ echo $KEY_MATERIAL
sADDNDE3pcJlbYXu2z5QFORvsxV1PosRiAPERrhYJdk=
# extract the nonce that was created by the "kp import-token create" command
$ NONCE=$(ibmcloud kp import-token show | jq -r '.["nonce"]')
$ echo $NONCE
/QhqOsqlVPC+ZPWz
# extract the public key that was created by the "kp import-token create" command
$ PUBLIC_KEY=$(ibmcloud kp import-token show | jq -r '.["payload"]')
$ echo $PUBLIC_KEY
LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t ...<redacted>... QyBLRVktLS0tLQo=
# encrypt the key material using the public key
$ ibmcloud kp import-token key-encrypt -k $KEY_MATERIAL -p $PUBLIC_KEY
Encrypted Key
C+/puHn1v5p7aohitM4r6N4ohiVkCecP ...<redacted>... eWmJRuvsSxDg/OY=
# capture the encrypted key material
$ ENCRYPTED_KEY=C+/puHn1v5p7aohitM4r6N4ohiVkCecP ...<redacted>... eWmJRuvsSxDg/OY=
# encrypt the nonce
$ ibmcloud kp import-token nonce-encrypt -k $KEY_MATERIAL -n $NONCE
Encrypted Nonce IV
TxrgdayWnM5OB3JoYuQR97oulxvREptk8TzciQ== 7BiIpcbGxXBzuXZP
# capture the encrypted nonce and the initialization vector (IV)
$ ENCRYPTED_NONCE=TxrgdayWnM5OB3JoYuQR97oulxvREptk8TzciQ==
$ IV=7BiIpcbGxXBzuXZP
# create a root key using an import token, provide an encrypted key, nonce, and initialization vector (IV)
$ KEY_ID=$(ibmcloud kp key create my-imported-root-key -k $ENCRYPTED_KEY -n $ENCRYPTED_NONCE -v $IV --output json | jq -r '.["id"]')
$ echo $KEY_ID
c42c6f2c-8b67-4016-b2c3-99fba9490f5d
# list keys - verify the key was created
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
c42c6f2c-8b67-4016-b2c3-99fba9490f5d my-imported-root-key
# delete the root key
$ ibmcloud kp key delete $KEY_ID
Deleting key: c42c6f2c-8b67-4016-b2c3-99fba9490f5d, from instance: a192d603-0b8d-452f-aac3-f9e1f95e7411...
OK
Deleted Key
c42c6f2c-8b67-4016-b2c3-99fba9490f5d
# list keys - verify the key was deleted
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
步驟 2-建立還原金鑰及還原金鑰所需的匯入記號
# NOTE: "kp key restore" requires an import token to complete the process,
# if you follow this example, the previously created import token may still
# exist and the example works; otherwise, if the import token has expired then
# you need to create a new import token prior to restoring the key
# create an import token that expires in 5 minutes and allows 10 retrievals
$ ibmcloud kp import-token create -e 300 -m 10
Created Expires Max Retrievals Remaining Retrievals
2020-06-18 12:30:54 +0000 UTC 2020-06-18 12:35:54 +0000 UTC 10 10
# extract the nonce that was created by the "kp import-token create" command
$ NONCE=$(ibmcloud kp import-token show | jq -r '.["nonce"]')
$ echo $NONCE
N3x8F0ihAZ51nj6M
# extract the public key that was created by the "kp import-token create" command
$ PUBLIC_KEY=$(ibmcloud kp import-token show | jq -r '.["payload"]')
$ echo $PUBLIC_KEY
LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t ...<redacted>... QyBLRVktLS0tLQo=
# encrypt the key material using the public key
$ ibmcloud kp import-token key-encrypt -k $KEY_MATERIAL -p $PUBLIC_KEY
Encrypted Key
Ch7hcsT1EOfSdghjOHKAemBZuzDoqJoH ...<redacted>... F4p/mkGT/EQJS5o=
# capture the encrypted key material
$ ENCRYPTED_KEY=Ch7hcsT1EOfSdghjOHKAemBZuzDoqJoH ...<redacted>... F4p/mkGT/EQJS5o=
# encrypt the nonce
$ ibmcloud kp import-token nonce-encrypt -k $KEY_MATERIAL -n $NONCE
Encrypted Nonce IV
nrrCczvYXvc6T7J2G+EOLjHZO1cpPyu/nhsIlA== N6oLJnUqaKF3v5Sd
# capture the encrypted nonce and the initialization vector (IV)
$ ENCRYPTED_NONCE=nrrCczvYXvc6T7J2G+EOLjHZO1cpPyu/nhsIlA==
$ IV=N6oLJnUqaKF3v5Sd
# restore the deleted key
$ ibmcloud kp key restore $KEY_ID -k $ENCRYPTED_KEY -n $ENCRYPTED_NONCE -v $IV --output json
{
"id": "c42c6f2c-8b67-4016-b2c3-99fba9490f5d",
"name": "my-imported-root-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:key:c42c6f2c-8b67-4016-b2c3-99fba9490f5d"
}
# list keys - verify the key was restored
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
c42c6f2c-8b67-4016-b2c3-99fba9490f5d my-imported-root-key
必要參數
-
KEY_ID_OR_ALIAS
您要還原之金鑰的 v4 UUID 或別名。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-k, --key-material
Deprecated
來自先前匯入之 base64-encoded 金鑰的金鑰資料。如果您使用
import token
建立根金鑰,則-k, --key-material
選項的值是 加密資料金鑰。 請參閱範例 2,其使用匯入記號來建立根金鑰,並使用匯入記號來還原根金鑰。 -
-n, --encrypted-nonce
Deprecated
提供已加密的 Nonce 來驗證匯入金鑰的要求。如需相關資訊,請參閱 kp import-token nonce-encrypt。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-v, --iv
Deprecated
提供在加密暫時性要求之後產生的起始設定向量 (IV)。如需相關資訊,請參閱 kp import-token nonce-encrypt。
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰環
列出與 kp 實例相關聯的金鑰環。
範例
此範例顯示使用 CLI 外掛程式來列出適用於給定實例的金鑰環。
ibmcloud kp key-rings -i <INSTANCE_ID>
必要參數
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
kp 金鑰環建立
在 kp 實例內建立金鑰環。
範例
此範例顯示使用 CLI 外掛程式在給定實例中建立金鑰環。
ibmcloud kp key-ring create KEY_RING_ID -i <INSTANCE_ID>
必要參數
-
KEY_RING_ID
金鑰環的英數參照長度大於或等於 2 個字元,且小於或等於 100。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
kp key-ring delete
刪除 kp 實例內的金鑰環。
範例
此範例顯示使用 CLI 外掛程式來刪除給定實例中的金鑰環。 請注意,已新增強制 (-f
)。
ibmcloud kp key-ring delete KEY_RING_ID -i <INSTANCE_ID> -f
必要參數
-
KEY_RING_ID
金鑰環的英數參照長度大於或等於 2 個字元,且小於或等於 100。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-f, --force
強制刪除仍具有處於 已毀損 狀態之金鑰的金鑰環。 不刪除金鑰處於任何其他狀態的金鑰環。 如果金鑰環包含處於 已毀損 狀態的金鑰,且未新增此旗標,則金鑰環刪除會失敗。
kp 金鑰輪替
替換根金鑰(儲存在您的 Key Protect 服務中)。
當您替換根金鑰時,請將金鑰取代為新的金鑰資料。
如果 Key Protect 已建立金鑰 (金鑰為
不是 以 -k
參數建立的) Key Protect 會建立新的金鑰。 您不能將 kp key rotate
與 -k
一起指定 參數。
如果您已建立金鑰並提供金鑰資料 (kp key create key-name -k $KEY_MATERIAL
),則在替換金鑰時必須提供新的金鑰資料 (kp key rotate $KEY_ID_OR_ALIAS -k $NEW_KEY_MATERIAL
)
您無法替換 standard
金鑰,亦即,使用下列項目建立的金鑰:
kp create key-name --standard-key
指令。
ibmcloud kp key rotate KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-k, --key-material KEY_MATERIAL]
範例
這些是 kp key rotate
的範例。
範例 1
旋轉根金鑰。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad my-root-key
# rotate the key
$ ibmcloud kp key rotate 1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad
Rotating root key...
OK
# show key details
$ ibmcloud kp key show 1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad
Grabbing info for key id: 1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad...
OK
Key ID Key Name Description Creation Date Expiration Date
1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad my-root-key 2020-05-06 17:25:22 +0000 UTC Key does not expire
# create a new key material
$ NEW_KEY_MATERIAL=$(openssl rand -base64 32)
# Key Protect created the root key, providing a new key material will fail
$ ibmcloud kp key rotate 1a6d5be8-287c-4eb3-9c44-cf0c2b0d67ad -k $NEW_KEY_MATERIAL
Rotating root key...
FAILED
範例 2
旋轉 base64-encoded 或匯入的記號金鑰。
# create a random, base64-encoded, 32-byte key material
$ KEY_MATERIAL=$(openssl rand -base64 32)
# create a root key from a base64-encoded value
$ ibmcloud kp key create my-base64-root-key -k $KEY_MATERIAL
Creating key: 'my-base64-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
e55f86ab-6984-4594-ad23-3024f6440a58 my-base64-root-key
# create a new key material
$ NEW_KEY_MATERIAL=$(openssl rand -base64 32)
# rotate the key
$ ibmcloud kp key rotate e55f86ab-6984-4594-ad23-3024f6440a58 -k $NEW_KEY_MATERIAL
Rotating root key...
OK
# the key was created from a key material, NOT providing a new key material will fail
$ ibmcloud kp key rotate e55f86ab-6984-4594-ad23-3024f6440a58
Rotating root key...
FAILED
範例 3
本範例說明如何...
-
建立根金鑰
-
建立資料加密金鑰 (DEK),這是
plaintext
-
使用根金鑰包裝 DEK,這會建立
ciphertext
-
替換根金鑰
-
解除包裝密文以顯示原始 DEK (純文字) 及新密文 (新密文是使用新旋轉根金鑰包裝的純文字)
-
解除包裝新的密文以顯示原始 DEK (純文字)
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
5b976173-7804-4f82-acfa-bb98098bc528
# create a random, base64-encoded, 32-byte data encryption key (DEK)
$ PLAINTEXT=$(openssl rand -base64 32)
$ echo $PLAINTEXT
UPJ4YDwbQMjQG/aqlHsPhHV1CBkpIXngLHFS5+i4UZ4=
# wrap the plaintext key with the root key, creating a DEK (this is the ciphertext)
$ CIPHERTEXT=$(ibmcloud kp key wrap $KEY_ID -p $PLAINTEXT --output json | jq -r '.["Ciphertext"]')
$ echo $CIPHERTEXT
eyJjaXBoZXJ0ZXh0IjoiQkFrTlJrS2Q0 ...<redacted>... ODA5OGJjNTI4In0=
# rotate the root key
$ ibmcloud kp key rotate $KEY_ID
Rotating root key...
OK
# show key details
$ ibmcloud kp key show $KEY_ID --output json
{
"id": "5b976173-7804-4f82-acfa-bb98098bc528",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-10T18:09:27Z",
"lastUpdateDate": "2020-06-10T18:13:31Z",
"lastRotateDate": "2020-06-10T18:13:31Z",
"keyVersion": {
"id": "4330715a-918b-4718-b5ca-9475a214067e",
"creationDate": "2020-06-10T18:13:31Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:5b976173-7804-4f82-acfa-bb98098bc528"
}
# unwrap the ciphertext, reveal the original DEK (plaintext),
# and see the new ciphertext (the plaintext wrapped with the rotated root key)
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT --output json
{
"Plaintext": "UPJ4YDwbQMjQG/aqlHsPhHV1CBkpIXngLHFS5+i4UZ4=",
"Rewrapped Plaintext": "eyJjaXBoZXJ0ZXh0IjoiS0FITEFRWjdh ...<redacted>... NWEyMTQwNjdlIn0="
}
# capture the new (rewrapped) plaintext
$ NEWCIPHERTEXT=eyJjaXBoZXJ0ZXh0IjoiS0FITEFRWjdh ...<redacted>... NWEyMTQwNjdlIn0=
# unwrap the ciphertext and reveal the original DEK (plaintext)
$ ibmcloud kp key unwrap $KEY_ID $NEWCIPHERTEXT --output json
{
"Plaintext": "UPJ4YDwbQMjQG/aqlHsPhHV1CBkpIXngLHFS5+i4UZ4=",
"Rewrapped Plaintext": ""
}
必要參數
-
KEY_ID_OR_ALIAS
您要替換之根金鑰的 v4 UUID 或別名。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-k, --key-material
若要替換最初產生但不含
--key-material
參數 (即kp key create my-key
) 的金鑰,請省略--key-material
參數。如果使用
--key-material
參數建立金鑰,請指定新的 base64-encoded 金鑰資料,以用來替換現有的根金鑰。若要旋轉最初匯入服務的金鑰,請提供新的 32 位元組 (256 位元組) 金鑰。
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp key schedule-delete
具有 dual-auth-delete
原則的金鑰需要兩個管理使用者的授權,才能刪除金鑰。
請遵循此處理程序,以使用 dual-auth-delete
原則來刪除金鑰。
-
建立金鑰並啟用
dual-auth-delete
原則 -
使用者 1 使用來排程 (授權) 金鑰刪除
kp key schedule-delete
指令 -
使用者 2 排程 (授權) 金鑰刪除
-
在執行使用者介面、API 及 CLI 中支援的第二個
schedule-delete
之後,會刪除金鑰 -
如果在 7 天內未進行第二次授權,則金鑰會回到其預設狀態
有兩種方式可啟用 dual-auth-delete
原則:
- 使用
kp key policy-update dual-auth-delete
來設定單一金鑰的原則 - 使用來設定實例的原則
kp instance policy-update dual-auth-delete
; 在啟用實例原則之後建立的所有金鑰都會繼承實例原則設定
The kp key cancel-delete 指令會取消或移除先前的授權。
ibmcloud kp key schedule-delete KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
範例
這是排定要刪除金鑰的範例。
# schedule this key to be deleted
$ ibmcloud kp key schedule-delete $KEY_ID_OR_ALIAS
Scheduling key for deletion...
OK
# this key has a dual-auth-delete policy
$ ibmcloud kp key policies $KEY_ID_OR_ALIAS --output json
[
{
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-06-22T19:13:00Z",
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:a192d603-0b8d-452f-aac3-f9e1f95e7411:policy:2427dbde-6cff-41eb-8b5a-ff26b038cafc",
"lastUpdateDate": "2020-06-22T21:36:16Z",
"updatedBy": "user id ...<redacted>...",
"dualAuthDelete": { "enabled": true
}
}
]
必要參數
-
KEY_ID_OR_ALIAS
您要刪除之金鑰的 v4 UUID 或別名。 若要擷取 執行 kp keys 指令。
選用參數
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰顯示
擷取金鑰的詳細資料,例如,金鑰 meta 資料和金鑰資料。
如果金鑰被指定為根金鑰,則系統無法傳回該金鑰的金鑰資料。
ibmcloud kp key show KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-o, --output OUTPUT]
範例
這些是 kp key show
的範例。
範例 1
建立根金鑰並顯示詳細資料。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
8635b804-9966-4918-a16b-d561fdbf181f my-root-key
# show key details
$ ibmcloud kp key show 8635b804-9966-4918-a16b-d561fdbf181f
Grabbing info for key id: 8635b804-9966-4918-a16b-d561fdbf181f...
OK
Key ID Key Name Description Creation Date Expiration Date
8635b804-9966-4918-a16b-d561fdbf181f my-root-key 2020-05-05 19:58:02 +0000 UTC Key does not expire
範例 2
這是 kp key show
中 JSON 索引鍵及值的說明 指令。 在此範例中,已旋轉金鑰,以確保顯示所有 JSON 金鑰/值配對。
$ ibmcloud kp key show 8635b804-9966-4918-a16b-d561fdbf181f --output json
{
"id": "8635b804-9966-4918-a16b-d561fdbf181f",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-05-05T19:58:02Z",
"lastUpdateDate": "2020-05-05T19:58:24Z",
"lastRotateDate": "2020-05-05T19:58:24Z",
"keyVersion": {
"id": "85b65b20-4165-4da3-8ba9-880e72390461",
"creationDate": "2020-05-05T19:58:24Z"
},
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:8635b804-9966-4918-a16b-d561fdbf181f"
}
索引鍵 | 說明 |
---|---|
ID | 這是 KEY_ID,它是唯一的,並且在 CLI 指定 KEY_ID 時使用 |
名稱 | 建立金鑰時所提供的名稱 |
類型 | API 用來在 REST 呼叫中設定內容類型 |
algorithmType | 演算法類型是進階加密標準 (AES) 或密碼區塊鏈 (CBC) |
createdBy | 建立金鑰的使用者 ID |
creationDate | 建立金鑰的日期和時間 |
lastUpdateDate | 前次更新金鑰的日期和時間 |
lastRotateDate | 前次輪替金鑰的日期和時間; 僅當已輪替金鑰時才存在此項目 |
keyVersion /id | 這會識別主要金鑰的最新版本 |
keyVersion / creationDate | 前次更新金鑰資料的日期和時間 |
可擷取 | 決定關鍵資料是否可以離開服務的布林值。 如果設為 false,Key Protect 會將金鑰指定為用於 wrap 和 unwrap 動作的不可擷取根金鑰。 如果設為 true,Key Protect 會將金鑰指定為您可以儲存在應用程式和服務中的標準金鑰。 一旦設為 false,就無法將它變更為 true。 |
狀態 | 1-金鑰處於作用中; 2-金鑰已暫停; 請參閱 金鑰狀態 |
CRN | 雲端資源名稱 (CRN) |
必要參數
-
KEY_ID_OR_ALIAS
您要顯示之根金鑰的 v4 UUID 或別名。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰同步
這個次指令會同步處理金鑰的相關聯資源。
ibmcloud kp key sync KEY_ID
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-o, --output FORMAT]
範例
這是 kp key sync
的範例。
範例
同步化金鑰並顯示結果。
# synchronize the associated resources for a given key
$ ibmcloud kp key sync 94c06f9c-a07a-4961-8548-553cf7431f18
Synchronizing key...
OK
Key's associated resources are synchronized successfully
必要參數
-
KEY_ID
您要同步的金鑰 ID。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰更新
使用現有金鑰環或中的新金鑰環來 更新金鑰 Key Protect 實例。
ibmcloud kp key update KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
-r, --new-key-ring KEY_RING_ID
[-o, --output OUTPUT]
必要參數
-
KEY_ID_OR_ALIAS
您要顯示之根金鑰的 v4 UUID 或別名。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。 -
-r, --new-key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
選用參數
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。
範例
請注意,必須已在建立金鑰的過程中建立金鑰環,或建立金鑰環本身。
這是 kp key update
的範例。
ic kp key update 5f2cc155-fe16-492c-845c-4d1f0688c7ba -r TestRing
執行指令具有一般結果:
Updating key...
OK
Key ID Key Name Key Ring ID
5f2cc155-fe16-492c-845c-4d1f0688c7ba TestKey TestRing
kp 金鑰解除包裝
開啟資料加密金鑰 使用儲存在您的 Key Protect 實例。
ibmcloud kp key unwrap KEY_ID_OR_ALIAS CIPHERTEXT_FROM_WRAP
-i, --instance-id INSTANCE_ID
[-a, --aad ADDITIONAL_DATA]
[--key-ring KEY_RING_ID]
[-o, --output OUTPUT]
範例
這些是 kp key unwrap
的範例。
範例 1
解除包裝密文以顯示純文字資料加密金鑰 (DEK)。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# create a data encryption key (DEK), wrapped with the root key
$ ibmcloud kp key wrap 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Wrapping key...
OK
Ciphertext
eyJjaXBoZXJ0ZXh0IjoiKzhjbHVqcUNP ...<redacted>... NmY3MTJjNGViIn0=
# capture the ciphertext
$ CIPHERTEXT=eyJjaXBoZXJ0ZXh0IjoiKzhjbHVqcUNP ...<redacted>... NmY3MTJjNGViIn0=
# unwrap the ciphertext to reveal the plaintext data encryption key (DEK)
$ ibmcloud kp key unwrap 807eb0a6-cc10-4bfe-8331-41a6f712c4ea $CIPHERTEXT
Unwrapping key...
OK
Plaintext Rewrapped Plaintext
mXW4GmBhkRG1+Dzkx1D6dMX99a4KyYwtwbghaaLEQZ0=
範例 2
解除包裝密文並提供 AAD 資訊。
提供額外鑑別資料 (AAD) 的一個使用案例是「密碼保護」密文,使它更難以解除包裝。
需要密文和 AAD 才能解除包裝密文並顯示純文字資料加密金鑰 (DEK)。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
5f2cc155-fe16-492c-845c-4d1f0688c7ba
# create a random, base64-encoded, 32-byte data encryption key (DEK)
$ PLAINTEXT=$(openssl rand -base64 32)
$ echo $PLAINTEXT
H4ZfQe66aKcxirfCdNZ/3Na0JECP6HsAM3yclKmIfPQ=
# set the additional authentication data (AAD)
$ AAD1=My-Secret-Password
$ AAD2=My-Verification-Phrase
# wrap the plaintext with the root key and AAD
$ CIPHERTEXT=$(ibmcloud kp key wrap $KEY_ID -a "$AAD1,$AAD2" -p $PLAINTEXT --output json | jq -r '.["Ciphertext"]')
$ echo $CIPHERTEXT
eyJjaXBoZXJ0ZXh0IjoiL1pQUzRLbUxQ ...<redacted>... ZjA2ODhjN2JiIn0=
# unwrap the ciphertext and reveal the original plaintext DEK
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD1,$AAD2
Unwrapping key...
OK
Plaintext Rewrapped Plaintext
H4ZfQe66aKcxirfCdNZ/3Na0JECP6HsAM3yclKmIfPQ=
# this should fail (missing some of the AAD)
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD1
Unwrapping key...
FAILED
# this should fail (AAD is in a different order)
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD2,$AAD1
Unwrapping key...
FAILED
必要參數
-
KEY_ID_OR_ALIAS
v4 UUID 或您用於初始包裝請求的根密鑰的別名。
-
CIPHERTEXT_FROM_WRAP
在起始 wrap 作業期間傳回的已加密資料金鑰。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-a, --aad
用來進一步保護金鑰的其他鑑別資料 (AAD)。 您可以提供最多 255 個字串,每個以逗點分界。 如果您在包裝時提供了 AAD,則在拆包時必須以相同的順序指定相同的 AAD。
Key Protect 服務不會儲存額外的驗證資料。 如果您提供 AAD,請將資料儲存到安全的位置,以確保您可以在後續的 unwrap 要求期間存取及提供相同的 AAD。
-o, --output
Set the CLI output format. By default, all commands print in table format. To change the output format to JSON, use `--output json`.
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰版本
當您替換根金鑰時,Key Protect 會建立金鑰的新版本。 列出 Key Protect 實例中可用於 KeyID 或金鑰別名的所有金鑰版本。
ibmcloud kp key versions KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[-r, --key-ring KEY_RING_ID]
[-n, --number-of-key-versions VERSION_LIMIT]
[-o, --output OUTPUT]
[-s, --starting-offset OFFSET]
[-t, --total-count TOTAL_COUNT]
[-a, --all-key-states ALL_KEY_STATES]
範例
這些是 kp key versions
的範例。
範例 1
一個使用案例是透過檢視其金鑰版本歷程,以安全管理者身分審核根金鑰的輪替歷程。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# rotate the root key
$ ibmcloud kp key rotate 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Rotating root key...
OK
# Inspect the versions
$ ibmcloud kp key versions 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Retrieving key Versions...
OK
Key Version ID Creation Date
21562e93-8882-420e-90a7-912c70023373 2022-07-08T17:02:10Z
390086ac-76fa-4094-8cf3-c0829bd69526 2022-07-08T17:02:40Z
範例 2
以安全管理者身分審核根金鑰並檢視歷程的相同使用案例,其總計數在 JSON 輸出中。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# rotate the root key
$ ibmcloud kp key rotate 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Rotating root key...
OK
# Inspect the versions
$ ibmcloud kp key versions 807eb0a6-cc10-4bfe-8331-41a6f712c4ea -t -o json
{
"metadata": {
"collectionType": "application/vnd.ibm.kms.key.version+json",
"collectionTotal": 2,
"totalCount": 2
},
"resources": [
{
"id": "21562e93-8882-420e-90a7-912c70023373",
"creationDate": "2022-07-08T17:02:10Z"
},
{
"id": "390086ac-76fa-4094-8cf3-c0829bd69526",
"creationDate": "2022-07-08T17:02:40Z"
}
]
}
範例 3
另一個使用案例會列出過去一年每月輪流使用金鑰集的前 12 個金鑰版本。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# rotate the root key
$ ibmcloud kp key rotate 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Rotating root key...
OK
# Inspect the versions
$ ibmcloud kp key versions 807eb0a6-cc10-4bfe-8331-41a6f712c4ea -n 12 -o json
{
"metadata": {
"collectionType": "application/vnd.ibm.kms.key.version+json",
"collectionTotal": 12
},
"resources": [
{
"id": "21562e93-8882-420e-90a7-912c70023373",
"creationDate": "2021-07-08T17:02:10Z"
},
{
"id": "390086ac-76fa-4094-8cf3-c0829bd69526",
"creationDate": "2021-08-08T17:02:40Z"
},[...10x]
]
}
範例 4
另一個使用案例會列出過去兩年每月輪替的金鑰集的第二個 12 個金鑰版本。
ibmcloud kp 金鑰版本 $KEY_ID_OR_ALIAS -n 12 -s 12
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# rotate the root key
$ ibmcloud kp key rotate 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Rotating root key...
OK
# Inspect the versions
$ ibmcloud kp key versions 807eb0a6-cc10-4bfe-8331-41a6f712c4ea -n 12 -s 12 -o json
{
"metadata": {
"collectionType": "application/vnd.ibm.kms.key.version+json",
"collectionTotal": 12
},
"resources": [
{
"id": "21562e93-8882-420e-90a7-912c70023373",
"creationDate": "2021-07-08T17:02:10Z"
},
{
"id": "390086ac-76fa-4094-8cf3-c0829bd69526",
"creationDate": "2021-08-08T17:02:40Z"
},[...10x]
]
}
範例 5
選用旗標,用於傳回目前非作用中金鑰的版本數。 先前,指令會失敗,如下列範例所示:
# Attempt to show version count
$ ibmcloud kp key versions af61298c-d75d-42a8-aa76-e04178cf4685 -i 99980ccc-d482-4cd0-bb41-deb4f7f1eb92 -t
Retrieving key Versions...
FAILED
KEY_ACTION_INVALID_STATE_ERR
Key is not in a valid state
Correlation-ID:a494bf49-be82-426f-88d8-17b58cc8634d
使用 CLI 0.8.0 版及更新版本,在新增 -a
旗標時指令會成功,如下列範例所示:
# Attempt to show version count
$ ibmcloud kp key versions af61298c-d75d-42a8-aa76-e04178cf4685 -i 99980ccc-d482-4cd0-bb41-deb4f7f1eb92 -t -a
Retrieving key Versions...
OK
TotalCount: 2
Key Version ID Creation Date
14dfde20-a751-4c3e-b6b0-e8d00a17d8d1 2023-06-22T15:16:09Z
af61298c-d75d-42a8-aa76-e04178cf4685 2023-06-22T15:10:28Z
請注意,如果未提供 -a
旗標,則仍會針對處於非作用中狀態的金鑰傳回 KEY_ACTION_INVALID_STATE_ERR
。
必要參數
-
KEY_ID_OR_ALIAS
v4 UUID 或您用於初始包裝請求的根密鑰的別名。
-
-i, --instance-ID
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
-
-n --number-of-key-versions
以提供的整數值來限制要擷取的金鑰版本數目 (預設值: 200)。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-s --starting-offset
從所提供整數值指定的偏移中擷取金鑰版本。
-
-t --total-count
用來依所提供的整數值重新取得金鑰的金鑰版本總數。
-
-a --all-key-states
選用旗標,用於傳回所有金鑰狀態 (包括非作用中金鑰) 的版本數。
kp 金鑰包裝
使用儲存在中的根金鑰來包裝資料加密金鑰 (DEK) Key Protect 實例。 DEK 通常用來加密「其他」資訊片段。
當您使用根金鑰包裝 DEK 時, Key Protect 結合多個演算法的強度,以保護已加密資料的隱私權和完整性。
您無法包裝 standard
金鑰,亦即,使用 -s
建立的金鑰 參數 (ibmcloud kp key create my-key-name -s
)。
ibmcloud kp key wrap KEY_ID_OR_ALIAS
-i, --instance-id INSTANCE_ID
[--key-ring KEY_RING_ID]
[-a, --aad ADDITIONAL_DATA]
[-o, --output OUTPUT]
[-p, --plaintext DATA_KEY]
最佳作法
包裝資料加密金鑰 (DEK) 會建立 ciphertext
。 密文是加密資訊,當解除包裝時,會顯示原始 DEK。
Key Protect 服務不會儲存您的 DEK。 儲存或持續保存至儲存體中的密文,以確保您可以使用 kp key unwrap
指令來擷取 DEK。
建議您永不儲存或持續保存至儲存體純文字 DEK。 在應用程式中,從儲存體載入密文,呼叫 Key Protect,以取得純文字 DEK,並使用 DEK 來加密或包裝「其他」資訊片段。
請勿將 DEK 儲存至持續性儲存體。 公開 DEK 可能容許其他人解密您的資料。
每次包裝根金鑰時,都會建立新的密文。
範例
這些是 kp key wrap
的範例。
範例 1
Key Protect 會建立新的 base64-encoded 資料加密金鑰 (DEK),並以根金鑰包裝它。
# create a root key
$ ibmcloud kp key create my-root-key
Creating key: 'my-root-key', in instance: '390086ac-76fa-4094-8cf3-c0829bd69526'...
OK
Key ID Key Name
807eb0a6-cc10-4bfe-8331-41a6f712c4ea my-root-key
# create a new key and wrap it with the root key, creating a DEK (this is the ciphertext)
$ ibmcloud kp key wrap 807eb0a6-cc10-4bfe-8331-41a6f712c4ea
Wrapping key...
OK
Ciphertext
eyJjaXBoZXJ0ZXh0IjoiKzhjbHVqcUNP ...<redacted>... NmY3MTJjNGViIn0=
# capture the ciphertext
$ CIPHERTEXT=eyJjaXBoZXJ0ZXh0IjoiKzhjbHVqcUNP ...<redacted>... NmY3MTJjNGViIn0=
# unwrap the ciphertext to reveal the plaintext (DEK)
$ ibmcloud kp key unwrap 807eb0a6-cc10-4bfe-8331-41a6f712c4ea $CIPHERTEXT
Unwrapping key...
OK
Plaintext Rewrapped Plaintext
mXW4GmBhkRG1+Dzkx1D6dMX99a4KyYwtwbghaaLEQZ0=
範例 2
產生 base64-encoded 資料加密金鑰 (DEK),並以根金鑰包裝它。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
9052d914-bebe-4177-90e9-6073a167b507
# create a random, base64-encoded, 32-byte data encryption key (DEK)
$ PLAINTEXT=$(openssl rand -base64 32)
$ echo $PLAINTEXT
tEqoiCu9CeUsbqRe6yBUkrJg80QKKG/z46OkX0YQMV8=
# wrap the plaintext key with the root key, creating a DEK (this is the ciphertext)
$ CIPHERTEXT=$(ibmcloud kp key wrap $KEY_ID -p $PLAINTEXT --output json | jq -r '.["Ciphertext"]')
$ echo $CIPHERTEXT
eyJjaXBoZXJ0ZXh0IjoiTkdQRlhCb1dT ...<redacted>... M2ExNjdiNTA3In0=
# unwrap the ciphertext and reveal the original DEK
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT
tEqoiCu9CeUsbqRe6yBUkrJg80QKKG/z46OkX0YQMV8=
範例 3
包裝根金鑰並提供 AAD 資訊。
提供額外鑑別資料 (AAD) 的一個使用案例是「密碼保護」,並在密文中加入「驗證詞組」,使其更難以解除包裝。
需要密文和 AAD 才能解除包裝密文並顯示純文字 DEK。
# create a root key
$ KEY_ID=$(ibmcloud kp key create my-root-key --output json | jq -r '.["id"]')
$ echo $KEY_ID
5f2cc155-fe16-492c-845c-4d1f0688c7ba
# set the additional authentication data (AAD)
$ AAD1=My-Secret-Password
$ AAD2=My-Verification-Phrase
# wrap the plaintext DEK with the root key and AAD
$ CIPHERTEXT=$(ibmcloud kp key wrap $KEY_ID -a "$AAD1,$AAD2" --output json | jq -r '.["Ciphertext"]')
$ echo $CIPHERTEXT
eyJjaXBoZXJ0ZXh0IjoiL1pQUzRLbUxQ ...<redacted>... ZjA2ODhjN2JiIn0=
# unwrap the ciphertext and reveal the original DEK
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD1,$AAD2
Unwrapping key...
OK
Plaintext Rewrapped Plaintext
H4ZfQe66aKcxirfCdNZ/3Na0JECP6HsAM3yclKmIfPQ=
# this should fail (missing some of the AAD)
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD1
Unwrapping key...
FAILED
# this should fail (AAD is in a different order)
$ ibmcloud kp key unwrap $KEY_ID $CIPHERTEXT -a $AAD2,$AAD1
Unwrapping key...
FAILED
必要參數
-
KEY_ID_OR_ALIAS
v4 UUID 或您要用來包裝的根金鑰的別名。 您無法包裝標準金鑰。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-a, --aad
用來進一步保護金鑰的其他鑑別資料 (AAD)。 AAD 是一個字串陣列,用來檢查金鑰內容的完整性。 每一個字串最多可以保留 255 個字元。
如果您在包裝請求中提供 AAD,則必須在隨後的解除包裝請求中以相同的順序指定相同的 AAD。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。 -
-p, --plaintext
plaintext
指定由根金鑰 (由KEY_ID
或ALIAS
參數識別) 包裝的 base64-encoded 資料加密金鑰 (DEK)。您要管理和保護的 base64-encoded 資料加密金鑰 (DEK)。 若要匯入現有的金鑰,請提供 32 位元組 (256 位元組) 金鑰。
若要產生並包裝新的 DEK,請省略
--plaintext
參數。 -
--key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
kp 金鑰
列出 Key Protect 範例中可用的金鑰。
金鑰以 key id
順序列出; 請參閱
範例 5。
ibmcloud kp keys
-i, --instance-id INSTANCE_ID
[-b --sort-by SORT_BY]
[-c, --crn]
[-f, --key-filter FILTERS]
[--key-ring KEY_RING_ID]
[--key-states STATES]
[-l --key-search KEY_SEARCH]
[-n, --number-of-keys NUMBER_OF_KEYS]
[-o, --output OUTPUT]
[-s, --starting-offset STARTING_OFFSET]
[-t, --key-type TYPE]
範例
這些是 kp keys
的範例。
範例 1
列出金鑰。 請注意,依預設,這只會列出實例中的前 200 個金鑰。 若要顯示更多或更少金鑰數,請提供 --number-of-keys
參數的值。
# list keys
$ ibmcloud kp keys
Retrieving keys...
OK
Key ID Key Name
5f2cc155-fe16-492c-845c-4d1f0688c7ba my-root-key
c36e9f3a-feaf-4033-8603-687784dc7e51 my-root-key
範例 2
使用 --crn
列出金鑰並顯示雲端資源名稱 (CRN) 參數。
# list keys and show the cloud resource name (CRN)
$ ibmcloud kp keys -c
Retrieving keys...
OK
Key ID Key Name CRN
5f2cc155-fe16-492c-845c-4d1f0688c7ba my-root-key crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:5f2cc155-fe16-492c-845c-4d1f0688c7ba
c36e9f3a-feaf-4033-8603-687784dc7e51 my-root-key crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:c36e9f3a-feaf-4033-8603-687784dc7e51
範例 3
以 JSON 格式列出金鑰。
--output json
參數暗示 --crn
(雲端資源名稱) 參數。
# list keys
$ ibmcloud kp keys --output json
[
{
"id": "5f2cc155-fe16-492c-845c-4d1f0688c7ba",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-05-10T18:04:01Z",
"lastUpdateDate": "2020-05-10T18:04:01Z",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:5f2cc155-fe16-492c-845c-4d1f0688c7ba"
},
{
"id": "c36e9f3a-feaf-4033-8603-687784dc7e51",
"name": "my-root-key",
"type": "application/vnd.ibm.kms.key+json",
"algorithmType": "AES",
"createdBy": "user id ...<redacted>...",
"creationDate": "2020-05-10T17:56:37Z",
"lastUpdateDate": "2020-05-10T17:56:37Z",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:390086ac-76fa-4094-8cf3-c0829bd69526:key:c36e9f3a-feaf-4033-8603-687784dc7e51"
}
]
範例 4
列出索引鍵並反覆運算,以顯示詳細資料。
# list keys and convert to a list
$ KEYS=$(ibmcloud kp keys --output json | jq -r '.[] | .id')
$ for key in $(echo "${KEYS}"); do
ibmcloud kp key show ${key}
done
Grabbing info for key id: 5f2cc155-fe16-492c-845c-4d1f0688c7ba...
OK
Key ID Key Name Description Creation Date Expiration Date
5f2cc155-fe16-492c-845c-4d1f0688c7ba my-root-key 2020-05-10 18:04:01 +0000 UTC Key does not expire
Grabbing info for key id: c36e9f3a-feaf-4033-8603-687784dc7e51...
OK
Key ID Key Name Description Creation Date Expiration Date
c36e9f3a-feaf-4033-8603-687784dc7e51 my-root-key 2020-05-10 17:56:37 +0000 UTC Key does not expire
範例 5
使用 kp keys -n -s
選項建立 20 個金鑰,並以 5 個群組顯示它們。
# create 20 test keys
$ for I in {1..20}; do
KEY_ID=$(ibmcloud kp key create my-test-key-$I --output json | jq -r '.["id"]')
KEY_NAME=$(ibmcloud kp key show $KEY_ID --output json | jq -r '.["name"]')
echo $KEY_ID $KEY_NAME
done
b70f62a1-4d52-4526-91a9-ce47bf14c2a5 my-test-key-1
215f592c-3e42-47b6-867c-3cc1cce8a8fd my-test-key-2
df530c55-39c0-44e8-b7db-397593f70d90 my-test-key-3
768c9ceb-368b-46f7-9b1d-be211e036fe1 my-test-key-4
f141be88-5a34-4290-8513-4f01d934e75a my-test-key-5
b8794334-eea6-4c0d-8fe1-8086300b13f7 my-test-key-6
87679194-52d0-42af-81e1-bffd64f87315 my-test-key-7
cc7faf46-43cf-43b2-be98-7d1815371639 my-test-key-8
e9b08526-3227-406c-b83f-c28844bd952b my-test-key-9
3ee0d859-2968-4444-8e4d-3d28614f055c my-test-key-10
bc459a2f-56cb-445e-b4ee-9d1866b57560 my-test-key-11
62090ba8-7363-408e-9edc-aa9fb69c09be my-test-key-12
3b4b0511-00df-48e6-ad65-fad35bb6ce17 my-test-key-13
16276369-ba81-4eb5-be92-f13512147ad4 my-test-key-14
3d683d56-d340-40cb-b8b6-605dcfded01f my-test-key-15
10954149-0217-472d-8137-42fc330dbd03 my-test-key-16
54dd2745-7718-487f-85e6-a67e758dd945 my-test-key-17
3a5a3b52-6942-463d-9f7a-5b216bbf5123 my-test-key-18
90138be5-1dd1-4eea-b7c1-73cc8609e7f7 my-test-key-19
cf0a3d8b-4856-4aa5-be6a-88cca465eab0 my-test-key-20
# this is the same list sorted in KEY_ID order
# this is the order we expect when listing keys
10954149-0217-472d-8137-42fc330dbd03 my-test-key-16
16276369-ba81-4eb5-be92-f13512147ad4 my-test-key-14
215f592c-3e42-47b6-867c-3cc1cce8a8fd my-test-key-2
3a5a3b52-6942-463d-9f7a-5b216bbf5123 my-test-key-18
3b4b0511-00df-48e6-ad65-fad35bb6ce17 my-test-key-13
3d683d56-d340-40cb-b8b6-605dcfded01f my-test-key-15
3ee0d859-2968-4444-8e4d-3d28614f055c my-test-key-10
54dd2745-7718-487f-85e6-a67e758dd945 my-test-key-17
62090ba8-7363-408e-9edc-aa9fb69c09be my-test-key-12
768c9ceb-368b-46f7-9b1d-be211e036fe1 my-test-key-4
87679194-52d0-42af-81e1-bffd64f87315 my-test-key-7
90138be5-1dd1-4eea-b7c1-73cc8609e7f7 my-test-key-19
b70f62a1-4d52-4526-91a9-ce47bf14c2a5 my-test-key-1
b8794334-eea6-4c0d-8fe1-8086300b13f7 my-test-key-6
bc459a2f-56cb-445e-b4ee-9d1866b57560 my-test-key-11
cc7faf46-43cf-43b2-be98-7d1815371639 my-test-key-8
cf0a3d8b-4856-4aa5-be6a-88cca465eab0 my-test-key-20
df530c55-39c0-44e8-b7db-397593f70d90 my-test-key-3
e9b08526-3227-406c-b83f-c28844bd952b my-test-key-9
f141be88-5a34-4290-8513-4f01d934e75a my-test-key-5
# define a function for listing keys
$ list_keys () {
N=$1
S=$2
KEYS=$(ibmcloud kp keys --number-of-keys $N --starting-offset $S --output json | jq -r '.[] | .id')
for KEY_ID in $(echo "${KEYS}"); do
KEY_ID=$(ibmcloud kp key show $KEY_ID --output json | jq -r '.["id"]')
KEY_NAME=$(ibmcloud kp key show $KEY_ID --output json | jq -r '.["name"]')
echo $KEY_ID $KEY_NAME
done
}
# list the first group of keys
$ list_keys 5 0
10954149-0217-472d-8137-42fc330dbd03 my-test-key-16
16276369-ba81-4eb5-be92-f13512147ad4 my-test-key-14
215f592c-3e42-47b6-867c-3cc1cce8a8fd my-test-key-2
3a5a3b52-6942-463d-9f7a-5b216bbf5123 my-test-key-18
3b4b0511-00df-48e6-ad65-fad35bb6ce17 my-test-key-13
# list the second group of keys
$ list_keys 5 5
3d683d56-d340-40cb-b8b6-605dcfded01f my-test-key-15
3ee0d859-2968-4444-8e4d-3d28614f055c my-test-key-10
54dd2745-7718-487f-85e6-a67e758dd945 my-test-key-17
62090ba8-7363-408e-9edc-aa9fb69c09be my-test-key-12
768c9ceb-368b-46f7-9b1d-be211e036fe1 my-test-key-4
# list the third group of keys
$ list_keys 5 10
87679194-52d0-42af-81e1-bffd64f87315 my-test-key-7
90138be5-1dd1-4eea-b7c1-73cc8609e7f7 my-test-key-19
b70f62a1-4d52-4526-91a9-ce47bf14c2a5 my-test-key-1
b8794334-eea6-4c0d-8fe1-8086300b13f7 my-test-key-6
bc459a2f-56cb-445e-b4ee-9d1866b57560 my-test-key-11
# list the last group of keys
$ list_keys 5 15
cc7faf46-43cf-43b2-be98-7d1815371639 my-test-key-8
cf0a3d8b-4856-4aa5-be6a-88cca465eab0 my-test-key-20
df530c55-39c0-44e8-b7db-397593f70d90 my-test-key-3
e9b08526-3227-406c-b83f-c28844bd952b my-test-key-9
f141be88-5a34-4290-8513-4f01d934e75a my-test-key-5
# delete the test keys
$ KEYS=$(ibmcloud kp keys --output json | jq -r '.[] | .id')
$ for KEY_ID in $(echo "${KEYS}"); do
KEY_NAME=$(ibmcloud kp key show $KEY_ID --output json | jq -r '.["name"]')
if [[ $KEY_NAME == *"my-test-key-"* ]]; then
echo "Deleting... $KEY_NAME $KEY_ID"
ibmcloud kp key delete $KEY_ID
fi
done
(output not shown)
範例 6
根據 Key Protect 實例中的金鑰狀態 (Active
,Suspended
) 列出金鑰。
# list active and suspended keys
$ ibmcloud kp keys --key-states active,suspended
Retrieving keys...
OK
Key ID Key Name
ef2cc155-fe56-492c-845c-4d1f0688c7ba my-active-key
636e9f3a-feaf-4033-8603-687754dc7e51 my-suspended-key
範例 7
根據 Key Protect 實例中的金鑰類型 (根) 列出金鑰。
# list root keys
$ ibmcloud kp keys -t root
Retrieving keys...
OK
Key ID Key Name
2f1cb135-fa16-40dc-815c-4d1f0ee8c7ba my-root-key
範例 8
列出 Key Protect 實例中的金鑰,其金鑰名稱或別名完全符合不含引號的字串 "TEST" 中的字元。
# list keys with identifiers exactly matching TEST
$ ibmcloud kp keys -l exact:TEST
Retrieving keys...
OK
Key ID Key Name
636e9f3a-feaf-4033-8603-687754dc7e51 TEST
範例 9
列出 Key Protect 實例中的金鑰,並根據其 ID 及金鑰建立日期 (從最新的連字號 '-' 開始,指示依遞減順序排序) 來排序金鑰。
# sort keys by id and descending creationDate
$ ibmcloud kp keys -b id,-creationDate
Retrieving keys...
OK
Key ID Key Name
ef2cc155-fe56-492c-845c-4d1f0688c7ba my-last-key
2f1cb135-fa16-40dc-815c-4d1f0ee8c7ba my-first-key
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-b, --sort-by
根據參數來排序索引鍵。 排序結果的預設內容是 "id"。參數之前的 '-' 指出依降冪排序。 目前支援的排序參數為
- ID
- 狀態
- 可擷取
- 已匯入
- creationDate
- lastUpdateDate
- lastRotateDate
- deletionDate
- expirationDate
-
-c, --crn
在輸出中包含雲端資源名稱 (CRN)。
-
-f, --key-filter
根據參數過濾金鑰。 支援的索引鍵過濾參數如下:
- creationDate
- deletionDate
- expirationDate
- 可擷取
- lastUpdateDate
- lastRotateDate
- 狀態
日期的支援運算子如下:
- GT(大於)
- gte (大於或等於)
- LT(小於)
- LTE(小於或等於)
如果遺漏任何這些運算子,則結果會完全相符。
-
--key-states
要擷取金鑰的狀態。 包含有效狀態的字串清單-
Active
、Suspended
、Deactivated
、Destroyed
。(預設值:active,suspended,deactivated
)。 -
-l, --key-search
根據具有附加在前面的限定元 (例如
exact
、not
、alias
、name
) 的搜尋字串來列出索引鍵。如需詳細資料,請參閱 API 文件。 -
-n, --number-of-keys
限制要擷取的金鑰數量。 預設值為 200,上限為 5000。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。將輸出設為 JSON (
--output json
) 會在輸出中包括雲端資源名稱 (CRN)。 -
-r, --key-ring
鑰匙圈的唯一、可讀的名稱。 如果使用者對預設金鑰環沒有許可權,則為必要。
-
-s, --starting-offset
從指定的偏移開始擷取索引鍵。 偏移以零為基礎,表示偏移 0 (零) 是第一個索引鍵。
-
-t, --key-type
要擷取的金鑰類型。 如果設為
standard-key
,則會擷取標準金鑰。 如果設為root-key
,則會擷取根金鑰。
kp region-set
將目標設為不同的 Key Protect 區域端點。
ibmcloud kp region-set REGION
-i, --instance-id INSTANCE_ID
[-u, --unset]
範例
這些是 kp region-set
的範例。
範例 1
如果未指定 REGION
參數,則會提示您選取區域。
# set the region endpoint
$ ibmcloud kp region-set
Select a Region:
1. au-syd
2. ca-tor
3. eu-de
4. eu-gb
5. jp-osa
6. jp-tok
7. us-east
8. us-south
9. br-sao
10. staging (us-south)
Enter a number:
5
OK
範例 2
明確設定區域。
# set the region endpoint to "us-south"
$ ibmcloud kp region-set us-south
OK
REGION
必須是有效的地區端點。
# this should fail (not a valid regional endpoint)
$ ibmcloud kp region-set not-a-region
FAILED
範例 3
取消設定 (移除) 地區端點。
# remove the regional endpoint
$ ibmcloud kp region-set -u
OK
必要參數
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
REGION
指定地區端點。 這是選用參數,如果未指定,則會提示您從清單中選取地區端點。
-
-u, --unset
取消設定 (移除) 區域端點。
kp 登錄
登錄是根金鑰與其他雲端資源 (例如 Cloud Object Storage (COS) 儲存區或 Cloud Databases 部署) 之間的關聯。
例如,在 Key Protect 中,您可以建立根金鑰,COS 會使用該金鑰來保護靜態資料。
其他雲端資源與 Key Protect 稱為 registration
。
如果有資源 (例如 COS 儲存區和物件) 依賴根金鑰,請不要刪除根金鑰。 刪除主要金鑰表示您無法回復那些資源。 這稱為「加密解構」,且沒有從此動作回復。
ibmcloud kp registrations
-i, --instance-id INSTANCE_ID
[-r, --key-ring KEY_RING_ID]
[-c, --crn-query CRN_PATTERN]
[-k, --key-id KEY_ID_OR_ALIAS]
[-o, --output OUTPUT]
範例
這些是 kp registrations
的範例。
登錄範例顯示許多「雲端資源名稱 (CRN)」。 CRN 遵循下列格式:
crn:version:cname:ctype:service-name:location:scope:service-instance:resource-type:resource
請參閱 雲端資源名稱,以取得 CRN 欄位的深度說明。
範例 1
列出所有登錄,其中可能包括雲端資源,例如資料庫、儲存體、運算、儲存器或傳訊。
此範例顯示 Cloud Object Storage (COS) 與 Key Protect.
# view all registrations
$ ibmcloud kp registrations --output json
[
{
"keyId": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f",
"resourceCrn": "crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8:bucket:my-cos-kms-bucket",
"createdBy": "crn-crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8::",
"creationDate": "2020-06-15T16:07:37Z",
"lastUpdated": "2020-06-15T16:07:37Z",
"keyVersion": { "id": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f", "creationDate": "2020-06-15T16:05:53Z"
}
}
]
範例 2
此範例顯示兩個雲端資源 (Cloud Object Storage 和 Key Protect-從建立 Key Protect 實例並在它們之間建立原則以刪除實例。
步驟的摘要如下:
步驟 | 其中 | 說明 |
---|---|---|
1 | CLI | 建立雲端物件儲存體 (COS) 及 Key Protect (KP) 實例 |
2 | CLI | 建立 COS 的原則以存取 KP 加密金鑰 |
3 | CLI | 建立 COS 用來加密資料的 KP 根金鑰 |
4 | 主控台使用者介面 | 建立 COS 儲存區並指定 KP 加密; 這是在主控台使用者介面 (UI) 中完成,因為此時沒有 API 或 CLI 支援 |
5 | CLI | 檢視 KP 登錄 |
6 | CLI | 上傳並下載物件以驗證 COS 與 KP 一起運作 |
7 | CLI | 刪除 COS 儲存區及 KP 根金鑰 |
8 | CLI | 刪除 COS 與 KP 之間的授權原則 |
9 | CLI | 刪除 COS 及 KP 實例 |
這些指令顯示 COS 及 Key Protect 服務方案。 ibmcloud resource service-instance-create
指令需要 service plan name
和 location
(位於型錄中)。
# show the catalog offerings for cloud object storage (COS) and Key Protect
$ ibmcloud catalog service cloud-object-storage
$ ibmcloud catalog service kms
此範例涵蓋多個步驟,應在諮詢所提供的摘要後執行。
# create a Cloud Object Storage (COS) instance
# "lite" is the pricing plan and "global" is the region
$ COS_NAME=my-cos-1
$ ibmcloud resource service-instance-create $COS_NAME cloud-object-storage lite global
Creating service instance my-cos-1 in resource group Default of account <account name> as <email address>...
OK
Service instance my-cos-1 was created.
Name: my-cos-1
ID: crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8::
GUID: 4b636e74-f3ca-40bb-80b8-3bd21801ccb8
Location: global
State: active
Type: service_instance
Sub Type:
Allow Cleanup: false
Locked: false
Created at: 2020-06-15T16:03:39Z
Updated at: 2020-06-15T16:03:39Z
Last Operation: Status create succeeded Message Completed create instance operation
# capture the COS instance id (GUID)
$ COS_INSTANCE_ID=4b636e74-f3ca-40bb-80b8-3bd21801ccb8
# create a Key Management Service (KMS) service instance
# "tiered-pricing" is the pricing plan and "us-south" is the region
$ KMS_NAME=my-kms-1
$ ibmcloud resource service-instance-create $KMS_NAME kms tiered-pricing us-south
Creating service instance my-kms-1 in resource group Default of account <account name> as <email address>...
OK
Service instance my-kms-1 was created.
Name: my-kms-1
ID: crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:b3933ab0-d579-46fc-8ed5-351aea657b9a::
GUID: b3933ab0-d579-46fc-8ed5-351aea657b9a
Location: us-south
State: active
Type: service_instance
Sub Type: kms
Allow Cleanup: false
Locked: false
Created at: 2020-06-15T16:04:40Z
Updated at: 2020-06-15T16:04:40Z
Last Operation: Status create succeeded Message Completed create instance operation
# capture the Key Protect (KP) instance id (GUID)
$ KP_INSTANCE_ID=b3933ab0-d579-46fc-8ed5-351aea657b9a
# create a policy for COS to read KMS; source is COS, target is KMS
$ ibmcloud iam authorization-policy-create cloud-object-storage kms Reader \
--source-service-instance-id $COS_INSTANCE_ID \
--target-service-instance-id $KP_INSTANCE_ID
Creating authorization policy under account ea998d3389c3473aa0987652b46fb146 as <email address>...
OK
Authorization policy 18cfc980-4458-4313-972e-93f312cdcd81 was created.
ID: 18cfc980-4458-4313-972e-93f312cdcd81
Source service name: cloud-object-storage
Source service instance: 4b636e74-f3ca-40bb-80b8-3bd21801ccb8
Target service name: kms
Target service instance: b3933ab0-d579-46fc-8ed5-351aea657b9a
Roles: Reader
# capture the COS-to-KMS authorization policy id
$ COS_KMS_AUTHORIZATION=18cfc980-4458-4313-972e-93f312cdcd81
# create a KP root key that COS uses to encrypt data
$ ibmcloud kp key create my-cos-key --output json
{
"id": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f",
"name": "my-cos-key",
"type": "application/vnd.ibm.kms.key+json",
"extractable": false,
"state": 1,
"crn": "crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:b3933ab0-d579-46fc-8ed5-351aea657b9a:key:2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f"
}
# capture the KP root key id
$ MY_COS_KEY_ID=2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f
# create a COS bucket and set KP encryption
# must be done in the console user interface (UI) because
# there is no API or CLI support at this time
# 1 - In the UI, go to... Resource list -> Storage -> my-cos-1
# 2 - Create bucket -> custom bucket
# 3 - Properties of a custom bucket
# a - bucket name: my-cos-kms-bucket
# b - location: us-south (same region as KP)
# c - checkbox: Key Protect
# d - instance: my-kms-1
# e - key name: my-cos-key
# f - button: Create bucket
# capture the name of the COS bucket that was created
$ COS_BUCKET=my-cos-kms-bucket
# view the KP registration; it's a result of creating the COS bucket
$ ibmcloud kp registrations --output json
[
{
"keyId": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f",
"resourceCrn": "crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8:bucket:my-cos-kms-bucket",
"createdBy": "crn-crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8::",
"creationDate": "2020-06-15T16:07:37Z",
"lastUpdated": "2020-06-15T16:07:37Z",
"keyVersion": { "id": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f", "creationDate": "2020-06-15T16:05:53Z"
}
}
]
# list the bucket
$ ibmcloud cos list-buckets --ibm-service-instance-id $COS_INSTANCE_ID
OK
1 bucket found in your account:
Name Date Created
my-cos-kms-bucket Jun 15, 2020 at 16:07:38
# upload an object to COS
$ ibmcloud cos put-object --bucket $COS_BUCKET --key '/cos-file.txt' --body cos-file-upload.txt
OK
Successfully uploaded object '/cos-file.txt' to bucket 'my-cos-kms-bucket'.
# get the object from COS
$ ibmcloud cos get-object --bucket $COS_BUCKET --key '/cos-file.txt' cos-file-download.txt
OK
Successfully downloaded '/cos-file.txt' from bucket 'my-cos-kms-bucket'
20 B downloaded.
# verify that the upload and download files are the same
$ cat cos-file-upload.txt
This is a test file
$ cat cos-file-download.txt
This is a test file
# delete the object
$ ibmcloud cos delete-object --bucket $COS_BUCKET --key '/cos-file.txt' --force
OK
Delete '/cos-file.txt' from bucket 'my-cos-kms-bucket' ran successfully.
# delete the bucket
$ ibmcloud cos delete-bucket --bucket $COS_BUCKET --force
OK
Successfully deleted bucket 'my-cos-kms-bucket'. The bucket 'my-cos-kms-bucket' will be available for reuse after 15 minutes.
# list the bucket (it should no longer exist)
$ ibmcloud cos list-buckets --ibm-service-instance-id $COS_INSTANCE_ID
OK
No buckets found in your account.
# view the KP registration (it should no longer exist)
$ ibmcloud kp registrations --output json
# delete the KP root key; COS no longer uses it
$ ibmcloud kp key delete $MY_COS_KEY_ID --output json
{
"id": "2cbea94c-6070-4a24-b0f8-7a56e4d7cb6f"
}
# delete the authorization policy between COS AND KMS
$ ibmcloud iam authorization-policy-delete $COS_KMS_AUTHORIZATION --force
Deleting authorization policy 18cfc980-4458-4313-972e-93f312cdcd81 under account ea998d3389c3473aa0987652b46fb146...
OK
Authorization policy 18cfc980-4458-4313-972e-93f312cdcd81 is deleted successfully
# view the authorization policy (it should no longer exist)
$ ibmcloud iam authorization-policies
Getting authorization policies under account ea998d3389c3473aa0987652b46fb146 as <email address>...
OK
No policy found
# delete the KMS instance
$ ibmcloud resource service-instance-delete $KMS_NAME --force
Deleting service instance my-kms-1 in resource group Default under account <account name> as <email address>...
OK
Service instance my-kms-1 with ID crn:v1:bluemix:public:kms:us-south:a/ea998d3389c3473aa0987652b46fb146:b3933ab0-d579-46fc-8ed5-351aea657b9a:: is deleted successfully
# delete the COS instance
$ ibmcloud resource service-instance-delete $COS_NAME --force
Deleting service instance my-cos-1 in resource group Default under account <account name> as <email address>...
OK
Service instance my-cos-1 with ID crn:v1:bluemix:public:cloud-object-storage:global:a/ea998d3389c3473aa0987652b46fb146:4b636e74-f3ca-40bb-80b8-3bd21801ccb8:: is deleted successfully
# view resources (COS and KMS should no longer exist)
$ ibmcloud resource service-instances
Retrieving instances with type service_instance in resource group Default in all locations under account <account name> as <email address>...
OK
No service instance found.
範例 3
此範例顯示在 COS 與 Key Protect (KP)-COS 無法存取 Key Protect 根金鑰。
- 刪除 KP 根金鑰
- 移除 CMS/KP 授權原則
此範例不會顯示指令輸出,但相關時除外。
# create a Cloud Object Storage (COS) service instance
# "lite" is the pricing plan and "global" is the region
$ COS_NAME=my-cos-1
$ ibmcloud resource service-instance-create $COS_NAME cloud-object-storage lite global
# capture the COS instance id (GUID)
$ COS_INSTANCE_ID=c488e11a-c8a0-4688-b002-9327266ea55f
# create a Key Management Service (KMS) service instance
# "tiered-pricing" is the pricing plan and "us-south" is the region
$ KMS_NAME=my-kms-1
$ ibmcloud resource service-instance-create $KMS_NAME kms tiered-pricing us-south
# capture the Key Protect (KP) instance id (GUID)
$ KP_INSTANCE_ID=26f4b198-952a-47ab-9f44-ef69c038b3c5
# create a policy for COS to read KMS; source is COS, target is KMS (Key Protect)
$ ibmcloud iam authorization-policy-create cloud-object-storage kms Reader \
--source-service-instance-id $COS_INSTANCE_ID \
--target-service-instance-id $KP_INSTANCE_ID
# capture the COS-to-KMS authorization policy id
$ COS_KMS_AUTHORIZATION=594b946e-0e90-44ea-ac62-6cbb42450cd5
# create a KP root key that COS uses to encrypt data
$ ibmcloud kp key create my-cos-key --output json
# capture the KP root key id
$ MY_COS_KEY_ID=464d78c3-57dc-49a5-b932-8ebf8f8c7771
# create a COS bucket and set KP encryption
# must be done in the console user interface (UI) because
# there is no API or CLI support at this time
# capture the name of the COS bucket that was created
$ COS_BUCKET=my-cos-kms-bucket
# upload an object to COS
$ ibmcloud cos put-object --bucket $COS_BUCKET --key '/cos-file.txt' --body cos-file-upload.txt
# delete the authorization policy between COS AND KMS - this breaks everything
$ ibmcloud iam authorization-policy-delete $COS_KMS_AUTHORIZATION --force
# get the object from COS - this fails because COS no longer has access to KMS
$ ibmcloud cos get-object --bucket $COS_BUCKET --key '/cos-file.txt' cos-file-download.txt
FAILED
ServiceNotAuthorized: The specified COS Service Instance does not have sufficient
permissions to access the resource provided in the ibm-sse-kp-customer-root-key-crn request header
status code: 401,
request id: a51e1da3-9bf7-4cc9-9eb0-0d074c7f9093,
host id:
# delete the object
$ ibmcloud cos delete-object --bucket $COS_BUCKET --key '/cos-file.txt' --force
# delete the bucket
$ ibmcloud cos delete-bucket --bucket $COS_BUCKET --force
# delete the KP root key - this fails because the registration was not deleted
$ ibmcloud kp key delete $MY_COS_KEY_ID --output json
FAILED
kp.Error:
correlation_id='fffdd8a9-405a-4a91-a5a7-52c30d11424d',
msg='Conflict: Key could not be deleted. Please see "reasons" for more details.',
reasons='[PROTECTED_RESOURCE_ERR: Key is protecting one or more cloud resources -
FOR_MORE_INFO_REFER: https://cloud.ibm.com/docs/key-protect?topic=key-protect-troubleshooting#unable-to-delete-keys]'
# delete the KP root key; use --force because the registration between COS and KMS still exists
$ ibmcloud kp key delete $MY_COS_KEY_ID --force --output json
# delete the KMS instance
$ ibmcloud resource service-instance-delete $KMS_NAME --force
# delete the COS instance
$ ibmcloud resource service-instance-delete $COS_NAME --force
# view resources (COS and KMS should no longer exist)
$ ibmcloud resource service-instances
Retrieving instances with type service_instance in resource group Default in all locations under account <account name> as <email address>...
OK
No service instance found.
必要參數
-
KEY_ID_OR_ALIAS
您要查詢之金鑰的 v4 UUID 或別名。
-
-i, --instance-id
IBM Cloud 識別您的 Key Protect 的實體 ID。
您可以設定環境變數,而不是使用下列指令來指定
-i
:$ export KP_INSTANCE_ID=<INSTANCE_ID>
。
選用參數
-
-c, --crn-query
指定需要列出其登錄的 crn 查詢
-
-k, --key-id
指定需要列出其登錄的金鑰 ID。
-
-o, --output
設定 CLI 輸出格式。 依預設,所有指令都會以表格格式列印。 若要將輸出格式變更為 JSON,請使用
--output json
。將輸出設為 JSON (
--output json
) 會在輸出中包括雲端資源名稱 (CRN)。 -
-r, --key-ring
鑰匙圈的唯一、可讀的名稱。 需要在給定的金鑰環上顯示登錄。
ibmcloud kp kmip 指令
KMIP 指令容許 API 存取 KMIP 配接卡及物件。
次指令 | 狀態 v0.10 | 說明 |
---|---|---|
配接器-建立 | 建立 KMIP 配接卡 | |
配接器 | 擷取 KMIP 配接卡 | |
配接器 | 列出實例中的 KMIP 配接器 | |
配接器-刪除 | 刪除 KMIP 配接卡 | |
cert-create | 建立與配接卡相關聯的 KMIP 用戶端憑證 | |
cert | 擷取 KMIP 用戶端憑證 | |
憑證 | 列出與 KMIP 配接卡相關聯的 KMIP 用戶端憑證 | |
cert-delete | 刪除 KMIP 用戶端憑證 | |
物件 | 擷取 KMIP 物件 | |
物件 | 列出 KMIP 配接卡中的 KMIP 物件 | |
object-delete | 刪除 KMIP 物件 |
kp kmip 配接器-建立
使用 kmip adapter-create
在 Key Protect 實例下建立 KMIP 配接器。 配接器用來分組及管理 KMIP 物件。 相同 Key Protect 實例下的 KMIP 配接器必須具有唯一名稱,因為可以依名稱或 ID 來擷取配接器。 對於所有 KMIP 相關 CLI 指令,任何採用配接卡 ID 的引數或旗標也可以使用配接卡名稱。
視設定檔而定,可能需要提供不同的資訊來建立配接器。 目前僅支援 KMIP 配接卡的一個設定檔: native_1.0
。
native_1.0
設定檔只需要在 -k
旗標中提供根金鑰的 ID。
$ ibmcloud kp kmip adapter-create
-i, --instance-id INSTANCE_ID
-p, --profile PROFILE
[-k, --crk-id CRK_ID]
[-n, --name NAME]
[-d, --description DESC]
[-o, --output OUTPUT]
範例
這些是 kp kmip adapter-create
的範例。
範例 1
此範例會使用 native_1.0
設定檔來建立 KMIP 配接卡
$ ibmcloud kp kmip adapter-create -n myadapter -k 47a0ad90-204d-4e45-aa5b-68ed40a05fa2 -p native_1.0 -d "my description"
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Adapter...
OK
Adapter ID Adapter Profile Adapter Name Adapter Description
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter my description
$ ibmcloud kp kmip adapters
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Listing KMIP Adapters...
OK
Adapter ID Adapter Profile Adapter Name Created At Updated At
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter 2024-03-20 22:06:43 +0000 UTC 2024-03-20 22:06:43 +0000 UTC
kp kmip 配接卡
擷取 KMIP 配接卡的相關詳細資料,包括建立及更新日期。 您可以使用配接卡 ID 或配接卡名稱。
$ ibmcloud kp kmip adapter ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip adapter
的範例。
範例 1
請注意,配接器的部分屬性僅以 JSON 輸出格式可見。
$ ibmcloud kp key create rootKmip
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating key: 'rootKmip', in instance: '8944cc2d-7e00-46b2-baa4-787051e0f7b3'...
OK
Key ID Key Name
47a0ad90-204d-4e45-aa5b-68ed40a05fa2 rootKmip
$ ibmcloud kp kmip adapter-create -n myadapter -k 47a0ad90-204d-4e45-aa5b-68ed40a05fa2 -p native_1.0
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Adapter...
OK
Adapter ID Adapter Profile Adapter Name Adapter Description
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter -
# retreiving adapter by name
$ ibmcloud kp kmip adapter myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Getting KMIP Adapter...
OK
Adapter ID Adapter Profile Adapter Name Created At Updated At Adapter Description
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter 2024-03-20 22:06:43 +0000 UTC 2024-03-20 22:06:43 +0000 UTC -
# retrieving adapter by ID
$ ibmcloud kp kmip adapter d6a00af1-277f-40e8-b33e-da3a68752209 -o json
{
"id": "d6a00af1-277f-40e8-b33e-da3a68752209",
"profile": "native_1.0",
"profile_data": {
"crk_id": "47a0ad90-204d-4e45-aa5b-68ed40a05fa2"
},
"name": "myadapter",
"description": "",
"created_by": "IBMid-664003LB2T",
"created_at": "2024-03-20T22:06:43Z",
"updated_by": "IBMid-664003LB2T",
"updated_at": "2024-03-20T22:06:43Z"
}
kp kmip 配接卡
列出 Key Protect 實例中可用的 KMIP 配接器。
$ ibmcloud kp kmip adapters
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
[-n, --limit LIMIT]
[-s, --starting-offset OFFSET]
[-t, --total-count]
[-k, --crk-id CRK_ID]
範例
這些是 kp kmip adapters
的範例。 使用 -k
標誌僅顯示使用特定 CRK ID 的轉接器。
範例 1
$ ibmcloud kp kmip adapters -n 100 -s 0
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Listing KMIP Adapters...
OK
Adapter ID Adapter Profile Adapter Name Created At Updated At
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter 2024-03-20 22:06:43 +0000 UTC 2024-03-20 22:06:43 +0000 UTC
kp kmip adapter-delete
刪除 KMIP 配接卡。 這將刪除與配接器相關聯的任何物件和憑證。
$ ibmcloud kp kmip adapter-delete ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
[-f, --force]
[-y, --skip-confirm]
範例
這些是 kp kmip adapter-delete
的範例。
範例 1
$ ibmcloud kp kmip adapter-create -n adap -k 47a0ad90-204d-4e45-aa5b-68ed40a05fa2 -p native_1.0
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Adapter...
OK
Adapter ID Adapter Profile Adapter Name Adapter Description
e97e4297-4a6f-41c9-ae67-0920715964fd native_1.0 adap -
$ ibmcloud kp kmip adapter-delete e97e4297-4a6f-41c9-ae67-0920715964fd
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Deleting KMIP Adapter...
OK
kp kmip cert-create
使用 kp kmip cert-create
來建立 KMIP 用戶端憑證,以與特定的 KMIP 配接卡相關聯。 -c
旗標中提供的憑證應該為 x509 PEM 格式。 您可以使用字首 @
來指定檔案路徑,或將憑證檔的內容直接提供給旗標,來上傳憑證檔。
「KMIP 用戶端憑證」是用來透過相互 TLS (mTLS) 連接及鑑別 KMIP 伺服器。 必須先登錄憑證,才能使用 KMIP 配接卡執行任何 KMIP 通訊協定作業。 可能需要長達 5 分鐘,憑證才能在 KMIP 作業中使用。
憑證在相同的 KMIP 配接器內必須具有唯一名稱,且憑證內容必須是唯一的,即使在多個配接器之間也是如此。
另請參閱: KMIP 通訊協定規格
$ ibmcloud kp kmip cert-create
-a, --adapter ADAPTER_NAME_OR_ID
-c, --cert-string {@path/to/cert | CERTIFICATE_STRING}
[-n, --name NAME]
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip cert-create
的範例。
範例 1
此範例顯示兩種上傳相同憑證檔案的方法。
$ ibmcloud kp key create rootKmip
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating key: 'rootKmip', in instance: '8944cc2d-7e00-46b2-baa4-787051e0f7b3'...
OK
Key ID Key Name
47a0ad90-204d-4e45-aa5b-68ed40a05fa2 rootKmip
$ ibmcloud kp kmip adapter-create -n myadapter -k 47a0ad90-204d-4e45-aa5b-68ed40a05fa2 -p native_1.0
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Adapter...
OK
Adapter ID Adapter Profile Adapter Name Adapter Description
d6a00af1-277f-40e8-b33e-da3a68752209 native_1.0 myadapter -
$ export CERT=$(cat ./cert.pem)
$ ibmcloud kp kmip cert-create -n mycert -c "$CERT" -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Client Certificate...
OK
Certificate ID Certificate Name Created At
3f550b96-86bc-44fe-8d1d-113e57067219 mycert 2024-03-20 22:08:03 +0000 UTC
## Alternatively, you can also provide the filepath of the certificate
$ ibmcloud kp kmip cert-delete mycert -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Deleting KMIP Client Certificate...
OK
$ ibmcloud kp kmip cert-create -n mycert -c @./cert.pem -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Creating KMIP Client Certificate...
OK
Certificate ID Certificate Name Created At
a279fded-06d1-45a1-8a95-901f194fb937 mycert 2024-03-20 22:11:34 +0000 UTC
kp kmip cert
擷取特定的 KMIP 用戶端憑證。 可以依 ID 或名稱來擷取憑證。
$ ibmcloud kp kmip cert CERTIFICATE_ID
-a, --adapter ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip cert
的範例。
範例 1
依名稱取得憑證:
$ ibmcloud kp kmip cert mycert -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Getting KMIP Client Certificate...
OK
Certificate ID Certificate Name Created At
a279fded-06d1-45a1-8a95-901f194fb937 mycert 2024-03-20 22:11:34 +0000 UTC
範例 2
依 UUID 取得 JSON 格式的憑證。 將在 JSON 主體中傳回憑證的 PEM 格式內容。
$ ibmcloud kp kmip cert a279fded-06d1-45a1-8a95-901f194fb937 -a myadapter -o json
{
"id": "a279fded-06d1-45a1-8a95-901f194fb937",
"name": "mycert",
"certificate": "-----BEGIN CERTIFICATE-----\nMIIFqzCCA5OgAwIBAgIUNXqfJMkAHOBHz6+ekETDlCqIEqUwDQYJKoZIhvcNAQEL\nBQAw
... CERTIFICATE CONTENTS ABBREVIATED ...
Y6uFtHuQSpud0C\n-----END CERTIFICATE-----\n",
"created_by": "IBMid-12345678",
"created_at": "2024-03-20T22:11:34Z"
}
kp kmip certs
列出與特定 KMIP 配接卡相關聯的所有 KMIP 用戶端憑證。
$ ibmcloud kp kmip certs
-a, --adapter ADAPTER_NAME_OR_ID
[-n, --limit LIMIT]
[-s, --starting-offset OFFSET]
[-t, --total-count]
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip certs
的範例。
範例 1
$ ibmcloud kp kmip certs -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Listing KMIP Client Certificates...
OK
Certificate ID Certificate Name Created At
a279fded-06d1-45a1-8a95-901f194fb937 mycert 2024-03-20 22:11:34 +0000 UTC
kp kmip cert-delete
刪除 KMIP 用戶端憑證。
$ ibmcloud kp kmip cert-delete CERTIFICATE_ID
-a, --adapter ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
範例
這些是 kp kmip cert-delete
的範例
範例 1
$ ibmcloud kp kmip cert-delete -a myadapter mycert
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Deleting KMIP Client Certificate...
OK
kp kmip 物件
「KMIP 物件」是透過使用 KMIP 通訊協定透過 KMIP 用戶端執行的作業來建立。 無法透過 API 建立它們,但可以讀取及刪除它們。 物件屬於單一配接器。
物件沒有名稱,必須依 ID 來擷取。
$ ibmcloud kp kmip object OBJECT_ID
-a, --adapter ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip object
的範例
範例 1
$ ibmcloud kp kmip object 12365a82-5404-4bd9-a4c7-2b628ee18304 -a testadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Getting KMIP Object...
OK
Object ID Object Type Object State Created At Updated At
12365a82-5404-4bd9-a4c7-2b628ee18304 Symmetric Key Active 2024-03-14 21:01:45 +0000 UTC 2024-03-14 21:01:45 +0000 UTC
範例 2
將 KMIP 物件作為 JSON 取得將會顯示在一般表格視圖中不可見的部分額外屬性。
$ ibmcloud kp kmip object 12365a82-5404-4bd9-a4c7-2b628ee18304 -a testadapter -o json
{
"id": "12365a82-5404-4bd9-a4c7-2b628ee18304",
"kmip_object_type": 2,
"state": 2,
"created_by_kmip_client_cert_id": "531c18f3-4e37-447e-a7e0-e8676407bb75",
"created_by": "IBMid-123456",
"created_at": "2024-03-14T21:01:45Z",
"updated_by_kmip_client_cert_id": "531c18f3-4e37-447e-a7e0-e8676407bb75",
"updated_by": "IBMid-123456",
"updated_at": "2024-03-14T21:01:45Z"
}
kp kmip 物件
列出「KMIP 物件」,並在其他 meta 資料中檢視其「物件類型」及「物件」狀態的相關資訊。 使用 -f
旗標來僅過濾處於特定狀態的物件。 依預設,狀態過濾器會設為 1,2,3,4
。
數字對應於物件狀態,如下所示:
- 前置作用中 = 1
- 作用中 = 2
- 已取消啟動 = 3
- 已受損 = 4
- 毀損 = 5
- 已毀損已受損 = 6
請參閱 KMIP 狀態列舉
ibmcloud kp kmip objects
-a, --adapter ADAPTER_NAME_OR_ID
[-n, --limit LIMIT]
[-s, --starting-offset OFFSET]
[-t, --total-count]
-i, --instance-id INSTANCE_ID
[-o, --output OUTPUT]
範例
這些是 kp kmip objects
的範例。
範例 1
$ ibmcloud kp kmip objects -a myadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Listing KMIP Objects...
OK
Object ID Object Type Object State Created At Updated At
00196c59-c5c2-42d8-9729-703cd0389f60 Symmetric Key Compromised 2024-03-14 20:47:54 +0000 UTC 2024-03-14 20:47:54 +0000 UTC
02f1043c-0494-4399-82af-5395a14b019f Symmetric Key Pre-Active 2024-03-14 20:58:06 +0000 UTC 2024-03-14 20:58:06 +0000 UTC
08082ff4-821b-4689-83ec-15cac5bd1939 Symmetric Key Pre-Active 2024-02-22 00:10:46 +0000 UTC 2024-02-22 00:11:23 +0000 UTC
0c1ea28d-dfaa-404a-b9c4-fcdc3f5d8b02 Symmetric Key Deactivated 2024-03-14 21:05:48 +0000 UTC 2024-03-14 21:05:48 +0000 UTC
10b49b05-0101-4234-927b-20a3356da291 Symmetric Key Pre-Active 2024-03-14 21:26:54 +0000 UTC 2024-03-14 21:26:54 +0000 UTC
12365a82-5404-4bd9-a4c7-2b628ee18304 Symmetric Key Active 2024-03-14 21:01:45 +0000 UTC 2024-03-14 21:01:45 +0000 UTC
範例 2
使用 -f
旗標來過濾特定狀態的物件。 請使用逗點來指定多個狀態。
$ ibmcloud kp kmip objects -a testadapter -f 5,6
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Listing KMIP Objects...
OK
Object ID Object Type Object State Created At Updated At
03d38805-2bb2-4aa0-bbf3-dc4a6d5d0475 Symmetric Key Destroyed 2024-03-14 20:47:58 +0000 UTC 2024-03-14 20:47:58 +0000 UTC
08c94f34-0100-4331-b759-5937ed5b1228 Symmetric Key Destroyed 2024-03-14 20:46:38 +0000 UTC 2024-03-14 20:46:38 +0000 UTC
1a13e112-41f8-4d52-be08-a0946b8c22fa Symmetric Key Destroyed Compromised 2024-03-14 20:58:20 +0000 UTC 2024-03-14 20:58:20 +0000 UTC
kp kmip object-delete
刪除 KMIP 物件。 只能順利刪除其狀態不是「作用中」或「已毀損」的物件。
$ ibmcloud kp kmip object-delete OBJECT_ID
-a, --adapter ADAPTER_NAME_OR_ID
-i, --instance-id INSTANCE_ID
[-f, --force]
[-y, --skip-confirm]
範例
這些是 kp kmip object-delete
的範例
範例 1
$ ibmcloud kp kmip object-delete 9b2f5af5-3534-4f02-8836-f89af37c4351 -a testadapter
Targeting endpoint: https://qa.us-south.kms.test.cloud.ibm.com
Deleting KMIP Object...
OK
後續步驟
在 API 文件 中尋找相關作業。