diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/databricks.yml.tmpl new file mode 100644 index 00000000000..016684b2c8c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/output.txt new file mode 100644 index 00000000000..628dbcb0b5d --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/output.txt @@ -0,0 +1,53 @@ + +=== The service principal deploys a job that declares no permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The current identity is granted CAN_MANAGE on the job, outside the bundle + +CAN_MANAGE [USERNAME] +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_job: + name: test-job-[UNIQUE_NAME] ++ permissions: ++ - level: IS_OWNER ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +=== The job's ACL after the deploy + +IS_OWNER [TEST_SP_APPLICATION_ID] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/script new file mode 100644 index 00000000000..046080fee49 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/script @@ -0,0 +1,26 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys a job that declares no permissions" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') + +title "The current identity is granted CAN_MANAGE on the job, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"}, + {"permission_level":"CAN_MANAGE","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/test.toml new file mode 100644 index 00000000000..880752fe801 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/can_manage/test.toml @@ -0,0 +1 @@ +Badness = "Run by an identity other than the deployer, config-remote-sync leaves that identity's own CAN_MANAGE out of the permissions it imports (it assumes the syncing identity is the one that deploys), so the deployer's next deploy revokes it. The job declared no permissions, so before the sync that deploy left the ACL alone." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/databricks.yml.tmpl new file mode 100644 index 00000000000..a639a1947ea --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/databricks.yml.tmpl @@ -0,0 +1,13 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME + permissions: + - level: CAN_VIEW + group_name: users diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/output.txt new file mode 100644 index 00000000000..8834e0b0065 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/output.txt @@ -0,0 +1,68 @@ + +=== The service principal deploys a job that declares permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Created jobs.my_job.permissions +Files: 2 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged + +=== The job's ACL after the deploy + +CAN_VIEW users +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity runs config-remote-sync without any remote change + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions[service_principal_name='[TEST_SP_APPLICATION_ID]']: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -12,2 +12,4 @@ + - level: CAN_VIEW + group_name: users ++ - level: IS_OWNER ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The current identity is granted CAN_MANAGE on the job, outside the bundle + +CAN_MANAGE [USERNAME] +CAN_VIEW users +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +No changes detected. + + +>>> diff.py databricks.yml.backup databricks.yml + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Updated jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged + +=== The job's ACL after the deploy + +CAN_VIEW users +IS_OWNER [TEST_SP_APPLICATION_ID] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/script new file mode 100644 index 00000000000..cc57a802b75 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/script @@ -0,0 +1,33 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys a job that declares permissions" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id + +title "The current identity runs config-remote-sync without any remote change" +sync_and_show_diff + +title "The current identity is granted CAN_MANAGE on the job, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"}, + {"permission_level":"CAN_MANAGE","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"}, + {"permission_level":"CAN_VIEW","group_name":"users"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/test.toml new file mode 100644 index 00000000000..ad3d8e706f0 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/declared/test.toml @@ -0,0 +1 @@ +Badness = "Run by an identity other than the deployer, config-remote-sync adds the deployer's IS_OWNER to the declared permissions although nobody changed the ACL. It also reports no change for a grant made to the syncing identity itself, so the deployer's next deploy revokes that grant (the revoke predates the permissions sync, which was meant to prevent it)." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/databricks.yml.tmpl new file mode 100644 index 00000000000..467ef984f64 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + experiments: + my_experiment: + name: /Users/$TEST_SP_APPLICATION_ID/test-experiment-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/output.txt new file mode 100644 index 00000000000..d88fcab582a --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/output.txt @@ -0,0 +1,53 @@ + +=== The service principal deploys an experiment that declares no permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created experiments.my_experiment +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The current identity is granted CAN_MANAGE on the experiment, outside the bundle + +CAN_MANAGE [TEST_SP_APPLICATION_ID] +CAN_MANAGE [USERNAME] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.experiments.my_experiment + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_experiment: + name: /Users/[TEST_SP_APPLICATION_ID]/test-experiment-[UNIQUE_NAME] ++ permissions: ++ - level: CAN_MANAGE ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created experiments.my_experiment.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +=== The experiment's ACL after the deploy + +CAN_MANAGE [TEST_SP_APPLICATION_ID] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.experiments.my_experiment + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/script new file mode 100644 index 00000000000..e7ac945a23c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/script @@ -0,0 +1,26 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys an experiment that declares no permissions" +trace as-test-sp $CLI bundle deploy +experiment_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.experiments.my_experiment.id') + +title "The current identity is granted CAN_MANAGE on the experiment, outside the bundle\n" +$CLI permissions set experiments $experiment_id --json '{"access_control_list":[ + {"permission_level":"CAN_MANAGE","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"}, + {"permission_level":"CAN_MANAGE","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"} +]}' > /dev/null +print_acl experiments $experiment_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy + +title "The experiment's ACL after the deploy\n" +print_acl experiments $experiment_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/test.toml new file mode 100644 index 00000000000..a422e397e4b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/experiment/test.toml @@ -0,0 +1 @@ +Badness = "Same as ../can_manage for a resource type without IS_OWNER: the syncing identity's own CAN_MANAGE is left out of the imported permissions, so the deployer's next deploy revokes it." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/databricks.yml.tmpl new file mode 100644 index 00000000000..016684b2c8c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/output.txt new file mode 100644 index 00000000000..5d1640a262f --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/output.txt @@ -0,0 +1,61 @@ + +=== The current identity deploys a job that declares no permissions + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The service principal is granted CAN_MANAGE on the job, outside the bundle + +CAN_MANAGE [TEST_SP_APPLICATION_ID] +IS_OWNER [USERNAME] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_job: + name: test-job-[UNIQUE_NAME] ++ permissions: ++ - level: CAN_MANAGE ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal takes over the deployment and deploys the synced config + +>>> errcode as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Error: cannot create resources.jobs.my_job.permissions: [TEST_SP_APPLICATION_ID] does not have Manage permissions on Jobs: only workspace admins can change the owner of a job. Please contact the owner or an administrator for access. (403 PERMISSION_DENIED) + +Endpoint: PUT [DATABRICKS_URL]/api/2.0/permissions/jobs/[MY_JOB_ID] +HTTP Status: 403 Forbidden +API error_code: PERMISSION_DENIED +API message: [TEST_SP_APPLICATION_ID] does not have Manage permissions on Jobs: only workspace admins can change the owner of a job. Please contact the owner or an administrator for access. + +Files: 1 uploaded, 0 deleted + +Exit code: 1 + +=== The job's ACL after the deploy + +CAN_MANAGE [TEST_SP_APPLICATION_ID] +IS_OWNER [USERNAME] + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/script new file mode 100644 index 00000000000..a60a30267fa --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/handover/script @@ -0,0 +1,30 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The current identity deploys a job that declares no permissions" +trace $CLI bundle deploy +job_id=$($CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') +add_repl "$job_id" MY_JOB_ID + +title "The service principal is granted CAN_MANAGE on the job, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"}, + {"permission_level":"CAN_MANAGE","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +# Undefined: whether a deploy by another identity than the one that synced may ask for the job's +# ownership. It fails unless that identity is a workspace admin, who would become the owner. +# Before the sync wrote a permissions block, such a deploy left the ACL alone. +title "The service principal takes over the deployment and deploys the synced config" +trace errcode as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/databricks.yml.tmpl new file mode 100644 index 00000000000..016684b2c8c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/output.txt new file mode 100644 index 00000000000..a492621362b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/output.txt @@ -0,0 +1,48 @@ + +=== The service principal deploys a job that declares no permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Nobody changes the job's ACL: the deployer is its owner + +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_job: + name: test-job-[UNIQUE_NAME] ++ permissions: ++ - level: IS_OWNER ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/script new file mode 100644 index 00000000000..53ec2acc235 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/script @@ -0,0 +1,26 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys a job that declares no permissions" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') + +title "Nobody changes the job's ACL: the deployer is its owner\n" +# The backend makes the creator of a job its owner. The testserver does not record that, so set +# it there; on a real workspace the ACL is left as the deploy made it. +if [ -z "$(print_acl jobs $job_id)" ]; then + $CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"} + ]}' > /dev/null +fi +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/test.toml new file mode 100644 index 00000000000..1b0e2eac715 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/no_grants/test.toml @@ -0,0 +1 @@ +Badness = "Run by an identity other than the deployer, config-remote-sync reports a permissions change although nobody changed the ACL: it writes the deployer's IS_OWNER into the config, and the next deploy starts managing the job's ACL." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/databricks.yml.tmpl new file mode 100644 index 00000000000..016684b2c8c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/output.txt new file mode 100644 index 00000000000..2995816f6af --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/output.txt @@ -0,0 +1,61 @@ + +=== The service principal deploys a job that declares no permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The job's ownership is transferred to the current identity, outside the bundle + +CAN_MANAGE [TEST_SP_APPLICATION_ID] +IS_OWNER [USERNAME] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_job: + name: test-job-[UNIQUE_NAME] ++ permissions: ++ - level: CAN_MANAGE ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> errcode as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Error: cannot create resources.jobs.my_job.permissions: [TEST_SP_APPLICATION_ID] does not have Manage permissions on Jobs: only workspace admins can change the owner of a job. Please contact the owner or an administrator for access. (403 PERMISSION_DENIED) + +Endpoint: PUT [DATABRICKS_URL]/api/2.0/permissions/jobs/[MY_JOB_ID] +HTTP Status: 403 Forbidden +API error_code: PERMISSION_DENIED +API message: [TEST_SP_APPLICATION_ID] does not have Manage permissions on Jobs: only workspace admins can change the owner of a job. Please contact the owner or an administrator for access. + +Files: 1 uploaded, 0 deleted + +Exit code: 1 + +=== The job's ACL after the deploy + +CAN_MANAGE [TEST_SP_APPLICATION_ID] +IS_OWNER [USERNAME] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/script new file mode 100644 index 00000000000..2f64d351c00 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/script @@ -0,0 +1,27 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys a job that declares no permissions" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') +add_repl "$job_id" MY_JOB_ID + +title "The job's ownership is transferred to the current identity, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"}, + {"permission_level":"CAN_MANAGE","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace errcode as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/test.toml new file mode 100644 index 00000000000..eef0ac0e552 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/owner/test.toml @@ -0,0 +1 @@ +Badness = "After the job's ownership is transferred to another identity, a config-remote-sync run by that identity leaves its own IS_OWNER out of the permissions it imports, so the deployer's next deploy asks for the ownership back. That deploy fails, since only a workspace admin can change the owner of a job; a deployer who is an admin becomes the owner again and the new owner loses its grant on the job. The job declared no permissions, so before the sync that deploy left the ACL alone." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/script.prepare b/acceptance/bundle/config-remote-sync/permissions/other_identity/script.prepare new file mode 100644 index 00000000000..3fa23d269e8 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/script.prepare @@ -0,0 +1,5 @@ +# In these tests the test service principal deploys the bundle, as a CI pipeline would, and the +# current identity is someone else working with the same deployment. +TEST_SP_APPLICATION_ID=$(as-test-sp $CLI current-user me | jq -r .userName) +export TEST_SP_APPLICATION_ID +add_repl "$TEST_SP_APPLICATION_ID" TEST_SP_APPLICATION_ID diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/databricks.yml.tmpl new file mode 100644 index 00000000000..e54758f426f --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$CURRENT_USER_NAME/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/out.test.toml new file mode 100644 index 00000000000..2b485919a99 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/out.test.toml @@ -0,0 +1,5 @@ +Cloud = false +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/output.txt new file mode 100644 index 00000000000..230d2358483 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/output.txt @@ -0,0 +1,53 @@ + +=== The service principal deploys a job that declares no permissions into the current identity's home folder + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The current identity is granted CAN_MANAGE on the job, outside the bundle + +CAN_MANAGE [USERNAME] +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity runs config-remote-sync + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -9,2 +9,5 @@ + my_job: + name: test-job-[UNIQUE_NAME] ++ permissions: ++ - level: IS_OWNER ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +=== The job's ACL after the deploy + +IS_OWNER [TEST_SP_APPLICATION_ID] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/script new file mode 100644 index 00000000000..e7727068c74 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/script @@ -0,0 +1,27 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +# E.g. a production target whose root_path is in the home folder of the bundle's author, deployed by CI. +title "The service principal deploys a job that declares no permissions into the current identity's home folder" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') + +title "The current identity is granted CAN_MANAGE on the job, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"}, + {"permission_level":"CAN_MANAGE","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity runs config-remote-sync" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/test.toml new file mode 100644 index 00000000000..893a19f58d6 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/syncer_home/test.toml @@ -0,0 +1,5 @@ +Badness = "Same as ../can_manage, with the deployment in the syncing identity's home folder: where the deployment state lives does not tell who deploys it." + +# On a real workspace the service principal cannot deploy into another identity's home folder +# without a grant on that folder. +Cloud = false diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/test.toml new file mode 100644 index 00000000000..a217bd603e5 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/test.toml @@ -0,0 +1,3 @@ +# The Azure test env does not provide TEST_SP_TOKEN. +CloudEnvs.azure = false +RunsOnDbr = false # Requires TEST_SP_TOKEN, which is not available on DBR diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/databricks.yml.tmpl new file mode 100644 index 00000000000..016684b2c8c --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +workspace: + root_path: /Workspace/Users/$TEST_SP_APPLICATION_ID/.bundle/test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/out.test.toml new file mode 100644 index 00000000000..288f93ffc5b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/out.test.toml @@ -0,0 +1,5 @@ +Cloud = true +RunsOnDbr = false +GOOS.windows = false +CloudEnvs.azure = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/output.txt new file mode 100644 index 00000000000..57198c8619a --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/output.txt @@ -0,0 +1,55 @@ + +=== The service principal deploys a job that declares no permissions + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== The current identity is granted CAN_MANAGE on the job, outside the bundle + +CAN_MANAGE [USERNAME] +IS_OWNER [TEST_SP_APPLICATION_ID] + +=== The current identity adds a permissions block to the config and syncs before it is deployed + +>>> [CLI] bundle config-remote-sync --save +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions[group_name='users']: remove + permissions[service_principal_name='[TEST_SP_APPLICATION_ID]']: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -10,4 +10,4 @@ + name: test-job-[UNIQUE_NAME] + permissions: +- - level: CAN_VIEW +- group_name: users ++ - level: IS_OWNER ++ service_principal_name: [TEST_SP_APPLICATION_ID] + +=== The service principal deploys the synced config + +>>> as-test-sp [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/files... +Created jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +=== The job's ACL after the deploy + +IS_OWNER [TEST_SP_APPLICATION_ID] + +>>> as-test-sp [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME] + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/script b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/script new file mode 100644 index 00000000000..1316ff70444 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/script @@ -0,0 +1,32 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace as-test-sp $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +title "The service principal deploys a job that declares no permissions" +trace as-test-sp $CLI bundle deploy +job_id=$(as-test-sp $CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id') + +title "The current identity is granted CAN_MANAGE on the job, outside the bundle\n" +$CLI permissions set jobs $job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","service_principal_name":"'"$TEST_SP_APPLICATION_ID"'"}, + {"permission_level":"CAN_MANAGE","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"} +]}' > /dev/null +print_acl jobs $job_id + +title "The current identity adds a permissions block to the config and syncs before it is deployed" +update_file.py databricks.yml " name: test-job-$UNIQUE_NAME +" " name: test-job-$UNIQUE_NAME + permissions: + - level: CAN_VIEW + group_name: users +" +sync_and_show_diff + +title "The service principal deploys the synced config" +trace as-test-sp $CLI bundle deploy + +title "The job's ACL after the deploy\n" +print_acl jobs $job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/test.toml b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/test.toml new file mode 100644 index 00000000000..8222bc2cec2 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_identity/undeployed/test.toml @@ -0,0 +1 @@ +Badness = "A permissions block is added to the config by an identity other than the deployer and synced before it is deployed. config-remote-sync adds the deployer's IS_OWNER to the block and removes the new entry, but leaves out the syncing identity's own CAN_MANAGE, so the deployer's next deploy revokes it." diff --git a/acceptance/bundle/config-remote-sync/permissions/other_target/databricks.yml.tmpl b/acceptance/bundle/config-remote-sync/permissions/other_target/databricks.yml.tmpl new file mode 100644 index 00000000000..da6a246f1a6 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_target/databricks.yml.tmpl @@ -0,0 +1,12 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + jobs: + my_job: + name: test-job-$UNIQUE_NAME-${bundle.target} + +targets: + staging: + default: true + prod: {} diff --git a/acceptance/bundle/config-remote-sync/permissions/other_target/out.test.toml b/acceptance/bundle/config-remote-sync/permissions/other_target/out.test.toml new file mode 100644 index 00000000000..a4f8dd5ef74 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_target/out.test.toml @@ -0,0 +1,3 @@ +Cloud = true +GOOS.windows = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/config-remote-sync/permissions/other_target/output.txt b/acceptance/bundle/config-remote-sync/permissions/other_target/output.txt new file mode 100644 index 00000000000..ac7316ddac6 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_target/output.txt @@ -0,0 +1,74 @@ + +=== Deploy a job that declares no permissions to two targets + +>>> [CLI] bundle deploy -t staging +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/staging/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] bundle deploy -t prod +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/prod/files... +Created jobs.my_job +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Each target's job gets its own grant, outside the bundle + +staging: +CAN_VIEW users +IS_OWNER [USERNAME] +prod: +CAN_MANAGE_RUN users +IS_OWNER [USERNAME] + +=== Sync the staging target + +>>> [CLI] bundle config-remote-sync --save -t staging +Detected changes in 1 resource(s): + +Resource: resources.jobs.my_job + permissions: add + + + +>>> diff.py databricks.yml.backup databricks.yml +--- databricks.yml.backup ++++ databricks.yml +@@ -6,4 +6,7 @@ + my_job: + name: test-job-[UNIQUE_NAME]-${bundle.target} ++ permissions: ++ - group_name: users ++ level: CAN_VIEW + + targets: + +=== Deploy the synced config to prod + +>>> [CLI] bundle deploy -t prod +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/prod/files... +Created jobs.my_job.permissions +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +=== The prod job's ACL after the deploy + +CAN_VIEW users +IS_OWNER [USERNAME] + +>>> errcode [CLI] bundle destroy --auto-approve -t staging +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/staging + +Destroy: 1 deleted + +>>> errcode [CLI] bundle destroy --auto-approve -t prod +The following resources will be deleted: + delete resources.jobs.my_job + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/prod + +Destroy: 1 deleted diff --git a/acceptance/bundle/config-remote-sync/permissions/other_target/script b/acceptance/bundle/config-remote-sync/permissions/other_target/script new file mode 100644 index 00000000000..d2137a15b04 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/other_target/script @@ -0,0 +1,39 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace errcode $CLI bundle destroy --auto-approve -t staging + trace errcode $CLI bundle destroy --auto-approve -t prod +} +trap cleanup EXIT + +title "Deploy a job that declares no permissions to two targets" +trace $CLI bundle deploy -t staging +trace $CLI bundle deploy -t prod +staging_job_id=$($CLI bundle summary -t staging -o json | jq -r '.resources.jobs.my_job.id') +prod_job_id=$($CLI bundle summary -t prod -o json | jq -r '.resources.jobs.my_job.id') + +title "Each target's job gets its own grant, outside the bundle\n" +$CLI permissions set jobs $staging_job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"}, + {"permission_level":"CAN_VIEW","group_name":"users"} +]}' > /dev/null +$CLI permissions set jobs $prod_job_id --json '{"access_control_list":[ + {"permission_level":"IS_OWNER","'"$CURRENT_USER_FIELD"'":"'"$CURRENT_USER_NAME"'"}, + {"permission_level":"CAN_MANAGE_RUN","group_name":"users"} +]}' > /dev/null +echo "staging:" +print_acl jobs $staging_job_id +echo "prod:" +print_acl jobs $prod_job_id + +title "Sync the staging target" +sync_and_show_diff -t staging + +# Undefined: whether an ACL imported from one target's deployment should replace the ACL of the +# same resource in other targets. The job declared no permissions, so until the sync a deploy to +# prod left the prod job's ACL alone. +title "Deploy the synced config to prod" +trace $CLI bundle deploy -t prod + +title "The prod job's ACL after the deploy\n" +print_acl jobs $prod_job_id diff --git a/acceptance/bundle/config-remote-sync/permissions/script.prepare b/acceptance/bundle/config-remote-sync/permissions/script.prepare new file mode 100644 index 00000000000..28dea290d50 --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/script.prepare @@ -0,0 +1,20 @@ +# The current identity is a user locally and a service principal in some cloud environments. +if [[ "$CURRENT_USER_NAME" == *@* ]]; then + export CURRENT_USER_FIELD=user_name +else + export CURRENT_USER_FIELD=service_principal_name +fi + +# print_acl prints the direct grants of an object, one " " per line. +print_acl() { + # Sorted after the replacements: the principals' names differ between environments. + $CLI permissions get "$1" "$2" | jq -r '(.access_control_list // [])[] | (.user_name // .service_principal_name // .group_name) as $who | .all_permissions[] | select(.inherited | not) | "\(.permission_level) \($who)"' | sort_lines.py --repl +} + +# sync_and_show_diff [flags] saves the changes config-remote-sync detects and prints what it wrote. +sync_and_show_diff() { + cp databricks.yml databricks.yml.backup + trace $CLI bundle config-remote-sync --save "$@" + trace diff.py databricks.yml.backup databricks.yml + rm databricks.yml.backup +} diff --git a/acceptance/bundle/config-remote-sync/permissions/test.toml b/acceptance/bundle/config-remote-sync/permissions/test.toml new file mode 100644 index 00000000000..5ee5490027b --- /dev/null +++ b/acceptance/bundle/config-remote-sync/permissions/test.toml @@ -0,0 +1,5 @@ +Cloud = true +RecordRequests = false +Ignore = [".databricks", "databricks.yml", "databricks.yml.backup"] + +Env.DATABRICKS_BUNDLE_ENABLE_EXPERIMENTAL_YAML_SYNC = "true" diff --git a/libs/testserver/permissions.go b/libs/testserver/permissions.go index a3584c1d49a..b67e1fe2c41 100644 --- a/libs/testserver/permissions.go +++ b/libs/testserver/permissions.go @@ -1,6 +1,7 @@ package testserver import ( + "cmp" "encoding/json" "fmt" "slices" @@ -110,6 +111,24 @@ func (s *FakeWorkspace) guestHasJobAccess(jobId int64, principal string) bool { return false } +// jobOwner returns the principal with IS_OWNER in a job's ACL or, while no owner was set +// explicitly, the job's creator. Call with s.mu held. +func (s *FakeWorkspace) jobOwner(jobId int64) string { + return cmp.Or(aclOwner(s.Permissions[fmt.Sprintf("/jobs/%d", jobId)]), s.Jobs[jobId].CreatorUserName) +} + +// aclOwner returns the principal with IS_OWNER in an ACL, if any. +func aclOwner(perms iam.ObjectPermissions) string { + for _, acl := range perms.AccessControlList { + for _, p := range acl.AllPermissions { + if p.PermissionLevel == "IS_OWNER" { + return cmp.Or(acl.UserName, acl.ServicePrincipalName) + } + } + } + return "" +} + // GetPermissions retrieves permissions for a given object type and ID func (s *FakeWorkspace) GetPermissions(req Request) any { defer s.LockUnlock()() @@ -355,6 +374,18 @@ func (s *FakeWorkspace) SetPermissions(req Request) any { } } + // Only a workspace admin can change the owner of a job (verified against the backend). The + // primary identity is treated as an admin; an as-test-sp guest that is not the owner is not. + if requestObjectType == "jobs" && isGuestToken(req.Token) { + caller := userForToken(req.Token).UserName + if jobId, err := strconv.ParseInt(objectId, 10, 64); err == nil { + owner := s.jobOwner(jobId) + if owner != caller && aclOwner(existingPermissions) != owner { + return jobPermissionDenied(caller + " does not have Manage permissions on Jobs: only workspace admins can change the owner of a job. Please contact the owner or an administrator for access.") + } + } + } + s.Permissions[responseObjectID] = existingPermissions // A directory under /Workspace/Users/ grants the owner CAN_MANAGE