Skip to content

Commit

Permalink
Fix issue where Stratos SSO failed to show (#4764)
Browse files Browse the repository at this point in the history
* Fix issue where Stratos SSO failed to show
- ensure x-stratos-sso-login header is returned for verify
- also ensure secure cache middlewear rungs for /api

* fix error
  • Loading branch information
richard-cox authored Nov 10, 2020
1 parent bc7f4e9 commit 1c047c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
7 changes: 5 additions & 2 deletions src/jetstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,11 @@ func (p *portalProxy) registerRoutes(e *echo.Echo, needSetupMiddleware bool) {

staticDir, staticDirErr := getStaticFiles(p.Env().String("UI_PATH", "./ui"))

api := e.Group("/api")
api.Use(p.setSecureCacheContentMiddleware)

// Verify Session
e.GET("/api/v1/auth/verify", p.verifySession)
api.GET("/v1/auth/verify", p.verifySession)

// Always serve the backend API from /pp
pp := e.Group("/pp")
Expand Down Expand Up @@ -1010,7 +1013,7 @@ func (p *portalProxy) registerRoutes(e *echo.Echo, needSetupMiddleware bool) {
apiKeyGroupConfig := MiddlewareConfig{Skipper: p.apiKeySkipper}

// API endpoints with Swagger documentation and accessible with an API key
stableAPIGroup := e.Group("/api/v1")
stableAPIGroup := api.Group("/v1")
stableAPIGroup.Use(p.apiKeyMiddleware)
stableAPIGroup.Use(p.sessionMiddlewareWithConfig(apiKeyGroupConfig))
stableAPIGroup.Use(p.xsrfMiddlewareWithConfig(apiKeyGroupConfig))
Expand Down
14 changes: 0 additions & 14 deletions src/jetstream/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const cfSessionCookieName = "JSESSIONID"
// Header to communicate the configured Cookie Domain
const StratosDomainHeader = "x-stratos-domain"

// Header to communicate whether SSO Login is enabled and if so, any configured options
const StratosSSOHeader = "x-stratos-sso-login"

// Header to communicate any error during SSO
const StratosSSOErrorHeader = "x-stratos-sso-error"

Expand All @@ -42,17 +39,6 @@ const APIKeyAuthScheme = "Bearer"
func handleSessionError(config interfaces.PortalConfig, c echo.Context, err error, doNotLog bool, msg string) error {
log.Debug("handleSessionError")

// Add header so front-end knows SSO login is enabled
if config.SSOLogin {
// A non-empty SSO Header means SSO is enabled
// Use the string "enabled" or send the options string if we have one
options := "enabled"
if len(config.SSOOptions) > 0 {
options = config.SSOOptions
}
c.Response().Header().Set(StratosSSOHeader, options)
}

if strings.Contains(err.Error(), "dial tcp") {
return interfaces.NewHTTPShadowError(
http.StatusServiceUnavailable,
Expand Down
38 changes: 22 additions & 16 deletions src/jetstream/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
jetstreamSessionName = "console-session"
jetStreamSessionContextKey = "jetstream-session"
jetStreamSessionContextUpdatedKey = "jetstream-session-updated"

// Header to communicate whether SSO Login is enabled and if so, any configured options
stratosSSOHeader = "x-stratos-sso-login"
)

// SessionValueNotFound - Error returned when a requested key was not found in the session
Expand Down Expand Up @@ -274,32 +277,35 @@ func (p *portalProxy) verifySession(c echo.Context) error {
return info, err
}

var jsonErr error

info, sessionVerifyErr := collectErrors(p, c)
if sessionVerifyErr != nil {
p.clearSessionCookie(c, true)

jsonErr = c.JSON(
// Add header so front-end knows SSO login is enabled
if p.Config.SSOLogin {
// A non-empty SSO Header means SSO is enabled
// Use the string "enabled" or send the options string if we have one
options := "enabled"
if len(p.Config.SSOOptions) > 0 {
options = p.Config.SSOOptions
}
c.Response().Header().Set(stratosSSOHeader, options)
}

return c.JSON(
http.StatusOK,
SessionInfoEnvelope{
Status: "error",
Error: sessionVerifyErr.Error(),
},
)
} else {
jsonErr = c.JSON(
http.StatusOK,
SessionInfoEnvelope{
Status: "ok",
Data: info,
},
)
}

if jsonErr != nil {
return jsonErr
}

return nil
return c.JSON(
http.StatusOK,
SessionInfoEnvelope{
Status: "ok",
Data: info,
},
)
}

0 comments on commit 1c047c4

Please sign in to comment.