Authentication using Athenz

Athenz is a role-based authentication/authorization system. In Pulsar, you can use Athenz role tokens (also known as z-tokens) to establish the identify of the client.

Athenz 身份验证设置

A decentralized Athenz system contains an authoriZation Management System (ZMS) server and an authoriZation Token System (ZTS) server.

首先,你需要启用 Athenz 的服务访问控制。 You need to create domains for the provider (which provides some resources to other services with some authentication/authorization policies) and the tenant (which is provisioned to access some resources in a provider). 在这种情况下,供应商与 Pulsar 服务本身相对应,租户与使用 Pulsar 的每个应用程序相对应(通常情况下,指 Pulsar 中的租户)。

创建租户域和服务

租户 一侧,你需要做以下事情:

  1. 创建一个域名,如 shopping
  2. 生成私钥/公钥对
  3. 使用公钥在域上创建服务,例如 some _app

请注意,当 Pulsar 客户端必须使用步骤2生成的私钥连接到 broker。(参见 JavaC++ 的客户端配置示例)。

For more specific steps involving the Athenz UI, refer to Example Service Access Control Setup.

创建提供商域并将租户服务添加到某些角色成员

在提供商一侧,你需要做以下事情:

  1. 创建一个域名,例如 pulsar
  2. 创建角色
  3. 将租户服务添加到角色成员

请注意,你可以在步骤2中指定任何动作和资源,因为它们不在 Pulsar上使用。 In other words, Pulsar uses the Athenz role token only for authentication, not for authorization.

For more specific steps involving UI, refer to Example Service Access Control Setup.

配置 Athenz 的 broker

TLS 加密

注意当你使用 Athenz 作为认证提供者时, 可以更好地使用 TLS 加密 ,因为它可以保护角色令牌不被拦截和重新使用。 (for more details involving TLS encrption see Architecture - Data Model).

conf/broker.onf 中,你的 Pulsar 安装的配置文件,需要提供 Athenz 身份验证提供者的类名以及一个逗号分隔的提供者域名列表。

  1. # Add the Athenz auth provider
  2. authenticationEnabled=true
  3. authorizationEnabled=true
  4. authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderAthenz
  5. athenzDomainNames=pulsar
  6. # Enable TLS
  7. tlsEnabled=true
  8. tlsCertificateFilePath=/path/to/broker-cert.pem
  9. tlsKeyFilePath=/path/to/broker-key.pem
  10. # Authentication settings of the broker itself. Used when the broker connects to other brokers, either in same or other clusters
  11. brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationAthenz
  12. brokerClientAuthenticationParameters={"tenantDomain":"shopping","tenantService":"some_app","providerDomain":"pulsar","privateKey":"file:///path/to/private.pem","keyId":"v1"}

conf/broker中可以找到完整的参数列表.onf 文件,你也可以在 Broker 配置 中找到这些参数的默认值。

配置 Athenz 客户端

关于使用 Athenz 的 Pulsar 客户端身份验证的更多信息,请参阅以下针对语言的文件:

配置 Athenz 的 CLI 工具

命令行工具 pulsar-admin, pulsar-perf pulsar-client 使用 conf/client. onf 配置文件在 Pulsar 安装中。

你需要将以下验证参数添加到 conf/client.conff 配置文件以使用 Athenz 的 Pulsar 的 CLI 工具:

  1. # URL for the broker
  2. serviceUrl=https://broker.example.com:8443/
  3. # Set Athenz auth plugin and its parameters
  4. authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationAthenz
  5. authParams={"tenantDomain":"shopping","tenantService":"some_app","providerDomain":"pulsar","privateKey":"file:///path/to/private.pem","keyId":"v1"}
  6. # Enable TLS
  7. useTls=true
  8. tlsAllowInsecureConnection=false
  9. tlsTrustCertsFilePath=/path/to/cacert.pem