EronWright commented on a change in pull request #11794: URL: https://github.com/apache/pulsar/pull/11794#discussion_r715749203
########## File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderTokenOIDC.java ########## @@ -0,0 +1,361 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.pulsar.broker.authentication; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.SocketAddress; +import java.net.URL; + +import java.security.interfaces.RSAPublicKey; +import java.util.Date; +import java.util.List; + +import javax.naming.AuthenticationException; +import javax.net.ssl.SSLSession; + +import com.auth0.jwk.Jwk; +import com.auth0.jwk.JwkException; +import com.auth0.jwk.JwkProvider; +import com.auth0.jwk.UrlJwkProvider; +import com.auth0.jwt.JWT; +import com.auth0.jwt.algorithms.Algorithm; +import com.auth0.jwt.exceptions.SignatureVerificationException; +import com.google.common.annotations.VisibleForTesting; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import io.prometheus.client.Counter; +import io.prometheus.client.Histogram; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.pulsar.broker.ServiceConfiguration; +import org.apache.pulsar.broker.authentication.metrics.AuthenticationMetrics; +import org.apache.pulsar.common.api.AuthData; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtException; +import com.auth0.jwt.interfaces.DecodedJWT; + + +public class AuthenticationProviderTokenOIDC implements AuthenticationProvider { + + static final String HTTP_HEADER_NAME = "Authorization"; + static final String HTTP_HEADER_VALUE_PREFIX = "Bearer "; + + // The token's claim that corresponds to the "role" string + static final String CONF_TOKEN_AUTH_CLAIM = "tokenAuthClaim"; + + + static final String CONF_ISSUER_URL = "tokenAuthenticationOIDCIssuerUrl"; + + // When using public key's, the algorithm of the key + static final String CONF_TOKEN_PUBLIC_ALG = "tokenPublicKeytokenPublicKey"; + + // The token audience "claim" name, e.g. "aud", that will be used to get the audience from token. + static final String CONF_TOKEN_AUDIENCE_CLAIM = "tokenAudienceClaim"; + + // The token audience stands for this broker. The field `tokenAudienceClaim` of a valid token, need contains this. + static final String CONF_TOKEN_AUDIENCE = "tokenAudience"; Review comment: I would suggest that audience validation is not always performed in OIDC-based authentication. OIDC tokens typically have an audience that is equal to the subject (because the token is obtained by, and primarily intended for, the user themself). Am not objecting to having audience validation, but is an edge case. Audience validation is typical in OAuth 2.0 authentication, which this provider is assumedly not intended for. -- 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]
