Skip to content

Commit 269ec82

Browse files
authored
Add a test for deleting already deleted job without permissions (#3922)
1 parent 8630a9b commit 269ec82

21 files changed

+279
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
jobs:
6+
foo:
7+
permissions:
8+
- service_principal_name: $CURRENT_USER_NAME
9+
level: CAN_MANAGE
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
>>> musterr as-test-sp [CLI] bundle destroy --auto-approve
3+
Warn: cannot read resources.jobs.foo id="[NUMID]": User [UUID] does not have View or Admin or Manage Run or Owner permissions on job [NUMID]
4+
Warn: cannot read resources.jobs.foo.permissions id="/jobs/[NUMID]": [UUID] does not have Manage permissions on Job with ID: ElasticJobId([NUMID]). Please contact the owner or an administrator for access.
5+
The following resources will be deleted:
6+
delete job foo
7+
8+
All files and directories at the following location will be deleted: /Workspace/Users/[UUID]/.bundle/test-bundle-[UNIQUE_NAME]/default
9+
10+
Error: cannot delete resources.jobs.foo: deleting id=[NUMID]: User [UUID] does not have Admin or Owner permissions on job [NUMID] (403 PERMISSION_DENIED)
11+
12+
Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/delete
13+
HTTP Status: 403 Forbidden
14+
API error_code: PERMISSION_DENIED
15+
API message: User [UUID] does not have Admin or Owner permissions on job [NUMID]
16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
>>> musterr as-test-sp [CLI] bundle destroy --auto-approve
3+
Error: exit status 1
4+
5+
Error: cannot read job: User [UUID] does not have View or Admin or Manage Run or Owner permissions on job [NUMID]
6+
7+
with databricks_job.foo,
8+
on bundle.tf.json line 27, in resource.databricks_job.foo:
9+
27: }
10+
11+
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
>>> errcode as-test-sp [CLI] bundle destroy --auto-approve
3+
Warn: cannot read resources.jobs.foo id="[NUMID]": User [UUID] does not have View or Admin or Manage Run or Owner permissions on job [NUMID]
4+
The following resources will be deleted:
5+
delete job foo
6+
7+
All files and directories at the following location will be deleted: /Workspace/Users/[UUID]/.bundle/test-bundle-[UNIQUE_NAME]/default
8+
9+
Error: cannot delete resources.jobs.foo: deleting id=[NUMID]: User [UUID] does not have Admin or Owner permissions on job [NUMID] (403 PERMISSION_DENIED)
10+
11+
Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/delete
12+
HTTP Status: 403 Forbidden
13+
API error_code: PERMISSION_DENIED
14+
API message: User [UUID] does not have Admin or Owner permissions on job [NUMID]
15+
16+
17+
Exit code: 1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
>>> errcode as-test-sp [CLI] bundle destroy --auto-approve
3+
Error: exit status 1
4+
5+
Error: cannot read job: User [UUID] does not have View or Admin or Manage Run or Owner permissions on job [NUMID]
6+
7+
with databricks_job.foo,
8+
on bundle.tf.json line 27, in resource.databricks_job.foo:
9+
27: }
10+
11+
12+
13+
14+
Exit code: 1

acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/out.test.toml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
>>> cat take_ownership.json
3+
{
4+
"access_control_list": [{"permission_level": "IS_OWNER", "service_principal_name": "[USERNAME]"}]
5+
}
6+
7+
>>> as-test-sp [CLI] current-user me
8+
"deco-test-spn"
9+
10+
>>> [CLI] bundle destroy --auto-approve
11+
No active deployment found to destroy!
12+
13+
>>> as-test-sp [CLI] bundle deploy
14+
Uploading bundle files to /Workspace/Users/[UUID]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
15+
Deploying resources...
16+
Updating deployment state...
17+
Deployment complete!
18+
19+
>>> [CLI] permissions set jobs [NUMID] --json @take_ownership.json
20+
21+
>>> [CLI] jobs delete [NUMID]
22+
23+
>>> musterr [CLI] jobs get [NUMID]
24+
Error: Job [NUMID] does not exist.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
envsubst < take_ownership.json.tmpl > take_ownership.json
3+
trace cat take_ownership.json
4+
5+
trace as-test-sp $CLI current-user me | jq .displayName
6+
7+
cleanup() {
8+
trace $CLI bundle destroy --auto-approve
9+
}
10+
cleanup EXIT
11+
12+
trace as-test-sp $CLI bundle deploy
13+
14+
job_id=$($CLI bundle summary --output json | jq -r '.resources.jobs.foo.id')
15+
16+
trace $CLI permissions set jobs $job_id --json @take_ownership.json > /dev/null
17+
18+
trace musterr as-test-sp $CLI bundle destroy --auto-approve &> out.destroy1.$DATABRICKS_BUNDLE_ENGINE.txt
19+
20+
trace $CLI jobs delete $job_id
21+
trace musterr $CLI jobs get $job_id
22+
23+
# This shows that even if job is deleted, you still get permission error when trying to delete it.
24+
trace errcode as-test-sp $CLI bundle destroy --auto-approve &> out.destroy2.$DATABRICKS_BUNDLE_ENGINE.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"access_control_list": [{"permission_level": "IS_OWNER", "service_principal_name": "$DATABRICKS_CLIENT_ID"}]
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Local = false
2+
Cloud = true
3+
RecordRequests = false
4+
CloudEnvs.gcp = false
5+
CloudEnvs.azure = false
6+
7+
Ignore = ["take_ownership.json", "databricks.yml"]

0 commit comments

Comments
 (0)