第 3 章 保护服务器的用户及其管理界面
3.1. 使用 Elytron 进行用户身份验证
3.1.1. 默认配置
默认情况下,JBoss EAP 管理接口通过传统的核心管理身份验证进行保护。
示例:默认配置
/core-service=management/management-interface=http-interface:read-resource() { "outcome" => "success", "result" => { "allowed-origins" => undefined, "console-enabled" => true, "http-authentication-factory" => undefined, "http-upgrade" => {"enabled" => true}, "http-upgrade-enabled" => true, "sasl-protocol" => "remote", "secure-socket-binding" => undefined, "security-realm" => "ManagementRealm", "server-name" => undefined, "socket-binding" => "management-http", "ssl-context" => undefined }
/core-service=management/management-interface=http-interface:read-resource()
{
"outcome" => "success",
"result" => {
"allowed-origins" => undefined,
"console-enabled" => true,
"http-authentication-factory" => undefined,
"http-upgrade" => {"enabled" => true},
"http-upgrade-enabled" => true,
"sasl-protocol" => "remote",
"secure-socket-binding" => undefined,
"security-realm" => "ManagementRealm",
"server-name" => undefined,
"socket-binding" => "management-http",
"ssl-context" => undefined
}
JBoss EAP 在 elytron
子系统中提供 management-http-authentication
和 management-sasl-authentication
,以保护管理接口。
更新 JBoss EAP 以使用默认 Elytron 组件:
设置
http-authentication-factory
以使用management-http-authentication
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=management-http-authentication)
/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=management-http-authentication)
设置
sasl-authentication-factory
以使用management-sasl-authentication
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=management-sasl-authentication)
/core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=management-sasl-authentication)
取消定义
security-realm
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management/management-interface=http-interface:undefine-attribute(name=security-realm)
/core-service=management/management-interface=http-interface:undefine-attribute(name=security-realm)
- 重新加载 JBoss EAP 以使更改生效:
reload
reload
管理接口现在使用 elytron
子系统提供的默认组件进行保护。
3.1.1.1. 默认 Elytron HTTP 验证配置
当您通过 http 访问管理界面时,例如在使用基于 Web 的管理控制台时,JBoss EAP 将使用 management-http-authentication
http-authentication-factory。
/subsystem=elytron/http-authentication-factory=management-http-authentication:read-resource() { "outcome" => "success", "result" => { "http-server-mechanism-factory" => "global", "mechanism-configurations" => [{ "mechanism-name" => "DIGEST", "mechanism-realm-configurations" => [{"realm-name" => "ManagementRealm"}] }], "security-domain" => "ManagementDomain" } }
/subsystem=elytron/http-authentication-factory=management-http-authentication:read-resource()
{
"outcome" => "success",
"result" => {
"http-server-mechanism-factory" => "global",
"mechanism-configurations" => [{
"mechanism-name" => "DIGEST",
"mechanism-realm-configurations" => [{"realm-name" => "ManagementRealm"}]
}],
"security-domain" => "ManagementDomain"
}
}
management-http-authentication
http-authentication-factory 配置为使用 ManagementDomain
安全域。
/subsystem=elytron/security-domain=ManagementDomain:read-resource() { "outcome" => "success", "result" => { "default-realm" => "ManagementRealm", "permission-mapper" => "default-permission-mapper", "post-realm-principal-transformer" => undefined, "pre-realm-principal-transformer" => undefined, "principal-decoder" => undefined, "realm-mapper" => undefined, "realms" => [ { "realm" => "ManagementRealm", "role-decoder" => "groups-to-roles" }, { "realm" => "local", "role-mapper" => "super-user-mapper" } ], "role-mapper" => undefined, "trusted-security-domains" => undefined } }
/subsystem=elytron/security-domain=ManagementDomain:read-resource()
{
"outcome" => "success",
"result" => {
"default-realm" => "ManagementRealm",
"permission-mapper" => "default-permission-mapper",
"post-realm-principal-transformer" => undefined,
"pre-realm-principal-transformer" => undefined,
"principal-decoder" => undefined,
"realm-mapper" => undefined,
"realms" => [
{
"realm" => "ManagementRealm",
"role-decoder" => "groups-to-roles"
},
{
"realm" => "local",
"role-mapper" => "super-user-mapper"
}
],
"role-mapper" => undefined,
"trusted-security-domains" => undefined
}
}
ManagementDomain
安全域由 ManagementRealm
Elytron 安全域支持,它是基于属性的域。
基于属性的域仅在服务器启动时读取。在服务器启动后添加的任何用户(手动或使用 add-user
脚本)都要求重新加载服务器。此重新加载是通过从管理 CLI 运行 reload
命令来完成的。
reload
reload
/subsystem=elytron/properties-realm=ManagementRealm:read-resource() { "outcome" => "success", "result" => { "groups-attribute" => "groups", "groups-properties" => { "path" => "mgmt-groups.properties", "relative-to" => "jboss.server.config.dir" }, "plain-text" => false, "users-properties" => { "path" => "mgmt-users.properties", "relative-to" => "jboss.server.config.dir" } } }
/subsystem=elytron/properties-realm=ManagementRealm:read-resource()
{
"outcome" => "success",
"result" => {
"groups-attribute" => "groups",
"groups-properties" => {
"path" => "mgmt-groups.properties",
"relative-to" => "jboss.server.config.dir"
},
"plain-text" => false,
"users-properties" => {
"path" => "mgmt-users.properties",
"relative-to" => "jboss.server.config.dir"
}
}
}
3.1.1.2. 默认 Elytron 管理 CLI 身份验证
默认情况下,管理 CLI(jboss-cli.sh
)配置为通过 remote+http
进行连接。
示例:默认 jboss-cli.xml
<jboss-cli xmlns="urn:jboss:cli:3.1"> <default-protocol use-legacy-override="true">remote+http</default-protocol> <!-- The default controller to connect to when 'connect' command is executed w/o arguments --> <default-controller> <protocol>remote+http</protocol> <host>localhost</host> <port>9990</port> </default-controller>
<jboss-cli xmlns="urn:jboss:cli:3.1">
<default-protocol use-legacy-override="true">remote+http</default-protocol>
<!-- The default controller to connect to when 'connect' command is executed w/o arguments -->
<default-controller>
<protocol>remote+http</protocol>
<host>localhost</host>
<port>9990</port>
</default-controller>
这将通过 HTTP 建立连接,并使用 HTTP 升级将通信协议更改为 Remoting
。HTTP 升级连接在 http-interface
的 http-upgrade
部分中使用 sasl-authentication-factory
进行了保护。
示例:使用默认组件配置
/core-service=management/management-interface=http-interface:read-resource() { "outcome" => "success", "result" => { "allowed-origins" => undefined, "console-enabled" => true, "http-authentication-factory" => "management-http-authentication", "http-upgrade" => { "enabled" => true, "sasl-authentication-factory" => "management-sasl-authentication" }, "http-upgrade-enabled" => true, "sasl-protocol" => "remote", "secure-socket-binding" => undefined, "security-realm" => undefined, "server-name" => undefined, "socket-binding" => "management-http", "ssl-context" => undefined } }
/core-service=management/management-interface=http-interface:read-resource()
{
"outcome" => "success",
"result" => {
"allowed-origins" => undefined,
"console-enabled" => true,
"http-authentication-factory" => "management-http-authentication",
"http-upgrade" => {
"enabled" => true,
"sasl-authentication-factory" => "management-sasl-authentication"
},
"http-upgrade-enabled" => true,
"sasl-protocol" => "remote",
"secure-socket-binding" => undefined,
"security-realm" => undefined,
"server-name" => undefined,
"socket-binding" => "management-http",
"ssl-context" => undefined
}
}
默认的 sasl-authentication-factory 是 management-sasl-authentication
。
/subsystem=elytron/sasl-authentication-factory=management-sasl-authentication:read-resource() { "outcome" => "success", "result" => { "mechanism-configurations" => [ { "mechanism-name" => "JBOSS-LOCAL-USER", "realm-mapper" => "local" }, { "mechanism-name" => "DIGEST-MD5", "mechanism-realm-configurations" => [{"realm-name" => "ManagementRealm"}] } ], "sasl-server-factory" => "configured", "security-domain" => "ManagementDomain" } }
/subsystem=elytron/sasl-authentication-factory=management-sasl-authentication:read-resource()
{
"outcome" => "success",
"result" => {
"mechanism-configurations" => [
{
"mechanism-name" => "JBOSS-LOCAL-USER",
"realm-mapper" => "local"
},
{
"mechanism-name" => "DIGEST-MD5",
"mechanism-realm-configurations" => [{"realm-name" => "ManagementRealm"}]
}
],
"sasl-server-factory" => "configured",
"security-domain" => "ManagementDomain"
}
}
management-sasl-authentication
sasl-authentication-factory 指定 JBOSS-LOCAL-USER
和 DIGEST-MD5
机制。
ManagementRealm
Elytron 安全域(在 DIGEST-MD5
中使用的域)与 management-http-authentication
http-authentication-factory 中使用的 realm 相同。
示例:JBOSS-LOCAL-USER Realm
/subsystem=elytron/identity-realm=local:read-resource() { "outcome" => "success", "result" => { "attribute-name" => undefined, "attribute-values" => undefined, "identity" => "$local" } }
/subsystem=elytron/identity-realm=local:read-resource()
{
"outcome" => "success",
"result" => {
"attribute-name" => undefined,
"attribute-values" => undefined,
"identity" => "$local"
}
}
本地
Elytron 安全域用于处理本地用户的静默身份验证。
3.1.2. 使用新身份存储保护管理接口
为您的身份存储创建安全域以及任何支持的安全域、解码器或映射程序。
JBoss EAP 的 如何配置身份管理指南中的 Elytron subsystem 部分中介绍了此过程。例如,如果要使用基于文件系统的身份存储保护管理接口,则需要遵循使用基于文件系统的身份存储 配置身份验证 中的步骤。
创建
http-authentication-factory
或sasl-authentication-factory
。示例:http-authentication-factory
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/http-authentication-factory=example-http-auth:add(http-server-mechanism-factory=global, security-domain=exampleSD, mechanism-configurations=[{mechanism-name=DIGEST, mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]}])
/subsystem=elytron/http-authentication-factory=example-http-auth:add(http-server-mechanism-factory=global, security-domain=exampleSD, mechanism-configurations=[{mechanism-name=DIGEST, mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]}])
示例:sasl-authentication-factory
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/sasl-authentication-factory=example-sasl-auth:add(sasl-server-factory=configured, security-domain=exampleSD, mechanism-configurations=[{mechanism-name=DIGEST-MD5, mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]}])
/subsystem=elytron/sasl-authentication-factory=example-sasl-auth:add(sasl-server-factory=configured, security-domain=exampleSD, mechanism-configurations=[{mechanism-name=DIGEST-MD5, mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]}])
将 pattern-filter 添加到
配置的
configurable-sasl-server-factory
中。示例:在 Configured configurable-sasl-server-factory 中添加 GSSAPI
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/configurable-sasl-server-factory=configured:list-add(name=filters, value={pattern-filter=GSSAPI})
/subsystem=elytron/configurable-sasl-server-factory=configured:list-add(name=filters, value={pattern-filter=GSSAPI})
这是可选步骤。当客户端尝试连接到 HTTP 管理接口时,JBoss EAP 会向 HTTP 响应发送一个状态代码
401 Unauthorized
,以及一组列出支持的验证机制(如 Digest、GSSAPI 等)的标头。如需更多信息,请参阅 JBoss EAP 安全架构指南中的本地和远程客户端身份验证章节。更新管理接口以使用
http-authentication-factory
或sasl-authentication-factory
。示例:更新 http-authentication-factory
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=example-http-auth) reload
/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=example-http-auth) reload
示例:更新 sasl-authentication-factory
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=example-sasl-auth) reload
/core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=example-sasl-auth) reload
注意在使用旧的核心管理身份验证时,您只能使用单一传统安全域来保护 http 管理接口。这会强制 HTTP 和 SASL 配置出现在单一的旧安全域中。使用
elytron
子系统时,您可以单独配置http-authentication-factory
和sasl-authentication-factory
,从而使用不同的安全域来保护 http 管理界面的 HTTP 和 SASL 机制。
如果在传统安全性和 Elytron 中分别使用相似实施的两个不同属性,则在管理界面中仅配置 Elytron 相关配置。例如,如果对旧安全和 Elytron 的 security-realm
进行了配置,则由
。
http-authentication-factory
配置来处理身份验证
当管理界面同时包含 http-authentication-factory
或 sasl-authentication-factory
(用于 HTTP 接口)以及 security-realm
,并且 ssl-context
属性没有使用 ssl-context 属性时,身份验证由 Elytron 处理,并且 SSL 由旧的安全域处理。
当管理界面同时包含 security-realm
和 ssl-context
时,以及 http-authentication-factory
或 sasl-authentication-factory
用于 HTTP 接口时,不使用 HTTP 接口的身份验证时,由旧安全域和 SSL 处理。
3.1.3. 添加 Silent 身份验证
默认情况下,JBoss EAP 提供本地用户的验证机制,也 通过本地
安全域来作为静默身份验证。更多信息请参阅 Silent 身份验证 部分。
静默身份验证必须添加到 sasl-authentication-factory
中。
在现有的 sasl-authentication-factory
中添加静默身份验证:
/subsystem=elytron/sasl-authentication-factory=example-sasl-auth:list-add(name=mechanism-configurations, value={mechanism-name=JBOSS-LOCAL-USER, realm-mapper=local}) reload
/subsystem=elytron/sasl-authentication-factory=example-sasl-auth:list-add(name=mechanism-configurations, value={mechanism-name=JBOSS-LOCAL-USER, realm-mapper=local})
reload
使用 silent 身份验证创建新 sasl-server-factory
:
/subsystem=elytron/sasl-authentication-factory=example-sasl-auth:add(sasl-server-factory=configured,security-domain=ManagementDomain,mechanism-configurations=[{mechanism-name=DIGEST-MD5,mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]},{mechanism-name=JBOSS-LOCAL-USER, realm-mapper=local}]) reload
/subsystem=elytron/sasl-authentication-factory=example-sasl-auth:add(sasl-server-factory=configured,security-domain=ManagementDomain,mechanism-configurations=[{mechanism-name=DIGEST-MD5,mechanism-realm-configurations=[{realm-name=exampleManagementRealm}]},{mechanism-name=JBOSS-LOCAL-USER, realm-mapper=local}])
reload
上面的示例使用现有的 ManagementDomain
安全域,但您也可以创建和使用其他安全域。您可以在 JBoss EAP 如何配置身份管理 指南的 Elytron subsystem 部分中找到更多创建安全域的示例。
如果使用了 Elytron 安全性,并且身份验证尝试尝试使用 JBOSS-LOCAL-USER SASL
机制及与实际身份不匹配的身份验证名称,身份验证会失败。
在传统的 security
子系统中,可以为 JBOSS-LOCAL-USER
选择自定义用户名。身份验证通过将用户名映射到 特殊身份来继续。
3.1.4. Authenticated Management 用户映射身份
使用 elytron
子系统保护管理接口时,您可以为通过身份验证用户身份映射提供安全域。这允许经过身份验证的用户在登录到管理界面时显示适当的身份。
应用程序服务器会公开多个管理界面。每种接口都可以与 独立的身份验证关联
,以处理该接口的身份验证要求。
为做出授权决策,当前安全身份从安全域获得。返回的安全身份根据该安全域中定义的规则映射和权限分配。
在大多数情况下,通用安全域用于所有管理;为了对管理接口进行身份验证,以及获取用于授权决策的安全身份。在这些情况下,安全域与管理接口的身份验证工厂相关联,并且不需要定义任何特殊的 access=identity
。
在某些情况下,会使用不同的安全域来获取授权决策的身份。此处定义了 access=identity
资源。它包含对安全域的引用,以获取授权的身份。
以下示例假定您已使用 exampleSD
Elytron 安全域保护了管理接口,并将其公开为 exampleManagementRealm
。
要定义身份映射,请将 身份资源
添加到管理界面。
示例:添加 身份资源
/core-service=management/access=identity:add(security-domain=exampleSD)
/core-service=management/access=identity:add(security-domain=exampleSD)
添加 身份资源
后,访问管理界面时将会出现经过身份验证的用户的身份。如果没有添加 identity
资源,则使用用于身份验证的安全域的身份。
例如,如果您以 user1
身份登录管理 CLI,您的身份将正确显示。
示例:从管理 CLI 显示 Authenticated User 的身份
:whoami { "outcome" => "success", "result" => {"identity" => {"username" => "user1"}} }
:whoami
{
"outcome" => "success",
"result" => {"identity" => {"username" => "user1"}}
}
如果添加了 identity
资源,并且使用旧安全域来保护管理界面,经过身份验证的用户将始终具有 匿名
身份。删除 identity
资源后,通过旧安全域验证的用户会出现适当的身份。
管理操作的授权始终使用安全域,它是 access=identity
中指定的域。如果未指定,则这是用于身份验证的域。任何角色映射始终位于安全域的上下文中。
当前请求的 identity
资源将使用 Elytron 配置返回一组角色,作为映射。当使用基于 RBAC 的角色映射定义时,identity
资源的角色将作为组并放入管理 角色映射
以获取当前请求的管理角色。
场景 | 没有 access=identity 定义 | access=identity 引用 Elytron security-domain |
---|---|---|
使用旧的 | 来自连接的身份。 | 不支持或匿名身份。 |
使用由 | 来自连接的身份。 |
如果成功使用 |
原生管理,包括通过 HTTP 升级,使用旧的 | 来自连接的身份。 | 不支持或匿名身份。 |
原生管理,包括通过 HTTP 升级,使用 | 来自连接的身份。 |
如果成功使用 |
如果 identity
资源中使用的安全域不信任来自身份验证的安全域,则会使用匿名身份。
当两者都使用相同的安全域时,身份资源
中使用的安全域不需要信任来自身份验证的安全域。
可信安全域不是传输。
如果未定义 access=identity
资源,则使用针对管理接口身份验证过程中建立的身份。在这种情况下,通过 remoting
子系统或使用应用程序使用连接建立的身份。
如果定义了 access=identity
资源,但管理接口使用的安全域不同,且未列在域列表中,不会建立身份。将使用在身份验证过程中建立的身份尝试 inflow。使用 remoting
subsystem 或使用应用程序建立的连接建立的身份不会以这种方式流处理。
如果管理接口使用旧的安全域进行保护,其身份将无法在不同的安全域之间被控制。在这种情况下,不应定义 access=identity
资源。因此,可以在身份验证过程中建立的身份直接使用。因此,identity
资源不支持使用 PicketBox 保护的应用程序。
3.1.5. 通过管理 CLI 使用 Elytron 客户端
您可以将管理 CLI 配置为使用 Elytron 客户端在连接到 JBoss EAP 时提供安全信息。
使用 Elytron 保护管理接口。
要将 Elytron 客户端与管理 CLI 搭配使用,您必须使用 Elytron 保护管理界面。您可以使用 Elytron 在 用户身份验证中使用 Elytron 保护管理接口的详细信息。
创建 Elytron 客户端配置文件。
您需要创建一个 Elytron 客户端配置文件,该文件中包含您的身份验证配置以及使用该配置的规则。您可以在 JBoss EAP 如何配置身份管理指南的配置文件方法一节中找到创建身份验证配置的更多详细信息。
示例: custom-config.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <configuration> <authentication-client xmlns="urn:elytron:client:1.2"> <authentication-rules> <rule use-configuration="configuration1"> <match-host name="localhost" /> </rule> </authentication-rules> <authentication-configurations> <configuration name="configuration1"> <sasl-mechanism-selector selector="DIGEST-MD5" /> <providers> <use-service-loader /> </providers> <set-user-name name="user1" /> <credentials> <clear-password password="password123" /> </credentials> <set-mechanism-realm name="exampleManagementRealm" /> </configuration> </authentication-configurations> </authentication-client> </configuration>
<configuration> <authentication-client xmlns="urn:elytron:client:1.2"> <authentication-rules> <rule use-configuration="configuration1"> <match-host name="localhost" /> </rule> </authentication-rules> <authentication-configurations> <configuration name="configuration1"> <sasl-mechanism-selector selector="DIGEST-MD5" /> <providers> <use-service-loader /> </providers> <set-user-name name="user1" /> <credentials> <clear-password password="password123" /> </credentials> <set-mechanism-realm name="exampleManagementRealm" /> </configuration> </authentication-configurations> </authentication-client> </configuration>
通过管理 CLI 脚本使用 Elytron 客户端配置文件。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ./jboss-cli.sh -c -Dwildfly.config.url=/path/to/custom-config.xml
$ ./jboss-cli.sh -c -Dwildfly.config.url=/path/to/custom-config.xml