Skip to content

Commit 1c047c4

Browse files
authored
Fix issue where Stratos SSO failed to show (#4764)
* 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
1 parent bc7f4e9 commit 1c047c4

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

src/jetstream/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,11 @@ func (p *portalProxy) registerRoutes(e *echo.Echo, needSetupMiddleware bool) {
957957

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

960+
api := e.Group("/api")
961+
api.Use(p.setSecureCacheContentMiddleware)
962+
960963
// Verify Session
961-
e.GET("/api/v1/auth/verify", p.verifySession)
964+
api.GET("/v1/auth/verify", p.verifySession)
962965

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

10121015
// API endpoints with Swagger documentation and accessible with an API key
1013-
stableAPIGroup := e.Group("/api/v1")
1016+
stableAPIGroup := api.Group("/v1")
10141017
stableAPIGroup.Use(p.apiKeyMiddleware)
10151018
stableAPIGroup.Use(p.sessionMiddlewareWithConfig(apiKeyGroupConfig))
10161019
stableAPIGroup.Use(p.xsrfMiddlewareWithConfig(apiKeyGroupConfig))

src/jetstream/middleware.go

-14
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const cfSessionCookieName = "JSESSIONID"
2424
// Header to communicate the configured Cookie Domain
2525
const StratosDomainHeader = "x-stratos-domain"
2626

27-
// Header to communicate whether SSO Login is enabled and if so, any configured options
28-
const StratosSSOHeader = "x-stratos-sso-login"
29-
3027
// Header to communicate any error during SSO
3128
const StratosSSOErrorHeader = "x-stratos-sso-error"
3229

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

45-
// Add header so front-end knows SSO login is enabled
46-
if config.SSOLogin {
47-
// A non-empty SSO Header means SSO is enabled
48-
// Use the string "enabled" or send the options string if we have one
49-
options := "enabled"
50-
if len(config.SSOOptions) > 0 {
51-
options = config.SSOOptions
52-
}
53-
c.Response().Header().Set(StratosSSOHeader, options)
54-
}
55-
5642
if strings.Contains(err.Error(), "dial tcp") {
5743
return interfaces.NewHTTPShadowError(
5844
http.StatusServiceUnavailable,

src/jetstream/session.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const (
3333
jetstreamSessionName = "console-session"
3434
jetStreamSessionContextKey = "jetstream-session"
3535
jetStreamSessionContextUpdatedKey = "jetstream-session-updated"
36+
37+
// Header to communicate whether SSO Login is enabled and if so, any configured options
38+
stratosSSOHeader = "x-stratos-sso-login"
3639
)
3740

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

277-
var jsonErr error
278-
279280
info, sessionVerifyErr := collectErrors(p, c)
280281
if sessionVerifyErr != nil {
281282
p.clearSessionCookie(c, true)
282283

283-
jsonErr = c.JSON(
284+
// Add header so front-end knows SSO login is enabled
285+
if p.Config.SSOLogin {
286+
// A non-empty SSO Header means SSO is enabled
287+
// Use the string "enabled" or send the options string if we have one
288+
options := "enabled"
289+
if len(p.Config.SSOOptions) > 0 {
290+
options = p.Config.SSOOptions
291+
}
292+
c.Response().Header().Set(stratosSSOHeader, options)
293+
}
294+
295+
return c.JSON(
284296
http.StatusOK,
285297
SessionInfoEnvelope{
286298
Status: "error",
287299
Error: sessionVerifyErr.Error(),
288300
},
289301
)
290-
} else {
291-
jsonErr = c.JSON(
292-
http.StatusOK,
293-
SessionInfoEnvelope{
294-
Status: "ok",
295-
Data: info,
296-
},
297-
)
298302
}
299303

300-
if jsonErr != nil {
301-
return jsonErr
302-
}
303-
304-
return nil
304+
return c.JSON(
305+
http.StatusOK,
306+
SessionInfoEnvelope{
307+
Status: "ok",
308+
Data: info,
309+
},
310+
)
305311
}

0 commit comments

Comments
 (0)