World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#9713] fix(oauth): Allow JWKS validators without serverUri or tokenPath (#9717)
Bharath Krishna07256309c317
diff --git a/docs/security/how-to-authenticate.md b/docs/security/how-to-authenticate.mdindex 8834c330f7..ef5338cb5f 100644--- a/docs/security/how-to-authenticate.md+++ b/docs/security/how-to-authenticate.md@@ -125,8 +125,8 @@ Gravitino server and Gravitino Iceberg REST server share the same configuration| `gravitino.authenticator.oauth.allowSkewSecs` | The JWT allows skew seconds when Gravitino uses OAuth as the authenticator. | `0` | No | 0.3.0 || `gravitino.authenticator.oauth.defaultSignKey` | The signing key of JWT when Gravitino uses OAuth as the authenticator. | (none) | Yes if use `oauth` as the authenticator | 0.3.0 || `gravitino.authenticator.oauth.signAlgorithmType` | The signature algorithm when Gravitino uses OAuth as the authenticator. | `RS256` | No | 0.3.0 |-| `gravitino.authenticator.oauth.serverUri` | The URI of the default OAuth server. | (none) | Yes if use `oauth` as the authenticator | 0.3.0 |-| `gravitino.authenticator.oauth.tokenPath` | The path for token of the default OAuth server. | (none) | Yes if use `oauth` as the authenticator | 0.3.0 |+| `gravitino.authenticator.oauth.serverUri` | The URI of the default OAuth server. Required when using StaticSignKeyValidator, not required for JWKS-based validators. | (none) | Yes if using `StaticSignKeyValidator` | 0.3.0 |+| `gravitino.authenticator.oauth.tokenPath` | The path for token of the default OAuth server. Required when using StaticSignKeyValidator, not required for JWKS-based validators. | (none) | Yes if using `StaticSignKeyValidator` | 0.3.0 || `gravitino.authenticator.oauth.provider` | OAuth provider type (default, oidc). Determines the Web UI authentication flow. Use 'oidc' for Web UI OIDC login, 'default' for legacy login or API-only authentication. | `default` | No | 1.0.0 || `gravitino.authenticator.oauth.clientId` | OAuth client ID for Web UI authentication. | (none) | Yes if provider is `oidc` | 1.0.0 || `gravitino.authenticator.oauth.authority` | OAuth authority/issuer URL for OIDC providers for web UI authentication. (e.g., Azure AD tenant URL). | (none) | Yes if provider is `oidc` | 1.0.0 |diff --git a/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuth2TokenAuthenticator.java b/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuth2TokenAuthenticator.javaindex 7f2821e411..4b1f3ff81f 100644--- a/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuth2TokenAuthenticator.java+++ b/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuth2TokenAuthenticator.java@@ -49,14 +49,6 @@ class OAuth2TokenAuthenticator implements Authenticator {StringUtils.isNotBlank(serviceAudience),"Service audience cannot be blank for OAuth authentication");- Preconditions.checkArgument(- StringUtils.isNotBlank(config.get(OAuthConfig.DEFAULT_TOKEN_PATH)),- "The path for token of the default OAuth server can't be blank");- Preconditions.checkArgument(- StringUtils.isNotBlank(config.get(OAuthConfig.DEFAULT_SERVER_URI)),- "The uri of the default OAuth server can't be blank");-- // Create the appropriate token validator based on configurationthis.tokenValidator = OAuthTokenValidatorFactory.createValidator(config);}diff --git a/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.java b/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.javaindex 4f7078bde5..5fd3613458 100644--- a/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.java+++ b/server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.java@@ -61,7 +61,8 @@ public interface OAuthConfig {ConfigEntry<String> DEFAULT_SERVER_URI =new ConfigBuilder(OAUTH_CONFIG_PREFIX + "serverUri")- .doc("The uri of the default OAuth server")+ .doc(+ "The uri of the default OAuth server. Required when using StaticSignKeyValidator, not required for JWKS-based validators").version(ConfigConstants.VERSION_0_3_0).stringConf().checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)@@ -69,7 +70,8 @@ public interface OAuthConfig {ConfigEntry<String> DEFAULT_TOKEN_PATH =new ConfigBuilder(OAUTH_CONFIG_PREFIX + "tokenPath")- .doc("The path for token of the default OAuth server")+ .doc(+ "The path for token of the default OAuth server. Required when using StaticSignKeyValidator, not required for JWKS-based validators").version(ConfigConstants.VERSION_0_3_0).stringConf().checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)diff --git a/server-common/src/test/java/org/apache/gravitino/server/authentication/TestOAuth2TokenAuthenticator.java b/server-common/src/test/java/org/apache/gravitino/server/authentication/TestOAuth2TokenAuthenticator.javaindex 080ceb439b..d6571df6bd 100644--- a/server-common/src/test/java/org/apache/gravitino/server/authentication/TestOAuth2TokenAuthenticator.java+++ b/server-common/src/test/java/org/apache/gravitino/server/authentication/TestOAuth2TokenAuthenticator.java@@ -174,6 +174,27 @@ public class TestOAuth2TokenAuthenticator {assertThrows(IllegalArgumentException.class, () -> authenticator.initialize(config));}+ @Test+ public void testInitializeStaticKeyValidatorRequiresServerUriAndTokenPath() {+ OAuth2TokenAuthenticator authenticator = new OAuth2TokenAuthenticator();+ Config config = new Config(false) {};+ config.set(OAuthConfig.SERVICE_AUDIENCE, "test-service");+ Key tempKey = Keys.secretKeyFor(SignatureAlgorithm.HS256);+ config.set(+ OAuthConfig.DEFAULT_SIGN_KEY, Base64.getEncoder().encodeToString(tempKey.getEncoded()));+ // Use default StaticSignKeyValidator which requires serverUri and tokenPath+ config.set(+ OAuthConfig.TOKEN_VALIDATOR_CLASS,+ "org.apache.gravitino.server.authentication.StaticSignKeyValidator");++ // Should fail when serverUri and tokenPath are missing for StaticSignKeyValidator+ IllegalArgumentException e =+ assertThrows(IllegalArgumentException.class, () -> authenticator.initialize(config));+ assertTrue(+ e.getMessage().contains("token") || e.getMessage().contains("uri"),+ "Expected error message about token path or server URI, got: " + e.getMessage());+ }+@Testpublic void testInitializeWithJwksConfiguration() {OAuth2TokenAuthenticator authenticator = new OAuth2TokenAuthenticator();@@ -183,13 +204,10 @@ public class TestOAuth2TokenAuthenticator {config.set(OAuthConfig.JWKS_URI, "https://login.microsoftonline.com/common/discovery/v2.0/keys");config.set(OAuthConfig.AUTHORITY, "https://login.microsoftonline.com");- config.set(OAuthConfig.DEFAULT_TOKEN_PATH, "/token");- config.set(OAuthConfig.DEFAULT_SERVER_URI, "http://localhost:8080");+ // Note: DEFAULT_TOKEN_PATH and DEFAULT_SERVER_URI are not required for JWKS validatorconfig.set(OAuthConfig.TOKEN_VALIDATOR_CLASS,"org.apache.gravitino.server.authentication.JwksTokenValidator");-- // Should initialize with JWKS validatorauthenticator.initialize(config);assertTrue(authenticator.isDataFromToken());}