Skip to content

Fixes 36581: Authorize a non-admin PUT of a new test case - #36590

Merged
Khairajani merged 5 commits into
mainfrom
fix/test-case-put-create-authorization
Oct 30, 2026
Merged

Khairajani merged 5 commits into
mainfrom
fix/test-case-put-create-authorization

Conversation

@Khairajani

@Khairajani Khairajani commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36581

Since #36156, AuthorizationLogic.ANY evaluates every request. PUT /v1/dataQuality/testCases built its test-case checks on a context that loads the test case by name, so a non-admin PUT of a new test case failed with 404 Entity not found: testCase …. Admins skip the authorizer, so only non-admin callers (e.g. the ingestion bot) hit it.

  • PUT and ODCSTestCaseWriteGuard now build their checks from one helper, TestCaseWriteAuthRequests. Creating needs CreateTests on the table or Create on the test case, as POST does, checked against the request. Updating needs EditTests on the table, or Create or EditAll on the existing test case.
  • The existence check uses the FQN the repository stores. The old one dropped the column and the quoting, so it never matched a column-level test case.
  • prepareInternal still runs after authorization, because it creates the table's test suite when one is missing.

Behaviour change: a role whose only grant is EditTests on tables can no longer create a test case through PUT. It needs CreateTests, as it already did for POST. The rule is recorded in ADR:2026-10-30-a-test-case-write-is-authorized-as-a-create-or-an-update.

Out of scope, and the same as before #36156: PUT-create skips enforceLimits, which POST calls.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Backend integration tests

  • TestCaseCreateOrUpdateAuthorizationIT (new), each case as a non-admin with a single grant. Table CreateTests creates a table test and a column test but can't update them. Table EditTests updates them but can't create one. Create on test cases creates one. EditAll updates an existing column test. A caller with no permissions gets 403 and no test suite is created.
  • Before the fix, these tests fail with exactly the 404 above. With the fix, all 4 pass (MySQL + ES).
  • The impacted suite from make java_affected passed on 7ecbf6f. On 48f31fa: TestCaseCreateOrUpdateAuthorizationIT, TestCaseResourceIT, TestCaseResultAuthorizationIT, DataContractResourceIT, DataContractPermissionIT and SubResourceAuthorizationIT pass (845 tests, 0 failures).
  • No unit test for TestCaseWriteAuthRequests / ODCSTestCaseWriteGuard: CreateResourceContext needs the live entity registry, so the ITs above cover them.

Playwright (UI) tests

  • Not applicable (no UI changes).

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the diff against REVIEW.md and fixed its 🔴 findings: prepareInternal had moved before authorization, and the update checks had drifted from the ODCS guard.
  • Decision check: adds ADR:2026-10-30-a-test-case-write-is-authorized-as-a-create-or-an-update.

🤖 Generated with Claude Code

PUT /v1/dataQuality/testCases authorized CREATE and EDIT_ALL on a context
that loads the test case by name. Since AuthorizationLogic.ANY evaluates
every request, a non-admin PUT of a new test case failed with 404 from that
lookup. Ask for CREATE against the request for a new test case and EDIT_ALL
for an existing one, using the FQN the repository stores.
prepare creates the table's test suite when it is missing, so it must not
run for a caller the PUT refuses. Set only the FQN before authorizing.
Cover a Create-only and an EditAll-only caller on test cases.
Only a new test case changes how it is authorized. An existing one is
checked as before, the same way ODCSTestCaseWriteGuard checks an update.
@Khairajani
Khairajani requested a review from a team as a code owner October 29, 2026 18:03
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@Khairajani Khairajani added the safe to test Add this label to run secure Github workflows on PRs label Oct 29, 2026
// Only the FQN before authorizing: prepare creates the table's test suite if it is missing.
repository.setFullyQualifiedName(test);
OperationContext tableOpContext =
new OperationContext(Entity.TABLE, MetadataOperation.EDIT_TESTS);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to apply the same logic here too -- if we create do you have createTest on table resource if we edit do you have edittest on table resource

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 53af873: a create now checks CreateTests on the table, an update EditTests, the same request sets as ODCSTestCaseWriteGuard. The IT covers both directions (CreateTests creates but can't update, EditTests updates but can't create).

Creating needs CreateTests on the table, as POST does, and updating needs
EditTests, the same request sets ODCSTestCaseWriteGuard uses.
…port

Both build their create and update request sets from TestCaseWriteAuthRequests,
and the rule is recorded in a decision record.
@gitar-bot

gitar-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · Changing test-case PUT authorization grants create and update paths different permissions; a faulty check could allow unauthorized writes to data-quality tests.

Fixes non-admin PUT of new test cases failing with a 404 by building test-case write authorization from a shared helper, TestCaseWriteAuthRequests, that checks CreateTests for creates and EditTests, Create, or EditAll for updates. Resolved the duplicated auth request sets that could drift from ODCSTestCaseWriteGuard, and the ADR recording the create-or-update rule is now in place. No open issues found.

✅ 2 closed
✅ Quality: PUT-create no longer accepts table EditTests; rule is not recorded

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestCaseResource.java:904-918 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TestCaseCreateOrUpdateAuthorizationIT.java:82-96
This commit changes createRequests (TestCaseResource.java:921-928) so a PUT that creates a test case checks CreateTests on the table instead of EditTests. A caller whose only grant is EditTests on the table (which PUT-create used to accept) now gets 403, and the new IT asserts that at lines 100-103. That narrows the permission on a public endpoint and is a judgment call. The only place the rule lives is the PR description: "Creating needs CreateTests on the table or Create on the test case, as POST does... Updating needs EditTests on the table, or Create or EditAll on the existing test case." No record in docs/decisions/ says this. ADR 2026-10-24-any-authorization-honours-an-explicit-deny, which the PR cites, covers only how ANY evaluates requests, not which operations a test-case write needs. The rule also has to stay the same in ODCSTestCaseWriteGuard, a separate file. Please add a record stating: "A test-case write that creates is authorized as POST (table CreateTests or testCase Create, checked against the request); a write that overwrites an existing test case needs table EditTests or testCase Create/EditAll on the stored test case; PUT and the ODCS import guard share these sets." Also mention the narrowing in the release notes, since custom roles that granted only EditTests will break.

✅ Quality: PUT auth request sets duplicate ODCSTestCaseWriteGuard and can drift

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestCaseResource.java:911-925
In TestCaseResource.java:921-942, createRequests and updateRequests copy ODCSTestCaseWriteGuard.createRequests and updateRequests line for line. The PR description says these sets have already drifted once ("the update checks had drifted from the ODCS guard"), and the guard's Javadoc promises it applies the same checks as PUT. With two copies, the next permission change made in one place will quietly break that promise again. The repo guideline asks for extracted shared logic. Move both builders into one package-visible helper, for example TestCaseWriteAuthRequests with forCreate(TestCase) and forUpdate(TestCase), and call it from both places.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Khairajani
Khairajani enabled auto-merge October 30, 2026 06:48
@sonarqubecloud

Copy link
Copy Markdown

@pmbrull
pmbrull requested a review from TeddyCr October 30, 2026 07:28
@pmbrull
pmbrull dismissed TeddyCr’s stale review October 30, 2026 07:29

feedback handled, unblocking merge

@Khairajani
Khairajani added this pull request to the merge queue Oct 30, 2026
@karanh37
karanh37 removed this pull request from the merge queue due to a manual request Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-30T08:25:23Z)

No failing check on merge-queue commit 39e0505 — invalidated by an entry ahead in the queue, or a required check timed out.

@Khairajani
Khairajani added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 23e3cd0 Oct 30, 2026
89 of 91 checks passed
@Khairajani
Khairajani deleted the fix/test-case-put-create-authorization branch October 30, 2026 12:09
manerow pushed a commit that referenced this pull request Oct 30, 2026
* Authorize a test case PUT for a test case that does not exist yet

PUT /v1/dataQuality/testCases authorized CREATE and EDIT_ALL on a context
that loads the test case by name. Since AuthorizationLogic.ANY evaluates
every request, a non-admin PUT of a new test case failed with 404 from that
lookup. Ask for CREATE against the request for a new test case and EDIT_ALL
for an existing one, using the FQN the repository stores.

* Authorize before preparing a test case PUT, and test each grant

prepare creates the table's test suite when it is missing, so it must not
run for a caller the PUT refuses. Set only the FQN before authorizing.
Cover a Create-only and an EditAll-only caller on test cases.

* Keep the update checks a test case PUT shared with the ODCS import guard

Only a new test case changes how it is authorized. An existing one is
checked as before, the same way ODCSTestCaseWriteGuard checks an update.

* Check CreateTests on the table when a test case PUT creates

Creating needs CreateTests on the table, as POST does, and updating needs
EditTests, the same request sets ODCSTestCaseWriteGuard uses.

* Share the test-case write permission sets between PUT and the ODCS import

Both build their create and update request sets from TestCaseWriteAuthRequests,
and the rule is recorded in a decision record.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-admin PUT of a new test case returns 404 since ANY authorization evaluates every request

4 participants