Skip to content

Commit 033538e

Browse files
btiplingclaude
andcommitted
[BB-610] Remove automatic database user creation
Only create the Windows login without adding users to all databases. Database access should be managed through ConductorOne's access request flow. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6b7e4a6 commit 033538e

File tree

1 file changed

+2
-39
lines changed

1 file changed

+2
-39
lines changed

pkg/connector/server_user.go

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (d *userPrincipalSyncer) Grants(ctx context.Context, resource *v2.Resource,
8787
return nil, "", nil, nil
8888
}
8989

90-
// CreateAccount creates a SQL Server login and database user for an Active Directory user.
90+
// CreateAccount creates a SQL Server login for an Active Directory user without adding database users.
9191
// It implements the AccountManager interface.
9292
func (d *userPrincipalSyncer) CreateAccount(
9393
ctx context.Context,
@@ -117,56 +117,19 @@ func (d *userPrincipalSyncer) CreateAccount(
117117
return nil, nil, nil, fmt.Errorf("failed to create Windows login: %w", err)
118118
}
119119

120-
// Determine the formatted username for the database user
120+
// Determine the formatted username for the login
121121
var formattedUsername string
122122
if domain != "" {
123123
formattedUsername = fmt.Sprintf("%s\\%s", domain, username)
124124
} else {
125125
formattedUsername = username
126126
}
127127

128-
// Get list of databases to create users in
129-
databases, _, err := d.client.ListDatabases(ctx, &mssqldb.Pager{})
130-
if err != nil {
131-
l.Error("Failed to retrieve databases", zap.Error(err))
132-
errMsg := fmt.Sprintf("Login created successfully, but failed to retrieve databases: %v", err)
133-
result := &v2.CreateAccountResponse_ActionRequiredResult{
134-
Message: errMsg,
135-
IsCreateAccountResult: true,
136-
}
137-
return result, nil, nil, nil
138-
}
139-
140-
// Create user in each database
141-
var dbsCreated []string
142-
for _, db := range databases {
143-
// Skip system databases
144-
if db.Name == "master" || db.Name == "tempdb" || db.Name == "model" || db.Name == "msdb" {
145-
continue
146-
}
147-
148-
err = d.client.CreateDatabaseUserForPrincipal(ctx, db.Name, formattedUsername)
149-
if err != nil {
150-
l.Error("Failed to create user in database",
151-
zap.String("database", db.Name),
152-
zap.String("user", formattedUsername),
153-
zap.Error(err))
154-
errMsg := fmt.Sprintf("Login created successfully, but failed to create user in some databases: %v", err)
155-
result := &v2.CreateAccountResponse_ActionRequiredResult{
156-
Message: errMsg,
157-
IsCreateAccountResult: true,
158-
}
159-
return result, nil, nil, nil
160-
}
161-
dbsCreated = append(dbsCreated, db.Name)
162-
}
163-
164128
// Create a resource for the newly created login
165129
profile := map[string]interface{}{
166130
"username": username,
167131
"domain": domain,
168132
"formatted_login": formattedUsername,
169-
"databases": dbsCreated,
170133
}
171134

172135
// Use email as name if it looks like an email address

0 commit comments

Comments
 (0)