nixonrodrigues commented on code in PR #762: URL: https://github.com/apache/atlas/pull/762#discussion_r4082404452
########## notification/src/main/java/org/apache/atlas/security/kafka/KubernetesOAuthHandler.java: ########## @@ -0,0 +1,264 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.security.kafka; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.kafka.common.security.auth.AuthenticateCallbackHandler; +import org.apache.kafka.common.security.auth.SaslExtensions; +import org.apache.kafka.common.security.auth.SaslExtensionsCallback; +import org.apache.kafka.common.security.oauthbearer.OAuthBearerToken; +import org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.AppConfigurationEntry; + +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Base64; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Kafka SASL/OAUTHBEARER callback handler for Kubernetes projected service-account + * tokens. Reads a JWT from a {@code file://} URL configured via + * {@link #SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL} and supplies it to the + * Kafka client without OAuth 2.0 scope validation. The broker validates the JWT. + * <p> + * Kubernetes rotates projected SA tokens in place (same path, new contents). Kafka's + * {@code ExpiringCredentialRefreshingLogin} re-invokes this handler on each login / + * refresh; {@link #handle(Callback[])} always re-reads the token file and builds a + * new {@link OAuthBearerToken} from the current JWT (including updated {@code exp}). + * Token bytes are never cached between callbacks. + */ +public class KubernetesOAuthHandler implements AuthenticateCallbackHandler { Review Comment: Updated the classname to AtlasKafkaOAuthCallbackHandler and tested. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
