为 CloudHSM CLI 设置 MFA
按照以下步骤设置适用于 CloudHSM CLI 的多重身份验证(MFA)。
要使用令牌签名策略设置 MFA,您必须首先生成 2048 位的 RSA 私有密钥以及关联的公有密钥。
$
openssl genrsa -out officer1.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes) ...........................................................+++++ ....................................................................+++++ e is 65537 (0x010001)$
openssl rsa -in officer1.key -outform PEM -pubout -out officer1.pub
writing RSA key-
使用 CloudHSM CLI 登录您的用户账户。
$
cloudhsm-cli interactive
aws-cloudhsm >
login --username
Enter password: { "error_code": 0, "data": { "username": "admin", "role": "admin" } }admin
--roleadmin
--cluster-id<cluster ID>
-
接下来,执行命令以更改您的 MFA 策略。您必须提供参数
--token
。此参数指定将写入未签名令牌的文件。aws-cloudhsm >
user change-mfa token-sign --token unsigned-tokens.json --username
Enter password: Confirm password:<USERNAME>
--role crypto-user --change-quorum -
现在,您有一个包含未签名令牌的待签名文件:
unsigned-tokens.json
。此文件中的令牌数取决于集群中的 HSM 数。每个令牌均代表一个 HSM。此文件采用 JSON 格式,包含能证明您拥有私有密钥的待签名令牌。$
cat unsigned-tokens.json
{ "version": "2.0", "tokens": [ { { "unsigned": "Vtf/9QOFY45v/E1osvpEMr59JsnP/hLDm4ItOO2vqL8=", "signed": "" }, { "unsigned": "wVbC0/5IKwjyZK2NBpdFLyI7BiayZ24YcdUdlcxLwZ4=", "signed": "" }, { "unsigned": "z6aW9RzErJBL5KqFG5h8lhTVt9oLbxppjod0Ebysydw=", "signed": "" } ] } -
下一步是使用步骤 1 中创建的私有密钥签署此类令牌。将签名放回文件。首先,您必须提取和解码 base64 编码的令牌。
$
echo "Vtf/9QOFY45v/E1osvpEMr59JsnP/hLDm4ItOO2vqL8=" > token1.b64
$
echo "wVbC0/5IKwjyZK2NBpdFLyI7BiayZ24YcdUdlcxLwZ4=" > token2.b64
$
echo "z6aW9RzErJBL5KqFG5h8lhTVt9oLbxppjod0Ebysydw=" > token3.b64
$
base64 -d token1.b64 > token1.bin
$
base64 -d token2.b64 > token2.bin
$
base64 -d token3.b64 > token3.bin
现在,您有了二进制令牌,可以使用步骤 1 中创建的 RSA 私有密钥对其进行签名。
$
openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token1.bin \ -out token1.sig.bin
$
openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token2.bin \ -out token2.sig.bin
$
openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token3.bin \ -out token3.sig.bin
现在,您有了令牌的二进制签名。您必须使用 base64 对其编码,然后把其放回令牌文件中。
$
base64 -w0 token1.sig.bin > token1.sig.b64
$
base64 -w0 token2.sig.bin > token2.sig.b64
$
base64 -w0 token3.sig.bin > token3.sig.b64
-
最后,您可以将 base64 值复制并粘贴回令牌文件中:
{ "version": "2.0", "tokens": [ { "unsigned": "1jqwxb9bJOUUQLiNb7mxXS1uBJsEXh0B9nj05BqnPsE=", "signed": "eiw3fZeCKIY50C4zPeg9Rt90M1Qlq3WlJh6Yw7xXm4nF6e9ETLE39+9M+rUqDWMRZjaBfaMbg5d9yDkz5p13U7ch2tlF9LoYabsWutkT014KRq/rcYMvFsU9n/Ey/TK0PVaxLN42X+pebV4juwMhN4mK4CzdFAJgM+UGBOj4yB9recpOBB9K8QFSpJZALSEdDgUc/mS1eDq3rU0int6+4NKuLQjpR+LSEIWRZ6g6+MND2vXGskxHjadCQ09L7Tz8VcWjKDbxJcBiGKvkqyozl9zrGo8fA3WHBmwiAgS61Merx77ZGY4PFR37+j/YMSC14prCN15DtMRv2xA1SGSb4w==" }, { "unsigned": "LMMFc34ASPnvNPFzBbMbr9FProS/Zu2P8zF/xzk5hVQ=", "signed": "HBImKnHmw+6R2TpFEpfiAg4+hu2pFNwn43ClhKPkn2higbEhUD0JVi+4MerSyvU/NN79iWVxDvJ9Ito+jpiRQjTfTGEoIteyuAr1v/Bzh+HjmrO53OQpZaJ/VXGIgApD0myuu/ZGNKQTCSkkL7+V81FG7yR1Nm22jUeGa735zvm/E+cenvZdy0VVx6A7WeWrl3JEKKBweHbi+7BwbaW+PTdCuIRd4Ug76Sy+cFhsvcG1k7cMwDh8MgXzIZ2m1f/hdy2j8qAxORTLlmwyUOYvPYOvUhc+s83hx36QpGwGcD7RA0bPT5OrTx7PHd0N1CL+Wwy91We8yIOFBS6nxo1R7w==" }, { "unsigned": "dzeHbwhiVXQqcUGj563z51/7sLUdxjL93SbOUyZRjH8=", "signed": "VgQPvrTsvGljVBFxHnswduq16x8ZrnxfcYVYGf/N7gEzI4At3GDs2EVZWTRdvS0uGHdkFYp1apHgJZ7PDVmGcTkIXVD2lFYppcgNlSzkYlftr5EOjqS9ZjYEqgGuB4g//MxaBaRbJai/6BlcE92NIdBusTtreIm3yTpjIXNAVoeRSnkfuw7wZcL96QoklNb1WUuSHw+psUyeIVtIwFMHEfFoRC0t+VhmnlnFnkjGPb9W3Aprw2dRRvFM3R2ZTDvMCiOYDzUCd43GftGq2LfxH3qSD51oFHglHQVOY0jyVzzlAvub5HQdtOQdErIeO0/9dGx5yot07o3xaGl5yQRhwA==" } ] }
现在,您的令牌文件已包含所有必需签名,您可以继续操作。输入包含签名令牌的文件名称,然后按 Enter 键。最后,输入公有密钥的路径。
Enter signed token file path (press enter if same as the unsigned token file): Enter public key PEM file path:officer1.pub { "error_code": 0, "data": { "username": "<USERNAME>", "role": "crypto-user" } }
现在,您已经对用户设置了 MFA。
{ "username": "<USERNAME>", "role": "crypto-user", "locked": "false", "mfa": [ { "strategy": "token-sign", "status": "enabled" } ], "cluster-coverage": "full" },