Skip to content
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

Fix UserContext SSO detection in UI for Okta Users #47944

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions api/types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,15 @@ func (u UserV2) GetGCPServiceAccounts() []string {

// GetUserType indicates if the User was created by an SSO Provider or locally.
func (u UserV2) GetUserType() UserType {
if u.GetCreatedBy().Connector == nil {
return UserTypeLocal
if u.GetCreatedBy().Connector != nil ||
len(u.GetOIDCIdentities()) > 0 ||
len(u.GetGithubIdentities()) > 0 ||
len(u.GetSAMLIdentities()) > 0 {

return UserTypeSSO
}

return UserTypeSSO
return UserTypeLocal
}

// IsBot returns true if the user is a bot.
Expand Down
4 changes: 1 addition & 3 deletions lib/web/ui/usercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func NewUserContext(user types.User, userRoles services.RoleSet, features proto.
authType := authLocal

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

if isSSO {
// SSO user
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
Loading