トークン認証の構成

OAuth 2 Authorization Framework を使用すると、サードパーティアプリケーションに HTTP サービスへの限定的なアクセス権限の取得を許可できます。リソースオーナーと HTTP サービスの間で承認のためのやり取りを調整することでリソースオーナーの代理としてサードパーティアプリケーションにアクセスを許可することも、サードパーティアプリケーション自身によるアクセス要求を許可することもできます。SASL OAUTHBEARER メカニズムでは、SASL(HTTP 以外)のコンテキストで、このフレームワークの使用が可能になります( RFC 7628 で定義されています)。Apache Kafka® での OAUTHBEARER のデフォルト実装では、セキュアではない JSON Web Tokens を作成し、検証します。これが適しているのは、本稼働環境以外の Kafka インストールだけです。Kafka クライアントはもちろん、Confluent Metrics Reporter もブローカー間プロトコルも OAUTHBEARER を使用するべきではありません。詳細については、「SASL/OAUTHBEARER のセキュリティの考慮事項」を参照してください。

MDS では暗号で署名されたトークンの導入によってこれが拡張されているため、サービス間でユーザーシークレットを転送することなく、ユーザーの認証証明をやり取りできます。この機能が本稼働環境のシステムで一般的に使用できるようになった後は、暗号で署名されたトークンが最適なソリューションとなります。MDS の構成の詳細については、「Metadata Service (MDS) の構成」を参照してください。

Kafka ブローカーの構成

  1. server.properties で SASL ポートと SASL メカニズムを構成します(こちら を参照してください)。

    以下に例を示します。

    # Add named listener RBAC to existing listeners and advertised.listeners
    listeners=RBAC://:9092,existing_listener://:9093
    advertised.listeners=RBAC://localhost:9092,existing_listener://localhost:9093
    
    # Add protocol mapping for newly-added named listener RBAC
    listener.security.protocol.map=existinglistener:existingsecurity,RBAC:SASL_PLAINTEXT (or SASL_SSL if production)
    listener.name.rbac.sasl.enabled.mechanisms=OAUTHBEARER
    
    # Configure the public key used to verify RBAC Metadata Service signatures
    # username, password and metadataServerUrls must be set if used for inter-broker communication
    listener.name.rbac.oauthbearer.sasl.jaas.config= \
      org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
      publicKeyPath=“<path-to-mds-public-key>“;
    
    # Set SASL callback handler to verify authentication token signatures
    listener.name.rbac.oauthbearer.sasl.server.callback.handler.class=io.confluent.kafka.server.plugins.auth.token.TokenBearerValidatorCallbackHandler
    
    # Set interbroker protocol to SASL_PLAINTEXT
    sasl.mechanism.inter.broker.protocol=PLAIN
    security.inter.broker.protocol=SASL_PLAINTEXT
    
  2. クライアントトークンを検証するための OAuthBearerLoginModule コールバックハンドラーを構成します。

    sasl.server.callback.handler.class=io.confluent.kafka.server.plugins.auth.token.TokenBearerValidatorCallbackHandler
    sasl.login.callback.handler.class=io.confluent.kafka.server.plugins.auth.token.TokenBearerServerLoginCallbackHandler
    

上に示されているトークンリスナーの構成オプションの詳細については、「トークンリスナーの構成」を参照してください。

Confluent Schema Registry の構成

schema-registry.properties でベアラートークン認証を使用してログインサービスを構成します。詳細については、「Schema Registry のロールベースアクセス制御の構成」を参照してください。

以下に例を示します。

// Replace all text between ``<>`` with appropriate values.
schema.registry.resource.extension.class=io.confluent.kafka.schemaregistry.security.SchemaRegistrySecurityResourceExtension
confluent.schema.registry.authorizer.class=io.confluent.kafka.schemaregistry.security.authorizer.rbac.RbacAuthorizer

rest.servlet.initializor.classes=io.confluent.common.security.jetty.initializer.InstallBearerOrBasicSecurityHandler

confluent.schema.registry.auth.mechanism=JETTY_AUTH
confluent.metadata.bootstrap.server.urls=<http/s>://<host>:<port>
confluent.metadata.http.auth.credentials.provider=BASIC
confluent.metadata.basic.auth.user.info=<sr-user-name>:<sr-password>

confluent.metadata.public.key.path=<path-to-mds-public-key>

Confluent REST Proxy の構成

kafka-rest.properties でベアラートークン認証を使用してログインサービスを構成します。詳細については、「ロールベースアクセス制御(RBAC)」を参照してください。

以下に例を示します。

// Replace all text between ``<>`` with appropriate values.
kafka.rest.resource.extension.class=io.confluent.kafkarest.security.KafkaRestSecurityResourceExtension

rest.servlet.initializor.classes=io.confluent.common.security.jetty.initializer.InstallBearerOrBasicSecurityHandler

confluent.metadata.bootstrap.server.urls=<http/s>://<host>:<port>
confluent.metadata.http.auth.credentials.provider=BASIC
confluent.metadata.basic.auth.user.info=<test-user-name>:<rest-password>

confluent.metadata.public.key.path=<path-to-mds-public-key>

client.security.protocol=SASL_PLAINTEXT

Kafka Connect の構成

connect-distributed.properties でベアラートークン認証を使用してログインサービスを構成します。詳細については、「Kafka Connect と RBAC」を参照してください。

