-
Notifications
You must be signed in to change notification settings - Fork 174
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
Update DefaultOAuth2ApiService to support multiple token types and client secret without id #952
base: main
Are you sure you want to change the base?
Update DefaultOAuth2ApiService to support multiple token types and client secret without id #952
Conversation
…ient secret without id
// token exchange with client id and client secret means the client has previously | ||
// attempted to refresh an access token, but refreshing was not supported by the token broker. | ||
// Accept the client id and secret and treat it as a new token request | ||
if (authHeader != null && clientSecret == null && authHeader.startsWith("Basic ")) { |
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.
Sorry, but I'm not sure how this logic aligns with the comment above. "With ... client secret", but the secret is null
here?... Would you mind clarifying the 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.
I'm fine with this change as it is obviously meant to support existing Iceberg REST client, but I do not think this logic follows the client credentials flow in RFC 6749. Specifically, "client secret" is not supposed to be passed in the POST body (from where the initial value for clientSecret
comes, if I'm not mistaken).
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.
To be complete, RFC 6749 section 2.3.1 permits client secret in the request body, but does not recommend 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.
Thanks, @adutra . I missed that option 🤦
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.
In any case, I think Polaris ought to treat client ID and secret as a tuple and not mix ID from header and secret from POST body (or the other way around)... which seems possible ATM.
clientSecret = parts[0]; | ||
} else { | ||
LOGGER.debug("Don't know how to parse Basic auth header"); | ||
OAuthUtils.getResponseFromError(OAuthTokenErrorResponse.Error.invalid_request); |
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 this be returned?
@@ -75,43 +74,39 @@ public Response getToken( | |||
if (!tokenBroker.supportsRequestedTokenType(requestedTokenType)) { |
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.
Why do we check requestedTokenType
, but not use it?
} | ||
} | ||
TokenResponse tokenResponse; | ||
if (subjectToken != 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.
nit: In this case, client ID/secret appear to be parsed from the request data, but not used (not validated)... why bother parsing what we do not use?
} | ||
TokenResponse tokenResponse; | ||
if (subjectToken != null) { | ||
if (!tokenBroker.supportsRequestedTokenType(subjectTokenType)) { |
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.
why do we apply the "requested token type" check to the "subject token type"?
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.
IMHO, it is best to delegate all "supports" checks to the TokenBroker
implementation.
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.
Sigh. Too many token types. I removed this check :)
I am a bit sad to see support for this landing in Polaris, because this is one of the many Iceberg deviances from standard OAuth2. We are basically creating a broken server, so that it can understand broken clients. Also, no external IDP that I know of supports client secret without client id. |
No, generally they don't support client secret only for client_credentials flow, but they do support token exchange. Unfortunately, Iceberg has support for token exchange, but not at the catalog initialization. E.g., at https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L1120-L1133 , it can use a developer token to exchange for an OAuth token, but that code doesn't execute at initialization. The only way for someone to submit a token for exchange is via the client_secret parameter :( |
Yes, and this is a common trick among catalog implementors :-) – That said, you don't need to support client secret only for this; you can configure the client to send a fixed client id, something like I don't mind going down the route of supporting client secrets without ids, but let's keep in mind that we are getting closer to having the AuthManager API merged into Iceberg core. What would become possible then is to provide an alternate AuthManager that knows how to do initial token exchanges properly, e.g. to support impersonation and delegation scenarios. |
I support @adutra 's suggestion of using fixed (common) |
Iceberg supports multiple token types during a token exchange and also supports sending client secret without a client id. The default Polaris implementation doesn't support most of this, but the
TokenBroker
interface does allow for implementations that do. This merely updates theDefaultOAuth2ApiService
to delegate to theTokenBroker
to support these cases.