9.5. 迁移 SSL 配置
将应用程序中的 SSL 配置迁移到将 Elytron 与以下信息搭配使用:
将简单 SSL 配置迁移到 Elytron
如果您使用安全域保护到 JBoss EAP 服务器的 HTTP 连接,请使用本节中提供的信息将 SSL 配置迁移到 Elytron。
先决条件
使用安全域,具有到 JBoss EAP 服务器的安全 HTTP 连接。
以下示例假定您在 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,用于指定上一步中定义的key-store、别名和密码。/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 7.4 如何配置 服务器安全性 中的 Elytron 子系统 以及如何保护管理接口。
9.5.1. 将 CLIENT-CERT SSL 身份验证迁移到 Elytron 复制链接链接已复制到粘贴板!
要启用 CLIENT-CERT SSL 身份验证,请在 authentication 元素中添加 truststore 元素。
如果没有发生 CLIENT-CERT 身份验证,客户端可以回退到使用本地机制 或用户名/密码 身份验证机制。要使基于 CLIENT-CERT 的身份验证强制使用,请删除 local 和 properties 元素。
传统的 truststore 可以通过两种方式使用:
9.5.1.1. 传统的 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更新至新创建的 Elytronssl-context。/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context,value=LocalhostSslContext)
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context,value=LocalhostSslContext)Copy 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:14.0"> ... <https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/> ... </subsystem>
<subsystem xmlns="urn:jboss:domain:undertow:14.0">
...
<https-listener name="https" socket-binding="https" ssl-context="LocalhostSslContext" enable-http2="true"/>
...
</subsystem>
9.5.1.2. 安全域和域 复制链接链接已复制到粘贴板!
安全域用于两个情况:
- 当证书身份验证失败时,安全域将用于密码回退。
- 为密码和证书完成授权后,域将提供单个用户的角色。
要允许使用预定义的 Elytron ManagementDomain 安全域和管理 Realm 安全域,用户存储在标准属性文件中。
因此,对于任何客户端证书,用户必须存在于安全域中。
9.5.1.3. 主体 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)
9.5.1.4. 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}]}])
以上命令会产生: