Skip to content

Commit

Permalink
Fix panic in getWebConfig (#11389)
Browse files Browse the repository at this point in the history
Refactored the usage of the types.AuthPreference returned from
GetAuthPreference so that it is only accessed if there were no
errors.
  • Loading branch information
rosstimothy committed Mar 24, 2022
1 parent b060338 commit 1317f09
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,33 +879,23 @@ func (h *Handler) getWebConfig(w http.ResponseWriter, r *http.Request, p httprou
}

// get auth type & second factor type
authType := constants.Local
secondFactor := constants.SecondFactorOff
localAuth := true
cap, err := h.cfg.ProxyClient.GetAuthPreference(r.Context())
if err != nil {
var authSettings ui.WebConfigAuthSettings
if cap, err := h.cfg.ProxyClient.GetAuthPreference(r.Context()); err != nil {
h.log.WithError(err).Error("Cannot retrieve AuthPreferences.")
authSettings = ui.WebConfigAuthSettings{
Providers: authProviders,
SecondFactor: constants.SecondFactorOff,
LocalAuthEnabled: true,
AuthType: constants.Local,
}
} else {
authType = cap.GetType()
secondFactor = cap.GetSecondFactor()
localAuth = cap.GetAllowLocalAuth()
}

// disable joining sessions if proxy session recording is enabled
canJoinSessions := true
recCfg, err := h.cfg.ProxyClient.GetSessionRecordingConfig(r.Context())
if err != nil {
h.log.WithError(err).Error("Cannot retrieve SessionRecordingConfig.")
} else {
canJoinSessions = services.IsRecordAtProxy(recCfg.GetMode()) == false
}

authSettings := ui.WebConfigAuthSettings{
Providers: authProviders,
SecondFactor: secondFactor,
LocalAuthEnabled: localAuth,
AuthType: authType,
PreferredLocalMFA: cap.GetPreferredLocalMFA(),
authSettings = ui.WebConfigAuthSettings{
Providers: authProviders,
SecondFactor: cap.GetSecondFactor(),
LocalAuthEnabled: cap.GetAllowLocalAuth(),
AuthType: cap.GetType(),
PreferredLocalMFA: cap.GetPreferredLocalMFA(),
}
}

// get tunnel address to display on cloud instances
Expand All @@ -919,6 +909,15 @@ func (h *Handler) getWebConfig(w http.ResponseWriter, r *http.Request, p httprou
}
}

// disable joining sessions if proxy session recording is enabled
canJoinSessions := true
recCfg, err := h.cfg.ProxyClient.GetSessionRecordingConfig(r.Context())
if err != nil {
h.log.WithError(err).Error("Cannot retrieve SessionRecordingConfig.")
} else {
canJoinSessions = services.IsRecordAtProxy(recCfg.GetMode()) == false
}

webCfg := ui.WebConfig{
Auth: authSettings,
CanJoinSessions: canJoinSessions,
Expand Down

0 comments on commit 1317f09

Please sign in to comment.