@@ -382,9 +382,9 @@ func overrideSessionTimeZone(session *Session) {
382
382
// or caveats to nil for the migrated session in that scenario, so that the
383
383
// deep equals check does not fail in this scenario either.
384
384
//
385
- // Additionally, we sort the caveats of both the kv and sql sessions by
386
- // their ID, so that they are always comparable in a deterministic way with deep
387
- // equals.
385
+ // Additionally, we sort the caveats & permissions of both the kv and sql
386
+ // sessions by their ID, so that they are always comparable in a deterministic
387
+ // way with deep equals.
388
388
func overrideMacaroonRecipe (kvSession * Session , migratedSession * Session ) {
389
389
if kvSession .MacaroonRecipe != nil {
390
390
kvPerms := kvSession .MacaroonRecipe .Permissions
@@ -402,6 +402,7 @@ func overrideMacaroonRecipe(kvSession *Session, migratedSession *Session) {
402
402
}
403
403
404
404
sqlCaveats := migratedSession .MacaroonRecipe .Caveats
405
+ sqlPerms := migratedSession .MacaroonRecipe .Permissions
405
406
406
407
// If there have been caveats set for the MacaroonRecipe,
407
408
// the order of the postgres db caveats will in very rare cases
@@ -421,5 +422,28 @@ func overrideMacaroonRecipe(kvSession *Session, migratedSession *Session) {
421
422
) < 0
422
423
})
423
424
}
425
+
426
+ // Similarly, we sort the macaroon permissions for both the kv
427
+ // and sql sessions, so that we can compare them in a
428
+ // deterministic way.
429
+ if kvPerms != nil {
430
+ sort .Slice (kvPerms , func (i , j int ) bool {
431
+ if kvPerms [i ].Entity == kvPerms [j ].Entity {
432
+ return kvPerms [i ].Action <
433
+ kvPerms [j ].Action
434
+ }
435
+
436
+ return kvPerms [i ].Entity < kvPerms [j ].Entity
437
+ })
438
+
439
+ sort .Slice (sqlPerms , func (i , j int ) bool {
440
+ if sqlPerms [i ].Entity == sqlPerms [j ].Entity {
441
+ return sqlPerms [i ].Action <
442
+ sqlPerms [j ].Action
443
+ }
444
+
445
+ return sqlPerms [i ].Entity < sqlPerms [j ].Entity
446
+ })
447
+ }
424
448
}
425
449
}
0 commit comments