Skip to content

Add test recording permissions API behaviour - #3900

Merged
denik merged 12 commits into
mainfrom
denik/permissions-collapse
Nov 11, 2025
Merged

Add test recording permissions API behaviour#3900
denik merged 12 commits into
mainfrom
denik/permissions-collapse

Conversation

@denik

@denikdenik commented Nov 10, 2025

Copy link
Copy Markdown
Contributor

Changes

Add test recording permissions API behaviour wrt multiple levels for the same principal.

Why

Document behaviour (important for permissions processing). I also plan to use this test to fix the testserver.

@denik
denikforce-pushed the denik/permissions-collapse branch from a260d6f to 3ccae8cCompareNovember 10, 2025 17:02
Comment threadacceptance/acceptance_test.go Outdated
testdiff.PrepareReplacementsWorkspaceConfig(t, &repls, cfg)

cmd.Env = auth.ProcessEnv(cfg)
cmd.Env = append(cmd.Env, "USERNAME="+user.UserName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this as CURRENT_USER_NAME. Maybe chanage the replacement?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - missed that one; switched to that fd4aae8

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 10, 2025

Copy link
Copy Markdown
Collaborator

Run: 19268205281

Env🔄​flaky💚​RECOVERED🙈​SKIP✅​pass🙈​skipTime
💚​aws linux1135960219:22
💚​aws windows1136060122:03
🔄​aws-ucws linux3149249328:37
💚​aws-ucws windows1149549227:23
💚​azure linux1135960127:33
💚​azure windows1136060027:33
💚​azure-ucws linux1149049227:02
💚​azure-ucws windows1149149130:03
💚​gcp linux1135560421:23
🔄​gcp windows3135460319:19
6 failing tests:
Test Nameaws linuxaws windowsaws-ucws linuxaws-ucws windowsazure linuxazure windowsazure-ucws linuxazure-ucws windowsgcp linuxgcp windows
TestAccept💚​R💚​R🔄​f💚​R💚​R💚​R💚​R💚​R💚​R🔄​f
TestAccept/bundle/resources/registered_models/basic🙈​s🙈​s🔄​f✅​p🙈​s🙈​s✅​p✅​p🙈​s🙈​s
TestAccept/bundle/resources/registered_models/basic/DATABRICKS_BUNDLE_ENGINE=terraform🔄​f✅​p✅​p✅​p
TestAccept/bundle/run/app-with-job🙈​S🙈​S🙈​S🙈​S🙈​S🙈​S🙈​S🙈​S🙈​S🙈​S
TestAccept/bundle/templates/default-python/integration_classic✅​p✅​p✅​p✅​p✅​p✅​p✅​p✅​p✅​p🔄​f
TestAccept/bundle/templates/default-python/integration_classic/DATABRICKS_BUNDLE_ENGINE=direct/UV_PYTHON=3.12✅​p✅​p✅​p✅​p✅​p✅​p✅​p✅​p✅​p🔄​f
Top 42 slowest tests (at least 2 minutes):
durationenvtestname
16:11azure-ucws linuxTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
14:00aws windowsTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
12:58azure windowsTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
12:02azure linuxTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
10:54azure-ucws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
10:37azure-ucws windowsTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
9:28aws-ucws windowsTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
8:35azure-ucws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
8:12aws linuxTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
7:51azure linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
7:12aws-ucws linuxTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
7:01aws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
6:58azure-ucws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
6:32gcp windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
6:18aws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
6:14azure linuxTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
5:59gcp linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
5:58gcp windowsTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
5:55gcp linuxTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
5:51gcp linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
5:36gcp windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
5:24aws-ucws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
5:19aws-ucws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
5:18azure-ucws windowsTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
5:16aws-ucws windowsTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
5:10aws-ucws windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
5:02aws linuxTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
5:01aws-ucws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
4:49aws-ucws linuxTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
4:47azure-ucws linuxTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
4:44aws windowsTestAccept/bundle/resources/permissions/factcheck/DATABRICKS_BUNDLE_ENGINE=terraform
4:31azure-ucws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
3:05azure-ucws windowsTestAccept/bundle/resources/synced_database_tables/basic
2:57azure windowsTestAccept/bundle/resources/clusters/deploy/data_security_mode/DATABRICKS_BUNDLE_ENGINE=direct
2:57azure-ucws linuxTestAccept/bundle/resources/synced_database_tables/basic
2:29azure windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
2:25aws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform
2:18gcp linuxTestAccept/bundle/templates/default-python/combinations/classic/DATABRICKS_BUNDLE_ENGINE=direct/DLT=no/NBOOK=yes/PY=yes
2:13aws linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
2:13aws-ucws windowsTestAccept/bundle/resources/registered_models/basic/DATABRICKS_BUNDLE_ENGINE=terraform
2:08azure linuxTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=direct
2:07azure windowsTestAccept/bundle/resources/clusters/deploy/update-after-create/DATABRICKS_BUNDLE_ENGINE=terraform

@denik
denikforce-pushed the denik/permissions-collapse branch from fd4aae8 to 9c7375eCompareNovember 10, 2025 20:07
Comment threadacceptance/bundle/resources/permissions/factcheck/script Outdated
jobs CAN_MANAGE,IS_OWNER => IS_OWNER

=== Since we take the most recent level, IS_OWNER is lost, which results in the error due to lack of owner defined
jobs IS_OWNER,CAN_MANAGE => SET ERROR Error: The job must have exactly one owner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails because we try to define a second owner right? Not because we are unsetting the original owner?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this fails because there is no IS_OWNER in the request for a given principal according to backend logic (take last permission).

Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
@denik
denik enabled auto-merge November 11, 2025 10:00

@pieternpietern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. The best test is against the real thing.

Comment threadacceptance/bundle/resources/permissions/factcheck/check_permissions.py Outdated
try:
return json.loads(result.stdout)
except Exception as ex:
raise Error(f"{cmd} returned non-json: {ex}\n{result.stdout}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: function looks useful enough to put in a lib for acc testing.

def test_permissions(target_user, resource_type, resource_id, levels, expected):
acls = []
if resource_type == "jobs" and target_user != os.environ["CURRENT_USER_NAME"]:
# make sure we keep IS_OWNER

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because "last entry wins"?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need IS_OWNER since otherwise backend returns error and does not let set permissions.

@denik
denik added this pull request to the merge queueNov 11, 2025
Merged via the queue into main with commit 58549e4Nov 11, 2025
13 checks passed
@denik
denik deleted the denik/permissions-collapse branch November 11, 2025 15:08
github-merge-queueBot pushed a commit that referenced this pull request Nov 12, 2025
## Changes
When multiple permissions are present, select one per principal (highest
of all available),
## Why
Backend only stores one permission level per principal, whatever is
latest in the request. So if users define multiple levels for the same
principal, arbitrary level is going to be send to the backend, just
whatever happens to be last in request. In some case, terraform will
reject multiple levels and error.
Why we select max level: The intent is usually to have some default
permissions applied broadly (e.g., CAN_VIEW) and then grant higher
permission (e.g. CAN_MANAGE) to selected principal, in which case
principal has both CAN_VIEW and CAN_MANAGE which is the same as just
CAN_MANAGE.
Should fix#3864
## Tests
New acceptance test.
Fix testserver to match real backend as tested by
#3900
denik added a commit that referenced this pull request May 20, 2026
## Changes
Add test recording permissions API behaviour wrt multiple levels for the
same principal.
## Why
Document behaviour (important for permissions processing). I also plan
to use this test to fix the testserver.
---------
Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
denik added a commit that referenced this pull request May 20, 2026
## Changes
When multiple permissions are present, select one per principal (highest
of all available),
## Why
Backend only stores one permission level per principal, whatever is
latest in the request. So if users define multiple levels for the same
principal, arbitrary level is going to be send to the backend, just
whatever happens to be last in request. In some case, terraform will
reject multiple levels and error.
Why we select max level: The intent is usually to have some default
permissions applied broadly (e.g., CAN_VIEW) and then grant higher
permission (e.g. CAN_MANAGE) to selected principal, in which case
principal has both CAN_VIEW and CAN_MANAGE which is the same as just
CAN_MANAGE.
Should fix#3864
## Tests
New acceptance test.
Fix testserver to match real backend as tested by
#3900
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@denik@eng-dev-ecosystem-bot@pietern@shreyas-goenka