以下に例を示します。

// Replace all text between ``<>`` with appropriate values.
rest.extension.classes=io.confluent.connect.security.ConnectSecurityExtension

rest.servlet.initializor.classes=io.confluent.common.security.jetty.initializer.InstallBearerOrBasicSecurityHandler

confluent.metadata.bootstrap.server.urls=<http/s>://<host>:<port>
confluent.metadata.http.auth.credentials.provider=BASIC
confluent.metadata.basic.auth.user.info=<connect-user-name>:<connect-password>

public.key.path=<path-to-mds-public-key>

ksqlDB の構成

ksql-server.properties でベアラートークン認証を使用してログインサービスを構成します。詳細については、「ksqlDB と role-based access control (RBAC)」を参照してください。

以下に例を示します。

// Replace all text between ``<>`` with appropriate values.
ksql.security.extension.class=io.confluent.ksql.security.KsqlConfluentSecurityExtension

ksql.authentication.plugin.class=io.confluent.ksql.security.VertxBearerOrBasicAuthenticationPlugin

confluent.metadata.bootstrap.server.urls=<http/s>://<host>:<port>
confluent.metadata.http.auth.credentials.provider=BASIC
confluent.metadata.basic.auth.user.info=<ksql-user-name>:<ksql-password>

public.key.path=/path/to/public-pem-key

Confluent Control Center の構成

control-center.properties でベアラートークン認証を使用してログインサービスを構成します。詳細については、「Control Center 用の RBAC の構成」を参照してください。

以下に例を示します。

// Replace all text between ``<>`` with appropriate values.
confluent.controlcenter.rest.authentication.method=BEARER
confluent.controlcenter.streams.security.protocol=SASL_PLAINTEXT (or SASL_SSL if production)
confluent.controlcenter.auth.bearer.public.key.path=/etc/confluent-control-center/public.pem
confluent.controlcenter.metadata.username=<c3 user>
confluent.controlcenter.metadata.password=<c3 password>
confluent.controlcenter.metadata.urls=<http/s>://<host>:<port>

Kafka クライアントの構成

重要

Kafka クライアントを Schema Registry または REST Proxy セキュリティプラグイン用に構成する場合は、各パラメーターに confluent.license というプレフィックスを付ける必要があります。たとえば、security.protocolconfluent.license.security.protocol になります。

クライアントで SASL 認証を構成するには、以下のとおり実行します。

  1. 各クライアントの JAAS の構成プロパティを、producer.properties または consumer.properties で構成します。ログインモジュールで、プロデューサーやコンシューマーなどのクライアントが Kafka ブローカーに接続するための方法を記述します。OAUTHBEARER メカニズムを利用するクライアントの構成例を次に示します。

    // Replace all text between ``<>`` with appropriate values
    sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
      username="<username>" \
      password="<password>" \
      metadataServerUrls="<http/s>://<host>:<port>";
    

    重要

    外部クライアント通信には、トークンサービスまたは OAUTHBEARER の SASL メカニズム(listener.name.rbac.sasl.enabled.mechanisms=OAUTHBEARER)を使用しないでください。RBAC が有効になっている場合、トークンサービスの対象は Confluent Platform コンポーネント間の内部通信のみとなり(たとえば、Schema Registry ライセンスクライアントには有効)、長時間実行されるサービスプリンシパルやクライアント認証は対象になりません。OAUTHBEARER 設定は内部用であり、変更される可能性があります。また、フル機能の OAuth プロトコルは実装されていません。このため、長期またはクライアントのユースケースには、SASL や mTLS(相互 TLS)など、サポートされているいずれかの認証方法を使用してください。詳細については、「認証方法の概要」を参照してください。

  2. 次のプロパティを使用してクライアントを構成します(クライアントの properties ファイル、コード、またはフラグを使用。 kafka-console-producer--producer-property フラグなど)。

    security.protocol=SASL_SSL (or SASL_PLAINTEXT if non-production)
    sasl.mechanism=OAUTHBEARER
    sasl.login.callback.handler.class=io.confluent.kafka.clients.plugins.auth.token.TokenUserLoginCallbackHandler
    
  3. SASL/OAUTHBEARER のデフォルト実装は、jackson-databind ライブラリをベースにしています。オプションの依存関係があるため、使用するビルドツールで依存関係も構成する必要があります。

SASL/OAUTHBEARER 用のトークン更新

Kafka では、クライアントがブローカーに引き続き接続できるように、期限切れの前にトークンを定期的に更新します。更新アルゴリズムの処理方法に影響するパラメーターは、プロデューサー、コンシューマー、ブローカーの構成の一部として指定されます。以下を参照してください。デフォルト値を明示的に設定する必要はありません。

プロデューサー、コンシューマー、ブローカーの構成のプロパティ デフォルト
sasl.login.refresh.window.factor .8
sasl.login.refresh.window.jitter .05
sasl.login.refresh.min.period.seconds 60
sasl.login.refresh.min.buffer.seconds 300

SASL/OAUTHBEARER のセキュリティの考慮事項

  • 本稼働環境での OAUTHBEARER の使用は、TLS 暗号化を使用してトークンの傍受を回避できる場合に限定してください。
  • 一般的な OAuth 2 のセキュリティの考慮事項については、RFC 6749 Section 10 を参照してください。