Skip to content

Commit 9a1cc33

Browse files
authored
Ensure owner/mgmt permission for current user (#3780)
## Changes Instead of removing current user from permissions and relying on terraform to add it back, we'll instead add IS_OWNER/CAN_MANAGE ourselves. Previous attempt to remove this mutator completely #3688 failed because backend complains about "ambiguous" permissions when both CAN_MANAGE and IS_OWNER are present. Thus we do additional transformation here: we upgrade CAN_MANAGE to IS_OWNER if we can. Don't apply this logic to secret scopes resource as it's not implemented via databricks_permissions resource in terraform and does not have IS_OWNER/CAN_MANAGE insertion logic. This means we no longer filter out current user permissions from secret scopes resources. ## Why - Enables direct implementation which will not do any transformations, just use whatever in the config. With this PR, the request payload will match terraform's. - Final permissions visible in 'bundle validate -o json'. ## Tests #3781
1 parent 9b32fc1 commit 9a1cc33

File tree

31 files changed

+301
-345
lines changed

31 files changed

+301
-345
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
### Dependency updates
1010

1111
### Bundles
12+
* For secret scopes, no longer remove current user's permissions ([#3780](https://github.com/databricks/cli/pull/3780))
13+
* Automatically add owner permissions during bundle initialization, this makes final permissions visible in 'bundle validate -o json' ([#3780](https://github.com/databricks/cli/pull/3780))
1214

1315
### API Changes

acceptance/bundle/resources/permissions/apps/current_can_manage/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
{
1313
"level": "CAN_MANAGE",
1414
"service_principal_name": "[UUID]"
15+
},
16+
{
17+
"level": "CAN_MANAGE",
18+
"user_name": "[USERNAME]"
1519
}
1620
]
1721

acceptance/bundle/resources/permissions/apps/other_can_manage/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
{
1313
"level": "CAN_MANAGE",
1414
"service_principal_name": "[UUID]"
15+
},
16+
{
17+
"level": "CAN_MANAGE",
18+
"user_name": "[USERNAME]"
1519
}
1620
]
1721

acceptance/bundle/resources/permissions/jobs/current_can_manage/databricks.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ resources:
1414
group_name: data-team
1515
- level: CAN_MANAGE
1616
service_principal_name: f37d18cd-98a8-4db5-8112-12dd0a6bfe38
17-
# job with explicit CAN_MANAGE matching username, will be filtered out by DABs; terraform will add IS_OWNER
17+
# job with explicit CAN_MANAGE matching username, we will upgrade CAN_MANAGE to IS_OWNER
18+
# If we don't, then terraform will add IS_OWNER and we will end up with both CAN_MANAGE and IS_OWNER
19+
# which can lead to
20+
# Error: cannot create permissions: Permissions being set for UserName([USERNAME]) are ambiguous
1821
- level: CAN_MANAGE
1922
user_name: [email protected]

acceptance/bundle/resources/permissions/jobs/current_can_manage/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
{
1313
"level": "CAN_MANAGE",
1414
"service_principal_name": "[UUID]"
15+
},
16+
{
17+
"level": "IS_OWNER",
18+
"user_name": "[USERNAME]"
1519
}
1620
]
1721

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"method": "PUT",
3+
"path": "/api/2.0/permissions/jobs/[NUMID]",
4+
"body": {
5+
"access_control_list": [
6+
{
7+
"permission_level": "IS_OWNER",
8+
"user_name": "[USERNAME]"
9+
}
10+
]
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"method": "PUT",
3+
"path": "/api/2.0/permissions/jobs/[NUMID]",
4+
"body": {
5+
"access_control_list": [
6+
{
7+
"permission_level": "IS_OWNER",
8+
"user_name": "[USERNAME]"
9+
}
10+
]
11+
}
12+
}

acceptance/bundle/resources/permissions/jobs/current_is_owner/output.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
>>> [CLI] bundle validate -o json
3-
[]
3+
[
4+
{
5+
"level": "IS_OWNER",
6+
"user_name": "[USERNAME]"
7+
}
8+
]
49

510
>>> [CLI] bundle deploy
611
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...

acceptance/bundle/resources/permissions/jobs/other_can_manage/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
{
1313
"level": "CAN_MANAGE",
1414
"service_principal_name": "[UUID]"
15+
},
16+
{
17+
"level": "IS_OWNER",
18+
"user_name": "[USERNAME]"
1519
}
1620
]
1721

acceptance/bundle/resources/permissions/jobs/other_is_owner/out.requests.deploy.terraform.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
{
77
"permission_level": "IS_OWNER",
88
"user_name": "[email protected]"
9+
},
10+
{
11+
"permission_level": "IS_OWNER",
12+
"user_name": "[USERNAME]"
913
}
1014
]
1115
}

0 commit comments

Comments
 (0)