1.4. 使用 JBoss EAP 管理 CLI 的凭据存储操作


要在运行的 JBoss EAP 服务器中管理 JBoss EAP 凭据,请使用提供的管理 CLI 操作。您可以使用 JBoss EAP 管理 CLI 管理 PasswordCredentialSecretKeyCredential

注意

您只能对可修改的凭证存储进行这些操作。所有凭据存储类型默认为可修改。

1.4.1. 为独立服务器创建一个 credential-store

为在文件系统上的任意目录中作为独立服务器运行的 JBoss EAP 创建一个 credential-store。为安全起见,只有有限用户才可以访问包含存储的目录。

先决条件

  • 您对在其下运行 JBoss EAP 的用户帐户至少提供了对包含 KeyStoreCredentialStore 目录的读/写权限。
注意

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

流程

  • 使用以下管理 CLI 命令,创建一个 KeyStoreCredentialStore:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:add(path="<path_to_store_file>", relative-to=<base_path_to_store_file>, credential-reference={clear-text=<store_password>}, create=true)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:add(path="exampleKeyStoreCredentialStore.jceks", relative-to=jboss.server.data.dir, credential-reference={clear-text=password}, create=true)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

1.4.2. 为受管域创建一个 credential-store

您可以在受管域中创建一个 credential-store,但必须首先使用 WildFly Elytron 工具来准备您的 KeyStoreCredentialStore。如果在单个受管域中有多个主机控制器,请选择以下选项之一:

  • 在每个主机控制器中创建一个 credential-store,并向每一个 credential-store 添加凭证。
  • 将填充的 credential-store 从一个主机控制器拷贝到所有其他主机控制器。
  • credential-store 文件保存在网络文件系统(NFS)中,然后对您创建的所有 credential-store 资源使用该文件。

或者,您可以在主机控制器上创建一个带有凭证的 credential-store 文件,而无需使用 WildFly Elytron 工具。

注意

您不必在每台服务器上定义一个 credential-store 资源,因为同一配置文件上的每个服务器都包含您的 credential-store 文件。您可以在服务器的 data 目录 relative-to=jboss.server.data.dir 中找到 credential-store 文件 。

重要

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

以下流程描述了如何使用 NFS 来向所有主机控制器提供 credential-store 文件。

流程

  1. 使用 WildFly Elytron 工具来创建一个 credential-store 存储文件。有关此内容的更多信息,请参阅 WildFly Elytron 工具 credential-store 操作
  2. 分发存储文件。例如,使用 scp 命令将它分配给每个主机控制器,或者将其存储在 NFS 中,将其用于所有 credential-store 资源。

    注意

    为保持一致性,对于多个资源和主机控制器使用的且存储在 NFS 中的 credential-store 文件,您必须在只读模式下使用 credential-store 。另外,请确保您为 credential-store 文件提供了一个绝对路径。

    语法

    /profile=<profile_name>/subsystem=elytron/credential-store=<name_of_credential_store>:add(path=<absolute_path_to_store_keystore>,credential-reference={clear-text="<store_password>"},create=false,modifiable=false)
    Copy to Clipboard Toggle word wrap

    示例

    /profile=full-ha/subsystem=elytron/credential-store=exampleCredentialStoreDomain:add(path=/usr/local/etc/example-cred-store.cs,credential-reference={clear-text="password"},create=false,modifiable=false)
    Copy to Clipboard Toggle word wrap

  3. 可选: 如果您需要在配置集中定义 credential-store 资源,请使用存储文件来创建资源。

    语法

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

    Example

    /profile=full-ha/subsystem=elytron/credential-store=exampleCredentialStoreHA:add(path=/usr/local/etc/example-cred-store-ha.cs, credential-reference={clear-text="password"})
    Copy to Clipboard Toggle word wrap

  4. 可选: 为主机控制器创建 credential-store 资源。

    语法

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

    Example

    /host=master/subsystem=elytron/credential-store=exampleCredentialStoreHost:add(path=/usr/local/etc/example-cred-store-host.cs, credential-reference={clear-text="password"})
    Copy to Clipboard Toggle word wrap

使用管理 CLI 创建一个 secret-key-credential-store。当您创建 secret-key-credential-store 时,JBoss EAP 默认会生成一个 secret 密钥。生成的密钥的名称是 key,其大小为 256 位。

先决条件

  • JBoss EAP 正在运行。
  • 您为在其下运行 JBoss EAP 的用户帐户至少提供了对包含 secret-key-credential-store 的目录的读/写权限。

流程

  • 使用以下命令,使用管理 CLI 来创建一个 secret-key-credential-store

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_credential_store>:add(path="<path_to_the_credential_store>", relative-to=<path_to_store_file>)
    Copy to Clipboard Toggle word wrap

    Example

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:add(path=examplePropertiesCredentialStore.cs, relative-to=jboss.server.config.dir)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

