bharos commented on code in PR #15703: URL: https://github.com/apache/iceberg/pull/15703#discussion_r3126687830
########## core/src/main/java/org/apache/iceberg/rest/auth/oauth2/config/TokenRefreshConfig.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.iceberg.rest.auth.oauth2.config; + +import com.nimbusds.oauth2.sdk.GrantType; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import org.apache.iceberg.rest.auth.oauth2.OAuth2Config; +import org.immutables.value.Value; + +/** Configuration properties for the token refresh feature. */ [email protected] +public interface TokenRefreshConfig { + + String PREFIX = OAuth2Config.PREFIX + "token-refresh."; + + String ENABLED = PREFIX + "enabled"; + String TOKEN_EXCHANGE_ENABLED = PREFIX + "token-exchange-enabled"; + String ACCESS_TOKEN_LIFESPAN = PREFIX + "access-token-lifespan"; + String SAFETY_MARGIN = PREFIX + "safety-margin"; + Review Comment: Taking the example of long-running Spark jobs against an Iceberg REST catalog backed by Azure Entra ID. These jobs require per-user identity (user-delegated access), not a shared service account (client_credentials flow). As a first step, we can have the users handle the Authorization Code + PKCE flow externally (via a CLI wrapper) and obtain an access token + refresh token pair before submitting the job. Currently there's no way to pass that refresh token to Iceberg. The v1 OAuth2Util.refreshToken() only supports token exchange or client credentials re-auth. In the v2 config, TokenRefreshConfig controls refresh behavior but has no property to seed an external refresh token. The flow would be: 1. External tooling handles interactive auth (PKCE, device code, etc.) before job submission 2. User configures rest.auth.oauth2.token and rest.auth.oauth2.refresh-token 3. Iceberg uses the access token until near-expiry, then calls the token endpoint with grant_type=refresh_token 4. Subsequent refreshes use the rotating refresh token from each response Should we consider adding a config property like `rest.auth.oauth2.refresh-token` that provides an initial refresh token to RefreshTokenFlow, enabling `grant_type=refresh_token` without Iceberg needing to implement the interactive PKCE flow (which can be considered in a future update)? We can support it in later PR as well after this, but want to understand if it already works , or if it makes sense to try supporting this case ? ########## core/src/main/java/org/apache/iceberg/rest/auth/oauth2/config/BasicConfig.java: ########## @@ -0,0 +1,284 @@ +/* + * 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.iceberg.rest.auth.oauth2.config; + +import com.nimbusds.oauth2.sdk.GrantType; +import com.nimbusds.oauth2.sdk.Scope; +import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod; +import com.nimbusds.oauth2.sdk.auth.Secret; +import com.nimbusds.oauth2.sdk.id.ClientID; +import com.nimbusds.oauth2.sdk.token.AccessToken; +import com.nimbusds.oauth2.sdk.token.BearerAccessToken; +import java.net.URI; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import org.apache.iceberg.rest.RESTUtil; +import org.apache.iceberg.rest.auth.oauth2.OAuth2Config; +import org.immutables.value.Value; + +/** + * Basic OAuth2 properties. These properties are used to configure the basic OAuth2 options such as + * the issuer URL, token endpoint, client ID, and client secret. + */ [email protected] [email protected](redactedMask = "****") +@SuppressWarnings({"ImmutablesStyle", "SafeLoggingPropagation"}) +public interface BasicConfig { + + String PREFIX = OAuth2Config.PREFIX; + + String TOKEN = PREFIX + "token"; + String ISSUER_URL = PREFIX + "issuer-url"; + String TOKEN_ENDPOINT = PREFIX + "token-endpoint"; + String GRANT_TYPE = PREFIX + "grant-type"; + String CLIENT_ID = PREFIX + "client-id"; + String CLIENT_AUTH = PREFIX + "client-auth"; + String CLIENT_SECRET = PREFIX + "client-secret"; + String SCOPE = PREFIX + "scope"; + String EXTRA_PARAMS = PREFIX + "extra-params"; + String SESSION_CACHE_TIMEOUT = PREFIX + "session-cache.timeout"; + + GrantType DEFAULT_GRANT_TYPE = GrantType.CLIENT_CREDENTIALS; + ClientAuthenticationMethod DEFAULT_CLIENT_AUTH = ClientAuthenticationMethod.CLIENT_SECRET_BASIC; + Duration DEFAULT_SESSION_CACHE_TIMEOUT = Duration.parse("PT1H"); + + /** + * The initial access token to use. Optional. If this is set, the OAuth2 client will not attempt + * to fetch an initial token from the Authorization server, but will use this token instead. + * + * <p>This option should be avoided as in most cases, the token cannot be refreshed. Review Comment: for users who obtain tokens externally (PKCE, device code), this is the only entry point. As per my below comment, if refresh-token is supported, this option may become viable as well ? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
