public class JaasServerOauthOverPlainValidatorCallbackHandler extends JaasServerOauthValidatorCallbackHandler
Also, the client can use the access token to authenticate. In this case the client should set the username parameter to the same principal the broker will resolve from the access token (depending on the Kafka Broker configuration this is the value of 'sub' claim or one specified by 'oauth.username.claim' configuration). The password parameter depends on whether the 'oauth.token.endpoint.uri' is configured on the server or not. If configured, the password parameter value should be set to the constant $accessToken: followed by the actual access token string. The $accessToken: prefix lets the broker know that the password should be treated as an access token. If not configured, the client ID + secret (client credentials) mechanism is not available and the 'password' parameter is interpreted as a raw access token without a prefix.
Allowing the use of OAuth credentials over SASL/PLAIN allows all existing Kafka client tools to authenticate to your Kafka cluster even when they have no explicit OAuth support.
To install this CallbackHandler in your Kafka listener, specify the following in your 'server.properties':
# Declare a listener
listeners=CLIENT://kafka:9092
# Specify whether the TCP connection is unsecured or protected with TLS
#listener.security.protocol.map=CLIENT:SASL_PLAINTEXT
listener.security.protocol.map=CLIENT:SASL_SSL
# Configure the keystore and truststore for SASL_SSL
listener.name.client.ssl.keystore.location=/tmp/kafka/cluster.keystore.p12
listener.name.client.ssl.keystore.password=keypass
listener.name.client.ssl.keystore.type=PKCS12
listener.name.client.ssl.truststore.location=/tmp/kafka/cluster.truststore.p12
listener.name.client.ssl.truststore.password=trustpass
listener.name.client.ssl.truststore.type=PKCS12
# Enable SASL/PLAIN authentication mechanism on your listener in addition to any others
#sasl.enabled.mechanisms: PLAIN,OAUTHBEARER
sasl.enabled.mechanisms: PLAIN
# Install the SASL/PLAIN LoginModule using per-listener sasl.jaas.config
listener.name.client.plain.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \
oauth.token.endpoint.uri="https://sso-server/token" \
oauth.valid.issuer.uri="https://java-server" \
oauth.jwks.endpoint.uri="https://java-server/certs" \
oauth.username.claim="preferred_username";
# Install this CallbackHandler to provide custom handling of authentication
listener.name.client.plain.sasl.server.callback.handler.class=io.strimzi.kafka.oauth.server.plain.JaasServerOauthOverPlainValidatorCallbackHandler
There is additional sasl.jaas.config configuration that may need to be specified in order for this CallbackHandler to work with your authorization server.
Note: The following configuration keys can be specified as parameters to sasl.jaas.config in Kafka `server.properties` file, or as ENV vars in which case an all-uppercase key name is also attempted with '.' replaced by '_' (e.g. OAUTH_TOKEN_ENDPOINT_URI). They can also be specified as system properties. The priority is in reverse - system property overrides the ENV var, which overrides `server.properties`. When not specified as the parameters to sasl.jaas.config, the configuration keys will apply to all listeners.
Optional sasl.jaas.config configuration:
The rest of the configuration is the same as for JaasServerOauthValidatorCallbackHandler.
| Constructor and Description |
|---|
JaasServerOauthOverPlainValidatorCallbackHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
configure(java.util.Map<java.lang.String,?> configs,
java.lang.String saslMechanism,
java.util.List<javax.security.auth.login.AppConfigurationEntry> jaasConfigEntries) |
void |
handle(javax.security.auth.callback.Callback[] callbacks)
The callback method.
|
getPrincipalExtractor, getSocketFactory, getVerifier, isJwtpublic JaasServerOauthOverPlainValidatorCallbackHandler()
public void configure(java.util.Map<java.lang.String,?> configs,
java.lang.String saslMechanism,
java.util.List<javax.security.auth.login.AppConfigurationEntry> jaasConfigEntries)
configure in interface org.apache.kafka.common.security.auth.AuthenticateCallbackHandlerconfigure in class JaasServerOauthValidatorCallbackHandlerpublic void close()
close in interface org.apache.kafka.common.security.auth.AuthenticateCallbackHandlerclose in class JaasServerOauthValidatorCallbackHandlerpublic void handle(javax.security.auth.callback.Callback[] callbacks)
throws javax.security.auth.callback.UnsupportedCallbackException
handle in interface javax.security.auth.callback.CallbackHandlerhandle in class JaasServerOauthValidatorCallbackHandlerjavax.security.auth.callback.UnsupportedCallbackExceptionCopyright © 2021. All rights reserved.