7.5. 迁移 SSL 配置
7.5.1. 将简单 SSL 配置迁移到 Elytron 复制链接链接已复制到粘贴板!
如果您使用安全域保护了与 JBoss EAP 服务器的 HTTP 连接,您可以使用本节中提供的信息将该配置迁移到 Elytron。
以下示例假定您在 security-realm 中配置了以下 keystore :
示例:使用安全域密钥存储进行 SSL 配置
按照以下步骤,以使用 Elytron 实现相同的配置。
在
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)/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 Copied! Toggle word wrap Toggle overflow 在
elytron子系统中创建,用于指定上一步中定义的密钥存储、别名和密码。key-manager/subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})/subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
elytron子系统中创建server-ssl-context,它引用了上一步中定义的key-manager。/subsystem=elytron/server-ssl-context=LocalhostSslContext:add(key-manager=LocalhostKeyManager)
/subsystem=elytron/server-ssl-context=LocalhostSslContext:add(key-manager=LocalhostKeyManager)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将
https-listener从旧的security-realm切换到新创建的 Elytronssl-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
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-batchCopy to Clipboard Copied! Toggle word wrap Toggle overflow 重新加载服务器。
reload
reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow
这会在服务器配置文件中生成以下 elytron 子系统配置。
这会在服务器配置文件中生成以下 undertow 子系统配置。
<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
有关更多信息,请参阅如何为 JBoss EAP 配置服务器中的 Elytron 子系统和如何保护管理接口。
7.5.2. 将 CLIENT-CERT SSL 身份验证迁移到 Elytron 复制链接链接已复制到粘贴板!
要启用 CLIENT-CERT SSL 身份验证,请将 truststore 元素添加到 身份验证 元素中。
在没有 CLIENT-CERT 身份验证的情况下,客户端可以回退为使用本地机制 或用户名/密码 身份验证机制。要使基于 CLIENT-CERT 的身份验证强制使用,请删除 local 和 properties 元素。
传统的 truststore 可以通过两种方式使用:
传统的 truststore 只包括 CA
按照以下步骤配置服务器,以防止没有有效证书和私钥的用户使用 Elytron 访问服务器。
在
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)/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 Copied! Toggle word wrap Toggle overflow 在
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)/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 Copied! Toggle word wrap Toggle overflow 在
elytron子系统中创建key-manager,用于指定之前定义的LocalhostKeyStore密钥存储、别名和密码。/subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})/subsystem=elytron/key-manager=LocalhostKeyManager:add(key-store=LocalhostKeyStore,alias-filter=server,credential-reference={clear-text="key_password"})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
elytron子系统中创建trust-manager,用于指定之前创建的信任存储的key-store。/subsystem=elytron/trust-manager=TrustManager:add(key-store=TrustStore)
/subsystem=elytron/trust-manager=TrustManager:add(key-store=TrustStore)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
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)
/subsystem=elytron/server-ssl-context=LocalhostSslContext:add(key-manager=LocalhostKeyManager,trust-manager=TrustManager,need-client-auth=true)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将
https-listener从旧的security-realm切换到新创建的 Elytronssl-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
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-batchCopy to Clipboard Copied! Toggle word wrap Toggle overflow 重新加载服务器。
reload
reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow
这会在服务器配置文件中生成以下 elytron 子系统配置。
这会在服务器配置文件中生成以下 undertow 子系统配置。
<subsystem xmlns="urn:jboss:domain:undertow:10.0"> ... <https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/> ... </subsystem>
<subsystem xmlns="urn:jboss:domain:undertow:10.0">
...
<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
...
</subsystem>
realm 和 domain
要允许使用预定义的 Elytron ManagementDomain 安全域和管理 Realm 安全域,用户存储在标准属性文件中。
有两个情况下使用安全性域:
- 当证书身份验证失败时,安全域将用于密码回退。
- 为密码和证书完成授权后,域会提供各个用户的角色。
因此,对于任何客户端证书,安全域中必须存在一个用户。
主体 Decoder
当使用证书身份验证并且安全域接受用户名来解析身份时,必须有定义的方法是从客户端证书获取 用户名。
在这种情况下,CN 属性在证书主体中使用。
/subsystem=elytron/x500-attribute-principal-decoder=x500-decoder:add(attribute-name=CN)
/subsystem=elytron/x500-attribute-principal-decoder=x500-decoder:add(attribute-name=CN)
HTTP 身份验证工厂
对于 HTTP 连接,会使用之前定义的资源来定义 HTTP 身份验证工厂。它被配置为支持 CLIENT_CERT 和 DIGEST 身份验证。
由于属性域仅验证密码且无法验证客户端证书,您需要首先添加配置机制工厂。这禁用对安全域的证书验证。
/subsystem=elytron/configurable-http-server-mechanism-factory=configured-cert:add(http-server-mechanism-factory=global, properties={org.wildfly.security.http.skip-certificate-verification=true})
/subsystem=elytron/configurable-http-server-mechanism-factory=configured-cert:add(http-server-mechanism-factory=global, properties={org.wildfly.security.http.skip-certificate-verification=true})
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}]}])
./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}]}])
以上命令结果如下: