Skip to content

Commit f6aecd3

Browse files
authored
Create UC External Location, Schema, and Table Grants based on workspace-wide Azure SPN mount points (#1374)
## Changes Most work already addressed in #1285 ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> Closes #94 ### Functionality - [ ] added relevant user documentation - [ ] added new CLI command - [ ] modified existing command: `databricks labs ucx ...` - [ ] added a new workflow - [ ] modified existing workflow: `...` - [ ] added a new table - [ ] modified existing table: `...` ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] manually tested - [ ] added unit tests - [ ] added integration tests - [ ] verified on staging environment (screenshot attached)
1 parent b13c4d9 commit f6aecd3

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

src/databricks/labs/ucx/hive_metastore/grants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ def get_interactive_cluster_grants(self) -> list[Grant]:
532532
grants.update(cluster_usage)
533533
catalog_grants = [Grant(principal, "USE", "hive_metastore") for principal in principals]
534534
grants.update(catalog_grants)
535-
536535
return list(grants)
537536

538537
def _get_privilege(self, table: Table, locations: dict[str, str], mounts: list[Mount]):

tests/integration/hive_metastore/test_migrate.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,34 +444,50 @@ def prepared_principal_acl(runtime_ctx, env_or_skip, make_mounted_location, make
444444

445445

446446
@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
449449
):
450450
if not ws.config.is_azure:
451451
pytest.skip("only works in azure test env")
452452
ctx, table_full_name = prepared_principal_acl
453453
cluster = make_cluster(single_node=True, spark_conf=_SPARK_CONF, data_security_mode=DataSecurityMode.NONE)
454454
ctx.with_dummy_resource_permission()
455455
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()
457460
make_cluster_permissions(
458461
object_id=cluster.cluster_id,
459462
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,
461465
)
462466
table_migrate.migrate_tables(what=What.EXTERNAL_SYNC, acl_strategy=[AclMigrationWhat.PRINCIPAL])
463467

464468
target_table_grants = ws.grants.get(SecurableType.TABLE, table_full_name)
465469
match = False
466470
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]:
468472
match = True
469473
break
470474
assert match
471475

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+
472488

473489
@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(
475491
ws, make_user, prepared_principal_acl, make_cluster_permissions, make_cluster, env_or_skip
476492
):
477493
ctx, table_full_name = prepared_principal_acl
@@ -497,3 +513,31 @@ def test_migrate_managed_tables_with_principal_acl_aws(
497513
match = True
498514
break
499515
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

Comments
 (0)