-
Notifications
You must be signed in to change notification settings - Fork 135
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
SSO: Allow a Cloud Foundry endpoint to be connected with SSO login #2928
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b30531a
Merge remote-tracking branch 'origin/token-linking' into sso-endpoints
nwmac f98eaae
Get SSO working for endpoints
nwmac eefbad8
Merge remote-tracking branch 'origin/v2-master' into sso-endpoints
richard-cox 8bc9bd5
Fix e2e test
richard-cox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...end/app/features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.connection-dialog { | ||
$dialog-padding: 24px; | ||
width: 300px; | ||
&__content { | ||
display: flex; | ||
flex-direction: column; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,17 +98,22 @@ func (p *portalProxy) initSSOlogin(c echo.Context) error { | |
return err | ||
} | ||
|
||
redirectURL := fmt.Sprintf("%s/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s", p.Config.ConsoleConfig.UAAEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, state))) | ||
redirectURL := fmt.Sprintf("%s/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s", p.Config.ConsoleConfig.UAAEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, state, ""))) | ||
c.Redirect(http.StatusTemporaryRedirect, redirectURL) | ||
return nil | ||
} | ||
|
||
func getSSORedirectURI(base string, state string) string { | ||
func getSSORedirectURI(base string, state string, endpointGUID string) string { | ||
baseURL, _ := url.Parse(base) | ||
baseURL.Path = "" | ||
baseURL.RawQuery = "" | ||
baseURLString := strings.TrimRight(baseURL.String(), "?") | ||
return fmt.Sprintf("%s/pp/v1/auth/sso_login_callback?state=%s", baseURLString, url.QueryEscape(state)) | ||
|
||
returnURL := fmt.Sprintf("%s/pp/v1/auth/sso_login_callback?state=%s", baseURLString, url.QueryEscape(state)) | ||
if len(endpointGUID) > 0 { | ||
returnURL = fmt.Sprintf("%s&guid=%s", returnURL, endpointGUID) | ||
} | ||
return returnURL | ||
} | ||
|
||
// Logout of the UAA | ||
|
@@ -125,7 +130,7 @@ func (p *portalProxy) ssoLogoutOfUAA(c echo.Context) error { | |
// Redirect to the UAA to logout of the UAA session as well (if configured to do so), otherwise redirect back to the UI login page | ||
var redirectURL string | ||
if p.hasSSOOption("logout") { | ||
redirectURL = fmt.Sprintf("%s/logout.do?client_id=%s&redirect=%s", p.Config.ConsoleConfig.UAAEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, "logout"))) | ||
redirectURL = fmt.Sprintf("%s/logout.do?client_id=%s&redirect=%s", p.Config.ConsoleConfig.UAAEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, "logout", ""))) | ||
} else { | ||
redirectURL = "/login?SSO_Message=You+have+been+logged+out" | ||
} | ||
|
@@ -153,6 +158,13 @@ func (p *portalProxy) ssoLoginToUAA(c echo.Context) error { | |
return err | ||
} | ||
|
||
// We use the same callback URL for both UAA and endpoint login | ||
// Check if it is an endpoint login and dens to the right handler | ||
endpointGUID := c.QueryParam("guid") | ||
if len(endpointGUID) > 0 { | ||
return p.ssoLoginToCNSI(c) | ||
} | ||
|
||
if state == "logout" { | ||
return c.Redirect(http.StatusTemporaryRedirect, "/login?SSO_Message=You+have+been+logged+out") | ||
} | ||
|
@@ -242,6 +254,65 @@ func (p *portalProxy) doLoginToUAA(c echo.Context) (*interfaces.LoginRes, error) | |
return resp, nil | ||
} | ||
|
||
// Start SSO flow for an Endpoint | ||
func (p *portalProxy) ssoLoginToCNSI(c echo.Context) error { | ||
log.Debug("loginToCNSI") | ||
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. log.Debug("ssoLoginToCNSI") |
||
endpointGUID := c.QueryParam("guid") | ||
if len(endpointGUID) == 0 { | ||
return interfaces.NewHTTPShadowError( | ||
http.StatusBadRequest, | ||
"Missing target endpoint", | ||
"Need Endpoint GUID passed as form param") | ||
} | ||
|
||
_, err := p.GetSessionStringValue(c, "user_id") | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusUnauthorized, "Could not find correct session value") | ||
} | ||
|
||
state := c.QueryParam("state") | ||
if len(state) == 0 { | ||
err := interfaces.NewHTTPShadowError( | ||
http.StatusUnauthorized, | ||
"SSO Login: State parameter missing", | ||
"SSO Login: State parameter missing") | ||
return err | ||
} | ||
|
||
cnsiRecord, err := p.GetCNSIRecord(endpointGUID) | ||
if err != nil { | ||
return interfaces.NewHTTPShadowError( | ||
http.StatusBadRequest, | ||
"Requested endpoint not registered", | ||
"No Endpoint registered with GUID %s: %s", endpointGUID, err) | ||
} | ||
|
||
// Check if this is first time in the flow, or via the callback | ||
code := c.QueryParam("code") | ||
|
||
if len(code) == 0 { | ||
// First time around | ||
// Use the standard SSO Login Callback endpoint, so this can be whitelisted for Stratos and Endpoint login | ||
returnURL := getSSORedirectURI(state, state, endpointGUID) | ||
redirectURL := fmt.Sprintf("%s/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s", | ||
cnsiRecord.AuthorizationEndpoint, cnsiRecord.ClientId, url.QueryEscape(returnURL)) | ||
c.Redirect(http.StatusTemporaryRedirect, redirectURL) | ||
return nil | ||
} | ||
|
||
// Callback | ||
_, err = p.DoLoginToCNSI(c, endpointGUID, false) | ||
status := "ok" | ||
if err != nil { | ||
status = "fail" | ||
} | ||
|
||
// Take the user back to Stratos on the endpoints page | ||
redirect := fmt.Sprintf("/endpoints?cnsi_guid=%s&status=%s", endpointGUID, status) | ||
c.Redirect(http.StatusTemporaryRedirect, redirect) | ||
return nil | ||
} | ||
|
||
// Connect to the given Endpoint | ||
// Note, an admin user can connect an endpoint as a system endpoint to share it with others | ||
func (p *portalProxy) loginToCNSI(c echo.Context) error { | ||
|
@@ -525,7 +596,9 @@ func (p *portalProxy) login(c echo.Context, skipSSLValidation bool, client strin | |
if c.Request().Method() == http.MethodGet { | ||
code := c.QueryParam("code") | ||
state := c.QueryParam("state") | ||
uaaRes, err = p.getUAATokenWithAuthorizationCode(skipSSLValidation, code, client, clientSecret, endpoint, state) | ||
// If this is login for a CNSI, then the redirect URL is slightly different | ||
cnsiGUID := c.QueryParam("guid") | ||
uaaRes, err = p.getUAATokenWithAuthorizationCode(skipSSLValidation, code, client, clientSecret, endpoint, state, cnsiGUID) | ||
} else { | ||
username := c.FormValue("username") | ||
password := c.FormValue("password") | ||
|
@@ -584,15 +657,15 @@ func (p *portalProxy) logout(c echo.Context) error { | |
return c.JSON(http.StatusOK, resp) | ||
} | ||
|
||
func (p *portalProxy) getUAATokenWithAuthorizationCode(skipSSLValidation bool, code, client, clientSecret, authEndpoint string, state string) (*UAAResponse, error) { | ||
func (p *portalProxy) getUAATokenWithAuthorizationCode(skipSSLValidation bool, code, client, clientSecret, authEndpoint string, state string, cnsiGUID string) (*UAAResponse, error) { | ||
log.Debug("getUAATokenWithCreds") | ||
|
||
body := url.Values{} | ||
body.Set("grant_type", "authorization_code") | ||
body.Set("code", code) | ||
body.Set("client_id", client) | ||
body.Set("client_secret", clientSecret) | ||
body.Set("redirect_uri", getSSORedirectURI(state, state)) | ||
body.Set("redirect_uri", getSSORedirectURI(state, state, cnsiGUID)) | ||
|
||
return p.getUAAToken(body, skipSSLValidation, client, clientSecret, authEndpoint) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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's
Single Sign-On
in the text below, whileSingle sign-on
here