@@ -444,34 +444,50 @@ def prepared_principal_acl(runtime_ctx, env_or_skip, make_mounted_location, make
444
444
445
445
446
446
@retried (on = [NotFound ], timeout = timedelta (minutes = 2 ))
447
- def test_migrate_managed_tables_with_principal_acl_azure (
448
- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster
447
+ def test_migrate_external_tables_with_principal_acl_azure (
448
+ ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , make_ucx_group
449
449
):
450
450
if not ws .config .is_azure :
451
451
pytest .skip ("only works in azure test env" )
452
452
ctx , table_full_name = prepared_principal_acl
453
453
cluster = make_cluster (single_node = True , spark_conf = _SPARK_CONF , data_security_mode = DataSecurityMode .NONE )
454
454
ctx .with_dummy_resource_permission ()
455
455
table_migrate = ctx .tables_migrator
456
- user = make_user ()
456
+
457
+ user_with_cluster_access = make_user ()
458
+ user_without_cluster_access = make_user ()
459
+ group_with_cluster_access , _ = make_ucx_group ()
457
460
make_cluster_permissions (
458
461
object_id = cluster .cluster_id ,
459
462
permission_level = PermissionLevel .CAN_ATTACH_TO ,
460
- user_name = user .user_name ,
463
+ user_name = user_with_cluster_access .user_name ,
464
+ group_name = group_with_cluster_access .display_name ,
461
465
)
462
466
table_migrate .migrate_tables (what = What .EXTERNAL_SYNC , acl_strategy = [AclMigrationWhat .PRINCIPAL ])
463
467
464
468
target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
465
469
match = False
466
470
for _ in target_table_grants .privilege_assignments :
467
- if _ .principal == user .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
471
+ if _ .principal == user_with_cluster_access .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
468
472
match = True
469
473
break
470
474
assert match
471
475
476
+ match = False
477
+ for _ in target_table_grants .privilege_assignments :
478
+ if _ .principal == group_with_cluster_access .display_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
479
+ match = True
480
+ break
481
+ assert match
482
+
483
+ for _ in target_table_grants .privilege_assignments :
484
+ if _ .principal == user_without_cluster_access .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
485
+ assert False , "User without cluster access should not have access to the table"
486
+ assert True
487
+
472
488
473
489
@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
474
- def test_migrate_managed_tables_with_principal_acl_aws (
490
+ def test_migrate_external_tables_with_principal_acl_aws (
475
491
ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , env_or_skip
476
492
):
477
493
ctx , table_full_name = prepared_principal_acl
@@ -497,3 +513,31 @@ def test_migrate_managed_tables_with_principal_acl_aws(
497
513
match = True
498
514
break
499
515
assert match
516
+
517
+
518
+ def test_migrate_external_tables_with_spn_azure (
519
+ ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster
520
+ ):
521
+ if not ws .config .is_azure :
522
+ pytest .skip ("temporary: only works in azure test env" )
523
+ ctx , table_full_name = prepared_principal_acl
524
+ cluster = make_cluster (single_node = True , spark_conf = _SPARK_CONF , data_security_mode = DataSecurityMode .NONE )
525
+ ctx .with_dummy_resource_permission ()
526
+
527
+ table_migrate = ctx .tables_migrator
528
+
529
+ spn_with_mount_access = "5a11359f-ba1f-483f-8e00-0fe55ec003ed"
530
+ make_cluster_permissions (
531
+ object_id = cluster .cluster_id ,
532
+ permission_level = PermissionLevel .CAN_ATTACH_TO ,
533
+ service_principal_name = spn_with_mount_access ,
534
+ )
535
+ table_migrate .migrate_tables (what = What .EXTERNAL_SYNC , acl_strategy = [AclMigrationWhat .PRINCIPAL ])
536
+
537
+ target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
538
+ match = False
539
+ for _ in target_table_grants .privilege_assignments :
540
+ if _ .principal == spn_with_mount_access and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
541
+ match = True
542
+ break
543
+ assert match
0 commit comments