Skip to content

Commit 903fc1b

Browse files
committed
Wire in BatonID matching for database roles
1 parent 14c2166 commit 903fc1b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pkg/connector/database_role.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ func (d *databaseRolePrincipalSyncer) Grants(
217217
return nil, "", nil, fmt.Errorf("invalid state: principalID is nil")
218218
}
219219

220-
ret = append(ret, grTypes.NewGrant(resource, "member", principalID))
220+
grantOpts, err := BuildBatonIDGrantOptions(principalID, dbPrincipal.Type, dbPrincipal.Name)
221+
if err != nil {
222+
return nil, "", nil, err
223+
}
224+
225+
ret = append(ret, grTypes.NewGrant(resource, "member", principalID, grantOpts...))
221226
}
222227

223228
visited[b.ResourceID()] = true

pkg/connector/server_role.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (d *serverRolePrincipalSyncer) Grants(ctx context.Context, resource *v2.Res
179179
return nil, "", nil, err
180180
}
181181

182-
grantOpts, err := BuildBatonIDGrantOptions(principalID, principal)
182+
grantOpts, err := BuildBatonIDGrantOptions(principalID, principal.Type, principal.Name)
183183
if err != nil {
184184
return nil, "", nil, err
185185
}
@@ -201,10 +201,10 @@ func (d *serverRolePrincipalSyncer) Grants(ctx context.Context, resource *v2.Res
201201
return ret, npt, nil, nil
202202
}
203203

204-
func BuildBatonIDGrantOptions(principalID *v2.ResourceId, principal *mssqldb.RolePrincipalModel) ([]grTypes.GrantOption, error) {
204+
func BuildBatonIDGrantOptions(principalID *v2.ResourceId, principalType string, principalName string) ([]grTypes.GrantOption, error) {
205205
grantOpts := []grTypes.GrantOption{}
206206

207-
switch principal.Type {
207+
switch principalType {
208208
case "G": // Configure BatonID matching for Active Directory groups
209209
gr := &v2.Resource{
210210
Id: principalID,
@@ -220,7 +220,7 @@ func BuildBatonIDGrantOptions(principalID *v2.ResourceId, principal *mssqldb.Rol
220220
grTypes.WithAnnotation(&v2.ExternalResourceMatch{
221221
ResourceType: v2.ResourceType_TRAIT_GROUP,
222222
Key: "downlevel_logon_name",
223-
Value: principal.Name,
223+
Value: principalName,
224224
}),
225225
grTypes.WithAnnotation(&v2.GrantExpandable{
226226
EntitlementIds: []string{bidEnt},
@@ -232,7 +232,7 @@ func BuildBatonIDGrantOptions(principalID *v2.ResourceId, principal *mssqldb.Rol
232232
grTypes.WithAnnotation(&v2.ExternalResourceMatch{
233233
ResourceType: v2.ResourceType_TRAIT_USER,
234234
Key: "downlevel_logon_name",
235-
Value: principal.Name,
235+
Value: principalName,
236236
}),
237237
)
238238
}

0 commit comments

Comments
 (0)