7.5. 迁移 SSL 配置


7.5.1. 将简单 SSL 配置迁移到 Elytron

如果您使用安全域保护了与 JBoss EAP 服务器的 HTTP 连接,您可以使用本节中提供的信息将该配置迁移到 Elytron。

以下示例假定您在 security-realm 中配置了以下 keystore

示例:使用安全域密钥存储进行 SSL 配置

<security-realm name="ApplicationRealm">
  <server-identities>
    <ssl>
      <keystore path="server.keystore" relative-to="jboss.server.config.dir" keystore-password="keystore_password" alias="server" key-password="key_password" />
    </ssl>
  </server-identities>
</security-realm>
Copy to Clipboard Toggle word wrap

按照以下步骤,以使用 Elytron 实现相同的配置。

  1. elytron 子系统中创建一个 key-store,用于指定密钥存储的位置及其加密的密码。此命令假定密钥存储是使用密钥tool 命令生成的,其类型是 JKS

    /subsystem=elytron/key-store=LocalhostKeyStore:add(path=server.keystore,relative-to=jboss.server.config.dir,credential-reference={clear-text="keystore_password"},type=JKS)
    Copy to Clipboard Toggle word wrap
  2. elytron 子系统中创建 key- manager,用于指定上一步中定义的密钥存储、别名和密码。

    /subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})
    Copy to Clipboard Toggle word wrap
  3. elytron 子系统中创建 server-ssl-context,它引用了上一步中定义的 key-manager

    /subsystem=elytron/server-ssl-context=LocalhostSslContext:add(key-manager=LocalhostKeyManager)
    Copy to Clipboard Toggle word wrap
  4. https-listener 从旧的 security-realm 切换到新创建的 Elytron ssl-context

    batch
    /subsystem=undertow/server=default-server/https-listener=https:undefine-attribute(name=security-realm)
    /subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context,value=LocalhostSslContext)
    run-batch
    Copy to Clipboard Toggle word wrap
  5. 重新加载服务器。

    reload
    Copy to Clipboard Toggle word wrap

这会在服务器配置文件中生成以下 elytron 子系统配置。

<subsystem xmlns="urn:wildfly:elytron:4.0" ...>
  ...
  <tls>
    <key-stores>
      <key-store name="LocalhostKeyStore">
        <credential-reference clear-text="keystore_password"/>
        <implementation type="JKS"/>
        <file path="server.keystore" relative-to="jboss.server.config.dir"/>
      </key-store>
    </key-stores>
    <key-managers>
      <key-manager name="LocalhostKeyManager" key-store="LocalhostKeyStore"  alias-filter="server">
        <credential-reference clear-text="key_password"/>
      </key-manager>
    </key-managers>
    <server-ssl-contexts>
      <server-ssl-context name="LocalhostSslContext" key-manager="LocalhostKeyManager"/>
    </server-ssl-contexts>
  </tls>
</subsystem>
Copy to Clipboard Toggle word wrap

这会在服务器配置文件中生成以下 undertow 子系统配置。

<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
Copy to Clipboard Toggle word wrap

有关更多信息,请参阅如何为 JBoss EAP 配置服务器中的 Elytron 子系统如何保护管理接口

7.5.2. 将 CLIENT-CERT SSL 身份验证迁移到 Elytron

要启用 CLIENT-CERT SSL 身份验证,请将 truststore 元素添加到 身份验证 元素中。

<security-realm name="ManagementRealm">
  <server-identities>
    <ssl>
      <keystore path="server.keystore" relative-to="jboss.server.config.dir" keystore-password="KEYSTORE_PASSWORD" alias="server" key-password="key_password" />
    </ssl>
  </server-identities>
  <authentication>
    <truststore path="server.truststore" relative-to="jboss.server.config.dir" keystore-password="TRUSTSTORE_PASSWORD" />
    <local default-user="$local"/>
    <properties path="mgmt-users.properties" relative-to="jboss.server.config.dir"/>
  </authentication>
</security-realm>
Copy to Clipboard Toggle word wrap
注意

在没有 CLIENT-CERT 身份验证的情况下,客户端可以回退为使用本地机制 或用户名/密码 身份验证机制。要使基于 CLIENT-CERT 的身份验证强制使用,请删除 localproperties 元素。

传统的 truststore 可以通过两种方式使用:

传统的 truststore 只包括 CA

按照以下步骤配置服务器,以防止没有有效证书和私钥的用户使用 Elytron 访问服务器。

  1. elytron 子系统中创建一个 key-store,用于指定密钥存储的位置及其加密的密码。此命令假定密钥存储是使用密钥tool 命令生成的,其类型是 JKS

    /subsystem=elytron/key-store=LocalhostKeyStore:add(path=server.keystore,relative-to=jboss.server.config.dir,credential-reference={clear-text="keystore_password"},type=JKS)
    Copy to Clipboard Toggle word wrap
  2. elytron 子系统中创建一个 key-store,用于指定信任存储的位置以及它加密的密码。此命令假定密钥存储是使用密钥tool 命令生成的,其类型是 JKS

    /subsystem=elytron/key-store=TrustStore:add(path=server.truststore,relative-to=jboss.server.config.dir,credential-reference={clear-text="truststore_password"},type=JKS)
    Copy to Clipboard Toggle word wrap
  3. elytron 子系统中创建 key-manager,用于指定之前定义的 LocalhostKeyStore 密钥存储、别名和密码。

    /subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})
    Copy to Clipboard Toggle word wrap
  4. elytron 子系统中创建 trust-manager,用于指定之前创建的信任存储的 key-store

    /subsystem=elytron/trust-manager=TrustManager:add(key-store=TrustStore)
    Copy to Clipboard Toggle word wrap
  5. elytron 子系统中创建 server-ssl-context,该子系统引用之前定义的 key-manager 属性,设置 trust-manager 属性并启用客户端身份验证。

    /subsystem=elytron/server-ssl-context=LocalhostSslContext:add(key-manager=LocalhostKeyManager,trust-manager=TrustManager,need-client-auth=true)
    Copy to Clipboard Toggle word wrap
  6. https-listener 从旧的 security-realm 切换到新创建的 Elytron ssl-context

    batch
    /subsystem=undertow/server=default-server/https-listener=https:undefine-attribute(name=security-realm)
    /subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context,value=LocalhostSslContext)
    run-batch
    Copy to Clipboard Toggle word wrap
  7. 重新加载服务器。

    reload
    Copy to Clipboard Toggle word wrap

这会在服务器配置文件中生成以下 elytron 子系统配置。

<subsystem xmlns="urn:wildfly:elytron:4.0"...>
  ...
  <tls>
    <key-stores>
      <key-store name="LocalhostKeyStore">
        <credential-reference clear-text="keystore_password"/>
        <implementation type="JKS"/>
        <file path="server.keystore" relative-to="jboss.server.config.dir"/>
      </key-store>
      <key-store name="TrustStore">
        <credential-reference clear-text="truststore_password"/>
        <implementation type="JKS"/>
        <file path="server.truststore" relative-to="jboss.server.config.dir"/>
      </key-store>
    </key-stores>
    <key-managers>
      <key-manager name="LocalhostKeyManager" key-store="LocalhostKeyStore" alias-filter="server">
        <credential-reference clear-text="key_password"/>
      </key-manager>
    </key-managers>
    <trust-managers>
      <trust-manager name="TrustManager" key-store="TrustStore"/>
    </trust-managers>
    <server-ssl-contexts>
      <server-ssl-context name="LocalhostSslContext" need-client-auth="true" key-manager="LocalhostKeyManager" trust-manager="TrustManager"/>
    </server-ssl-contexts>
  </tls>
</subsystem>
Copy to Clipboard Toggle word wrap

这会在服务器配置文件中生成以下 undertow 子系统配置。

<subsystem xmlns="urn:jboss:domain:undertow:10.0">
...
<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
...
</subsystem>
Copy to Clipboard Toggle word wrap
realm 和 domain

要允许使用预定义的 Elytron ManagementDomain 安全域和管理 Realm 安全域,用户存储在标准属性文件中。

<security-domains>
    <security-domain name="ManagementDomain" default-realm="ManagementRealm" permission-mapper="default-permission-mapper">
        <realm name="ManagementRealm" role-decoder="groups-to-roles"/>
        <realm name="local"/>
    </security-domain>
</security-domains>
<security-realms>
    <properties-realm name="ManagementRealm">
        <users-properties path="mgmt-users.properties" relative-to="jboss.server.config.dir" digest-realm-name="ManagementRealm"/>
        <groups-properties path="mgmt-groups.properties" relative-to="jboss.server.config.dir"/>
    </properties-realm>
</security-realms>
Copy to Clipboard Toggle word wrap

有两个情况下使用安全性域:

  • 当证书身份验证失败时,安全域将用于密码回退。
  • 为密码和证书完成授权后,域会提供各个用户的角色。

因此,对于任何客户端证书,安全域中必须存在一个用户。

主体 Decoder

当使用证书身份验证并且安全域接受用户名来解析身份时,必须有定义的方法是从客户端证书获取 用户名

在这种情况下,CN 属性在证书主体中使用。

/subsystem=elytron/x500-attribute-principal-decoder=x500-decoder:add(attribute-name=CN)
Copy to Clipboard Toggle word wrap
HTTP 身份验证工厂

对于 HTTP 连接,会使用之前定义的资源来定义 HTTP 身份验证工厂。它被配置为支持 CLIENT_CERTDIGEST 身份验证。

由于属性域仅验证密码且无法验证客户端证书,您需要首先添加配置机制工厂。这禁用对安全域的证书验证。

/subsystem=elytron/configurable-http-server-mechanism-factory=configured-cert:add(http-server-mechanism-factory=global, properties={org.wildfly.security.http.skip-certificate-verification=true})
Copy to Clipboard Toggle word wrap

HTTP 验证可以创建:

./subsystem=elytron/http-authentication-factory=client-cert-digest:add(http-server-mechanism-factory=configured-cert,security-domain=ManagementDomain,mechanism-configurations=[{mechanism-name=CLIENT_CERT,pre-realm-principal-transformer=x500-decoder},{mechanism-name=DIGEST, mechanism-realm-configurations=[{realm-name=ManagementRealm}]}])
Copy to Clipboard Toggle word wrap

以上命令结果如下:

<subsystem xmlns="urn:wildfly:elytron:4.0" final-providers="combined-providers" disallowed-providers="OracleUcrypto">
  ...
  <http>
    ...
    <http-authentication-factory name="client-cert-digest" http-server-mechanism-factory="configured-cert" security-domain="ManagementDomain">
      <mechanism-configuration>
        <mechanism mechanism-name="CLIENT_CERT" pre-realm-principal-transformer="x500-decoder"/>
        <mechanism mechanism-name="DIGEST">
          <mechanism-realm realm-name="ManagementRealm"/>
        </mechanism>
      </mechanism-configuration>
    </http-authentication-factory>
    ...
    <configurable-http-server-mechanism-factory name="configured-cert" http-server-mechanism-factory="configured-cert">
        <properties>
            <property name="org.wildfly.security.http.skip-certificate-verification" value="true"/>
        </properties>
    </configurable-http-server-mechanism-factory>
    ...
  </http>
  ...
</subsystem>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat