-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29020: Support OAuth 2 in Iceberg REST Catalog #6086
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
Conversation
@check-spelling-bot Report🔴 Please reviewSee the files view or the action log for details. Unrecognized words (6)calcualtion Previously acknowledged words that are now absentwwwTo accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the git@github.com:okumin/hive.git repository If the flagged items do not appear to be textIf items relate to a ...
|
| } | ||
|
|
||
| enum Route { | ||
| TOKENS(HTTPMethod.POST, "v1/oauth/tokens", null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial specification of Iceberg REST allows the Iceberg REST Catalog to act as an Authorization Server, which is why the list contains this endpoint. As this does not follow security best practices, it will be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be removed with Iceberg spec 2.0; at this point, it may be deprecated but should not be removed yet, should it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should.
The token endpoint is not of a Resource Server but of an Authorization Server, i.e., typically Identity Provider such as Keycloak or Okta. The token endpoint is responsible for issuing a secure(e.g., cryptographically signed) Access Token.
Our endpoint is just a copied and pasted from iceberg-core, which is almost like an echo server(no authentication happens). It is possible to embed the Authorization Server roles in HMS; however, we would need to implement an RFC 6749, RFC 9068, or another RFC-compliant Authorization Server in that case. Otherwise, no user exists(who wants OAuth 2 that allows unauthenticated access?).
Lines 243 to 265 in 96cf347
| private OAuthTokenResponse tokens(Object body) { | |
| @SuppressWarnings("unchecked") | |
| Map<String, String> request = (Map<String, String>) castRequest(Map.class, body); | |
| String grantType = request.get(GRANT_TYPE); | |
| switch (grantType) { | |
| case CLIENT_CREDENTIALS: | |
| return OAuthTokenResponse.builder() | |
| .withToken("client-credentials-token:sub=" + request.get(CLIENT_ID)) | |
| .withIssuedTokenType(URN_OAUTH_ACCESS_TOKEN) | |
| .withTokenType(BEARER) | |
| .build(); | |
| case URN_OAUTH_TOKEN_EXCHANGE: | |
| String actor = request.get(ACTOR_TOKEN); | |
| String token = | |
| String.format( | |
| "token-exchange-token:sub=%s%s", | |
| request.get(SUBJECT_TOKEN), actor != null ? ",act=" + actor : ""); | |
| return OAuthTokenResponse.builder() | |
| .withToken(token) | |
| .withIssuedTokenType(URN_OAUTH_ACCESS_TOKEN) | |
| .withTokenType(BEARER) | |
| .build(); |
| LOG.warn("Rejecting an expired JWT: {}", parsedJwt.getPayload()); | ||
| throw new AuthenticationException("JWT (ends with " + lastSevenChars + ") has been expired"); | ||
| } | ||
| public JWTValidator(Set<JOSEObjectType> acceptableTypes, List<URL> jwksURLs, String expectedIssuer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced our custom implementation, following the article below.
https://connect2id.com/products/nimbus-jose-jwt/examples/validating-jwt-access-tokens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dengzhhu653, @henrib
| .withEnv("KEYCLOAK_ADMIN","admin") | ||
| .withEnv("KEYCLOAK_ADMIN_PASSWORD","admin") | ||
| .withCommand("start-dev") | ||
| .withExposedPorts(8080); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried to use spring-security-oauth2-authorization-server, but gave it up because it has a hard dependency conflict on spring-core derived from Apache Atlas, and Nimbus we're using.
ab519b9 to
b2ae59a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM +1, thanks @okumin for adding OAuth2 support in RestCatalog
pending tests
|
I'm testing this in my local, and going to add how-to-setup to hive-site. I will merge this after that |
|
henrib
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove the oauth/tokens endpoint yet ?
| } | ||
|
|
||
| enum Route { | ||
| TOKENS(HTTPMethod.POST, "v1/oauth/tokens", null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be removed with Iceberg spec 2.0; at this point, it may be deprecated but should not be removed yet, should it ?
|
@deniskuzZ @henrib Thanks for your reviews! |



What changes were proposed in this pull request?
Add RFC 7662 or RFC 9068-based OAuth 2 support.
https://issues.apache.org/jira/browse/HIVE-29020
Why are the changes needed?
OAuth 2 is the most common authorization method for protecting the Iceberg REST Catalog. As the Iceberg library officially supports it, Iceberg users would be able to use it without custom patches if we were to support it. Additionally, OAuth 2 is an industry-standard protocol as of 2025.
The security principles and considerations are written in the following document.
https://docs.google.com/document/d/1wOlmpKP4jZb4Je67wusdMoQ4VWgGfi5JLe8w3MP5mpE/edit?usp=sharing
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added integration tests.