-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implement session logout in OAuth2Authenticator #18753
Changes from all commits
340b8c8
5eccba2
c25d71d
180b3ab
e066e29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,32 +14,63 @@ | |
package io.trino.server.ui; | ||
|
||
import com.google.common.io.Resources; | ||
import com.google.inject.Inject; | ||
import io.trino.server.security.ResourceSecurity; | ||
import io.trino.server.security.oauth2.OAuth2Client; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.SecurityContext; | ||
import jakarta.ws.rs.core.UriBuilder; | ||
import jakarta.ws.rs.core.UriInfo; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.Optional; | ||
|
||
import static io.trino.server.security.ResourceSecurity.AccessType.PUBLIC; | ||
import static io.trino.server.security.ResourceSecurity.AccessType.WEB_UI; | ||
import static io.trino.server.ui.FormWebUiAuthenticationFilter.UI_LOGOUT; | ||
import static io.trino.server.ui.OAuthIdTokenCookie.ID_TOKEN_COOKIE; | ||
import static io.trino.server.ui.OAuthWebUiCookie.delete; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
@Path(UI_LOGOUT) | ||
public class OAuth2WebUiLogoutResource | ||
{ | ||
private final OAuth2Client auth2Client; | ||
|
||
@Inject | ||
public OAuth2WebUiLogoutResource(OAuth2Client auth2Client) | ||
{ | ||
this.auth2Client = requireNonNull(auth2Client, "auth2Client is null"); | ||
} | ||
|
||
@ResourceSecurity(WEB_UI) | ||
@GET | ||
public Response logout(@Context HttpHeaders httpHeaders, @Context UriInfo uriInfo, @Context SecurityContext securityContext) | ||
throws IOException | ||
{ | ||
Optional<String> idToken = OAuthIdTokenCookie.read(httpHeaders.getCookies().get(ID_TOKEN_COOKIE)); | ||
URI callBackUri = UriBuilder.fromUri(uriInfo.getAbsolutePath()) | ||
.path("logout.html") | ||
.build(); | ||
|
||
return Response.seeOther(auth2Client.getLogoutEndpoint(idToken, callBackUri).orElse(callBackUri)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to call sso logout ourselves behind the scenes instead of depending on user browser's doing that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec here mentions that
So I guess we should redirect on the User browser instead of handling it. Additionally each IdP can have its own way to redirecting the user right ? |
||
.cookie(delete(), OAuthIdTokenCookie.delete()) | ||
.build(); | ||
} | ||
|
||
@ResourceSecurity(PUBLIC) | ||
@GET | ||
@Path("/logout.html") | ||
public Response logoutPage(@Context HttpHeaders httpHeaders, @Context UriInfo uriInfo, @Context SecurityContext securityContext) | ||
throws IOException | ||
{ | ||
return Response.ok(Resources.toString(Resources.getResource(getClass(), "/oauth2/logout.html"), UTF_8)) | ||
.cookie(delete()) | ||
.build(); | ||
} | ||
} |
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 provide an override value for END_SESSION_URL which comes from the OidcDiscoveryConfig. Similar to the other URL values. This allows non-standard endpoint values.
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.
That's a good point but
OidcDiscoveryConfig
actually allows providing urls explicitly (effectively overriding those obtained from metadata discovery) for backward compatibility, allowing for non-standard endpoint values wasn't the objective. We intend to drop these properties #18101That said, is it something you think we should support? Is this something you use these properties for?
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.
This END_SESSION_URL, Optional.empty()) becomes this END_SESSION_URL, logoutUrl), where logoutUrl is set in the constructor
logoutUrl = requireNonNull(oidcConfig.getEndSessionUrl(), "logoutUrl is null");
I had to make these changes for a customer, who is using Ping. The "standard" endpoint found with end_session_endpoint is not being found because the well-known endpoint is returning ping_end_session_endpoint. So the customer had to be able to specify the logout URL explicitly.
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.
But if we disable the OIDC discovery then we could inject them via
StaticConfigurationProvider
- we could provide custom end-points right ? cc : @lukasz-walkiewicz Are we removing that endpoint also ?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.
No,
StaticConfigurationProvider
is here to stay. I think we ultimately would like to remove this overriding some day and users should provide configuration explicitly if the IdP does not conform OIDC spec.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.
@thorbjornsen In this case we could still use
StaticOAuth2ServerConfiguration
but we need to specify the configuration explicitly.