Skip to content

fix: use default org over index [0] for new scim #12284

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

Merged
merged 1 commit into from
Feb 23, 2024
Merged
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
15 changes: 5 additions & 10 deletions enterprise/coderd/scim.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,22 @@ func (api *API) scimPostUser(rw http.ResponseWriter, r *http.Request) {
sUser.UserName = httpapi.UsernameFrom(sUser.UserName)
}

var organizationID uuid.UUID
// TODO: This is a temporary solution that does not support multi-org
// deployments. This assumption places all new SCIM users into the
// default organization.
//nolint:gocritic
organizations, err := api.Database.GetOrganizations(dbauthz.AsSystemRestricted(ctx))
defaultOrganization, err := api.Database.GetDefaultOrganization(dbauthz.AsSystemRestricted(ctx))
if err != nil {
_ = handlerutil.WriteError(rw, err)
return
}

if len(organizations) > 0 {
// Add the user to the first organization. Once multi-organization
// support is added, we should enable a configuration map of user
// email to organization.
organizationID = organizations[0].ID
}

//nolint:gocritic // needed for SCIM
dbUser, _, err = api.AGPL.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, agpl.CreateUserRequest{
CreateUserRequest: codersdk.CreateUserRequest{
Username: sUser.UserName,
Email: email,
OrganizationID: organizationID,
OrganizationID: defaultOrganization.ID,
},
LoginType: database.LoginTypeOIDC,
})
Expand Down