Skip to content

Commit 46c243a

Browse files
denikIsaac
andauthored
direct: Do not drop MANAGE and other privileges not implied by ALL_PRIVILEGES (databricks#6733)
## Changes Keep the four privileges Unity Catalog does not include in `ALL_PRIVILEGES` (`MANAGE`, `READ_METADATA`, `EXTERNAL_USE_SCHEMA`, `EXTERNAL_USE_LOCATION`) when normalizing grants, and revoke a dropped one by name. ## Why On the direct engine, granting e.g. `[MANAGE, ALL_PRIVILEGES]` silently sent only `ALL_PRIVILEGES`. `normalizeAssignments` (added in databricks#6064 for databricks#6030) collapsed any principal holding `ALL_PRIVILEGES` down to just `ALL_PRIVILEGES` on both the config and the read side, so `MANAGE` was dropped from the request and the missing grant went unnoticed in the plan. Terraform sends both, which is why the bug showed up only after the engine default changed. `ALL_PRIVILEGES` does not imply these four: https://docs.databricks.com/aws/en/data-governance/unity-catalog/manage-privileges/privileges ## Tests New acceptance tests `grants/schemas/all_privileges_manage` (grant `MANAGE` + `ALL_PRIVILEGES`) and `grants/schemas/manage_out_of_band` (an out-of-band `MANAGE` grant is reconciled without a perpetual update), plus unit coverage. Local + cloud, both engines. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <[email protected]>
1 parent f39affb commit 46c243a

13 files changed

Lines changed: 296 additions & 32 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Fixed the direct engine dropping `MANAGE`, `READ_METADATA`, `EXTERNAL_USE_SCHEMA` and `EXTERNAL_USE_LOCATION` grants when they were combined with `ALL_PRIVILEGES`. ([#6733](https://github.com/databricks/cli/pull/6733))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bundle:
2+
name: schema-grants-all-privileges-manage-$UNIQUE_NAME
3+
4+
resources:
5+
schemas:
6+
grants_schema:
7+
name: schema_all_priv_manage_$UNIQUE_NAME
8+
catalog_name: main
9+
grants:
10+
# Config declares both MANAGE and ALL_PRIVILEGES for the principal.
11+
# ALL_PRIVILEGES does not imply MANAGE (UC treats MANAGE as a distinct
12+
# privilege), so both must reach the backend. Reproduces the bug where
13+
# normalizeAssignments collapses the list to just ALL_PRIVILEGES and
14+
# silently drops MANAGE.
15+
- principal: $CURRENT_USER_NAME
16+
privileges:
17+
- MANAGE
18+
- ALL_PRIVILEGES

‎acceptance/bundle/resources/grants/schemas/all_privileges_manage/out.test.toml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/schema-grants-all-privileges-manage-[UNIQUE_NAME]/default/files...
4+
Created schemas.grants_schema
5+
Created schemas.grants_schema.grants
6+
Files: 3 uploaded, 0 deleted
7+
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
8+
9+
>>> print_requests.py --method PATCH //permissions
10+
{
11+
"method": "PATCH",
12+
"path": "/api/2.1/unity-catalog/permissions/schema/main.schema_all_priv_manage_[UNIQUE_NAME]",
13+
"body": {
14+
"changes": [
15+
{
16+
"add": [
17+
"ALL_PRIVILEGES",
18+
"MANAGE"
19+
],
20+
"principal": "[USERNAME]"
21+
}
22+
]
23+
}
24+
}
25+
26+
>>> [CLI] grants get schema main.schema_all_priv_manage_[UNIQUE_NAME] -o json
27+
ALL_PRIVILEGES
28+
MANAGE
29+
30+
>>> [CLI] bundle plan
31+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
32+
33+
>>> errcode [CLI] bundle destroy --auto-approve
34+
The following resources will be deleted:
35+
delete resources.schemas.grants_schema
36+
37+
This action will result in the deletion of the following UC schemas. Any underlying data may be lost:
38+
delete resources.schemas.grants_schema
39+
40+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/schema-grants-all-privileges-manage-[UNIQUE_NAME]/default
41+
42+
Destroy: 1 deleted
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SCHEMA_FULL_NAME=main.schema_all_priv_manage_$UNIQUE_NAME
2+
3+
envsubst < databricks.yml.tmpl > databricks.yml
4+
5+
cleanup() {
6+
trace errcode $CLI bundle destroy --auto-approve
7+
rm -f "$OUT_REQUESTS"
8+
}
9+
trap cleanup EXIT
10+
11+
trace $CLI bundle deploy
12+
13+
# The PATCH sent to the backend must add both MANAGE and ALL_PRIVILEGES: ALL_PRIVILEGES
14+
# does not imply MANAGE, so dropping MANAGE here silently strips the grant. Both engines
15+
# send the same request.
16+
trace print_requests.py --method PATCH //permissions
17+
18+
# Read the grants back: both MANAGE and ALL_PRIVILEGES must be present. Privilege order
19+
# is backend-controlled, so extract and sort the principal's privileges into a stable list.
20+
trace $CLI grants get schema "$SCHEMA_FULL_NAME" -o json | jq -r ".privilege_assignments[] | select(.principal == env.CURRENT_USER_NAME) | .privileges[]" | sort
21+
22+
# A follow-up plan must report no changes.
23+
trace $CLI bundle plan
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bundle:
2+
name: schema-grants-manage-out-of-band-$UNIQUE_NAME
3+
4+
resources:
5+
schemas:
6+
grants_schema:
7+
name: schema_manage_oob_$UNIQUE_NAME
8+
catalog_name: main
9+
grants:
10+
# Config declares only ALL_PRIVILEGES for the principal. MANAGE is granted
11+
# out of band below; because ALL_PRIVILEGES does not imply MANAGE, the
12+
# deploy must revoke it by name so the plan converges instead of reporting
13+
# a perpetual update.
14+
- principal: $CURRENT_USER_NAME
15+
privileges:
16+
- ALL_PRIVILEGES

‎acceptance/bundle/resources/grants/schemas/manage_out_of_band/out.test.toml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/schema-grants-manage-out-of-band-[UNIQUE_NAME]/default/files...
4+
Created schemas.grants_schema
5+
Created schemas.grants_schema.grants
6+
Files: 5 uploaded, 0 deleted
7+
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
8+
9+
>>> [CLI] grants update schema main.schema_manage_oob_[UNIQUE_NAME] --json @update.resolved.json
10+
11+
>>> [CLI] bundle plan
12+
update schemas.grants_schema.grants
13+
14+
Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged
15+
16+
>>> [CLI] bundle deploy -qq
17+
18+
>>> [CLI] bundle plan
19+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
20+
21+
>>> errcode [CLI] bundle destroy --auto-approve
22+
The following resources will be deleted:
23+
delete resources.schemas.grants_schema
24+
25+
This action will result in the deletion of the following UC schemas. Any underlying data may be lost:
26+
delete resources.schemas.grants_schema
27+
28+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/schema-grants-manage-out-of-band-[UNIQUE_NAME]/default
29+
30+
Destroy: 1 deleted
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SCHEMA_FULL_NAME=main.schema_manage_oob_$UNIQUE_NAME
2+
3+
envsubst < databricks.yml.tmpl > databricks.yml
4+
5+
cleanup() {
6+
trace errcode $CLI bundle destroy --auto-approve
7+
rm -f "$OUT_REQUESTS"
8+
}
9+
trap cleanup EXIT
10+
11+
trace $CLI bundle deploy
12+
13+
# Out of band, grant MANAGE in addition to the ALL_PRIVILEGES the config declares
14+
# for the same principal. Unlike a concrete privilege, MANAGE is not implied by
15+
# ALL_PRIVILEGES, so it shows up as real drift the deploy must reconcile. Both
16+
# engines detect the same drift, so the plan output is identical between them.
17+
envsubst < update.json > update.resolved.json
18+
trace $CLI grants update schema "$SCHEMA_FULL_NAME" --json @update.resolved.json > /dev/null
19+
20+
# The first plan reports drift: MANAGE is present remotely but not in the config.
21+
trace $CLI bundle plan
22+
23+
# After deploying, both engines converge: the follow-up plan reports no changes.
24+
# The deploy summary diverges between engines (each revokes MANAGE its own way),
25+
# so deploy with -qq to keep the output engine-stable.
26+
trace $CLI bundle deploy -qq
27+
trace $CLI bundle plan
28+
29+
# MANAGE must be gone; only ALL_PRIVILEGES remains.
30+
$CLI grants get schema "$SCHEMA_FULL_NAME" | gron.py --noindex | sort | contains.py ALL_PRIVILEGES '!MANAGE' > /dev/null
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore = ['update.resolved.json']

0 commit comments

Comments
 (0)