Data Grid 安全指南


Red Hat Data Grid 8.3

启用并配置数据网格安全性

Red Hat Customer Content Services

摘要

保护您的数据网格部署免受网络入侵者的影响。限制对授权用户的数据访问。

Red Hat Data Grid

数据网格是高性能分布式内存数据存储。

Schemaless 数据结构
灵活性以将不同对象存储为键值对。
基于网格的数据存储
旨在在集群中分发和复制数据。
弹性扩展
动态调整节点数量,以在不中断服务的情况下满足需求。
数据互操作性
从不同端点在网格中存储、检索和查询数据。

Data Grid 文档

红帽客户门户网站中提供了数据网格的文档。

Data Grid 下载

访问红帽客户门户网站中的 Data Grid 软件下载

注意

您必须有一个红帽帐户才能访问和下载 Data Grid 软件。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。详情请查看 CTO Chris Wright 的信息

第 1 章 配置用户角色和权限

授权是一项安全功能,要求用户具有某些权限,然后才能访问缓存或与 Data Grid 资源交互。您可以为提供不同权限级别的用户分配角色,从只读访问权限授予完整、超级用户权限。

1.1. 安全授权

数据网格授权通过限制用户访问保护您的部署。

用户应用程序或客户端必须属于分配了足够权限的角色,然后才能对缓存管理器或缓存执行操作。

例如,您可以在特定缓存实例上配置授权,以便调用 Cache.get () 的身份需要在 Cache.put ()处分配角色,而 Cache.put () 需要具有写入权限的角色。

在这种情况下,如果具有 io 角色的用户应用程序或客户端试图编写条目,Data Grid 会拒绝请求并抛出一个安全例外。如果具有 writer 角色的用户应用程序或客户端发送了写入请求,Data Grid 会验证授权并发出令牌以供后续操作。

身份

身份身份是 java.security.Principal 的安全主体。使用 javax.security.auth.Subject 类实施的主题代表一组安全主体。换句话说,使用者代表一个用户及其所属的所有组。

角色身份

Data Grid 使用角色映射程序,以便安全主体对应于您分配一个或多个权限的角色。

下图说明了安全主体与角色的对应方式:

1.1.1. 用户角色和权限

Data Grid 包含一组默认的角色,可授予用户访问数据并与 Data Grid 资源交互。

ClusterRoleMapper 是 Data Grid 用来将安全主体与授权角色关联的默认机制。

重要

ClusterRoleMapper 与角色名称匹配的主体名称。名为 admin 的用户会自动获得 admin 权限,名为 deployer 的用户会获取 deployer 权限,以此类推。

Expand
角色权限描述

admin

ALL

具有所有权限的超级用户,包括缓存管理器生命周期的控制。

deployer

ALL_READ, ALL_WRITE, LISTEN, EXEC, MONITOR, CREATE

除了 应用程序 权限外,还可创建和删除数据网格资源。

application

ALL_READ, ALL_WRITE, LISTEN, EXEC, MONITOR

观察者 权限之外,还具有对 Data Grid 资源的读写访问权限。还可以侦听事件并执行服务器任务和脚本。

observer

ALL_READ, MONITOR

除了监控权限外,还具有对数据网格 资源 的读取访问权限。

monitor

MONITOR

可以通过 JMX 和 指标端点 查看统计信息。

1.1.2. 权限

授权角色具有不同的权限,并有不同的访问级别到 Data Grid。权限可让您限制用户对缓存管理器和缓存的访问。

1.1.2.1. 缓存管理器权限
Expand
权限功能描述

配置

defineConfiguration

定义新的缓存配置。

LISTEN

addListener

针对缓存管理器注册监听程序。

生命周期

stop

停止缓存管理器。

创建

createCache,removeCache

创建和删除容器资源,如缓存、计数器、架构和脚本。

MONITOR

getStats

允许访问 JMX 统计数据和 指标端点

ALL

-

包括所有缓存管理器权限。

1.1.2.2. 缓存权限
Expand
权限功能描述

READ

get包含

从缓存检索条目。

put,putIfAbsent,replace,remove,evict

在缓存中写入、替换、删除、驱除数据。

EXEC

distexec,

允许对缓存执行代码。

LISTEN

addListener

根据缓存注册监听程序。

BULK_READ

keySet,,entrySet,query

执行批量检索操作。

BULK_WRITE

清除放置All

执行批量写入操作。

生命周期

启动停止

启动和停止缓存。

ADMIN

getVersion,addInterceptor*, removeInterceptor Chain ,get EvictionManager,getComponentRegistry,getDistributionManager,getAuthorizationManager,evict,getRpcManager, getCacheConfiguration ,getCacheConfiguration, getCacheManager,getInvocationContextContainer,setAvailability,getDataContainer,getStats,getXAResource

允许访问底层组件和内部结构。

MONITOR

getStats

允许访问 JMX 统计数据和 指标端点

ALL

-

包括所有缓存权限。

ALL_READ

-

组合 READ 和 BULK_READ 权限。

ALL_WRITE

-

组合 WRITE 和 BULK_WRITE 权限。

1.1.3. 角色映射器

Data Grid 包括一个 PrincipalRoleMapper API,它将对象中的安全主体映射到您可以分配给用户的授权角色。

1.1.3.1. 集群角色映射器

ClusterRoleMapper 使用持久复制缓存来动态存储默认角色和权限的 principal-to-role 映射。

默认情况下,使用 Principal 名称作为角色名称,并实施 org.infinispan.security.MutableRoleMapper,它会公开方法在运行时更改角色映射。

  • Java 类: org.infinispan.security.mappers.ClusterRoleMapper
  • 声明性配置:& lt;cluster-role-mapper />
1.1.3.2. 身份角色映射器

IdentityRoleMapper 使用主体名称作为角色名称。

  • Java 类: org.infinispan.security.mappers.IdentityRoleMapper
  • 声明配置:& lt;identity-role-mapper />
1.1.3.3. CommonName 角色映射器

如果主体名称是 Distinguished Name (DN),则 CommonNameRoleMapper 使用 Common Name (CN)作为角色名称。

例如,cn=managers,ou= person,dc=example,dc=com 映射到 managers 角色。

  • Java 类: org.infinispan.security.mappers.CommonRoleMapper
  • 声明配置:& lt;common-name-role-mapper />
1.1.3.4. 自定义角色映射器

自定义角色映射程序是 org.infinispan.security.PrincipalRoleMapper 实施。

  • 声明配置:& lt;custom-role-mapper class="my.custom.RoleMapper" />

1.2. 访问控制列表(ACL)缓存

数据网格缓存您在内部授予用户以获得最佳性能的角色。每当向用户授予或拒绝角色时,Data Grid 会清除 ACL 缓存以确保正确应用用户权限。

如果需要,您可以禁用 ACL 缓存,或使用 cache-sizecache-timeout 属性进行配置。

XML

<infinispan>
  <cache-container name="acl-cache-configuration">
    <security cache-size="1000"
              cache-timeout="300000">
      <authorization/>
    </security>
  </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

JSON

