Repository navigation
[Server] Add MANAGE permission - #2088
Conversation
|
/review |
126f95f to
a801ac0
Compare
c6e4f21 to
0a073a8
Compare
0a073a8 to
b41a2d3
Compare
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2091/files) to review incremental changes. - [**stack/permission-enums**](#2091) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2091/files)] ← _this PR_ - [stack/feat/browse-privilege](#2087) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2087/files/9f6b2ba7bcb2d8179b0dea15094d180602f95723..8504f42cac04ea8cac31e3b86807530ba0144057)] - [stack/feat/create-model-version-privilege](#2085) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2085/files/9f6b2ba7bcb2d8179b0dea15094d180602f95723..8575d777673066ca569002d40f6eab19631c936f)] - [stack/feat/manage-privilege](#2088) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2088/files/9f6b2ba7bcb2d8179b0dea15094d180602f95723..b41a2d34cfad7af957d8fd9ebd5446d0a42cd74b)] - [stack/feat/read-metadata-privilege](#2086) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2086/files/9f6b2ba7bcb2d8179b0dea15094d180602f95723..dd162f6987b22700fca3b18ac5105cc261e19e6a)] - [stack/feat/write-volume-privilege](#2084) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2084/files/9f6b2ba7bcb2d8179b0dea15094d180602f95723..7112a998365fc1d322bae3f26f6ba00d9fefc39e)] --------- **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Add `BROWSE`, `MANAGE`, `WRITE VOLUME`, `CREATE MODEL VERSION`, and `READ METADATA` to the API and server enums. Validate where each permission can be granted. The child PRs add the authorization checks for each permission. **Before** With authorization enabled, the owner of `main.public.sales` tries to grant an existing user metadata access: ```http PATCH /api/2.1/unity-catalog/permissions/table/main.public.sales Content-Type: application/json {"changes": [{"principal": "[email protected]", "add": ["READ METADATA"]}]} ``` The API rejects the request because `READ METADATA` is not a recognized privilege. **After** The owner repeats the same request: ```http PATCH /api/2.1/unity-catalog/permissions/table/main.public.sales Content-Type: application/json {"changes": [{"principal": "[email protected]", "add": ["READ METADATA"]}]} ``` The API accepts and saves the grant. It also accepts `BROWSE`, `MANAGE`, `WRITE VOLUME`, and `CREATE MODEL VERSION` on their supported object types. For example, `BROWSE` is valid on a catalog or external location and is rejected on a table. The child PRs add the authorization checks that make these grants affect metadata reads, grant changes, and credential requests. This is the shared parent for #2084, #2085, #2086, #2087, and #2088. Validation: 21 focused enum and permission tests passed on JDK 17. API generation, Java formatting, and server Compile/Test Checkstyle passed. Signed-off-by: Timothy Wang <[email protected]>
b41a2d3 to
9ed7ea4
Compare
9ed7ea4 to
bce3c2c
Compare
| * and catalog OWNER/MANAGE pass unconditionally; schema OWNER/MANAGE needs catalog {@code | ||
| * USE_CATALOG}; other callers need {@code USE_SCHEMA} + {@code USE_CATALOG} plus {@code OWNER}, | ||
| * {@code MANAGE}, or {@code SELECT} on the table. With strict privilege checks disabled, {@code | ||
| * MODIFY} also permits metadata access. {@code READ_METADATA} at metastore or catalog scope needs | ||
| * no usage grants; schema scope needs {@code USE_CATALOG}, and table scope needs both usage | ||
| * grants. |
There was a problem hiding this comment.
is the change in this comment basically just talking about also including MANAGE in some checks? based on the code changes, it just looks like we're adding MANAGE to authorization for some
There was a problem hiding this comment.
Yes. The policy change here is adding MANAGE alongside OWNER for table metadata access. The rest of the comment describes the existing rules.
| (#authorize(#principal, #catalog, USE_CATALOG) && | ||
| #authorizeAny(#principal, #schema, OWNER, MANAGE)) |
There was a problem hiding this comment.
it doesnt fit on one line?
There was a problem hiding this comment.
This would be 106 characters on one line. Checkstyle limits lines to 100, so I kept the break.
| READ_FILES, WRITE_FILES, CREATE_EXTERNAL_TABLE, CREATE_EXTERNAL_VOLUME, | ||
| CREATE_MANAGED_STORAGE) |
There was a problem hiding this comment.
this cant be on one line?
There was a problem hiding this comment.
I reduced it to two lines. A single line would be 177 characters; Checkstyle allows 100.
| (#authorize(#principal, #catalog, USE_CATALOG) && | ||
| #authorizeAny(#principal, #schema, OWNER, MANAGE)) || |
There was a problem hiding this comment.
it cant be on one line?
There was a problem hiding this comment.
This branch would be 109 characters on one line, including ||. Checkstyle allows 100, so I kept the break.
| (#authorize(#principal, #catalog, USE_CATALOG) && | ||
| #authorize(#principal, #schema, USE_SCHEMA) && | ||
| #authorizeAny(#principal, #table, OWNER, MANAGE)) |
There was a problem hiding this comment.
oh i see its cascading... like this anyOf(OWNER, MANAGE) moves down from catalog to table.
There was a problem hiding this comment.
Yes. The three branches check OWNER or MANAGE at catalog, schema, and table scope. The schema branch also needs USE CATALOG. The table branch needs both USE CATALOG and USE SCHEMA.
| public static final String UPDATE_FUNCTION = | ||
| """ | ||
| #authorizeAny(#principal, #catalog, OWNER, MANAGE) || | ||
| (#authorize(#principal, #catalog, USE_CATALOG) && | ||
| #authorizeAny(#principal, #schema, OWNER, MANAGE)) || | ||
| (#authorize(#principal, #catalog, USE_CATALOG) && | ||
| #authorize(#principal, #schema, USE_SCHEMA) && | ||
| #authorizeAny(#principal, #function, OWNER, MANAGE)) | ||
| """; | ||
|
|
||
| /** Volume management. File access still requires its own privileges. */ | ||
| public static final String UPDATE_VOLUME = |
There was a problem hiding this comment.
why do we need to introduce UPDATE_FUNCTION, UPDATE_VOLUME, and UPDATE_REGISTERED_MODEL? its nice but im just wondering.
There was a problem hiding this comment.
Volumes and models reuse these checks across updates and deletes. Models also use the same check for version metadata. UPDATE_FUNCTION has one caller here; #2149 reuses it for ownership transfer.
There was a problem hiding this comment.
[AI Assisted] UPDATE_FUNCTION has two callers in this PR, not one: FunctionService.deleteFunction and PermissionService.updateFunctionAuthorization. Because it also gates grants, a later change to delete semantics would silently change who can grant. Would MANAGE_FUNCTION read more accurately, with the same for the volume, model, and table constants? At minimum, the Javadoc should say the constant also gates grants.
There was a problem hiding this comment.
Updated the comments to say these policies also control grant changes. I kept the existing constant names.
| (#new_name == null || #authorize(#principal, #catalog, OWNER) || | ||
| #authorizeAny(#principal, #metastore, OWNER, CREATE_CATALOG)) | ||
| """) | ||
| @AuthorizeResourceKey(METASTORE) | ||
| public HttpResponse updateCatalog( | ||
| @Param("name") @AuthorizeResourceKey(CATALOG) String name, UpdateCatalog updateCatalog) { | ||
| @Param("name") @AuthorizeResourceKey(CATALOG) String name, | ||
| @AuthorizeKey(key = "new_name") UpdateCatalog updateCatalog) { |
There was a problem hiding this comment.
what? what is this new name thing?
There was a problem hiding this comment.
new_name is an existing request field for rename. @AuthorizeKey lets this check read it. A manager can update metadata with MANAGE, but a rename also needs metastore OWNER or CREATE CATALOG. Catalog owners keep their existing rename access.
There was a problem hiding this comment.
huh? you say its existing but we're adding it here.
There was a problem hiding this comment.
@AuthorizeKey is new here. My earlier reply referred to the request field, not the annotation.
Before this PR, {"new_name":"sales_new"} already renamed a catalog. The new annotation lets the permission check read that existing field.
We need it because a manager can edit a comment with MANAGE, while renaming also requires permission to create a catalog.
There was a problem hiding this comment.
ok im guessing rename was just not wired into these permissions rules...
| "(" | ||
| + AuthorizeExpressions.UPDATE_REGISTERED_MODEL | ||
| + """ | ||
| ) && | ||
| (#new_name == null || |
There was a problem hiding this comment.
wow this is a very ugly expression... oh i see its because the old vs new checks. what is the new vs old behaviour?
There was a problem hiding this comment.
Existing owners can still rename without a creation grant when strict checks are off. With strict checks on, rename also needs schema OWNER, or USE SCHEMA plus CREATE MODEL or CREATE FUNCTION. Managers must pass that creation check in both modes. The last branch preserves the old owner exception.
There was a problem hiding this comment.
i have no idea what you're saying.
There was a problem hiding this comment.
Take a model called fraud. Alice owns it. Bob has MANAGE on it. Both have USE CATALOG and USE SCHEMA.
Bob can send {"comment":"updated"}. To send {"new_name":"fraud_v2"}, he also needs creation permission, such as CREATE MODEL.
Alice already had rename access. An existing switch for stricter permission checks is called strict_privilege_checks in this expression. When it is false, Alice can rename without a create grant. When it is true, she must also pass the creation check.
The long branch that checks OWNER preserves Alice's access when that switch is off. Bob must pass the creation check in either mode.
| (#authorize(#principal, #schema, OWNER) || | ||
| (#authorize(#principal, #schema, USE_SCHEMA) && |
There was a problem hiding this comment.
why not authorizeAny(OWNER, USE_SCHEMA)...? similarly below.
There was a problem hiding this comment.
Applied this to the model, volume, and table rename checks. I kept OWNER in both authorizeAny calls so schema owners still pass without a create grant.
6cc1b65 to
8538624
Compare
|
/review |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Review of bd264af. Inline comments are on diff lines. Finding for api/all.yaml is outside the diff, so it is here: [AI Assisted] api/all.yaml:2753: This MANAGE description says it "does not grant data access, execution, or object creation." That holds only before a self-grant. Could we state the owner-equivalence rule once instead: MANAGE can do what an owner can do, except ownership transfer (#2149)? The updateCredential description also still reads "Updates a credential." and should mention MANAGE.
| ### MANAGE | ||
|
|
||
| `MANAGE` permits full metadata and grant inspection, grant changes, supported metadata updates, | ||
| and deletion. Managers can grant themselves other privileges, including data access. |
There was a problem hiding this comment.
[AI Assisted] Could we add these points to this section? (1) With strict-privilege-checks=false, MANAGE grants are still validated, so MANAGE on the metastore is rejected. (2) Renaming a catalog, schema, table, volume, or model with MANAGE needs the matching create privilege in both modes; the migration list shows volume and model rename as strict-only. (3) nit: the note that existing MANAGE grants become active after upgrade (line 264) does not apply, since MANAGE has not shipped in a release.
There was a problem hiding this comment.
Updated. The docs now explain that MANAGE validation and manager rename checks apply in both modes. I clarified the owner rename entries and removed the upgrade note.
| """ | ||
| #authorize(#principal, #catalog, OWNER) | ||
| #authorizeAny(#principal, #catalog, OWNER, MANAGE) && | ||
| (#new_name == null || #authorize(#principal, #catalog, OWNER) || |
There was a problem hiding this comment.
[AI Assisted] Could we add owner-path cases here? The new #new_name branches in updateCatalog and SchemaService.updateSchema have no test where the owner renames; the rename scenario only covers managers. Cases: a catalog owner renames with no create grant; a schema owner with USE CATALOG renames; a schema owner without USE CATALOG is denied.
There was a problem hiding this comment.
Added all three cases. The tests also check that renaming keeps the same object ID.
| (#authorizeAny(#principal, #catalog, OWNER, USE_CATALOG) && | ||
| #authorizeAny(#principal, #schema, OWNER, USE_SCHEMA) && | ||
| #authorizeAny(#principal, #schema, OWNER, CREATE_MODEL, CREATE_FUNCTION)) || | ||
| (!#strict_privilege_checks && |
There was a problem hiding this comment.
There was a problem hiding this comment.
I’d keep this cleanup with #2024. The model and volume checks use different resource keys, so sharing the whole expression would need another expression fragment.
| @@ -401,8 +394,16 @@ private HttpResponse updateAuthorization( | |||
| /** Validates additions only, so grants saved on invalid object types can still be removed. */ | |||
| static void validateAddedPrivileges( | |||
There was a problem hiding this comment.
[AI Assisted] nit: The two-argument validateAddedPrivileges overload is only used by PermissionServiceGrantValidationTest. Passing true from the test would drop the wrapper.
There was a problem hiding this comment.
I kept the overload. It lets tests use strict validation while the method that takes the flag stays private.
| @Patch("/catalog/{name}") | ||
| @AuthorizeExpression( | ||
| "#authorize(#principal, #metastore, OWNER) || #authorize(#principal, #catalog, OWNER)") | ||
| "#authorize(#principal, #metastore, OWNER) || #authorizeAny(#principal, #catalog, OWNER," |
There was a problem hiding this comment.
[AI Assisted] nit: These string concatenations split a single expression at the 100-column limit (here, and at lines 322 and 333). The neighboring endpoints use text blocks, so a text block would match the file.
There was a problem hiding this comment.
I left this formatting unchanged to keep the update focused.
bd264af to
29d5c03
Compare
|
@yili-db, on the API documentation: Updated the description to explain that managers can grant themselves other privileges, including data access. I kept the specific limits because managers still need creation rights for renames. I also documented credential update permissions. |
|
/review |
Delegate supported metadata and grant administration without changing ownership. Keep ownership transfer in a follow-up change. Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
db995be to
7a014a7
Compare
|
/review |
|
yaml changes LGTM |
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2149/files) to review incremental changes. - [stack/split/ownership-transfer-after-manage-20261106](#2149) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2149/files)] --------- **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** This adds ownership transfer for catalogs, schemas, tables and views, functions, volumes, registered models, external locations, and storage credentials. The new owner must be an existing user. For example, an authorized owner or manager can transfer `main.public.sales` to Bob: ```http PATCH /api/2.1/unity-catalog/tables/main.public.sales Content-Type: application/json {"owner": "[email protected]"} ``` Tables and functions get ownership PATCH endpoints. Other supported update requests gain missing owner fields or start saving the existing owner field. Views, functions, and models can be transferred to oneself; assigning another user requires a metastore administrator. Upgrade note: v0.3.0 accepted `owner` on credential and external location PATCH requests but ignored it. These requests now transfer ownership when `owner` is set. Clients must omit `owner` when changing only other fields, including clients that copy stored object fields into update requests. No database migration is required. Creation and transfer save the object owner field and its `OWNER` grant in one database transaction. After creation, the server loads only the saved `OWNER` grant for that object into its local permission cache. A delayed create request cannot restore a former owner's grant. Concurrent metadata edits preserve the current owner. After a transfer commits, the server reloads its local permission cache. Validation failures leave the permission cache unchanged. Other instances need `server.authorization.policy-refresh=true` to detect changes. Concurrent commits can leave the policy row count and maximum ID unchanged, so the poll can miss a transfer until another detectable change or a restart. The poll interval is not a guaranteed revocation deadline. If the local reload fails, the request returns an error even though the transfer may have committed. With native authorization, permission checks on that instance deny every user, including metastore admins, until a reload succeeds. Grant changes and grant listings also fail while the cache is incomplete. A denied request retries the reload even when policy refresh is disabled. Read the owner after recovery before retrying a transfer. Tests use real HTTP requests to transfer ownership for all eight resource types. They check that the new owner can change grants, the former owner cannot, and unrelated grants remain. They also cover delayed creation, rejected transfers, rollback, restart, concurrent changes, and failed reload recovery. This builds on the MANAGE support merged in #2088. API reference docs and UI types are regenerated from the API specification. The UI file also picks up existing API definitions, including staging tables and Delta commits, that were missing from the generated file. Validation: the full H2 server run reported 1,434 passing tests and one lifecycle failure because a local server already used port 8080. All nine lifecycle tests passed when rerun in a separate network namespace. All 157 focused checks passed on both MySQL 8 and PostgreSQL 18. Java formatting and server main/test Checkstyle passed. Release-upgrade tests were not run locally. ```sh build/sbt javafmtAll server/compileJavastyle server/Test/testJavastyle python3.11 dev/run-tests.py -p 4 server/test UC_TEST_DATABASE=MYSQL_8 python3.11 dev/run-tests.py -p 4 "server/testOnly io.unitycatalog.server.persist.OwnershipRepositoryTest io.unitycatalog.server.sdk.access.SdkManageAccessControlTest io.unitycatalog.server.service.PermissionServiceAuthorizationDisabledTest io.unitycatalog.server.auth.JCasbinAuthorizerTest io.unitycatalog.server.auth.JCasbinAuthorizerMultiInstanceTest io.unitycatalog.server.audit.AuditorTest io.unitycatalog.server.auth.OpaAuthorizerTest io.unitycatalog.server.sdk.access.SdkOpaAccessControlTest io.unitycatalog.server.auth.decorator.UnityAccessEvaluatorTest io.unitycatalog.server.sdk.access.SdkDeltaStagingTableAccessControlTest io.unitycatalog.server.sdk.access.SdkUCStagingTableAccessControlTest io.unitycatalog.server.sdk.access.SdkIcebergRestCatalogAccessControlTest" UC_TEST_DATABASE=POSTGRES_18 python3.11 dev/run-tests.py -p 4 "server/testOnly io.unitycatalog.server.persist.OwnershipRepositoryTest io.unitycatalog.server.sdk.access.SdkManageAccessControlTest io.unitycatalog.server.service.PermissionServiceAuthorizationDisabledTest io.unitycatalog.server.auth.JCasbinAuthorizerTest io.unitycatalog.server.auth.JCasbinAuthorizerMultiInstanceTest io.unitycatalog.server.audit.AuditorTest io.unitycatalog.server.auth.OpaAuthorizerTest io.unitycatalog.server.sdk.access.SdkOpaAccessControlTest io.unitycatalog.server.auth.decorator.UnityAccessEvaluatorTest io.unitycatalog.server.sdk.access.SdkDeltaStagingTableAccessControlTest io.unitycatalog.server.sdk.access.SdkUCStagingTableAccessControlTest io.unitycatalog.server.sdk.access.SdkIcebergRestCatalogAccessControlTest" ``` Related: #1823. --------- Signed-off-by: Timothy Wang <[email protected]>
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updatedDescription of changes
This lets an owner delegate object administration with
MANAGE. For example, an owner can let Alice manage access tomain.public.sales:With
USE CATALOGonmainandUSE SCHEMAonmain.public, Alice can grant BobSELECTwithout owning the table:Managers can read full metadata and grants, change grants, update supported metadata, and delete supported objects. Catalog and schema grants also cover their children. Callers need usage grants above the scope where they hold
MANAGE. The metastore does not supportMANAGE.Data credentials, model publishing, and creation still use their existing permission checks. Managers can grant themselves other privileges. Delegated managers need creation rights to rename catalogs, schemas, tables,
volumes, and models, including when strict checks are disabled.
They can rename external locations and credentials with
MANAGE.The implementation extends the existing authorization rules. API request formats and persistence code are unchanged.
Ownership transfer is the second PR in this stack: #2149. It depends on this PR.
Validation passed: 63 focused tests on H2 and 63 on MySQL 8. These cover authorization, grant handling, MANAGE, Iceberg credentials, and legacy rename rules. Java formatting and server/test Checkstyle also passed.
build/sbt javafmtAll server/checkstyle server/Test/checkstyle build/sbt "server/testOnly io.unitycatalog.server.auth.decorator.UnityAccessEvaluatorTest io.unitycatalog.server.service.PermissionServiceTest io.unitycatalog.server.sdk.access.SdkManageAccessControlTest io.unitycatalog.server.sdk.access.SdkIcebergCredentialMigrationTest io.unitycatalog.server.sdk.access.SdkModelRenameLegacyAccessControlTest io.unitycatalog.server.sdk.access.SdkVolumeRenameLegacyAccessControlTest"Related: #1823.