aws kms create-key --origin=EXTERNAL
Lệnh aws create-key đi kèm option –origin=EXTERNAL, chỉ ra rằng CMK sắp được tạo có Key Material không thuộc AWS KMS.
aws kms get-parameters-for-import --key-id <key ID of your External CMK> --wrapping-algorithm RSAES_OAEP_SHA_1 --wrapping-key-spec RSA_2048
vi pkey.b64
.
:wq
.Nhấn Enter để lưu file và thoát ra.
ls -lrt
để kiểm tra. Chúng ta sẽ thấy 2 file pkey.b64 và token.b64.
openssl enc -d -base64 -A -in pkey.b64 -out pkey.bin
.openssl enc -d -base64 -A -in token.b64 -out token.bin
.ls -lrt
để kiểm tra. Chúng ta sẽ thấy có thêm 2 file pkey.bin và token.bin
Thực tế, Key Material phải được tạo ra từ một hệ thống Quản lý Khóa chuyên biệt hoặc hệ thống HSM cho Doanh nghiệp. Tuy nhiên trong phạm vi bài lab, để nhanh chóng và đơn giản ta sẽ thực hiện tạo Key material bằng OpenSSL chạy trên chính Instance của chúng ta.
openssl rand -out genkey.bin 32
2. Thực hiện encrypt Key material. Key material sau khi encrypt sẽ được lưu vào file WrappedKeyMaterial.bin.
openssl rsautl -encrypt -in genkey.bin -oaep -inkey pkey.bin -keyform DER -pubin -out WrappedKeyMaterial.bin
.ls -lrt
để kiểm tra. Chúng ta sẽ thấy có thêm file WrappedKeyMaterial.bin.
aws kms import-key-material --key-id <key ID of your External CMK> --encrypted-key-material fileb://WrappedKeyMaterial.bin --import-token fileb://token.bin --expiration-model KEY_MATERIAL_EXPIRES --valid-to 2022-06-02T12:00:00-08:00
Để import ta dùng lệnh import-key-material
, yêu cầu phải có import token mà đã được tạo ở trên (token.b64) với tham số fileb://, thể hiện file được chọn phải ở dạng binary.
Ngoài ra expiration date cũng được nhắc tới trong câu lệnh, thể hiện tham số –expiration-model. Ta hoàn toàn có thể cấu hình để Key Material không bị expired bằng cách gán cho tham số này giá trị KEY_MATERIAL_DOES_NOT_EXPIRE
Chúng ta cần cấu hình ngày hết hạn cho tham số –expiration-model để có thể giám sát trong CloudWatch(phần 6)
aws kms create-alias --alias-name alias/ImportedCMK --target-key-id <key ID of your External CMK>
3. Để liệt kê toàn bộ CMK thuộc Account mà ta quản lý trên AWS CLI, chạy lệnh aws kms list-aliases
File JSON sẽ hiển thị các khóa chúng ta đã tạo và alias của nó, cùng với các CMK được tạo theo mặc định cho một số dịch vụ.