1.4.4. 向 credential-store 添加一个 PasswordCredential

为那些需要将密码作为 PasswordCredential 的资源,向 credential-store 中添加一个明文密码,以便在配置文件中隐藏该密码。然后,您可以引用该存储的凭证来访问这些资源,而不用暴露您的密码。

先决条件

流程

  • 将新的 PasswordCredential 添加到 credential-store 中:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:add-alias(alias=<alias>, secret-value=<secret-value>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:add-alias(alias=passwordCredentialAlias, secret-value=StrongPassword)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

验证

  • 发出以下命令来验证 PasswordCredential 是否已添加到 credential-store 中:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:read-aliases()
    {
        "outcome" => "success",
        "result" => ["passwordcredentialalias"]
    }
    Copy to Clipboard Toggle word wrap

credential-store 中生成一个 SecretKeyCredential。默认情况下,Elytron 创建 256 位密钥。如果需要不同的大小,您可以在 key-size 属性中指定 128 位或 192 位密钥。

先决条件

流程

  • 使用以下管理 CLI 命令,在 credential-store 中生成一个 SecretKeyCredential:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:generate-secret-key(alias=<alias>, key-size=<128_or_192>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:generate-secret-key(alias=secretKeyCredentialAlias)
    Copy to Clipboard Toggle word wrap

验证

  • 发出以下命令以验证您的 SecretKeyCredential 是否存储在 credential-store 中:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:read-aliases()
    {
        "outcome" => "success",
        "result" => [
            "secretkeycredentialalias"
        ]
    }
    Copy to Clipboard Toggle word wrap

secret-key-credential-store 中生成一个 SecretKeyCredential。默认情况下,Elytron 创建 256 位密钥。如果需要不同的大小,您可以在 key-size 属性中指定 128 位或 192 位密钥。

当您生成 SecretKeyCredential 时,Elytron 生成一个新的随机 secret 密钥,并将其保存为 SecretKeyCredential。您可以对 secret-key-credential-store 使用 export 操作来查看凭证的内容。

重要

确保您创建了一个 secret-key-credential-store ,SecretKeyCredential 的备份或两者的备份,因为 JBoss EAP 无法解密或检索丢失的 Elytron 凭证。

您可以对 secret-key-credential-store 使用 export 操作来获取 SecretKeyCredential 的值。然后您可以将这个值保存为备份。

先决条件

流程

  • 使用以下管理 CLI 命令在 secret-key-credential-store 中生成一个 SecretKeyCredential:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_the_properties_credential_store>:generate-secret-key(alias=<alias>, key-size=<128_or_192>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:generate-secret-key(alias=secretKeyCredentialAlias)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

验证

  • 发出以下命令以验证 Elytron 创建了 SecretKeyCredential:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_the_properties_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:read-aliases()
    {
        "outcome" => "success",
        "result" => [
            "secretkeycredentialalias",
            "key"
        ]
    }
    Copy to Clipboard Toggle word wrap

您可以将在 secret-key-credential-store 外创建的 SecretKeyCredential 导入到 Elytron secret-key-credential-store 中。假设您从另一个凭证存储中导出了一个 SecretKeyCredential,例如,您可以将 credential-store 导入到 secret-key-credential-store 中。

先决条件

流程

  1. 使用以下命令在管理 CLI 中禁用命令缓存:

    重要

    如果不禁用缓存,则可以访问管理 CLI 历史记录文件的任何人都可以看到 secret 密钥。

    history --disable
    Copy to Clipboard Toggle word wrap
  2. 使用以下管理 CLI 命令导入 secret 密钥:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_credential_store>:import-secret-key(alias=<alias>, key="<secret_key>")
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:import-secret-key(alias=imported, key="RUxZAUs+Y1CzEPw0g2AHHOZ+oTKhT9osSabWQtoxR+O+42o11g==")
    Copy to Clipboard Toggle word wrap

  3. 使用以下管理 CLI 命令重新启用命令缓存:

    history --enable
    Copy to Clipboard Toggle word wrap

1.4.8. 列出credential-store 中的凭证

要查看 credential-store 中存储的所有凭证,您可以使用管理 CLI 列出它们。

流程

  • 使用以下管理 CLI 命令列出存储在 credential-store 中的凭证:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    {
        "outcome" => "success",
        "result" => [
            "passwordcredentialalias",
            "secretkeycredentialalias"
        ]
    }
    Copy to Clipboard Toggle word wrap

1.4.9. 从 credential-store 中导出 SecretKeyCredential

您可以从 credential-store 中导出现一个现有的 SecretKeyCredential,以使用 SecretKeyCredential 或创建一个 SecretKeyCredential 的备份。

先决条件

流程

  • 使用以下管理 CLI 命令,从 credential-store 中导出 SecretKeyCredential:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:export-secret-key(alias=<alias>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:export-secret-key(alias=secretKeyCredentialAlias)
    {
        "outcome" => "success",
        "result" => {"key" => "RUxZAUui+8JkoDCE6mFyA3cCIbSAZaXq5wgYejj1scYgdDqWiw=="}
    }
    Copy to Clipboard Toggle word wrap

您可以从 secret-key-credential-store 中导出一个现有的 SecretKeyCredential 以使用 SecretKeyCredential,或创建一个 SecretKeyCredential 的备份。

先决条件

流程

  • 使用以下管理 CLI 命令从 secret-key-credential-store 中导出一个 SecretKeyCredential:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_credential_store>:export-secret-key(alias=<alias>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:export-secret-key(alias=secretkeycredentialalias)
    {
        "outcome" => "success",
        "result" => {"key" => "RUxZAUtxXcYvz0aukZu+odOynIr0ByLhC72iwzlJsi+ZPmONgA=="}
    }
    Copy to Clipboard Toggle word wrap

1.4.11. 从 credential-store 中删除一个凭证

您可以在 credential-store 中存储每个凭证类型,但默认情况下,当您删除凭证时,Elytron 会假定它是 PasswordCredential。如果要删除其他凭证类型,请在 entry-type 属性中指定它。

流程

  • 使用以下管理 CLI 命令,从 credential-store 中删除一个凭证:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:remove-alias(alias=<alias>, entry-type=<credential_type>)
    Copy to Clipboard Toggle word wrap

    删除 PasswordCredential 的示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:remove-alias(alias=passwordCredentialAlias)
    {
        "outcome" => "success",
        "response-headers" => {"warnings" => [{
            "warning" => "Update dependent resources as alias 'passwordCredentialAlias' does not exist anymore",
            "level" => "WARNING",
            "operation" => {
                "address" => [
                    ("subsystem" => "elytron"),
                    ("credential-store" => "exampleKeyStoreCredentialStore")
                ],
                "operation" => "remove-alias"
            }
        }]}
    }
    Copy to Clipboard Toggle word wrap

    删除 SecretKeyCredential 的示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:remove-alias(alias=secretKeyCredentialAlias, entry-type=SecretKeyCredential)
    {
        "outcome" => "success",
        "response-headers" => {"warnings" => [{
            "warning" => "Update dependent resources as alias 'secretKeyCredentialAl
    ias' does not exist anymore",
            "level" => "WARNING",
            "operation" => {
                "address" => [
                    ("subsystem" => "elytron"),
                    ("credential-store" => "exampleKeyStoreCredentialStore")
                ],
                "operation" => "remove-alias"
            }
        }]}
    }
    Copy to Clipboard Toggle word wrap

验证

  • 发出以下命令来验证 Elytron 是否删除了凭证:

    语法

    /subsystem=elytron/credential-store=<name_of_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/credential-store=exampleKeyStoreCredentialStore:read-aliases()
    {
        "outcome" => "success",
        "result" => []
    }
    Copy to Clipboard Toggle word wrap

    您删除的凭证不会被列出。

您只能将 SecretKeyCredential 类型存储在 secret-key-credential-store 中。这意味着,当您从 secret-key-credential-store 中删除一个凭证时,您不必指定一个 entry-type

流程

  • 使用以下命令,从 secret-key-credential-store 中删除一个 SecretKeyCredential:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_credential_store>:remove-alias(alias=<alias>)
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:remove-alias(alias=secretKeyCredentialAlias)
    {
        "outcome" => "success",
        "response-headers" => {"warnings" => [{
            "warning" => "Update dependent resources as alias 'secretKeyCredentialAlias' does not exist anymore",
            "level" => "WARNING",
            "operation" => {
                "address" => [
                    ("subsystem" => "elytron"),
                    ("secret-key-credential-store" => "examplePropertiesCredentialSt
    ore")
                ],
                "operation" => "remove-alias"
            }
        }]}
    }
    Copy to Clipboard Toggle word wrap

验证

  • 发出以下命令来验证 Elytron 是否删除了凭证:

    语法

    /subsystem=elytron/secret-key-credential-store=<name_of_credential_store>:read-aliases()
    Copy to Clipboard Toggle word wrap

    示例

    /subsystem=elytron/secret-key-credential-store=examplePropertiesCredentialStore:read-aliases()
    {
        "outcome" => "success",
        "result" => []
    }
    Copy to Clipboard Toggle word wrap

    您删除的凭证不会被列出。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部