1.5. 使用 WildFly Elytron 工具进行凭证存储操作


您可以使用 WildFly Elytron 工具对凭证存储执行各种操作。

在 Elytron 中,您可以在保存所有凭证类型的地方离线创建一个 credential-store

流程

  • 使用以下命令,使用 WildFly Elytron 工具创建一个 credential-store

    语法

    $ EAP_HOME/bin/elytron-tool.sh credential-store --create --location "<path_to_store_file>" --password <store_password>
    Copy to Clipboard Toggle word wrap

    示例

    $ EAP_HOME/bin/elytron-tool.sh credential-store --create --location "../cred_stores/example-credential-store.jceks" --password storePassword
    Credential Store has been successfully created
    Copy to Clipboard Toggle word wrap

    如果您不想将存储密码包含在命令中,请省略该参数,然后在提示符下手动输入密码。您还可以使用由 WildFly Elytron 工具生成的已屏蔽密码。有关生成屏蔽密码的详情,请参考 使用 WildFly Elytron 工具生成屏蔽的加密字符串

使用 Bouncy Castle 提供程序创建一个 credential-store

先决条件

  • 确保您的环境已配置为使用 Bouncy Castle。
注意

credential-storesecret-key-credential-store 不能同名,因为它们实现相同的 Elytron 功能:org.wildfly.security.credential-store

流程

  1. 定义 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>
    Copy to Clipboard Toggle word wrap
    重要

    确保密钥存储 keypassstorepass 属性相同。如果不是这样,elytron 子系统中的 BCFKS keystore 将无法定义它们。

  2. 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>
    Copy to Clipboard Toggle word wrap
  3. 使用以下命令,使用 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>"
    Copy to Clipboard Toggle word wrap

在 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
    Copy to Clipboard Toggle word wrap

    示例

    $ bin/elytron-tool.sh credential-store --create --location=standalone/configuration/properties-credential-store.cs --type PropertiesCredentialStore
    Credential Store has been successfully created
    Copy to Clipboard Toggle word wrap

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>
Copy to Clipboard Toggle word wrap

示例

$ 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
Copy to Clipboard Toggle word wrap

如果您不想将 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>
Copy to Clipboard Toggle word wrap

示例

$ 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
Copy to Clipboard Toggle word wrap

如果您不想将 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>
Copy to Clipboard Toggle word wrap

示例

$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=../cred_stores/example-credential-store.jceks --password=storePassword
Copy to Clipboard Toggle word wrap

输入您要导入的 secret 密钥。

列出所有的凭证

您可以使用以下 WildFly Elytron 工具命令列出 credential-store 中的凭证:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --aliases
Copy to Clipboard Toggle word wrap

例如:

$ 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
Copy to Clipboard Toggle word wrap

检查是否存在别名

使用以下命令检查凭证存储中是否存在别名:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --exists <alias>
Copy to Clipboard Toggle word wrap

示例

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "../cred_stores/example-credential-store.jceks" --password storePassword --exists examplepasswordcredential
Alias "examplepasswordcredential" exists
Copy to Clipboard Toggle word wrap

导出 SecretKeyCredential

您可以使用以下命令从 credential-store 中导出一个 SecretKeyCredential:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --export-secret-key=<alias> --location=<path_to_credential_store> --password=storePassword
Copy to Clipboard Toggle word wrap

示例

$ 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 Toggle word wrap

删除一个凭证

您可以使用以下命令从凭证存储中删除一个凭证:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --password <store_password> --remove <alias>
Copy to Clipboard Toggle word wrap

示例

$ 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
Copy to Clipboard Toggle word wrap

您可以使用 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
Copy to Clipboard Toggle word wrap

示例

$ 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
Copy to Clipboard Toggle word wrap

导入 SecretKeyCredential

您可以使用以下 WildFLy Elytron 工具命令导入 SecretKeyCredential:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location=<path_to_credential_store> --type PropertiesCredentialStore
Copy to Clipboard Toggle word wrap

示例

$ EAP_HOME/bin/elytron-tool.sh credential-store --import-secret-key=imported --location "standalone/configuration/properties-credential-store.cs" --type PropertiesCredentialStore
Copy to Clipboard Toggle word wrap

列出所有的凭证

您可以使用以下 WildFly Elytron 工具列出 secret-key-credential-store 中的凭证:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>"  --aliases --type PropertiesCredentialStore
Copy to Clipboard Toggle word wrap

示例

$ EAP_HOME/bin/elytron-tool.sh credential-store  --location "standalone/configuration/properties-credential-store.cs" --aliases --type PropertiesCredentialStore
Credential store contains following aliases: example
Copy to Clipboard Toggle word wrap

导出 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
Copy to Clipboard Toggle word wrap

示例

$ 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 Toggle word wrap

删除一个凭证

您可以使用以下命令从凭证存储中删除一个凭证:

语法

$ EAP_HOME/bin/elytron-tool.sh credential-store --location "<path_to_store_file>" --remove <alias> --type PropertiesCredentialStore
Copy to Clipboard Toggle word wrap

示例

$ 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
Copy to Clipboard Toggle word wrap

在使用 WildFly Elytron 工具创建了 credential-store 后,您可以将其添加到正在运行的 JBoss EAP 服务器中。

先决条件

流程

  • 使用以下管理 CLI 命令,将凭证存储添加到正在运行的 JBoss EAP 服务器中:

    语法

    /subsystem=elytron/credential-store=<store_name>:add(location="<path_to_store_file>",credential-reference={clear-text=<store_password>})
    Copy to Clipboard Toggle word wrap

    Example

    /subsystem=elytron/credential-store=my_store:add(location="../cred_stores/example-credential-store.jceks",credential-reference={clear-text=storePassword})
    Copy to Clipboard Toggle word wrap

将凭证存储添加到 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
Copy to Clipboard Toggle word wrap
导入一个密钥对

使用 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>
Copy to Clipboard Toggle word wrap
导出一个密钥对

使用 export-key-pair-public-key 命令显示密钥对的公钥。公钥具有 OpenSSH 格式的指定别名。以下示例显示了别名 example 的公钥:

$ EAP_HOME/bin/elytron-tool.sh credential-store --location=<path_to_store_file> --export-key-pair-public-key example

Credential store password:
Confirm credential store password:
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMfncZuHmR7uglb0M96ieArRFtp42xPn9+ugukbY8dyjOXoi
cZrYRyy9+X68fylEWBMzyg+nhjWkxJlJ2M2LAGY=
Copy to Clipboard Toggle word wrap
注意

在发出 export-key-pair-public-key 命令后,会提示您输入凭证存储密码短语。如果不存在密码短语,请将提示留空。

密钥对由两个独立的,但匹配的加密密钥组成:公钥和私钥。在 elytron 配置文件中引用密钥对之前,您需要将密钥对存储在凭证存储中。然后,您可以提供对 Git 的访问权限,来管理您的独立服务器配置数据。

以下示例引用了 elytron 配置文件的 <credential-stores> 元素中的凭证存储及其属性。<credential> 元素引用凭证存储和别名,用于存储密钥对。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <authentication-client xmlns="urn:elytron:client:1.6">

     <credential-stores>
        <credential-store name="${credential_store_name}">
           <protection-parameter-credentials>
              <clear-password password="${credential_store_password}"/>
           </protection-parameter-credentials>
           <attributes>
              <attribute name="path" value="${path_to_credential_store}"/>
           </attributes>
        </credential-store>
     </credential-stores>

     <authentication-rules>
        <rule use-configuration="${configuration_file_name}"/>
     </authentication-rules>

     <authentication-configurations>
        <configuration name="${configuration_file_name}">
           <credentials>
              <credential-store-reference store="${credential_store_name}" alias="${alias_of_key_pair}"/>
           </credentials>
        </configuration>
     </authentication-configurations>

  </authentication-client>
</configuration>
Copy to Clipboard Toggle word wrap

配置 elytron 配置文件后,密钥对可用于 SSH 身份验证。

您可以使用 WildFly Elytron 工具来生成用于凭证存储的加密的字符串,而不是使用明文密码。

流程

  • 要生成屏蔽的字符串,请使用以下命令,并为 salt 和iteration 数提供值:

    $ EAP_HOME/bin/elytron-tool.sh mask --salt <salt> --iteration <iteration_count> --secret <password>
    Copy to Clipboard Toggle word wrap

    例如:

    $ EAP_HOME/bin/elytron-tool.sh mask --salt 12345678 --iteration 123 --secret supersecretstorepassword
    
    MASK-8VzWsSNwBaR676g8ujiIDdFKwSjOBHCHgnKf17nun3v;12345678;123
    Copy to Clipboard Toggle word wrap

    如果您不想在命令中提供 secret,可以省略该参数,系统将提示您使用标准输入输入 secret。

如需更多信息,请使用 EAP_HOME/bin/elytron-tool.sh mask --help 命令来获取可用选项的详细列表。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat