Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Refactor databricks_permissions and allow the current user to set their own permissions #3956

Merged
merged 43 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ca45b53
Allow databricks_permissions to set permissions for the current user
mgyucht Aug 27, 2024
d457710
better integration test and docs
mgyucht Aug 27, 2024
6407156
Merge branch 'main' into issue-2407
mgyucht Sep 18, 2024
74d5d82
big refactor
mgyucht Sep 18, 2024
7ef4cf6
address
mgyucht Sep 18, 2024
600a63e
clearer naming
mgyucht Sep 18, 2024
1a8428c
everything is contained in resourcePermissions
mgyucht Sep 18, 2024
8e14e36
move things around a bit
mgyucht Sep 18, 2024
92ebb61
better
mgyucht Sep 18, 2024
a5f9189
fmt
mgyucht Sep 19, 2024
74e033d
fixes
mgyucht Sep 19, 2024
d1acfa1
fix anyways
mgyucht Sep 19, 2024
73118c5
some fixes
mgyucht Sep 19, 2024
332423e
some work
mgyucht Sep 19, 2024
3d292b7
fixes
mgyucht Sep 19, 2024
450935f
tweaks
mgyucht Sep 19, 2024
4f4abee
work
mgyucht Sep 19, 2024
974db83
add tests
mgyucht Sep 20, 2024
3aee4dd
fixes
mgyucht Sep 20, 2024
576baba
clean
mgyucht Sep 20, 2024
4382548
comments
mgyucht Sep 20, 2024
f776def
remove old test
mgyucht Sep 20, 2024
05b12c8
fix test
mgyucht Sep 20, 2024
f682a8b
fmt
mgyucht Sep 20, 2024
eac3d22
fix
mgyucht Sep 20, 2024
f567cd0
test fixes
mgyucht Sep 20, 2024
dd438e2
work
mgyucht Sep 24, 2024
0bc00f4
work
mgyucht Sep 25, 2024
39cadc3
hack
mgyucht Sep 25, 2024
d2e8193
all tests pass
mgyucht Sep 25, 2024
588a566
fix test
mgyucht Sep 25, 2024
932f2b5
address comments
mgyucht Sep 25, 2024
e28e1ad
fix some tests
mgyucht Sep 26, 2024
e52d9ec
more work
mgyucht Sep 26, 2024
91f203d
Do not run serving endpoint permissions tests on GCP
mgyucht Sep 26, 2024
b6153aa
fix test
mgyucht Sep 26, 2024
63397d4
fix test
mgyucht Sep 26, 2024
e1244f8
actually just skip serving endpoints tests
mgyucht Sep 26, 2024
81c9d7e
fixed
mgyucht Sep 26, 2024
f67c4e7
one last admin tweak
mgyucht Sep 26, 2024
abbcd75
better doccomment
mgyucht Sep 26, 2024
b24ee9d
fix test
mgyucht Sep 26, 2024
94e8197
tweaks and one more integration test
mgyucht Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/resources/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ subcategory: "Security"

# databricks_permissions Resource

