第 2 章 安全域
Security realms 将 Data Grid Server 部署与控制访问权限的环境中的网络协议和基础架构集成,并验证用户身份。
2.1. 创建安全域 复制链接链接已复制到粘贴板!
将安全域添加到 Data Grid 服务器配置,以控制对部署的访问。您可以在配置中添加一个或多个安全域。
在配置中添加安全域时,Data Grid 服务器会自动为 Hot Rod 和 REST 端点启用匹配的身份验证机制。
先决条件
- 根据需要在 Data Grid Server 配置中添加套接字绑定。
创建密钥存储或 PEM 文件,以使用 TLS/SSL 加密配置安全域。
数据网格服务器也可以在启动时生成密钥存储。
-
调配安全域配置所依赖的资源或服务。
例如,如果添加令牌域,则需要置备 OAuth 服务。
此流程演示了如何配置多个属性域。开始之前,您需要创建添加用户的属性文件并使用命令行接口(CLI)分配权限。使用用户 创建命令,如下所示:
user create <username> -p <changeme> -g <role> \
--users-file=application-users.properties \
--groups-file=application-groups.properties
user create <username> -p <changeme> -g <role> \
--users-file=management-users.properties \
--groups-file=management-groups.properties
如需示例和更多信息,运行 user create --help。
使用 CLI 将凭证添加到 properties realm 中,只能在您连接的服务器实例上创建用户。您必须手动将 properties 域中的凭证同步到集群中的每个节点。
流程
- 打开 Data Grid Server 配置进行编辑。
-
使用安全配置中的
元素来包含多个安全域。security-realms 添加具有
security-realm元素的安全域,并为它指定具有name属性的唯一名称。重要不要将特殊字符(如连字符(
-)或 符号( 和 )添加到安全域名称。如果安全域名称包含特殊字符,则数据网格服务器端点可能无法访问。要遵循示例,请创建一个名为
ApplicationRealm的安全域,另一个名为ManagementRealm。-
提供 Data Grid Server 的 TLS/SSL,
可根据需要配置服务器识别元素并配置密钥存储。 通过添加以下元素或字段来指定安全域类型:
-
properties-realm -
ldap-realm -
token-realm -
truststore-realm
-
根据情况指定您要配置的安全域类型的属性。
要跟踪示例,请使用
user-properties和group-properties元素或字段上的path属性指定通过 CLI 创建的*.properties文件。-
如果您在配置中添加多种不同类型的安全域,请包括
distributed-realm元素或字段,以便 Data Grid 服务器将 realm 与彼此结合使用。 -
配置 Data Grid Server 端点,将安全域与
security-realm属性搭配使用。 - 保存对您的配置的更改。
多个属性域
以下配置演示了如何以 XML、JSON 或 YAML 格式配置多个安全域:
XML
<server xmlns="urn:infinispan:server:13.0">
<security>
<security-realms>
<security-realm name="ApplicationRealm">
<properties-realm groups-attribute="Roles">
<user-properties path="application-users.properties"/>
<group-properties path="application-groups.properties"/>
</properties-realm>
</security-realm>
<security-realm name="ManagementRealm">
<properties-realm groups-attribute="Roles">
<user-properties path="management-users.properties"/>
<group-properties path="management-groups.properties"/>
</properties-realm>
</security-realm>
</security-realms>
</security>
</server>
JSON
{
"server": {
"security": {
"security-realms": [{
"name": "ManagementRealm",
"properties-realm": {
"groups-attribute": "Roles",
"user-properties": {
"digest-realm-name": "ManagementRealm",
"path": "management-users.properties"
},
"group-properties": {
"path": "management-groups.properties"
}
}
}, {
"name": "ApplicationRealm",
"properties-realm": {
"groups-attribute": "Roles",
"user-properties": {
"digest-realm-name": "ApplicationRealm",
"path": "application-users.properties"
},
"group-properties": {
"path": "application-groups.properties"
}
}
}]
}
}
}
YAML
server:
security:
securityRealms:
- name: "ManagementRealm"
propertiesRealm:
groupsAttribute: "Roles"
userProperties:
digestRealmName: "ManagementRealm"
path: "management-users.properties"
groupProperties:
path: "management-groups.properties"
- name: "ApplicationRealm"
propertiesRealm:
groupsAttribute: "Roles"
userProperties:
digestRealmName: "ApplicationRealm"
path: "application-users.properties"
groupProperties:
path: "application-groups.properties"