@@ -47,6 +47,34 @@ func RequiresMigration(ctx context.Context, db graph.Database) (bool, error) {
47
47
}
48
48
}
49
49
50
+ // Version_730_Migration removes the leftover 'adminrightscount' property from User nodes
51
+ func Version_730_Migration (ctx context.Context , db graph.Database ) error {
52
+ const adminRightsCount = "adminrightscount"
53
+
54
+ defer measure .LogAndMeasure (slog .LevelInfo , "Migration to remove admin_rights_count property from user nodes" )
55
+
56
+ return db .WriteTransaction (ctx , func (tx graph.Transaction ) error {
57
+ // MATCH(n:User) WHERE n.adminrightscount <> null
58
+ if nodes , err := ops .FetchNodes (tx .Nodes ().Filterf (func () graph.Criteria {
59
+ return query .And (
60
+ query .Kind (query .Node (), ad .User ),
61
+ query .IsNotNull (query .NodeProperty (adminRightsCount )),
62
+ )
63
+ })); err != nil {
64
+ return err
65
+ } else {
66
+ for _ , node := range nodes {
67
+ node .Properties .Delete (adminRightsCount )
68
+ if err := tx .UpdateNode (node ); err != nil {
69
+ return err
70
+ }
71
+ }
72
+
73
+ return nil
74
+ }
75
+ })
76
+ }
77
+
50
78
// Version_620_Migration is intended to rename the RemoteInteractiveLogonPrivilege edge to RemoteInteractiveLogonRight
51
79
// See: https://specterops.atlassian.net/browse/BED-4428
52
80
func Version_620_Migration (ctx context.Context , db graph.Database ) error {
@@ -62,7 +90,7 @@ func Version_620_Migration(ctx context.Context, db graph.Database) error {
62
90
edgeProperties := graph .NewProperties ()
63
91
edgeProperties .Set (common .LastSeen .String (), time .Now ().UTC ())
64
92
65
- //Get all RemoteInteractiveLogonPrivilege edges, use the start/end ids to insert new edges, and delete the old ones
93
+ // Get all RemoteInteractiveLogonPrivilege edges, use the start/end ids to insert new edges, and delete the old ones
66
94
return db .BatchOperation (ctx , func (batch graph.Batch ) error {
67
95
rels , err := ops .FetchRelationships (batch .Relationships ().Filter (targetCriteria ))
68
96
if err != nil {
@@ -200,7 +228,7 @@ func Version_277_Migration(ctx context.Context, db graph.Database) error {
200
228
node .Properties .Set (common .ObjectID .String (), strings .ToUpper (objectId ))
201
229
}
202
230
203
- //We may not always get these properties, so ignore errors
231
+ // We may not always get these properties, so ignore errors
204
232
if operatingSystem , err := node .Properties .Get (common .OperatingSystem .String ()).String (); err == nil && operatingSystem != "" && operatingSystem != strings .ToUpper (operatingSystem ) {
205
233
dirty = true
206
234
node .Properties .Set (common .OperatingSystem .String (), strings .ToUpper (operatingSystem ))
@@ -284,7 +312,7 @@ var Manifest = []Migration{
284
312
}
285
313
286
314
return db .WriteTransaction (ctx , func (tx graph.Transaction ) error {
287
- //Remove ADLocalGroup label from all nodes that also have the group label
315
+ // Remove ADLocalGroup label from all nodes that also have the group label
288
316
if nodes , err := ops .FetchNodes (tx .Nodes ().Filterf (func () graph.Criteria {
289
317
return query .And (
290
318
query .Kind (query .Node (), ad .LocalGroup ),
@@ -301,7 +329,7 @@ var Manifest = []Migration{
301
329
}
302
330
}
303
331
304
- //Delete all local group edges
332
+ // Delete all local group edges
305
333
if err := tx .Relationships ().Filterf (func () graph.Criteria {
306
334
return query .And (
307
335
query .Or (
@@ -335,6 +363,10 @@ var Manifest = []Migration{
335
363
Version : version.Version {Major : 6 , Minor : 2 , Patch : 0 },
336
364
Execute : Version_620_Migration ,
337
365
},
366
+ {
367
+ Version : version.Version {Major : 7 , Minor : 3 , Patch : 0 },
368
+ Execute : Version_730_Migration ,
369
+ },
338
370
}
339
371
340
372
func LatestGraphMigrationVersion () version.Version {
0 commit comments