{
  "infinispan" : {
    "cache-container" : {
      "name" : "acl-cache-configuration",
      "security" : {
        "cache-size" : "1000",
        "cache-timeout" : "300000",
        "authorization" : {}
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

infinispan:
  cacheContainer:
    name: "acl-cache-configuration"
    security:
      cache-size: "1000"
      cache-timeout: "300000"
      authorization: ~
Copy to Clipboard Toggle word wrap

1.3. 自定义角色和权限

您可以在 Data Grid 配置中自定义授权设置,以使用带有不同角色和权限组合的角色映射程序。

流程

  1. 在 Cache Manager 配置中声明一个角色映射程序以及一组自定义角色和权限。
  2. 配置缓存的授权,以限制基于用户角色的访问。
自定义角色和权限配置

XML

<infinispan>
  <cache-container name="custom-authorization">
    <security>
      <authorization>
        <!-- Declare a role mapper that associates a security principal
             to each role. -->
        <identity-role-mapper />
        <!-- Specify user roles and corresponding permissions. -->
        <role name="admin" permissions="ALL" />
        <role name="reader" permissions="READ" />
        <role name="writer" permissions="WRITE" />
        <role name="supervisor" permissions="READ WRITE EXEC"/>
      </authorization>
    </security>
  </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

JSON

{
  "infinispan" : {
    "cache-container" : {
      "name" : "custom-authorization",
      "security" : {
        "authorization" : {
          "identity-role-mapper" : null,
          "roles" : {
            "reader" : {
              "role" : {
                "permissions" : "READ"
              }
            },
            "admin" : {
              "role" : {
                "permissions" : "ALL"
              }
            },
            "writer" : {
              "role" : {
                "permissions" : "WRITE"
              }
            },
            "supervisor" : {
              "role" : {
                "permissions" : "READ WRITE EXEC"
              }
            }
          }
        }
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

infinispan:
  cacheContainer:
    name: "custom-authorization"
    security:
      authorization:
        identityRoleMapper: "null"
        roles:
          reader:
            role:
              permissions:
                - "READ"
          admin:
            role:
              permissions:
                - "ALL"
          writer:
            role:
              permissions:
                - "WRITE"
          supervisor:
            role:
              permissions:
                - "READ"
                - "WRITE"
                - "EXEC"
Copy to Clipboard Toggle word wrap

1.4. 使用安全授权配置缓存

在缓存配置中使用授权来限制用户访问。在他们可以读取或写缓存条目或删除缓存之前,用户必须具有足够级别的权限。

先决条件

  • 确保 authorization 元素包含在 cache-container 配置的 security 部分中。

    Data Grid 默认在 Cache Manager 中启用安全授权,并为缓存提供一组全局角色和权限。

  • 如有必要,在 Cache Manager 配置中声明自定义角色和权限。

流程

  1. 打开缓存配置进行编辑。
  2. 添加 authorization 元素以缓存,以根据用户的角色和权限限制用户访问权限。
  3. 保存对您的配置的更改。
授权配置

以下配置演示了如何将隐式授权配置与默认角色和权限一起使用:

XML

<distributed-cache>
  <security>
    <!-- Inherit authorization settings from the cache-container. --> <authorization/>
  </security>
</distributed-cache>
Copy to Clipboard Toggle word wrap

JSON

{
  "distributed-cache": {
    "security": {
      "authorization": {
        "enabled": true
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

distributedCache:
  security:
    authorization:
      enabled: true
Copy to Clipboard Toggle word wrap

自定义角色和权限

XML

<distributed-cache>
  <security>
    <authorization roles="admin supervisor"/>
  </security>
</distributed-cache>
Copy to Clipboard Toggle word wrap

JSON

{
  "distributed-cache": {
    "security": {
      "authorization": {
        "enabled": true,
        "roles": ["admin","supervisor"]
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

distributedCache:
  security:
    authorization:
      enabled: true
      roles: ["admin","supervisor"]
Copy to Clipboard Toggle word wrap

1.5. 禁用安全授权

在本地开发环境中,您可以禁用授权,以便用户不需要角色和权限。禁用安全授权意味着任何用户都可以访问数据并与数据网格资源交互。

流程

  1. 打开 Data Grid 配置进行编辑。
  2. 从 Cache Manager 的安全配置中 删除任何 授权 元素。
  3. 从缓存中删除任何 授权 配置。
  4. 保存对您的配置的更改。

1.6. 以编程方式配置授权

在使用嵌入式缓存时,您可以使用 GlobalSecurityConfigurationBuilderConfigurationBuilder 类配置授权。

流程

  1. 构建可启用授权的 GlobalConfigurationBuilder,指定角色映射器,并定义一组角色和权限。

    GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
    global
       .security()
          .authorization().enable() 
    1
    
             .principalRoleMapper(new IdentityRoleMapper()) 
    2
    
             .role("admin") 
    3
    
                .permission(AuthorizationPermission.ALL)
             .role("reader")
                .permission(AuthorizationPermission.READ)
             .role("writer")
                .permission(AuthorizationPermission.WRITE)
             .role("supervisor")
                .permission(AuthorizationPermission.READ)
                .permission(AuthorizationPermission.WRITE)
                .permission(AuthorizationPermission.EXEC);
    Copy to Clipboard Toggle word wrap
    1
    为缓存管理器启用 Data Grid 授权。
    2
    指定 PrincipalRoleMapper 实施,它将主体映射到角色。
    3
    定义角色及其关联的权限。
  2. ConfigurationBuilder 中启用授权,以根据用户角色限制访问。

    ConfigurationBuilder config = new ConfigurationBuilder();
    config
       .security()
          .authorization()
             .enable(); 
    1
    Copy to Clipboard Toggle word wrap
    1
    隐式添加来自全局配置的所有角色。

    如果您不想将所有角色应用到缓存,请显式定义缓存的角色,如下所示:

    ConfigurationBuilder config = new ConfigurationBuilder();
    config
       .security()
          .authorization()
             .enable()
             .role("admin") 
    1
    
             .role("supervisor")
             .role("reader");
    Copy to Clipboard Toggle word wrap
    1
    为缓存定义授权角色。在本例中,仅具有 writer 角色的用户不会授权给"安全"缓存。数据网格拒绝来自这些用户的任何访问请求。

1.7. 使用安全授权进行代码

当您为嵌入式缓存配置安全授权并构建 DefaultCacheManager 时,它会返回一个 SecureCache,用于在调用任何操作前检查安全上下文。SecureCache 还确保应用无法检索较低级别的不安全对象,如 DataContainer。因此,您必须使用具有所需授权的身份执行代码。

在 Java 中,使用特定身份执行代码通常意味着嵌套在 PrivilegedAction 中要执行的代码,如下所示:

import org.infinispan.security.Security;

Security.doAs(subject, new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
    cache.put("key", "value");
}
});
Copy to Clipboard Toggle word wrap

使用 Java 8,您可以按照如下所示简化前面的调用:

Security.doAs(mySubject, PrivilegedAction<String>() -> cache.put("key", "value"));
Copy to Clipboard Toggle word wrap

前面的调用使用 Security.doAs () 方法,而不是 Subject.doAs ()。您可以在 Data Grid 中使用以下任一方法,但 Security.doAs () 提供了更好的性能。

如果您需要当前的 Subject,使用以下调用从 Data Grid 上下文或从 AccessControlContext 检索它:

Security.getSubject();
Copy to Clipboard Toggle word wrap

第 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
Copy to Clipboard Toggle word wrap
提示

如需示例和更多信息,运行 user create --help

注意

使用 CLI 将凭证添加到 properties realm 中,只能在您连接的服务器实例上创建用户。您必须手动将 properties 域中的凭证同步到集群中的每个节点。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 使用安全配置中的 security -realms 元素来包含多个安全域。
  3. 添加具有 security-realm 元素的安全域,并为它指定具有 name 属性的唯一名称。

    重要

    不要将特殊字符(如连字符(-)或 符号( 和 )添加到安全域名称。如果安全域名称包含特殊字符,则数据网格服务器端点可能无法访问。

    要遵循示例,请创建一个名为 ApplicationRealm 的安全域,另一个名为 ManagementRealm

  4. 提供 Data Grid Server 的 TLS/SSL,可根据需要配置服务器 识别元素并配置密钥存储。
  5. 通过添加以下元素或字段来指定安全域类型:

    • properties-realm
    • ldap-realm
    • token-realm
    • truststore-realm
  6. 根据情况指定您要配置的安全域类型的属性。

    要跟踪示例,请使用 user-propertiesgroup-properties 元素或字段上的 path 属性指定通过 CLI 创建的 *.properties 文件。

  7. 如果您在配置中添加多种不同类型的安全域,请包括 distributed-realm 元素或字段,以便 Data Grid 服务器将 realm 与彼此结合使用。
  8. 配置 Data Grid Server 端点,将安全域与 security-realm 属性搭配使用。
  9. 保存对您的配置的更改。
多个属性域

以下配置演示了如何以 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>
Copy to Clipboard Toggle word wrap

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"
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

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"
Copy to Clipboard Toggle word wrap

2.2. 设置 Kerberos 身份

在 Data Grid Server 配置中的安全域中添加 Kerberos 身份,以使用包含服务主体名称和加密密钥(派生自 Kerberos 密码)的 keytab 文件。

先决条件

  • 具有 Kerberos 服务帐户主体。
注意

keytab 文件可以包含用户和服务帐户主体。但是,Data Grid 服务器只使用服务帐户主体,这意味着它可以向客户端提供身份并允许客户端与 Kerberos 服务器进行身份验证。

在大多数情况下,您可以为 Hot Rod 和 REST 端点创建唯一的主体。例如,如果您在 "INFINISPAN.ORG" 域中有"datagrid"服务器,则应创建以下服务主体:

  • HotRod/datagrid@INFINISPAN.ORG 标识 Hot Rod 服务。
  • HTTP/datagrid@INFINISPAN.ORG 标识 REST 服务。

流程

  1. 为 Hot Rod 和 REST 服务创建 keytab 文件。

    Linux
    ktutil
    ktutil:  addent -password -p datagrid@INFINISPAN.ORG -k 1 -e aes256-cts
    Password for datagrid@INFINISPAN.ORG: [enter your password]
    ktutil:  wkt http.keytab
    ktutil:  quit
    Copy to Clipboard Toggle word wrap
    Microsoft Windows
    ktpass -princ HTTP/datagrid@INFINISPAN.ORG -pass * -mapuser INFINISPAN\USER_NAME
    ktab -k http.keytab -a HTTP/datagrid@INFINISPAN.ORG
    Copy to Clipboard Toggle word wrap
  2. 将 keytab 文件复制到 Data Grid Server 安装的 server/conf 目录中。
  3. 打开 Data Grid Server 配置进行编辑。
  4. 在 Data Grid 服务器 安全域中添加服务器事件定义。
  5. 指定向 Hot Rod 和 REST 连接器提供服务主体的 keytab 文件的位置。
  6. 将 Kerberos 服务主体命名为 Kerberos。
  7. 保存对您的配置的更改。
Kerberos 身份配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="kerberos-realm">
        <server-identities>
          <!-- Specifies a keytab file that provides a Kerberos identity. -->
          <!-- Names the Kerberos service principal for the Hot Rod endpoint. -->
          <!-- The required="true" attribute specifies that the keytab file must be present when the server starts. -->
          <kerberos keytab-path="hotrod.keytab"
                    principal="hotrod/datagrid@INFINISPAN.ORG"
                    required="true"/>
          <!-- Specifies a keytab file and names the Kerberos service principal for the REST endpoint. -->
          <kerberos keytab-path="http.keytab"
                    principal="HTTP/localhost@INFINISPAN.ORG"
                    required="true"/>
        </server-identities>
      </security-realm>
    </security-realms>
  </security>
  <endpoints>
    <endpoint socket-binding="default"
              security-realm="KerberosRealm">
     <hotrod-connector>
        <authentication>
           <sasl server-name="datagrid"
                 server-principal="hotrod/datagrid@INFINISPAN.ORG"/>
        </authentication>
     </hotrod-connector>
     <rest-connector>
       <authentication server-principal="HTTP/localhost@INFINISPAN.ORG"/>
     </rest-connector>
   </endpoint>
  </endpoints>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "KerberosRealm",
        "server-identities": [{
          "kerberos": {
            "principal": "hotrod/datagrid@INFINISPAN.ORG",
            "keytab-path": "hotrod.keytab",
            "required": true
          },
          "kerberos": {
            "principal": "HTTP/localhost@INFINISPAN.ORG",
            "keytab-path": "http.keytab",
            "required": true
          }
        }]
      }]
    },
    "endpoints": {
      "endpoint": {
        "socket-binding": "default",
        "security-realm": "KerberosRealm",
        "hotrod-connector": {
          "authentication": {
            "security-realm": "kerberos-realm",
            "sasl": {
              "server-name": "datagrid",
              "server-principal": "hotrod/datagrid@INFINISPAN.ORG"
            }
          }
        },
        "rest-connector": {
          "authentication": {
            "server-principal": "HTTP/localhost@INFINISPAN.ORG"
          }
        }
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "KerberosRealm"
        serverIdentities:
          - kerberos:
              principal: "hotrod/datagrid@INFINISPAN.ORG"
              keytabPath: "hotrod.keytab"
              required: "true"
          - kerberos:
              principal: "HTTP/localhost@INFINISPAN.ORG"
              keytabPath: "http.keytab"
              required: "true"
  endpoints:
    endpoint:
      socketBinding: "default"
      securityRealm: "KerberosRealm"
      hotrodConnector:
        authentication:
          sasl:
            serverName: "datagrid"
            serverPrincipal: "hotrod/datagrid@INFINISPAN.ORG"
      restConnector:
        authentication:
          securityRealm: "KerberosRealm"
          serverPrincipal" : "HTTP/localhost@INFINISPAN.ORG"
Copy to Clipboard Toggle word wrap

2.3. 属性域

属性域使用属性文件来定义用户和组。

  • users.properties 包含 Data Grid 用户凭据。密码可以使用 DIGEST-MD5DIGEST 验证机制进行预先说明。
  • groups.properties 将用户与角色和权限相关联。
注意

属性文件包含将它们与 Data Grid 服务器配置中的安全域关联的标头。

users.properties

myuser=a_password
user2=another_password
Copy to Clipboard Toggle word wrap

groups.properties

myuser=supervisor,reader,writer
user2=supervisor
Copy to Clipboard Toggle word wrap

属性域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="default">
        <!-- groups-attribute configures the "groups.properties" file to contain security authorization roles. -->
        <properties-realm groups-attribute="Roles">
          <user-properties path="users.properties"
                           relative-to="infinispan.server.config.path"
                           plain-text="true"/>
          <group-properties path="groups.properties"
                            relative-to="infinispan.server.config.path"/>
        </properties-realm>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "default",
        "properties-realm": {
          "groups-attribute": "Roles",
          "user-properties": {
            "digest-realm-name": "default",
            "path": "users.properties",
            "relative-to": "infinispan.server.config.path",
            "plain-text": true
          },
          "group-properties": {
            "path": "groups.properties",
            "relative-to": "infinispan.server.config.path"
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "default"
        propertiesRealm:
          # groupsAttribute configures the "groups.properties" file
          # to contain security authorization roles.
          groupsAttribute: "Roles"
          userProperties:
            digestRealmName: "default"
            path: "users.properties"
            relative-to: 'infinispan.server.config.path'
            plainText: "true"
          groupProperties:
            path: "groups.properties"
            relative-to: 'infinispan.server.config.path'
Copy to Clipboard Toggle word wrap

2.4. LDAP 域

LDAP 域连接到 LDAP 服务器(如 OpenLDAP、Red Hat Directory Server、Apache Directory Server 或 Microsoft Active Directory)以验证用户身份并获取成员资格信息。

注意

LDAP 服务器可以有不同的条目布局,具体取决于服务器和部署的类型。此文档超出了本文档的范围,提供了有关所有可能的配置的示例。

重要

LDAP 连接主体必须具有必要的权限才能执行 LDAP 查询和访问特定属性。

作为使用 direct-verification 属性验证用户凭据的替代选择,您可以指定一个 LDAP 属性来验证密码的 user-password-mapper 元素。

注意

您不能使用通过 直接验证属性执行哈希的端点 身份验证机制。

由于 Active Directory 没有公开 密码 属性,所以只能使用 direct-verification 属性,而不是 user-password-mapper 元素。因此,您必须将 BASIC 身份验证机制与 REST 端点搭配使用,PL AIN 与 Hot Rod 端点与 Active Directory 服务器集成。更为安全的替代方案是使用 Kerberos,它允许 SPNEGOGSSAPIGS2-KRB5 身份验证机制。

rdn-identifier 属性指定 LDAP 属性,它根据提供的标识符查找用户条目,后者通常是用户名;例如,uidsAMAccountName 属性。将 search-recursive="true" 添加到配置中,以递归搜索目录。默认情况下,搜索用户条目使用 (rdn_identifier={0}) 过滤器。使用 filter-name 属性指定不同的过滤器。

attribute-mapping 元素检索用户所属的所有组。通常,存储成员资格信息的方法有两种:

  • member 属性中通常具有类 groupOfNames 的组条目下。在这种情况下,您可以使用如上例配置中的属性过滤器。此过滤器搜索与提供的过滤器匹配的条目,该过滤器查找带有与用户 DN 相等的 member 属性的组。然后,过滤器提取组条目的 CN ( 指定),并将其添加到用户的 Roles 中。
  • memberOf 属性中的用户条目中。在这种情况下,您应该使用属性引用,如下所示:

    <attribute-reference reference="memberOf" from="cn" to="Roles" />

    此引用从用户的条目获取所有 memberOf 属性,按照 提取 CN,并将它们添加到用户的 Roles 中。

LDAP 域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="LdapRealm">
        <!-- Specifies connection properties. -->
        <ldap-realm url="ldap://my-ldap-server:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org"
                    credential="strongPassword"
                    connection-timeout="3000"
                    read-timeout="30000"
                    connection-pooling="true"
                    referral-mode="ignore"
                    page-size="30"
                    direct-verification="true">
          <!-- Defines how principals are mapped to LDAP entries. -->
          <identity-mapping rdn-identifier="uid"
                            search-dn="ou=People,dc=infinispan,dc=org"
                            search-recursive="false">
            <!-- Retrieves all the groups of which the user is a member. -->
            <attribute-mapping>
              <attribute from="cn" to="Roles"
                         filter="(&amp;(objectClass=groupOfNames)(member={1}))"
                         filter-dn="ou=Roles,dc=infinispan,dc=org"/>
            </attribute-mapping>
          </identity-mapping>
        </ldap-realm>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "LdapRealm",
        "ldap-realm": {
          "url": "ldap://my-ldap-server:10389",
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "credential": "strongPassword",
          "connection-timeout": "3000",
          "read-timeout": "30000",
          "connection-pooling": "true",
          "referral-mode": "ignore",
          "page-size": "30",
          "direct-verification": "true",
          "identity-mapping": {
            "rdn-identifier": "uid",
            "search-dn": "ou=People,dc=infinispan,dc=org",
            "search-recursive": "false",
            "attribute-mapping": [{
              "from": "cn",
              "to": "Roles",
              "filter": "(&(objectClass=groupOfNames)(member={1}))",
              "filter-dn": "ou=Roles,dc=infinispan,dc=org"
            }]
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: LdapRealm
        ldapRealm:
          url: 'ldap://my-ldap-server:10389'
          principal: 'uid=admin,ou=People,dc=infinispan,dc=org'
          credential: strongPassword
          connectionTimeout: '3000'
          readTimeout: '30000'
          connectionPooling: true
          referralMode: ignore
          pageSize: '30'
          directVerification: true
          identityMapping:
            rdnIdentifier: uid
            searchDn: 'ou=People,dc=infinispan,dc=org'
            searchRecursive: false
            attributeMapping:
              - filter: '(&(objectClass=groupOfNames)(member={1}))'
                filterDn: 'ou=Roles,dc=infinispan,dc=org'
                from: cn
                to: Roles
Copy to Clipboard Toggle word wrap

2.4.1. LDAP 域主体重新编写

SASL 验证机制(如 GSSAPIGS2-KRB5Negotiate )包括需要 清理 的用户名,然后才能使用它来搜索 LDAP 目录。

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="LdapRealm">
        <ldap-realm url="ldap://${org.infinispan.test.host.address}:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org"
                    credential="strongPassword">
          <name-rewriter>
            <!-- Defines a rewriter that extracts the username from the principal using a regular expression. -->
            <regex-principal-transformer name="domain-remover"
                                         pattern="(.*)@INFINISPAN\.ORG"
                                         replacement="$1"/>
          </name-rewriter>
          <identity-mapping rdn-identifier="uid"
                            search-dn="ou=People,dc=infinispan,dc=org">
            <attribute-mapping>
              <attribute from="cn" to="Roles"
                         filter="(&amp;(objectClass=groupOfNames)(member={1}))"
                         filter-dn="ou=Roles,dc=infinispan,dc=org"/>
            </attribute-mapping>
            <user-password-mapper from="userPassword"/>
          </identity-mapping>
        </ldap-realm>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "LdapRealm",
        "ldap-realm": {
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "url": "ldap://${org.infinispan.test.host.address}:10389",
          "credential": "strongPassword",
          "name-rewriter": {
            "regex-principal-transformer": {
              "pattern": "(.*)@INFINISPAN\\.ORG",
              "replacement": "$1"
            }
          },
          "identity-mapping": {
            "rdn-identifier": "uid",
            "search-dn": "ou=People,dc=infinispan,dc=org",
            "attribute-mapping": {
              "attribute": {
                "filter": "(&(objectClass=groupOfNames)(member={1}))",
                "filter-dn": "ou=Roles,dc=infinispan,dc=org",
                "from": "cn",
                "to": "Roles"
              }
            },
            "user-password-mapper": {
              "from": "userPassword"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "LdapRealm"
        ldapRealm:
          principal: "uid=admin,ou=People,dc=infinispan,dc=org"
          url: "ldap://${org.infinispan.test.host.address}:10389"
          credential: "strongPassword"
          nameRewriter:
            regexPrincipalTransformer:
              pattern: (.*)@INFINISPAN\.ORG
              replacement: "$1"
          identityMapping:
            rdnIdentifier: "uid"
            searchDn: "ou=People,dc=infinispan,dc=org"
            attributeMapping:
              attribute:
                filter: "(&(objectClass=groupOfNames)(member={1}))"
                filterDn: "ou=Roles,dc=infinispan,dc=org"
                from: "cn"
                to: "Roles"
            userPasswordMapper:
              from: "userPassword"
Copy to Clipboard Toggle word wrap

2.5. 令牌域

令牌域使用外部服务来验证令牌并需要兼容 RFC-7662 (OAuth2 Token Introspection)的提供程序,如 Red Hat SSO。

令牌域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="TokenRealm">
        <!-- Specifies the URL of the authentication server. -->
        <token-realm name="token"
                     auth-server-url="https://oauth-server/auth/">
          <!-- Specifies the URL of the token introspection endpoint. -->
          <oauth2-introspection introspection-url="https://oauth-server/auth/realms/infinispan/protocol/openid-connect/token/introspect"
                                client-id="infinispan-server"
                                client-secret="1fdca4ec-c416-47e0-867a-3d471af7050f"/>
        </token-realm>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "TokenRealm",
        "token-realm": {
          "auth-server-url": "https://oauth-server/auth/",
          "oauth2-introspection": {
            "client-id": "infinispan-server",
            "client-secret": "1fdca4ec-c416-47e0-867a-3d471af7050f",
            "introspection-url": "https://oauth-server/auth/realms/infinispan/protocol/openid-connect/token/introspect"
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "TokenRealm"
        tokenRealm:
          authServerUrl: 'https://oauth-server/auth/'
          oauth2Introspection:
            clientId: infinispan-server
            clientSecret: '1fdca4ec-c416-47e0-867a-3d471af7050f'
            introspectionUrl: 'https://oauth-server/auth/realms/infinispan/protocol/openid-connect/token/introspect'
Copy to Clipboard Toggle word wrap

2.6. 信任存储域

信任存储域使用证书或证书链,验证数据网格服务器和客户端身份。

密钥存储
包含向客户端提供 Data Grid Server 身份的服务器证书。如果您使用服务器证书配置密钥存储,Data Grid 服务器使用行业标准 SSL/TLS 协议对流量进行加密。
信任存储
包含客户端提供给 Data Grid Server 的客户端证书或证书链。客户端信任存储是可选的,并允许数据网格服务器执行客户端证书身份验证。

客户端证书验证

如果您希望 Data Grid Server 来验证或验证客户端证书,您必须将 require-ssl-client-auth="true" 属性添加到端点配置。

信任存储域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="TrustStoreRealm">
        <server-identities>
          <ssl>
            <!-- Provides an SSL/TLS identity with a keystore that contains server certificates. -->
            <keystore path="server.p12"
                      relative-to="infinispan.server.config.path"
                      keystore-password="secret"
                      alias="server"/>
            <!-- Configures a trust store that contains client certificates or part of a certificate chain. -->
            <truststore path="trust.p12"
                        relative-to="infinispan.server.config.path"
                        password="secret"/>
          </ssl>
        </server-identities>
        <!-- Authenticates client certificates against the trust store. If you configure this, the trust store must contain the public certificates for all clients. -->
        <truststore-realm/>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "TrustStoreRealm",
        "server-identities": {
          "ssl": {
            "keystore": {
              "path": "server.p12",
              "relative-to": "infinispan.server.config.path",
              "keystore-password": "secret",
              "alias": "server"
            },
            "truststore": {
              "path": "trust.p12",
              "relative-to": "infinispan.server.config.path",
              "password": "secret"
            }
          }
        },
        "truststore-realm": {}
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "TrustStoreRealm"
        serverIdentities:
          ssl:
            keystore:
              path: "server.p12"
              relative-to: "infinispan.server.config.path"
              keystore-password: "secret"
              alias: "server"
            truststore:
              path: "trust.p12"
              relative-to: "infinispan.server.config.path"
              password: "secret"
        truststoreRealm: ~
Copy to Clipboard Toggle word wrap

2.7. 分布式安全域

分布式域组合了多个不同类型的安全域。当用户尝试访问 Hot Rod 或 REST 端点时,Data Grid Server 会依次使用每个安全域,直到它找到可以执行身份验证的用户。

分布式域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="DistributedRealm">
        <ldap-realm url="ldap://my-ldap-server:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org"
                    credential="strongPassword">
          <identity-mapping rdn-identifier="uid"
                            search-dn="ou=People,dc=infinispan,dc=org"
                            search-recursive="false">
            <attribute-mapping>
              <attribute from="cn" to="Roles"
                         filter="(&amp;(objectClass=groupOfNames)(member={1}))"
                         filter-dn="ou=Roles,dc=infinispan,dc=org"/>
            </attribute-mapping>
          </identity-mapping>
        </ldap-realm>
        <properties-realm groups-attribute="Roles">
          <user-properties path="users.properties"
                           relative-to="infinispan.server.config.path"/>
          <group-properties path="groups.properties"
                            relative-to="infinispan.server.config.path"/>
        </properties-realm>
        <distributed-realm/>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "DistributedRealm",
        "ldap-realm": {
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "url": "ldap://my-ldap-server:10389",
          "credential": "strongPassword",
          "identity-mapping": {
            "rdn-identifier": "uid",
            "search-dn": "ou=People,dc=infinispan,dc=org",
            "search-recursive": false,
            "attribute-mapping": {
              "attribute": {
                "filter": "(&(objectClass=groupOfNames)(member={1}))",
                "filter-dn": "ou=Roles,dc=infinispan,dc=org",
                "from": "cn",
                "to": "Roles"
              }
            }
          }
        },
        "properties-realm": {
          "groups-attribute": "Roles",
          "user-properties": {
            "digest-realm-name": "DistributedRealm",
            "path": "users.properties"
          },
          "group-properties": {
            "path": "groups.properties"
          }
        },
        "distributed-realm": {}
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "DistributedRealm"
        ldapRealm:
          principal: "uid=admin,ou=People,dc=infinispan,dc=org"
          url: "ldap://my-ldap-server:10389"
          credential: "strongPassword"
          identityMapping:
            rdnIdentifier: "uid"
            searchDn: "ou=People,dc=infinispan,dc=org"
            searchRecursive: "false"
            attributeMapping:
              attribute:
                filter: "(&(objectClass=groupOfNames)(member={1}))"
                filterDn: "ou=Roles,dc=infinispan,dc=org"
                from: "cn"
                to: "Roles"
        propertiesRealm:
          groupsAttribute: "Roles"
          userProperties:
            digestRealmName: "DistributedRealm"
            path: "users.properties"
          groupProperties:
            path: "groups.properties"
        distributedRealm: ~
Copy to Clipboard Toggle word wrap

第 3 章 端点验证机制

Data Grid 服务器可以为 Hot Rod 和 REST 端点使用自定义 SASL 和 HTTP 验证机制。

3.1. Data Grid 服务器身份验证

身份验证限制了用户对端点的访问以及数据网格控制台和命令行界面(CLI)。

Data Grid Server 包括可强制执行用户身份验证的"默认"安全域。默认身份验证使用属性 realm,其用户凭据存储在 server/conf/users.properties 文件中。Data Grid Server 还默认启用安全授权,因此您必须为用户授予存储在 server/conf/groups.properties 文件中的权限。

提示

使用用户 create 命令及命令行界面(CLI)来添加用户并分配权限。如需示例和更多信息,运行 user create --help

3.2. 配置 Data Grid 服务器验证机制

您可以明确配置 Hot Rod 和 REST 端点,以使用特定的身份验证机制。只有在需要显式覆盖安全域的默认机制时才需要配置验证机制。

注意

配置中的 每个端点 部分都必须包含 热连接器和其它 连接器 元素或字段。例如,如果您明确声明一个 热式连接器,还必须声明其他 连接器,即使它没有配置验证机制。

先决条件

  • 根据需要在 Data Grid Server 配置中添加安全域。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 添加 端点 元素或字段,并指定它与 security-realm 属性使用的安全域。
  3. 添加 hotrod-connector 元素或字段来配置 Hot Rod 端点。

    1. 添加 身份验证 元素或字段。
    2. 指定用于 sasl mechanisms 属性的 Hot Rod 端点的 SASL 验证机制。
    3. 如果适用,使用 qop 属性指定 SASL 质量保护设置。
    4. 如果需要,使用 server-name 属性指定 Data Grid Server 身份。
  4. 添加 rest-connector 元素或字段来配置 REST 端点。

    1. 添加 身份验证 元素或字段。
    2. 指定与 mechanisms 属性一起使用的 REST 端点的 HTTP 验证机制
  5. 保存对您的配置的更改。
身份验证机制配置

以下配置为用于身份验证的 Hot Rod 端点指定 SASL 机制:

XML

<server xmlns="urn:infinispan:server:13.0">
  <endpoints>
    <endpoint socket-binding="default"
              security-realm="my-realm">
      <hotrod-connector>
        <authentication>
           <sasl mechanisms="SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256
                             SCRAM-SHA-1 DIGEST-SHA-512 DIGEST-SHA-384
                             DIGEST-SHA-256 DIGEST-SHA DIGEST-MD5 PLAIN"
                 server-name="infinispan"
                 qop="auth"/>
        </authentication>
      </hotrod-connector>
      <rest-connector>
        <authentication mechanisms="DIGEST BASIC"/>
      </rest-connector>
    </endpoint>
  </endpoints>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "endpoints": {
      "endpoint": {
        "socket-binding": "default",
        "security-realm": "my-realm",
        "hotrod-connector": {
          "authentication": {
            "security-realm": "default",
            "sasl": {
              "server-name": "infinispan",
              "mechanisms": ["SCRAM-SHA-512", "SCRAM-SHA-384", "SCRAM-SHA-256", "SCRAM-SHA-1", "DIGEST-SHA-512", "DIGEST-SHA-384", "DIGEST-SHA-256", "DIGEST-SHA", "DIGEST-MD5", "PLAIN"],
              "qop": ["auth"]
            }
          }
        },
        "rest-connector": {
          "authentication": {
            "mechanisms": ["DIGEST", "BASIC"],
            "security-realm": "default"
          }
        }
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  endpoints:
    endpoint:
      socketBinding: "default"
      securityRealm: "my-realm"
      hotrodConnector:
        authentication:
          securityRealm: "default"
          sasl:
            serverName: "infinispan"
            mechanisms:
              - "SCRAM-SHA-512"
              - "SCRAM-SHA-384"
              - "SCRAM-SHA-256"
              - "SCRAM-SHA-1"
              - "DIGEST-SHA-512"
              - "DIGEST-SHA-384"
              - "DIGEST-SHA-256"
              - "DIGEST-SHA"
              - "DIGEST-MD5"
              - "PLAIN"
            qop:
              - "auth"
      restConnector:
        authentication:
          mechanisms:
            - "DIGEST"
            - "BASIC"
          securityRealm: "default"
Copy to Clipboard Toggle word wrap

3.2.1. 禁用身份验证

在本地开发环境或隔离的网络上,您可以将 Data Grid 配置为允许未经身份验证的客户端请求。当您禁用用户身份验证时,您也应该在 Data Grid 安全配置中禁用授权。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 端点 元素或字段移除 security-realm 属性。
  3. cache-container 和每个缓存配置 的安全 配置中删除任何 授权 元素。
  4. 保存对您的配置的更改。

XML

<server xmlns="urn:infinispan:server:13.0">
  <endpoints socket-binding="default"/>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "endpoints": {
      "endpoint": {
        "socket-binding": "default"
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  endpoints:
    endpoint:
      socketBinding: "default"
Copy to Clipboard Toggle word wrap

3.3. Data Grid 服务器验证机制

数据网格服务器自动配置端点,并提供与您的安全域配置匹配的身份验证机制。例如,如果您添加了 Kerberos 安全域,Data Grid Server 为 Hot Rod 端点启用 GSSAPIGS2-KRB5 验证机制。

热环端点

当配置包含对应的安全域时,Data Grid 服务器为 Hot Rod 端点启用以下 SASL 身份验证机制:

Expand
安全域SASL 身份验证机制

属性域和 LDAP 域

SCRAM-*, SCRAM-*, SCRAM-*

令牌域

OAUTHBEARER

信任域

EXTERNAL

Kerberos 身份

GSSAPI, GS2-KRB5

SSL/TLS 身份

PLAIN

REST 端点

当配置包含对应的安全域时,Data Grid 服务器为 REST 端点启用以下 HTTP 身份验证机制:

Expand
安全域HTTP 身份验证机制

属性域和 LDAP 域

DIGEST

令牌域

BEARER_TOKEN

信任域

CLIENT_CERT

Kerberos 身份

SPNEGO

SSL/TLS 身份

BASIC

3.3.1. SASL 验证机制

数据网格服务器支持以下 SASL 身份验证机制及 Hot Rod 端点:

Expand
身份验证机制描述Security realm 类型相关详情

PLAIN

以纯文本格式使用凭证。您应该只在加密连接中使用 PLAIN 身份验证。

属性域和 LDAP 域

BASIC HTTP 机制类似。

DIGEST-*

使用哈希算法和非ce 值。热环连接器支持 DIGEST-MD 5、DIGEST-SHA -256DIGEST-SHA-384、DIGEST-SHA-384 和 DIGEST-SHA-512 哈希算法。

属性域和 LDAP 域

Digest HTTP 机制类似。

SCRAM-*

除了哈希算法和非值外,还使用 salt 值。热环连接器支持 SCRAM-SHASCRAM-SHA-256SCRAM-SHA-384SCRAM-SHA-512 哈希算法,按强度排列。

属性域和 LDAP 域

Digest HTTP 机制类似。

GSSAPI

使用 Kerberos 票据并需要一个 Kerberos 域控制器。您必须在域配置中添加对应的 kerberos 服务器身份。在大多数情况下,您还要指定一个 ldap-realm 以提供用户成员资格信息。

Kerberos realms

SPNEGO HTTP 机制类似。

GS2-KRB5

使用 Kerberos 票据并需要一个 Kerberos 域控制器。您必须在域配置中添加对应的 kerberos 服务器身份。在大多数情况下,您还要指定一个 ldap-realm 以提供用户成员资格信息。

Kerberos realms

SPNEGO HTTP 机制类似。

EXTERNAL

使用客户端证书。

信任存储域

CLIENT_CERT HTTP 机制类似。

OAUTHBEARER

使用 OAuth 令牌并且需要 token-realm 配置。

令牌域

BEARER_TOKEN HTTP 机制类似。

3.3.2. SASL 质量保护(QoP)

如果 SASL 机制支持完整性和隐私保护(QoP)设置,您可以使用 qop 属性将它们添加到 Hot Rod 端点配置中。

Expand
QoP 设置描述

auth

仅身份验证.

auth-int

具备完整性保护的身份验证。

auth-conf

通过完整性和隐私保护进行身份验证.

3.3.3. SASL 策略

SASL 策略提供对 Hot Rod 验证机制的精细控制。

提示

Data Grid 缓存授权限制根据角色和权限对缓存的访问。配置缓存授权,然后设置 & lt;no-anonymous value=false /& gt; 以允许匿名登录并将访问逻辑委派给缓存授权。

Expand
策略描述默认值

forward-secrecy

仅使用支持会话间转发保密的 SASL 机制。这意味着,进入一个会话不会自动提供用于破坏未来会话的信息。

false

pass-credentials

仅使用需要客户端证书的 SASL 机制。

false

no-plain-text

请勿使用 SASL 机制,这些机制对于简单的纯被动攻击是不可避免的。

false

no-active

请勿使用 SASL 机制,这些机制容易激活、非字典、攻击。

false

no-dictionary

不要使用受被动字典攻击的 SASL 机制。

false

no-anonymous

不要使用接受匿名登录的 SASL 机制。

true

SASL 策略配置

在以下配置中,Hot Rod 端点使用 GSSAPI 机制进行身份验证,因为它是唯一符合所有 SASL 策略的机制:

XML

<server xmlns="urn:infinispan:server:13.0">
  <endpoints>
    <endpoint socket-binding="default"
              security-realm="default">
      <hotrod-connector>
        <authentication>
          <sasl mechanisms="PLAIN DIGEST-MD5 GSSAPI EXTERNAL"
                server-name="infinispan"
                qop="auth"
                policy="no-active no-plain-text"/>
        </authentication>
      </hotrod-connector>
      <rest-connector/>
    </endpoint>
  </endpoints>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "endpoints" : {
      "endpoint" : {
        "socket-binding" : "default",
        "security-realm" : "default",
        "hotrod-connector" : {
          "authentication" : {
            "sasl" : {
              "server-name" : "infinispan",
              "mechanisms" : [ "PLAIN","DIGEST-MD5","GSSAPI","EXTERNAL" ],
              "qop" : [ "auth" ],
              "policy" : [ "no-active","no-plain-text" ]
            }
          }
        },
        "rest-connector" : ""
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  endpoints:
    endpoint:
      socketBinding: "default"
      securityRealm: "default"
      hotrodConnector:
        authentication:
          sasl:
            serverName: "infinispan"
            mechanisms:
              - "PLAIN"
              - "DIGEST-MD5"
              - "GSSAPI"
              - "EXTERNAL"
            qop:
              - "auth"
            policy:
              - "no-active"
              - "no-plain-text"
      restConnector: ~
Copy to Clipboard Toggle word wrap

3.3.4. HTTP 验证机制

Data Grid Server 使用 REST 端点支持以下 HTTP 身份验证机制:

Expand
身份验证机制描述Security realm 类型相关详情

BASIC

以纯文本格式使用凭证。您应该只使用带有加密连接的 BASIC 身份验证。

属性域和 LDAP 域

对应于 基本 HTTP 身份验证方案,并类似于 PLAIN SASL 机制。

摘要

使用哈希算法和非ce 值。REST 连接器支持 SHA-512SHA-256MD5 哈希算法。

属性域和 LDAP 域

对应于 Digest HTTP 验证方案,它类似于 DIGEST-* SASL 机制。

SPNEGO

使用 Kerberos 票据并需要一个 Kerberos 域控制器。您必须在域配置中添加对应的 kerberos 服务器身份。在大多数情况下,您还要指定一个 ldap-realm 以提供用户成员资格信息。

Kerberos realms

对应于 Negotiate HTTP 身份验证方案,并类似于 GSSAPIGS2-KRB5 SASL 机制。

BEARER_TOKEN

使用 OAuth 令牌并且需要 token-realm 配置。

令牌域

对应于 Bearer HTTP 身份验证方案,并类似于 OAUTHBEARER SASL 机制。

CLIENT_CERT

使用客户端证书。

信任存储域

EXTERNAL SASL 机制类似。

第 4 章 配置 TLS/SSL 加密

您可以通过配置包含 Data Grid 的公钥和私钥的密钥存储来保护数据网格服务器连接的安全性。如果需要 mutual TLS,您还可以配置客户端证书身份验证。

4.1. 配置 Data Grid Server 密钥存储

将密钥存储添加到 Data Grid Server,并将它配置为提供 SSL/TLS 证书,以将其身份验证给客户端。如果安全域包含 TLS/SSL 身份,它将加密所有使用该安全域的 Data Grid Server 端点的连接。

先决条件

  • 创建含有 Data Grid Server 证书或证书链的密钥存储。

数据网格服务器支持以下密钥存储格式:JKS、JCEKS、PKCS12/PFX 和 PEM。如果存在 Bouncy Castle 库,还支持 BKS、BCFKS 和 UBER。

重要

在生产环境中,服务器证书应该由可信证书颁发机构(根)或 Intermediate CA 签名。

提示

如果它们同时包含以下内容,您可以使用 PEM 文件作为密钥存储:

  • PKCS#1 或 PKCS#8 格式的私钥。
  • 个或多个证书。

您还应该使用空密码(密码="")配置 PEM 文件密钥存储。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 将含有 Data Grid Server 的 SSL/TLS 身份的密钥存储添加到 $RHDG_HOME/server/conf 目录中。
  3. 在 Data Grid 服务器 安全域中添加服务器事件定义。
  4. 使用 path 属性指定密钥存储文件名。
  5. 为密钥存储密码和证书别名 提供密钥存储密码别名 属性。
  6. 保存对您的配置的更改。

后续步骤

使用信任存储配置客户端,以便他们可以验证用于 Data Grid 服务器的 SSL/TLS 身份。

密钥存储配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="default">
        <server-identities>
          <ssl>
            <!-- Adds a keystore that contains server certificates that provide SSL/TLS identities to clients. -->
            <keystore path="server.p12"
                      relative-to="infinispan.server.config.path"
                      password="secret"
                      alias="my-server"/>
          </ssl>
        </server-identities>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "default",
        "server-identities": {
          "ssl": {
            "keystore": {
              "alias": "my-server",
              "path": "server.p12",
              "password": "secret"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "default"
        serverIdentities:
          ssl:
            keystore:
              alias: "my-server"
              path: "server.p12"
              password: "secret"
Copy to Clipboard Toggle word wrap

4.1.1. 生成 Data Grid Server 密钥存储

配置 Data Grid Server,使其在启动时自动生成密钥存储。

重要

自动生成的密钥存储:

  • 不应在生产环境中使用。
  • 在需要时生成;例如,从客户端获取第一个连接。
  • 包含您可以在 Hot Rod 客户端中使用的证书。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 在服务器配置中,包含 keystore 元素的 generate-self-signed-certificate-host 属性。
  3. 将服务器证书的主机名指定为值。
  4. 保存对您的配置的更改。
生成的密钥存储配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="GeneratedKeystore">
        <server-identities>
          <ssl>
            <!-- Generates a keystore that includes a self-signed certificate with the specified hostname. -->
            <keystore path="server.p12"
                      relative-to="infinispan.server.config.path"
                      password="secret"
                      alias="server"
                      generate-self-signed-certificate-host="localhost"/>
          </ssl>
        </server-identities>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "GeneratedKeystore",
        "server-identities": {
          "ssl": {
            "keystore": {
              "alias": "server",
              "generate-self-signed-certificate-host": "localhost",
              "path": "server.p12",
              "password": "secret"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "GeneratedKeystore"
        serverIdentities:
          ssl:
            keystore:
              alias: "server"
              generateSelfSignedCertificateHost: "localhost"
              path: "server.p12"
              password: "secret"
Copy to Clipboard Toggle word wrap

4.1.2. 配置 TLS 版本和密码套件

当使用 SSL/TLS 加密来保护部署时,您可以将 Data Grid 服务器配置为使用特定的 TLS 协议版本以及协议中的特定密码套件。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. engine 元素添加到 Data Grid Server 的 SSL 配置中。
  3. 将 Data Grid 配置为使用具有 enabled-protocols 属性的一个或多个 TLS 版本。

    Data Grid Server 默认支持 TLS 版本 1.2 和 1.3。如果正确设置了 TLSv1.3,则只为了限制客户端连接的安全协议。数据网格不建议启用 TLSv1.1, 因为它是支持有限的旧协议,并提供弱的安全性。您应该不会启用任何比 1.1 旧的 TLS 版本。

    警告

    如果您修改 Data Grid Server 的 SSL 引擎 配置,则必须使用 enabled-protocols 属性显式配置 TLS 版本。省略 enabled-protocols 属性允许任何 TLS 版本。

    <engine enabled-protocols="TLSv1.3 TLSv1.2" />
    Copy to Clipboard Toggle word wrap
  4. 将 Data Grid 配置为使用带有 enabled-ciphersuites 属性(用于 TLSv1.2 及以下)的一个或多个密码套件,以及 enabled-ciphersuites-tls13 属性(用于 TLSv1.3)。

    您必须确保设置支持计划使用的任何协议功能的密码套件,例如 HTTP/2 ALPN

  5. 保存对您的配置的更改。
SSL 引擎配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="default">
        <server-identities>
          <ssl>
            <keystore path="server.p12"
                      relative-to="infinispan.server.config.path"
                      password="secret"
                      alias="server"/>
            <!-- Configures Data Grid Server to use specific TLS versions and cipher suites. -->
            <engine enabled-protocols="TLSv1.3 TLSv1.2"
                    enabled-ciphersuites="TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256"
                    enabled-ciphersuites-tls13="TLS_AES_256_GCM_SHA384"/>
          </ssl>
        </server-identities>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "default",
        "server-identities": {
          "ssl": {
            "keystore": {
              "alias": "server",
              "path": "server.p12",
              "password": "secret"
            },
            "engine": {
              "enabled-protocols": ["TLSv1.3"],
              "enabled-ciphersuites": "TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256",
              "enabled-ciphersuites-tls13": "TLS_AES_256_GCM_SHA384"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "default"
        serverIdentities:
          ssl:
            keystore:
              alias: "server"
              path: "server.p12"
              password: "secret"
            engine:
              enabledProtocols:
                - "TLSv1.3"
              enabledCiphersuites: "TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256"
              enabledCiphersuitesTls13: "TLS_AES_256_GCM_SHA384"
Copy to Clipboard Toggle word wrap

FIPS (Federal Information Processing Standards)是美国联邦计算机系统的标准和准则。虽然 FIPS 由美国联邦政府开发,但很多位于私营部门使用这些标准。

FIPS 140-2 定义加密模块的安全要求。您可以使用替代 JDK 安全供应商,将 Data Grid Server 配置为使用遵循 FIPS 140-2 规格的加密密码。

4.2.1. 配置 PKCS11 加密供应商

您可以使用 SunPKCS11-NSS-FIPS 供应商指定 PKCS11 密钥存储来配置 PKCS11 加密供应商。

先决条件

  • 为 FIPS 模式配置系统。您可以通过在 Data Grid 命令行界面(CLI)中发出 fips-mode-setup --check 命令检查您的系统是否启用了 FIPS 模式
  • 使用 certutil 工具初始化系统范围的 NSS 数据库。
  • 使用配置为启用 SunPKCS11 供应商的 java.security 文件安装 JDK。这个供应商指向 NSS 数据库和 SSL 供应商。
  • 在 NSS 数据库中安装证书。
注意

OpenSSL 供应商需要一个私钥,但您无法从 PKCS alternatives 存储检索私钥。FIPS 会阻止来自 FIPS 兼容加密模块的未加密的密钥导出,因此当处于 FIPS 模式时,您无法将 OpenSSL 供应商用于 TLS。您可以使用 -Dorg.infinispan.openssl=false 参数在启动时禁用 OpenSSL 供应商。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 在 Data Grid 服务器 安全域中添加服务器事件定义。
  3. 使用 SunPKCS11-NSS-FIPS 供应商指定 PKCS11 密钥存储。
  4. 保存对您的配置的更改。
密钥存储配置

XML

<server xmlns="urn:infinispan:server:13.0">
   <security>
      <security-realms>
         <security-realm name="default">
            <server-identities>
               <ssl>
                  <!-- Adds a keystore that reads certificates from the NSS database. -->
                  <keystore provider="SunPKCS11-NSS-FIPS" type="PKCS11"/>
               </ssl>
            </server-identities>
         </security-realm>
      </security-realms>
   </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "default",
        "server-identities": {
          "ssl": {
            "keystore": {
              "provider": "SunPKCS11-NSS-FIPS",
              "type": "PKCS11"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "default"
        serverIdentities:
          ssl:
            keystore:
              provider: "SunPKCS11-NSS-FIPS"
              type: "PKCS11"
Copy to Clipboard Toggle word wrap

4.2.2. 配置 Bouncy Castle FIPS 加密供应商

您可以在 Data Grid 服务器配置 中配置 Bouncy Castle FIPS (Federal Information Processing Standards)加密供应商。

先决条件

  • 为 FIPS 模式配置系统。您可以通过在 Data Grid 命令行界面(CLI)中发出 fips-mode-setup --check 命令检查您的系统是否启用了 FIPS 模式。
  • 以 BCFKS 格式创建包含证书的密钥存储。

流程

  1. 下载 Bouncy Castle FIPS JAR 文件,并将文件添加到 Data Grid Server 安装的 server/lib 目录中。
  2. 要安装 Bouncy Castle,请发出 install 命令:

    [disconnected]> install org.bouncycastle:bc-fips:1.0.2.3
    Copy to Clipboard Toggle word wrap
  3. 打开 Data Grid Server 配置进行编辑。
  4. 在 Data Grid 服务器 安全域中添加服务器事件定义。
  5. 使用 BCFIPS 供应商指定 BCFKS keystore。
  6. 保存对您的配置的更改。
密钥存储配置

XML

<server xmlns="urn:infinispan:server:13.0">
   <security>
      <security-realms>
         <security-realm name="default">
            <server-identities>
               <ssl>
                  <!-- Adds a keystore that reads certificates from the BCFKS keystore. -->
                  <keystore path="server.bcfks" password="secret" alias="server" provider="BCFIPS" type="BCFKS"/>
               </ssl>
            </server-identities>
         </security-realm>
      </security-realms>
   </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "default",
        "server-identities": {
          "ssl": {
            "keystore": {
              "path": "server.bcfks",
              "password": "secret",
              "alias": "server",
              "provider": "BCFIPS",
              "type": "BCFKS"
            }
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "default"
        serverIdentities:
          ssl:
            keystore:
              path: "server.bcfks"
              password: "secret"
              alias: "server"
              provider: "BCFIPS"
              type: "BCFKS"
Copy to Clipboard Toggle word wrap

4.3. 配置客户端证书身份验证

配置 Data Grid 服务器以使用 mutual TLS 来保护客户端连接。

您可以通过两种方式配置 Data Grid,以两种方式验证来自证书的客户端身份:

  • 需要仅包含签名证书的信任存储,通常是证书颁发机构(CA)。显示 CA 签名的证书的任何客户端都可以连接到 Data Grid。
  • 需要包含签名证书外的所有客户端证书的信任存储。只有存在信任存储中签名的证书的客户端才能连接到 Data Grid。
提示

另外,要提供信任存储,您可以使用共享系统证书。

先决条件

  • 创建包含 CA 证书或所有公共证书的客户端信任存储。
  • 为 Data Grid Server 创建密钥存储并配置 SSL/TLS 身份。
注意

PEM 文件可用作其包含一个或多个证书的信任存储。这些信任存储应配置为使用空密码: password=""

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. require-ssl-client-auth="true" 参数添加到您的 端点 配置中。
  3. 将客户端信任存储添加到 $RHDG_HOME/server/conf 目录中。
  4. 在 Data Grid Server security realm 配置中指定 truststore 元素 的路径 和密码 属性。
  5. 如果您希望 Data Grid Server 验证每个 客户端证书,请将 <truststore-realm /> 元素添加到安全域中。
  6. 保存对您的配置的更改。

后续步骤

  • 如果您使用安全角色和权限控制访问,请在 Data Grid Server 配置中使用客户端证书设置授权。
  • 将客户端配置为与 Data Grid Server 协商 SSL/TLS 连接。
客户端证书验证配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="TrustStoreRealm">
        <server-identities>
          <ssl>
            <!-- Provides an SSL/TLS identity with a keystore that
                 contains server certificates. -->
            <keystore path="server.p12"
                      relative-to="infinispan.server.config.path"
                      keystore-password="secret"
                      alias="server"/>
            <!-- Configures a trust store that contains client certificates
                 or part of a certificate chain. -->
            <truststore path="trust.p12"
                        relative-to="infinispan.server.config.path"
                        password="secret"/>
          </ssl>
        </server-identities>
        <!-- Authenticates client certificates against the trust store. If you configure this, the trust store must contain the public certificates for all clients. -->
        <truststore-realm/>
      </security-realm>
    </security-realms>
  </security>
  <endpoints>
    <endpoint socket-binding="default"
              security-realm="trust-store-realm"
              require-ssl-client-auth="true">
      <hotrod-connector>
        <authentication>
          <sasl mechanisms="EXTERNAL"
                server-name="infinispan"
                qop="auth"/>
        </authentication>
      </hotrod-connector>
      <rest-connector>
        <authentication mechanisms="CLIENT_CERT"/>
      </rest-connector>
    </endpoint>
  </endpoints>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "TrustStoreRealm",
        "server-identities": {
          "ssl": {
            "keystore": {
              "path": "server.p12",
              "relative-to": "infinispan.server.config.path",
              "keystore-password": "secret",
              "alias": "server"
            },
            "truststore": {
              "path": "trust.p12",
              "relative-to": "infinispan.server.config.path",
              "password": "secret"
            }
          }
        },
        "truststore-realm": {}
      }]
    },
    "endpoints": [{
      "socket-binding": "default",
      "security-realm": "TrustStoreRealm",
      "require-ssl-client-auth": "true",
      "connectors": {
        "hotrod": {
          "hotrod-connector": {
            "authentication": {
              "sasl": {
                "mechanisms": "EXTERNAL",
                "server-name": "infinispan",
                "qop": "auth"
              }
            }
          },
          "rest": {
            "rest-connector": {
              "authentication": {
                "mechanisms": "CLIENT_CERT"
              }
            }
          }
        }
      }
    }]
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    securityRealms:
      - name: "TrustStoreRealm"
        serverIdentities:
          ssl:
            keystore:
              path: "server.p12"
              relative-to: "infinispan.server.config.path"
              keystore-password: "secret"
              alias: "server"
            truststore:
              path: "trust.p12"
              relative-to: "infinispan.server.config.path"
              password: "secret"
        truststoreRealm: ~
  endpoints:
    socketBinding: "default"
    securityRealm: "trust-store-realm"
    requireSslClientAuth: "true"
    connectors:
      - hotrod:
          hotrodConnector:
            authentication:
              sasl:
                mechanisms: "EXTERNAL"
                serverName: "infinispan"
                qop: "auth"
      - rest:
          restConnector:
            authentication:
              mechanisms: "CLIENT_CERT"
Copy to Clipboard Toggle word wrap

4.4. 使用客户端证书配置授权

启用客户端证书身份验证意味着您无需在客户端配置中指定 Data Grid 用户凭证,这意味着您必须将角色与客户端证书中的通用名称(CN)字段关联。

先决条件

  • 为客户端提供包含其公共证书或证书链的一部分(通常是公共 CA 证书)的 Java 密钥存储。
  • 配置 Data Grid Server 以执行客户端证书身份验证。

流程

  1. 打开 Data Grid Server 配置进行编辑。
  2. 在安全授权配置中启用 common-name-role-mapper
  3. 为客户端证书中的通用名称(CN)分配一个具有适当权限的角色。
  4. 保存对您的配置的更改。
客户端证书授权配置

XML

<infinispan>
  <cache-container name="certificate-authentication" statistics="true">
    <security>
      <authorization>
        <!-- Declare a role mapper that associates the common name (CN) field in client certificate trust stores with authorization roles. -->
        <common-name-role-mapper/>
        <!-- In this example, if a client certificate contains `CN=Client1` then clients with matching certificates get ALL permissions. -->
        <role name="Client1" permissions="ALL"/>
      </authorization>
    </security>
  </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

JSON

{
  "infinispan": {
    "cache-container": {
      "name": "certificate-authentication",
      "security": {
        "authorization": {
          "common-name-role-mapper": null,
          "roles": {
            "Client1": {
              "role": {
                "permissions": "ALL"
              }
            }
          }
        }
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

infinispan:
  cacheContainer:
    name: "certificate-authentication"
    security:
      authorization:
        commonNameRoleMapper: ~
        roles:
          Client1:
            role:
              permissions:
                - "ALL"
Copy to Clipboard Toggle word wrap

外部服务需要凭证来使用 Data Grid 服务器进行身份验证。为保护敏感文本字符串,如密码,将它们添加到凭据密钥存储中,而不是直接在 Data Grid Server 配置文件中。

然后,您可以配置 Data Grid Server 以解密密码以便与数据库或 LDAP 目录等服务建立连接。

重要

$RHDG_HOME/server/conf 中的纯文本密码未加密。任何对主机文件系统具有读取访问权限的用户帐户都可以查看纯文本密码。

虽然凭据密钥存储是受密码保护的存储加密密码,对主机文件系统具有写入访问权限的任何用户帐户都可以篡改。

要完全安全的 Data Grid 服务器凭证,您应该只向可以配置和运行 Data Grid Server 的用户帐户授予读写访问权限。

5.1. 设置凭证密钥存储

创建用于加密 Data Grid 服务器访问的凭据的密钥存储。

凭据密钥存储至少包含一个与加密密码关联的别名。创建密钥存储后,您可以在连接配置(如数据库连接池)中指定别名。然后,在服务尝试身份验证时,Data Grid 服务器从密钥存储解密该别名的密码。

您可以根据需要,创建多个凭据密钥存储,使其具有许多别名。

流程

  1. $RHDG_HOME 中打开一个终端。
  2. 创建密钥存储并使用 credentials 命令向其添加 凭据

    提示

    默认情况下,密钥存储类型为 PKCS12。运行 帮助凭据,以获取有关更改密钥存储的默认值的详细信息。

    以下示例演示了如何为密码"changeme"创建包含"dbpassword"别名的密钥存储。在创建密钥存储时,您还将通过 -p 参数指定密钥存储的密码。

    Linux
    bin/cli.sh credentials add dbpassword -c changeme -p "secret1234!"
    Copy to Clipboard Toggle word wrap
    Microsoft Windows
    bin\cli.bat credentials add dbpassword -c changeme -p "secret1234!"
    Copy to Clipboard Toggle word wrap
  3. 检查别名是否已添加到密钥存储中。

    bin/cli.sh credentials ls -p "secret1234!"
    dbpassword
    Copy to Clipboard Toggle word wrap
  4. 配置 Data Grid 以使用凭据密钥存储。

    1. 在凭据存储配置中指定 凭据密钥存储的名称和位置
    2. credential-reference 配置中提供凭据密钥存储和别名。

      提示

      credential-reference 配置中的属性是可选的。

      • 只有在有多个密钥存储时才需要 存储
      • 只有在密钥存储包含多个别名时才需要别名。

5.2. 凭证密钥存储配置

本主题提供了 Data Grid Server 配置中凭据密钥存储的示例。

凭证密钥存储

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <!-- Uses a keystore to manage server credentials. -->
    <credential-stores>
      <!-- Specifies the name and filesystem location of a keystore. -->
      <credential-store name="credentials" path="credentials.pfx">
        <!-- Specifies the password for the credential keystore. -->
        <clear-text-credential clear-text="secret1234!"/>
      </credential-store>
    </credential-stores>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "credential-stores": [{
        "name": "credentials",
        "path": "credentials.pfx",
        "clear-text-credential": {
          "clear-text": "secret1234!"
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    credentialStores:
      - name: credentials
        path: credentials.pfx
        clearTextCredential:
          clearText: "secret1234!"
Copy to Clipboard Toggle word wrap

数据源连接

XML

<server xmlns="urn:infinispan:server:13.0">
  <data-sources>
    <data-source name="postgres"
                 jndi-name="jdbc/postgres">
      <!-- Specifies the database username in the connection factory. -->
      <connection-factory driver="org.postgresql.Driver"
                          username="dbuser"
                          url="${org.infinispan.server.test.postgres.jdbcUrl}">
        <!-- Specifies the credential keystore that contains an encrypted password and the alias for it. -->
        <credential-reference store="credentials"
                              alias="dbpassword"/>
      </connection-factory>
      <connection-pool max-size="10"
                       min-size="1"
                       background-validation="1000"
                       idle-removal="1"
                       initial-size="1"
                       leak-detection="10000"/>
    </data-source>
  </data-sources>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "data-sources": [{
      "name": "postgres",
      "jndi-name": "jdbc/postgres",
      "connection-factory": {
        "driver": "org.postgresql.Driver",
        "username": "dbuser",
        "url": "${org.infinispan.server.test.postgres.jdbcUrl}",
        "credential-reference": {
          "store": "credentials",
          "alias": "dbpassword"
        }
      }
    }]
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  dataSources:
    - name: postgres
      jndiName: jdbc/postgres
      connectionFactory:
        driver: org.postgresql.Driver
        username: dbuser
        url: '${org.infinispan.server.test.postgres.jdbcUrl}'
        credentialReference:
          store: credentials
          alias: dbpassword
Copy to Clipboard Toggle word wrap

LDAP 连接

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <credential-stores>
      <credential-store name="credentials"
                        path="credentials.pfx">
        <clear-text-credential clear-text="secret1234!"/>
      </credential-store>
    </credential-stores>
    <security-realms>
      <security-realm name="default">
        <!-- Specifies the LDAP principal in the connection factory. -->
        <ldap-realm name="ldap"
                    url="ldap://my-ldap-server:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org">
          <!-- Specifies the credential keystore that contains an encrypted password and the alias for it. -->
          <credential-reference store="credentials"
                                alias="ldappassword"/>
        </ldap-realm>
      </security-realm>
    </security-realms>
  </security>
</server>
Copy to Clipboard Toggle word wrap

JSON

{
  "server": {
    "security": {
      "credential-stores": [{
        "name": "credentials",
        "path": "credentials.pfx",
        "clear-text-credential": {
          "clear-text": "secret1234!"
        }
      }],
      "security-realms": [{
        "name": "default",
        "ldap-realm": {
          "name": "ldap",
          "url": "ldap://my-ldap-server:10389",
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "credential-reference": {
            "store": "credentials",
            "alias": "ldappassword"
          }
        }
      }]
    }
  }
}
Copy to Clipboard Toggle word wrap

YAML

server:
  security:
    credentialStores:
      - name: credentials
        path: credentials.pfx
        clearTextCredential:
          clearText: "secret1234!"
    securityRealms:
      - name: "default"
        ldapRealm:
          name: ldap
          url: 'ldap://my-ldap-server:10389'
          principal: 'uid=admin,ou=People,dc=infinispan,dc=org'
          credentialReference:
            store: credentials
            alias: ldappassword
Copy to Clipboard Toggle word wrap

第 6 章 加密集群传输

保护集群传输,以便节点与加密消息通信。您还可以配置 Data Grid 集群来执行证书验证,以便只有具有有效身份的节点可以加入。

6.1. 使用 TLS 身份保护集群传输

将 SSL/TLS 身份添加到 Data Grid 服务器安全域,并使用它们来保护集群传输。然后,Data Grid Server 集群中的节点交换 SSL/TLS 证书来加密 JGroups 消息,包括 RELAY 消息(如果配置了跨站点复制)。

先决条件

  • 安装 Data Grid Server 集群。

流程

  1. 创建一个 TLS 密钥存储,其中包含用于识别数据网格服务器的单一证书。

    如果它包含 PKCS#1 或 PKCS#8 格式的私钥,以及证书,以及一个空密码: password="",您可以使用 PEM 文件。

    注意

    如果密钥存储中的证书不是由公共证书颁发机构(CA)签名,则还必须创建包含签名证书或公钥的信任存储。

  2. 将密钥存储添加到 $RHDG_HOME/server/conf 目录中。
  3. 将密钥存储添加到 Data Grid Server 配置中的新安全域。

    重要

    您应该创建专用的密钥存储和安全域,以便 Data Grid Server 端点不像集群传输一样使用相同的安全域。

    <server xmlns="urn:infinispan:server:13.0">
      <security>
        <security-realms>
          <security-realm name="cluster-transport">
            <server-identities>
              <ssl>
                <!-- Adds a keystore that contains a certificate that provides SSL/TLS identity to encrypt cluster transport. -->
                <keystore path="server.pfx"
                          relative-to="infinispan.server.config.path"
                          password="secret"
                          alias="server"/>
              </ssl>
            </server-identities>
          </security-realm>
        </security-realms>
      </security>
    </server>
    Copy to Clipboard Toggle word wrap
  4. 使用 server:security-realm 属性指定安全域,将集群传输配置为使用安全域。

    <infinispan>
      <cache-container>
        <transport server:security-realm="cluster-transport"/>
      </cache-container>
    </infinispan>
    Copy to Clipboard Toggle word wrap

验证

当您启动 Data Grid Server 时,以下日志消息表示集群正在将安全域用于集群传输:

[org.infinispan.SERVER] ISPN080060: SSL Transport using realm <security_realm_name>
Copy to Clipboard Toggle word wrap

6.2. JGroups 加密协议

为保护集群流量,您可以配置 Data Grid 节点,以使用机密密钥加密 JGroups 消息有效负载。

Data Grid 节点可以从以下任一位置获取 secret 密钥:

  • 协调器节点(基本指标加密)。
  • 共享密钥存储(symmetric 加密)。

从协调器节点检索 secret 密钥

您可以通过在 Data Grid 配置中将 ASYM_ENCRYPT 协议添加到 JGroups 堆栈来配置非对称加密。这允许 Data Grid 集群生成并分发 secret 密钥。

重要

在使用非对称加密时,您还应提供密钥存储,以便节点能够执行证书身份验证和安全地交换密钥。这会防止集群不受中间人(MitM)攻击。

非对称加密可以保护集群流量,如下所示:

  1. Data Grid 集群中的第一个节点(协调器节点)会生成 secret 密钥。
  2. 加入的节点使用协调器执行证书验证,以相互验证身份。
  3. 加入的节点从协调器节点请求 secret 密钥。该请求包括加入节点的公钥。
  4. 协调器节点使用公钥加密 secret 密钥,并将其返回到加入的节点。
  5. 加入的节点解密并安装 secret 密钥。
  6. 节点加入集群,使用 secret 密钥加密和解密信息。

从共享密钥存储检索 secret 密钥

您可以通过在 Data Grid 配置中将 SYM_ENCRYPT 协议添加到 JGroups 堆栈来配置对称加密。这允许 Data Grid 集群从您提供的密钥存储中获取 secret 密钥。

  1. 节点在启动时从 Data Grid classpath 上的密钥存储安装 secret 密钥。
  2. 节点加入集群,使用 secret 密钥加密和解密信息。

非对称和对称加密的比较

带有证书身份验证的 ASYM_ENCRYPT 提供了额外的加密层,与 SYM_ENCRYPT 进行比较。您提供对请求进行加密的密钥存储,以协调机密密钥的节点。Data Grid 会自动生成该 secret 密钥并处理集群流量,同时让您指定何时生成 secret 密钥。例如,您可以配置集群以在节点离开时生成新的 secret 密钥。这样可确保节点无法绕过证书身份验证,并使用旧密钥加入。

另一方面,SY M_ENCRYPTASYM_ENCRYPT 快,因为节点不需要与集群协调器交换密钥。SYM_ENCRYPT 的一个潜在的缺点是,当集群成员资格更改时,没有配置可自动生成新的 secret 密钥。用户负责生成和分发节点用于加密集群流量的 secret 密钥。

6.3. 使用非对称加密保护集群传输

配置 Data Grid 集群,以生成和分发加密 JGroups 消息的 secret 密钥。

流程

  1. 创建具有证书链的密钥存储,使 Data Grid 能够验证节点身份。
  2. 将密钥存储放在集群中的每个节点的类路径上。

    对于 Data Grid Server,您可以将密钥存储放在 $RHDG_HOME 目录中。

  3. SSL_KEY_EXCHANGEASYM_ENCRYPT 协议添加到数据网格配置中的 JGroups 堆栈,如下例所示:

    <infinispan>
      <jgroups>
        <!-- Creates a secure JGroups stack named "encrypt-tcp" that extends the default TCP stack. -->
        <stack name="encrypt-tcp" extends="tcp">
          <!-- Adds a keystore that nodes use to perform certificate authentication. -->
          <!-- Uses the stack.combine and stack.position attributes to insert SSL_KEY_EXCHANGE into the default TCP stack after VERIFY_SUSPECT. -->
          <SSL_KEY_EXCHANGE keystore_name="mykeystore.jks"
                            keystore_password="changeit"
                            stack.combine="INSERT_AFTER"
                            stack.position="VERIFY_SUSPECT"/>
          <!-- Configures ASYM_ENCRYPT -->
          <!-- Uses the stack.combine and stack.position attributes to insert ASYM_ENCRYPT into the default TCP stack before pbcast.NAKACK2. -->
          <!-- The use_external_key_exchange = "true" attribute configures nodes to use the `SSL_KEY_EXCHANGE` protocol for certificate authentication. -->
          <ASYM_ENCRYPT asym_keylength="2048"
                        asym_algorithm="RSA"
                        change_key_on_coord_leave = "false"
                        change_key_on_leave = "false"
                        use_external_key_exchange = "true"
                        stack.combine="INSERT_BEFORE"
                        stack.position="pbcast.NAKACK2"/>
        </stack>
      </jgroups>
      <cache-container name="default" statistics="true">
        <!-- Configures the cluster to use the JGroups stack. -->
        <transport cluster="${infinispan.cluster.name}"
                   stack="encrypt-tcp"
                   node-name="${infinispan.node.name:}"/>
      </cache-container>
    </infinispan>
    Copy to Clipboard Toggle word wrap

验证

当您启动 Data Grid 集群时,以下日志消息表示集群使用 secure JGroups 堆栈:

[org.infinispan.CLUSTER] ISPN000078: Starting JGroups channel cluster with stack <encrypted_stack_name>
Copy to Clipboard Toggle word wrap

只有使用 ASYM_ENCRYPT,并且可以从协调器节点获取 secret 密钥时,才可以加入集群。否则,以下消息被写入 Data Grid 日志:

[org.jgroups.protocols.ASYM_ENCRYPT] <hostname>: received message without encrypt header from <hostname>; dropping it
Copy to Clipboard Toggle word wrap

6.4. 使用对称加密保护集群传输

配置 Data Grid 集群,以使用您提供的密钥存储的机密密钥加密 JGroups 消息。

流程

  1. 创建包含机密密钥的密钥存储。
  2. 将密钥存储放在集群中的每个节点的类路径上。

    对于 Data Grid Server,您可以将密钥存储放在 $RHDG_HOME 目录中。

  3. SYM_ENCRYPT 协议添加到数据网格配置中的 JGroups 堆栈。
<infinispan>
  <jgroups>
    <!-- Creates a secure JGroups stack named "encrypt-tcp" that extends the default TCP stack. -->
    <stack name="encrypt-tcp" extends="tcp">
      <!-- Adds a keystore from which nodes obtain secret keys. -->
      <!-- Uses the stack.combine and stack.position attributes to insert SYM_ENCRYPT into the default TCP stack after VERIFY_SUSPECT. -->
      <SYM_ENCRYPT keystore_name="myKeystore.p12"
                   keystore_type="PKCS12"
                   store_password="changeit"
                   key_password="changeit"
                   alias="myKey"
                   stack.combine="INSERT_AFTER"
                   stack.position="VERIFY_SUSPECT"/>
    </stack>
  </jgroups>
  <cache-container name="default" statistics="true">
    <!-- Configures the cluster to use the JGroups stack. -->
    <transport cluster="${infinispan.cluster.name}"
               stack="encrypt-tcp"
               node-name="${infinispan.node.name:}"/>
  </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

验证

当您启动 Data Grid 集群时,以下日志消息表示集群使用 secure JGroups 堆栈:

[org.infinispan.CLUSTER] ISPN000078: Starting JGroups channel cluster with stack <encrypted_stack_name>
Copy to Clipboard Toggle word wrap

只有使用 SYM_ENCRYPT 并且可以从共享密钥存储获取 secret 密钥时,才可以加入集群。否则,以下消息被写入 Data Grid 日志:

[org.jgroups.protocols.SYM_ENCRYPT] <hostname>: received message without encrypt header from <hostname>; dropping it
Copy to Clipboard Toggle word wrap

第 7 章 数据网格端口和协议

随着数据网格在整个网络上分发数据,并可为外部客户端请求建立连接,您应该了解数据网格用来处理网络流量的端口和协议。

如果以远程服务器身份运行 Data Grid,您可能需要通过防火墙允许远程客户端。同样,您应该调整 Data Grid 节点用于集群通信的端口,以防止冲突或网络问题。

7.1. Data Grid Server 端口和协议

Data Grid Server 提供网络端点,允许客户端访问不同的协议。

Expand
端口协议描述

11222

TCP

热环和 REST

11221

TCP

memcached (默认为禁用)

单个端口

数据网格服务器通过单个 TCP 端口 11222 公开多个协议。使用单一端口处理多个协议简化了配置,降低部署数据网格集群时的管理复杂性。使用单个端口还通过最小化网络上的攻击面来增强安全性。

数据网格服务器以不同的方式通过单一端口处理来自客户端的 HTTP/1.1、HTTP/2 和 Hot Rod 协议请求。

HTTP/1.1 升级标头

客户端请求可以包含 HTTP/1.1 upgrade 标头字段来发起与 Data Grid Server 的 HTTP/1.1 连接。然后,客户端应用程序可以发送 Upgrade: protocol 标头字段,其中 protocol 是服务器端点。

application-Layer Protocol Negotiation (ALPN)/Transport Layer Security (TLS)

客户端请求包括 Data Grid Server 端点的 Server Name Indication (SNI)映射,以便在 TLS 连接中协商协议。

注意

应用程序必须使用支持 ALPN 扩展的 TLS 库。数据网格将 WildFly OpenSSL 绑定用于 Java。

自动 Hot Rod 检测

包含 Hot Rod 标头的客户端请求会自动路由到 Hot Rod 端点。

7.1.1. 为 Data Grid 流量配置网络防火墙

调整防火墙规则,以允许 Data Grid 服务器和客户端应用程序之间的流量。

流程

例如,在 Red Hat Enterprise Linux (RHEL)工作站中,您可以使用 firewalld 来允许到端口 11222 的流量,如下所示:

# firewall-cmd --add-port=11222/tcp --permanent
success
# firewall-cmd --list-ports | grep 11222
11222/tcp
Copy to Clipboard Toggle word wrap

要配置网络适用的防火墙规则,您可以使用 nftables 实用程序。

7.2. 集群流量的 TCP 和 UDP 端口

Data Grid 将以下端口用于集群传输消息:

Expand
默认端口协议描述

7800

TCP/UDP

JGroups 集群绑定端口

46655

UDP

JGroups 多播

跨站点复制

数据网格为 JGroups RELAY2 协议使用以下端口:

7900
对于在 OpenShift 上运行的 Data Grid 集群。
7800
如果将 UDP 用于节点和 TCP 间的流量,用于集群间的流量。
7801
如果将 TCP 用于节点和 TCP 间的流量,用于集群间的流量。

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat