Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

collado-mike
Copy link
Contributor

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 the DefaultOAuth2ApiService to delegate to the TokenBroker to support these cases.

// 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 ")) {
Copy link
Contributor

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?

Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Contributor

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 🤦

Copy link
Contributor

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);
Copy link
Contributor

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)) {
Copy link
Contributor

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) {
Copy link
Contributor

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)) {
Copy link
Contributor

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"?

Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

@adutra
Copy link
Contributor

adutra commented Feb 6, 2025

also supports sending client secret without a client id.

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.

@collado-mike
Copy link
Contributor Author

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 :(

@adutra
Copy link
Contributor

adutra commented Feb 6, 2025

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 credential=polaris:${token}.

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.

@dimas-b
Copy link
Contributor

dimas-b commented Feb 6, 2025

I support @adutra 's suggestion of using fixed (common) userId for authenticating clients that do not have a real ID (as opposed to allowing missing/null ID). This is because both RFC 6749, section-2.3 (POST body) and RFC 2617 (Basic Auth) require the "user ID" to be present. It may be empty, apparently, but should be present, as far as I understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants