Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom oauth callback class #11069

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"readTimeoutSeconds", "httpRetries", "httpRetryPauseMs", "clientSecret", "passwordSecret", "accessToken",
"refreshToken", "tlsTrustedCertificates", "disableTlsHostnameVerification", "maxTokenExpirySeconds",
"accessTokenIsJwt", "enableMetrics", "includeAcceptHeader", "accessTokenLocation",
"clientAssertion", "clientAssertionLocation", "clientAssertionType", "saslExtensions"})
"clientAssertion", "clientAssertionLocation", "clientAssertionType", "saslExtensions", "customOauthCallbackClass"})
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class KafkaClientAuthenticationOAuth extends KafkaClientAuthentication {
Expand Down Expand Up @@ -62,6 +62,7 @@ public class KafkaClientAuthenticationOAuth extends KafkaClientAuthentication {
private String clientAssertionLocation;
private String clientAssertionType;
private Map<String, String> saslExtensions;
private String customOauthCallbackClass;

@Description("Must be `" + TYPE_OAUTH + "`")
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -314,4 +315,14 @@ public Map<String, String> getSaslExtensions() {
public void setSaslExtensions(Map<String, String> saslExtensions) {
this.saslExtensions = saslExtensions;
}

@Description("Custom oauth callback class. If not set, this value defaults to `io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler`.")
@JsonInclude(JsonInclude.Include.NON_NULL)
public String getCustomOauthCallbackClass() {
return customOauthCallbackClass;
}

public void setCustomOauthCallbackClass(String customOauthCallbackClass) {
this.customOauthCallbackClass = customOauthCallbackClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ public static void configureClientAuthenticationEnvVars(KafkaClientAuthenticatio
if (oauth.getPasswordSecret() != null) {
varList.add(ContainerUtils.createEnvVarFromSecret(envVarNamer.apply("OAUTH_PASSWORD_GRANT_PASSWORD"), oauth.getPasswordSecret().getSecretName(), oauth.getPasswordSecret().getPassword()));
}
if (oauth.getCustomOauthCallbackClass() != null) {
varList.add(ContainerUtils.createEnvVar(KafkaConnectCluster.ENV_VAR_CUSTOM_OAUTH_CALLBACK_CLASS, oauth.getCustomOauthCallbackClass()));
}

if (oauth.getTlsTrustedCertificates() != null && !oauth.getTlsTrustedCertificates().isEmpty()) {
varList.add(ContainerUtils.createEnvVar(envVarNamer.apply("OAUTH_TRUSTED_CERTS"), CertUtils.trustedCertsEnvVar(oauth.getTlsTrustedCertificates())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class KafkaConnectCluster extends AbstractModel implements SupportsMetric
protected static final String ENV_VAR_KAFKA_CONNECT_OAUTH_REFRESH_TOKEN = "KAFKA_CONNECT_OAUTH_REFRESH_TOKEN";
protected static final String ENV_VAR_KAFKA_CONNECT_OAUTH_PASSWORD_GRANT_PASSWORD = "KAFKA_CONNECT_OAUTH_PASSWORD_GRANT_PASSWORD";
protected static final String ENV_VAR_KAFKA_CONNECT_OAUTH_CLIENT_ASSERTION = "KAFKA_CONNECT_OAUTH_CLIENT_ASSERTION";
protected static final String ENV_VAR_CUSTOM_OAUTH_CALLBACK_CLASS = "CUSTOM_OAUTH_CALLBACK_CLASS";
protected static final String ENV_VAR_STRIMZI_TRACING = "STRIMZI_TRACING";

protected static final String CO_ENV_VAR_CUSTOM_CONNECT_POD_LABELS = "STRIMZI_CUSTOM_KAFKA_CONNECT_LABELS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1824,8 +1824,10 @@ public void testPodSetWithOAuthWithClientAssertion() {
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_SASL_MECHANISM.equals(var.getName())).findFirst().orElseThrow().getValue(), is("oauth"));
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_OAUTH_CLIENT_ASSERTION.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getName(), is("my-secret-secret"));
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_OAUTH_CLIENT_ASSERTION.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getKey(), is("my-secret-key"));
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_OAUTH_CONFIG.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getKey(), is("my-secret-key"));
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_OAUTH_CONFIG.equals(var.getName())).findFirst().orElseThrow().getValue().trim(),
is(String.format("%s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\"", ClientConfig.OAUTH_CLIENT_ID, "my-client-id", ClientConfig.OAUTH_TOKEN_ENDPOINT_URI, "http://my-oauth-server", ClientConfig.OAUTH_SCOPE, "all", ClientConfig.OAUTH_AUDIENCE, "kafka")));
assertThat(cont.getEnv().stream().filter(var -> KafkaConnectCluster.ENV_VAR_CUSTOM_OAUTH_CALLBACK_CLASS.equals(var.getName())).findFirst().orElseThrow().getValue(), is("my-callback-class"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if [ -n "$KAFKA_CONNECT_SASL_MECHANISM" ]; then
SASL_MECHANISM="OAUTHBEARER"
JAAS_CONFIG="org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required ${KAFKA_CONNECT_OAUTH_CONFIG} ${OAUTH_CLIENT_SECRET} ${OAUTH_REFRESH_TOKEN} ${OAUTH_ACCESS_TOKEN} ${OAUTH_PASSWORD_GRANT_PASSWORD} ${OAUTH_CLIENT_ASSERTION} ${OAUTH_TRUSTSTORE};"
OAUTH_CALLBACK_CLASS="sasl.login.callback.handler.class=io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler"
if [ -n "$CUSTOM_OAUTH_CALLBACK_CLASS" ]; then
JAAS_CONFIG="org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;"
OAUTH_CALLBACK_CLASS="sasl.login.callback.handler.class=${CUSTOM_OAUTH_CALLBACK_CLASS}"
fi
OAUTH_CALLBACK_CLASS_PRODUCER="producer.${OAUTH_CALLBACK_CLASS}"
OAUTH_CALLBACK_CLASS_CONSUMER="consumer.${OAUTH_CALLBACK_CLASS}"
OAUTH_CALLBACK_CLASS_ADMIN="admin.${OAUTH_CALLBACK_CLASS}"
Expand Down
Loading