This resource allows you to generically manage [access control](https://docs.databricks.com/security/access-control/index.html) in Databricks workspace. It would guarantee that only _admins_, _authenticated principal_ and those declared within `access_control` blocks would have specified access. It is not possible to remove management rights from _admins_ group.
This resource allows you to generically manage [access control](https://docs.databricks.com/security/access-control/index.html) in Databricks workspaces. It ensures that only _admins_, _authenticated principal_ and those declared within `access_control` blocks would have specified access. It is not possible to remove management rights from _admins_ group.

-> **Note** Configuring this resource for an object will **OVERWRITE** any existing permissions of the same type unless imported, and changes made outside of Terraform will be reset unless the changes are also reflected in the configuration.
-> **Note** This resource is _authoritative_ for permissions on objects. Configuring this resource for an object will **OVERWRITE** any existing permissions of the same type unless imported, and changes made outside of Terraform will be reset.

-> **Note** It is not possible to lower permissions for `admins` or your own user anywhere from `CAN_MANAGE` level, so Databricks Terraform Provider [removes](https://github.com/databricks/terraform-provider-databricks/blob/main/permissions/resource_permissions.go#L324-L332) those `access_control` blocks automatically.
-> **Note** It is not possible to lower permissions for `admins`, so Databricks Terraform Provider removes those `access_control` blocks automatically.

-> **Note** If multiple permission levels are specified for an identity (e.g. `CAN_RESTART` and `CAN_MANAGE` for a cluster), only the highest level permission is returned and will cause permanent drift.

Expand Down
48 changes: 24 additions & 24 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func TestImportingClusters(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/clusters/test1",
Resource: "/api/2.0/permissions/clusters/test1?",
Response: getJSONObject("test-data/get-cluster-permissions-test1-response.json"),
},
{
Expand Down Expand Up @@ -913,7 +913,7 @@ func TestImportingClusters(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/clusters/test2",
Resource: "/api/2.0/permissions/clusters/test2?",
Response: getJSONObject("test-data/get-cluster-permissions-test2-response.json"),
},
{
Expand All @@ -923,7 +923,7 @@ func TestImportingClusters(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/cluster-policies/123",
Resource: "/api/2.0/permissions/cluster-policies/123?",
Response: getJSONObject("test-data/get-cluster-policy-permissions.json"),
},
{
Expand All @@ -949,7 +949,7 @@ func TestImportingClusters(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/clusters/awscluster",
Resource: "/api/2.0/permissions/clusters/awscluster?",
Response: getJSONObject("test-data/get-cluster-permissions-awscluster-response.json"),
},
{
Expand All @@ -971,7 +971,7 @@ func TestImportingClusters(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/instance-pools/pool1",
Resource: "/api/2.0/permissions/instance-pools/pool1?",
ReuseRequest: true,
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func TestImportingJobs_JobList(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/jobs/14",
Resource: "/api/2.0/permissions/jobs/14?",
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
{
Expand All @@ -1112,7 +1112,7 @@ func TestImportingJobs_JobList(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/instance-pools/pool1",
Resource: "/api/2.0/permissions/instance-pools/pool1?",
ReuseRequest: true,
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
Expand Down Expand Up @@ -1202,7 +1202,7 @@ func TestImportingJobs_JobList(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/cluster-policies/123",
Resource: "/api/2.0/permissions/cluster-policies/123?",
Response: getJSONObject("test-data/get-cluster-policy-permissions.json"),
},
{
Expand All @@ -1218,7 +1218,7 @@ func TestImportingJobs_JobList(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/instance-pools/pool1",
Resource: "/api/2.0/permissions/instance-pools/pool1?",
ReuseRequest: true,
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
Expand Down Expand Up @@ -1307,7 +1307,7 @@ func TestImportingJobs_JobListMultiTask(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/jobs/14",
Resource: "/api/2.0/permissions/jobs/14?",
Response: getJSONObject("test-data/get-job-permissions-14.json"),
ReuseRequest: true,
},
Expand All @@ -1331,7 +1331,7 @@ func TestImportingJobs_JobListMultiTask(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/instance-pools/pool1",
Resource: "/api/2.0/permissions/instance-pools/pool1?",
ReuseRequest: true,
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
Expand Down Expand Up @@ -1470,7 +1470,7 @@ func TestImportingJobs_JobListMultiTask(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/cluster-policies/123",
Resource: "/api/2.0/permissions/cluster-policies/123?",
Response: getJSONObject("test-data/get-cluster-policy-permissions.json"),
},
{
Expand All @@ -1486,7 +1486,7 @@ func TestImportingJobs_JobListMultiTask(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/instance-pools/pool1",
Resource: "/api/2.0/permissions/instance-pools/pool1?",
ReuseRequest: true,
Response: getJSONObject("test-data/get-job-permissions-14.json"),
},
Expand Down Expand Up @@ -1777,7 +1777,7 @@ func TestImportingRepos(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/repos/121232342",
Resource: "/api/2.0/permissions/repos/121232342?",
Response: getJSONObject("test-data/get-repo-permissions.json"),
},
},
Expand Down Expand Up @@ -1902,7 +1902,7 @@ func TestImportingSqlObjects(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/directories/4451965692354143",
Resource: "/api/2.0/permissions/directories/4451965692354143?",
Response: getJSONObject("test-data/get-directory-permissions.json"),
},
{
Expand Down Expand Up @@ -1933,7 +1933,7 @@ func TestImportingSqlObjects(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/sql/warehouses/f562046bc1272886",
Resource: "/api/2.0/permissions/sql/warehouses/f562046bc1272886?",
Response: getJSONObject("test-data/get-sql-endpoint-permissions.json"),
},
{
Expand Down Expand Up @@ -1962,12 +1962,12 @@ func TestImportingSqlObjects(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/preview/sql/permissions/queries/16c4f969-eea0-4aad-8f82-03d79b078dcc",
Resource: "/api/2.0/permissions/sql/queries/16c4f969-eea0-4aad-8f82-03d79b078dcc?",
Response: getJSONObject("test-data/get-sql-query-permissions.json"),
},
{
Method: "GET",
Resource: "/api/2.0/preview/sql/permissions/dashboards/9cb0c8f5-6262-4a1f-a741-2181de76028f",
Resource: "/api/2.0/permissions/dbsql-dashboards/9cb0c8f5-6262-4a1f-a741-2181de76028f?",
Response: getJSONObject("test-data/get-sql-dashboard-permissions.json"),
},
{
Expand All @@ -1983,7 +1983,7 @@ func TestImportingSqlObjects(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/preview/sql/permissions/alerts/3cf91a42-6217-4f3c-a6f0-345d489051b9",
Resource: "/api/2.0/permissions/sql/alerts/3cf91a42-6217-4f3c-a6f0-345d489051b9?",
Response: getJSONObject("test-data/get-sql-alert-permissions.json"),
},
},
Expand Down Expand Up @@ -2039,7 +2039,7 @@ func TestImportingDLTPipelines(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/repos/123",
Resource: "/api/2.0/permissions/repos/123?",
Response: getJSONObject("test-data/get-repo-permissions.json"),
},
{
Expand Down Expand Up @@ -2085,12 +2085,12 @@ func TestImportingDLTPipelines(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/pipelines/123",
Resource: "/api/2.0/permissions/pipelines/123?",
Response: getJSONObject("test-data/get-pipeline-permissions.json"),
},
{
Method: "GET",
Resource: "/api/2.0/permissions/notebooks/123",
Resource: "/api/2.0/permissions/notebooks/123?",
Response: getJSONObject("test-data/get-notebook-permissions.json"),
},
{
Expand Down Expand Up @@ -2169,7 +2169,7 @@ func TestImportingDLTPipelines(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/files/789",
Resource: "/api/2.0/permissions/files/789?",
Response: getJSONObject("test-data/get-workspace-file-permissions.json"),
},
},
Expand Down Expand Up @@ -2257,7 +2257,7 @@ func TestImportingDLTPipelinesMatchingOnly(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/permissions/pipelines/123",
Resource: "/api/2.0/permissions/pipelines/123?",
Response: getJSONObject("test-data/get-pipeline-permissions.json"),
},
{
Expand Down
2 changes: 1 addition & 1 deletion exporter/importables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestPermissions(t *testing.T) {

d.MarkNewResource()
err := common.StructToData(permissions.PermissionsEntity{
AccessControlList: []permissions.AccessControlChange{
AccessControlList: []iam.AccessControlRequest{
{
UserName: "a",
},
Expand Down
Loading
Loading