1.5. 使用 WildFly Elytron 工具进行凭证存储操作
您可以使用 WildFly Elytron 工具对凭证存储执行各种操作。
1.5.1. 使用 WildFly Elytron 工具创建一个 credential-store 复制链接链接已复制到粘贴板!
在 Elytron 中,您可以在保存所有凭证类型的地方离线创建一个 credential-store 。
流程
使用以下命令,使用 WildFly Elytron 工具创建一个
credential-store:语法
EAP_HOME/bin/elytron-tool.sh credential-store --create --location "<path_to_store_file>" --password <store_password>
$ EAP_HOME/bin/elytron-tool.sh credential-store --create --location "<path_to_store_file>" --password <store_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --create --location "../cred_stores/example-credential-store.jceks" --password storePassword Credential Store has been successfully created
$ EAP_HOME/bin/elytron-tool.sh credential-store --create --location "../cred_stores/example-credential-store.jceks" --password storePassword Credential Store has been successfully createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您不想将存储密码包含在命令中,请省略该参数,然后在提示符下手动输入密码。您还可以使用由 WildFly Elytron 工具生成的已屏蔽密码。有关生成屏蔽密码的详情,请参考 使用 WildFly Elytron 工具生成屏蔽的加密字符串。
1.5.2. 使用 Bouncy Castle 提供程序创建一个 credential-store 复制链接链接已复制到粘贴板!
使用 Bouncy Castle 提供程序创建一个 credential-store。
先决条件
- 确保您的环境已配置为使用 Bouncy Castle。
credential-store 和 secret-key-credential-store 不能同名,因为它们实现相同的 Elytron 功能:org.wildfly.security.credential-store。
流程
定义 Bouncy Castle FIPS 密钥存储(
BCFKS)密钥存储。FIPS 代表联邦信息处理标准。如果您已有一个,请转到下一步。keytool -genkeypair -alias <key_pair_alias> -keyalg <key_algorithm> -keysize <key_size> -storepass <key_pair_and_keystore_password> -keystore <path_to_keystore> -storetype BCFKS -keypass <key_pair_and_keystore_password>
$ keytool -genkeypair -alias <key_pair_alias> -keyalg <key_algorithm> -keysize <key_size> -storepass <key_pair_and_keystore_password> -keystore <path_to_keystore> -storetype BCFKS -keypass <key_pair_and_keystore_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要确保密钥存储
keypass和storepass属性相同。如果不是这样,elytron子系统中的BCFKSkeystore 将无法定义它们。为
credential-store生成一个 secret 密钥。keytool -genseckey -alias <key_alias> -keyalg <key_algorithm> -keysize <key_size> -keystore <path_to_keystore> -storetype BCFKS -storepass <key_and_keystore_password> -keypass <key_and_keystore_password>
$ keytool -genseckey -alias <key_alias> -keyalg <key_algorithm> -keysize <key_size> -keystore <path_to_keystore> -storetype BCFKS -storepass <key_and_keystore_password> -keypass <key_and_keystore_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用以下命令,使用 WildFly Elytron 工具定义
credential-store:EAP_HOME/bin/elytron-tool.sh credential-store -c -a <alias> -x <alias_password> -p <key_and_keystore_password> -l <path_to_keystore> -u "keyStoreType=BCFKS;external=true;keyAlias=<key_alias>;externalPath=<path_to_credential_store>"
$ EAP_HOME/bin/elytron-tool.sh credential-store -c -a <alias> -x <alias_password> -p <key_and_keystore_password> -l <path_to_keystore> -u "keyStoreType=BCFKS;external=true;keyAlias=<key_alias>;externalPath=<path_to_credential_store>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
在 Elytron 中,您可以在保存 SecretKeyCredential 实例的地方离线创建一个 secret-key-credential-store 。
流程
使用以下命令,使用 WildFly Elytron 工具创建 PropertiesCredentialStore:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --create --location "<path_to_store_file>" --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --create --location "<path_to_store_file>" --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
bin/elytron-tool.sh credential-store --create --location=standalone/configuration/properties-credential-store.cs --type PropertiesCredentialStore Credential Store has been successfully created
$ bin/elytron-tool.sh credential-store --create --location=standalone/configuration/properties-credential-store.cs --type PropertiesCredentialStore Credential Store has been successfully createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.5.4. WildFly Elytron 工具 credential-store 操作 复制链接链接已复制到粘贴板!
您可以使用 WildFly Elytron 工具执行各种 credential-store 任务,其中包括:
- 添加一个 PasswordCredential
您可以使用以下 WildFly Elytron 工具命令向
credential-store添一个 PasswordCredential :语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --add <alias> --secret <sensitive_string>
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --add <alias> --secret <sensitive_string>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --add examplePasswordCredential --secret speci@l_db_pa$$_01 Alias "examplePasswordCredential" has been successfully stored
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --add examplePasswordCredential --secret speci@l_db_pa$$_01 Alias "examplePasswordCredential" has been successfully storedCopy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您不想将 secret 放在命令中,请省略该参数,然后在提示时手动输入 secret。
- 生成一个 SecretKeyCredential
您可以使用以下 WildFly Elytron 工具命令向
credential-store添加一个 SecretKeyCredential :语法
EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location=<path_to_the_credential_store> --password <store_password>
$ EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location=<path_to_the_credential_store> --password <store_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "../cred_stores/example-credential-store.jceks" --password storePassword Alias "example" has been successfully stored
$ EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "../cred_stores/example-credential-store.jceks" --password storePassword Alias "example" has been successfully storedCopy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您不想将 secret 放在命令中,请省略该参数,然后在提示时手动输入 secret。
默认情况下,当您在 JBoss EAP 中创建 SecretKeyCredential 时,您可以创建一个 256 位 secret 密钥。如果要更改大小,您可以指定
--size=128或--size=192来分别创建 128 位或 192 位密钥。- 导入 SecretKeyCredential
您可以使用以下 WildFLy Elytron 工具命令导入 SecretKeyCredential:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=<path_to_credential_store> --password=<store_password>
$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=<path_to_credential_store> --password=<store_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=../cred_stores/example-credential-store.jceks --password=storePassword
$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=../cred_stores/example-credential-store.jceks --password=storePasswordCopy to Clipboard Copied! Toggle word wrap Toggle overflow 输入您要导入的 secret 密钥。
- 列出所有的凭证
您可以使用以下 WildFly Elytron 工具命令列出
credential-store中的凭证:语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --aliases
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --aliasesCopy to Clipboard Copied! Toggle word wrap Toggle overflow 例如:
EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --aliases Credential store contains following aliases: examplepasswordcredential example
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --aliases Credential store contains following aliases: examplepasswordcredential exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 检查是否存在别名
使用以下命令检查凭证存储中是否存在别名:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --exists <alias>
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --exists <alias>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --exists examplepasswordcredential Alias "examplepasswordcredential" exists
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --exists examplepasswordcredential Alias "examplepasswordcredential" existsCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 导出 SecretKeyCredential
您可以使用以下命令从
credential-store中导出一个 SecretKeyCredential:语法
EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=<alias> --location=<path_to_credential_store> --password=storePassword
$ EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=<alias> --location=<path_to_credential_store> --password=storePasswordCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=example --location=../cred_stores/example-credential-store.jceks --password=storePassword Exported SecretKey for alias example=RUxZAUtBiAnoLP1CA+i6DtcbkZHfybBJxPeS9mlVOmEYwjjmEA==
$ EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=example --location=../cred_stores/example-credential-store.jceks --password=storePassword Exported SecretKey for alias example=RUxZAUtBiAnoLP1CA+i6DtcbkZHfybBJxPeS9mlVOmEYwjjmEA==Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 删除一个凭证
您可以使用以下命令从凭证存储中删除一个凭证:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --remove <alias>
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --remove <alias>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --remove examplepasswordcredential Alias "examplepasswordcredential" has been successfully removed
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --remove examplepasswordcredential Alias "examplepasswordcredential" has been successfully removedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.5.5. WildFly Elytron 工具 secret-key-credential-store 操作 复制链接链接已复制到粘贴板!
您可以使用 WildFly Elytron 工具为 SecretKeyCredential 执行以下 secret-key-credential-store 操作:
- 生成一个 SecretKeyCredential
您可以使用以下 WildFly Elytron 工具命令在
secret-key-credential-store中生成一个SecteKeyCredential:语法
EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "<path_to_the_credential_store>" --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "<path_to_the_credential_store>" --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore Alias "example" has been successfully stored
$ EAP_HOME/bin/elytron-tool.sh credential-store --generate-secret-key=example --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore Alias "example" has been successfully storedCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 导入 SecretKeyCredential
您可以使用以下 WildFLy Elytron 工具命令导入 SecretKeyCredential:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=<path_to_credential_store> --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=<path_to_credential_store> --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 列出所有的凭证
您可以使用以下 WildFly Elytron 工具列出
secret-key-credential-store中的凭证:语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --aliases --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --aliases --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --location "standalone/configuration/properties-credential-store.cs" --aliases --type PropertiesCredentialStore Credential store contains following aliases: example
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "standalone/configuration/properties-credential-store.cs" --aliases --type PropertiesCredentialStore Credential store contains following aliases: exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 导出 SecretKeyCredential
您可以使用以下命令从
secret-key-credential-store中导出一个 SecretKeyCredential:语法
EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=<alias> --location "<path_to_credential_store>" --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=<alias> --location "<path_to_credential_store>" --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=example --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore Exported SecretKey for alias example=RUxZAUt1EZM7PsYRgMGypkGirSel+5Eix4aSgwop6jfxGYUQaQ==
$ EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=example --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore Exported SecretKey for alias example=RUxZAUt1EZM7PsYRgMGypkGirSel+5Eix4aSgwop6jfxGYUQaQ==Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 删除一个凭证
您可以使用以下命令从凭证存储中删除一个凭证:
语法
EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --remove <alias> --type PropertiesCredentialStore
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --remove <alias> --type PropertiesCredentialStoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow 示例
EAP_HOME/bin/elytron-tool.sh credential-store --location "standalone/configuration/properties-credential-store.cs" --remove example --type PropertiesCredentialStore Alias "example" has been successfully removed
$ EAP_HOME/bin/elytron-tool.sh credential-store --location "standalone/configuration/properties-credential-store.cs" --remove example --type PropertiesCredentialStore Alias "example" has been successfully removedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
在使用 WildFly Elytron 工具创建了 credential-store 后,您可以将其添加到正在运行的 JBoss EAP 服务器中。
先决条件
您已使用 WildFly Elytron 工具创建了凭据存储。
如需更多信息,请参阅 使用 WildFly Elytron 工具创建一个
credential-store。
流程
使用以下管理 CLI 命令,将凭证存储添加到正在运行的 JBoss EAP 服务器中:
语法
/subsystem=elytron/credential-store=<store_name>:add(location="<path_to_store_file>",credential-reference={clear-text=<store_password>})/subsystem=elytron/credential-store=<store_name>:add(location="<path_to_store_file>",credential-reference={clear-text=<store_password>})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/credential-store=my_store:add(location="../cred_stores/example-credential-store.jceks",credential-reference={clear-text=storePassword})/subsystem=elytron/credential-store=my_store:add(location="../cred_stores/example-credential-store.jceks",credential-reference={clear-text=storePassword})Copy to Clipboard Copied! Toggle word wrap Toggle overflow
将凭证存储添加到 JBoss EAP 配置后,您可以使用 credential-reference 属性引用存储在凭证存储中的密码或敏感的字符串。
如需更多信息,请使用 EAP_HOME/bin/elytron-tool.sh credential-store --help 命令获得可用选项的详细列表。
1.5.7. WildFly Elytron 工具密钥对管理操作 复制链接链接已复制到粘贴板!
您可以使用以下参数操作 elytron-tool.sh ,来处理凭据存储,例如生成一个可在凭证存储中的一个别名下存储的新密钥对。
- 生成一个密钥对
使用
generate-key-pair命令创建一个密钥对。然后您可以将密钥对存储在凭证存储的一个别名下。以下示例显示了如何创建一个 RSA 密钥对,给其分配的大小为 3072 位,存储在为凭证存储指定的位置上。提供给密钥对的别名是example。EAP_HOME/bin/elytron-tool.sh credential-store --location=<path_to_store_file> --generate-key-pair example --algorithm RSA --size 3072
$ EAP_HOME/bin/elytron-tool.sh credential-store --location=<path_to_store_file> --generate-key-pair example --algorithm RSA --size 3072Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 导入一个密钥对
使用
import-key-pair命令将现有的 SSH 密钥对导入到具有指定别名的凭证存储中。以下示例导入一个密钥对,其别名 example 来自 /home/user/.ssh/id_rsa 文件,该文件包含采用 OpenSSH 格式的私钥:EAP_HOME/bin/elytron-tool.sh credential-store --import-key-pair example --private-key-location /home/user/.ssh/id_rsa --location=<path_to_store_file>
$ EAP_HOME/bin/elytron-tool.sh credential-store --import-key-pair example --private-key-location /home/user/.ssh/id_rsa --location=<path_to_store_file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 导出一个密钥对
使用
export-key-pair-public-key命令显示密钥对的公钥。公钥具有 OpenSSH 格式的指定别名。以下示例显示了别名 example 的公钥:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意在发出
export-key-pair-public-key命令后,会提示您输入凭证存储密码短语。如果不存在密码短语,请将提示留空。
1.5.8. 在 Elytron 配置文件中使用存储的密钥对示例 复制链接链接已复制到粘贴板!
密钥对由两个独立的,但匹配的加密密钥组成:公钥和私钥。在 elytron 配置文件中引用密钥对之前,您需要将密钥对存储在凭证存储中。然后,您可以提供对 Git 的访问权限,来管理您的独立服务器配置数据。
以下示例引用了 elytron 配置文件的 <credential-stores> 元素中的凭证存储及其属性。<credential> 元素引用凭证存储和别名,用于存储密钥对。
配置 elytron 配置文件后,密钥对可用于 SSH 身份验证。
1.5.9. 使用 WildFly Elytron 工具生成屏蔽的加密字符串 复制链接链接已复制到粘贴板!
您可以使用 WildFly Elytron 工具来生成用于凭证存储的加密的字符串,而不是使用明文密码。
流程
要生成屏蔽的字符串,请使用以下命令,并为 salt 和iteration 数提供值:
EAP_HOME/bin/elytron-tool.sh mask --salt <salt> --iteration <iteration_count> --secret <password>
$ EAP_HOME/bin/elytron-tool.sh mask --salt <salt> --iteration <iteration_count> --secret <password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 例如:
EAP_HOME/bin/elytron-tool.sh mask --salt 12345678 --iteration 123 --secret supersecretstorepassword MASK-8VzWsSNwBaR676g8ujiIDdFKwSjOBHCHgnKf17nun3v;12345678;123
$ EAP_HOME/bin/elytron-tool.sh mask --salt 12345678 --iteration 123 --secret supersecretstorepassword MASK-8VzWsSNwBaR676g8ujiIDdFKwSjOBHCHgnKf17nun3v;12345678;123Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您不想在命令中提供 secret,可以省略该参数,系统将提示您使用标准输入输入 secret。
如需更多信息,请使用 EAP_HOME/bin/elytron-tool.sh mask --help 命令来获取可用选项的详细列表。