Skip to content

Commit

Permalink
Fix UserContext SSO detection in UI for Okta Users
Browse files Browse the repository at this point in the history
Okta imported users are not being properly identified as SSO users.
Okta does not set any of the Users' identities and instead only sets the
User.Connector.CreatedBy field.

When building the UserContext, which is used by the WebUI, it was
returning `local` user type for Okta users.
  • Loading branch information
marcoandredinis committed Oct 25, 2024
1 parent 02bb832 commit 5caea60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/web/ui/usercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func NewUserContext(user types.User, userRoles services.RoleSet, features proto.
authType := authLocal

// check for any SSO identities
isSSO := len(user.GetOIDCIdentities()) > 0 ||
isSSO := user.GetUserType() == types.UserTypeSSO ||
len(user.GetOIDCIdentities()) > 0 ||
len(user.GetGithubIdentities()) > 0 ||
len(user.GetSAMLIdentities()) > 0

Expand Down
19 changes: 19 additions & 0 deletions lib/web/ui/usercontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ func TestNewUserContext(t *testing.T) {
userContext, err = NewUserContext(user, roleSet, proto.Features{}, true, false)
require.NoError(t, err)
require.Equal(t, authSSO, userContext.AuthType)

// test sso auth type for users with the CreatedBy.Connector field set.
// Eg users import from okta do not have any <IdP>Identities, so the CreatedBy.Connector must be checked.
userCreatedExternally := &types.UserV2{
Metadata: types.Metadata{
Name: "root",
},
Status: types.UserStatusV2{
PasswordState: types.PasswordState_PASSWORD_STATE_SET,
},
Spec: types.UserSpecV2{
CreatedBy: types.CreatedBy{
Connector: &types.ConnectorRef{},
},
},
}
userContext, err = NewUserContext(userCreatedExternally, roleSet, proto.Features{}, true, false)
require.NoError(t, err)
require.Equal(t, authSSO, userContext.AuthType)
}

func TestNewUserContextCloud(t *testing.T) {
Expand Down

0 comments on commit 5caea60

Please sign in to comment.