Repository navigation
[Server] Require schema creation permission for volume rename - #2017
Conversation
0323d50 to
5b216da
Compare
a4fa506 to
0ad5aee
Compare
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2023/files) to review incremental changes. - [**feat/strict-privilege-checks**](#2023) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2023/files)] ← _this PR_ - [fix/iceberg-credential-authorization](#2015) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2015/files/d63e70154a6f21c4d23d596491c779b66a250367..1e627b250bb34d8df390f050d8307fd5442dddc6)] - [fix/model-rename-permissions](#2018) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2018/files/d63e70154a6f21c4d23d596491c779b66a250367..49d68ec662b2f29c588c8f5d67ec74cfc3fe017f)] - [fix/permission-grant-validation](#2014) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2014/files/d63e70154a6f21c4d23d596491c779b66a250367..c6a5d3bf21127e62fc81b2b291ea54bb56463b55)] - [fix/table-details-permissions](#2016) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2016/files/d63e70154a6f21c4d23d596491c779b66a250367..6c897e034918a99ea3a2c4bdbeac64905c8f9d93)] - [fix/volume-rename-permissions](#2017) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2017/files/d63e70154a6f21c4d23d596491c779b66a250367..0ad5aee5216d2ed8085e969c287cc7dee7cdfa98)] --------- **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** Add `server.authorization.strict-privilege-checks`, which defaults to `true`. The following permission fixes use this setting so deployments can keep the previous rules temporarily while updating their applications and grants. Setting it to `false` retains the previous behavior, including access that the corrected checks would deny. This PR adds the validated setting and passes it to authorization expressions as the trusted `#strict_privilege_checks` variable. Request values cannot change it. The setting also reaches response filtering through the shared evaluator. This base PR does not change permission decisions. Use the same value on every server instance and restart each instance after changing it. The fallback conditions and the setting can be deleted after the migration. Tests passed with JDK 17: ```sh build/sbt javafmtAll "server/testOnly io.unitycatalog.server.utils.ServerPropertiesTest io.unitycatalog.server.UnityCatalogServerTest" build/sbt "server/testOnly io.unitycatalog.server.auth.decorator.UnityAccessEvaluatorTest" ``` 33 tests passed. Combined validation with all five dependent fixes: `build/sbt -J-Xmx2G javafmtAll "server/test"`: 923 tests passed. Signed-off-by: Timothy Wang <[email protected]>
4b7af66 to
822cc4e
Compare
|
/review |
| @AuthorizeExpression( | ||
| """ | ||
| #authorize(#principal, #catalog, OWNER) || | ||
| (#authorize(#principal, #catalog, OWNER) || |
There was a problem hiding this comment.
Please indent after the new (
There was a problem hiding this comment.
done, fixed the indentation.
| #authorize(#principal, #volume, OWNER)) | ||
| #authorize(#principal, #volume, OWNER))) && | ||
| (!#strict_privilege_checks || #new_name == null || | ||
| #new_name == #full_name.substring(#full_name.lastIndexOf('.') + 1) || |
There was a problem hiding this comment.
Let's remove the same-name check. It only changes the error for a request that does nothing anyway, so there's no need to handle it in the authorization rule. A rename to the current name now goes through the same checks as any other rename. The canComment branch in testVolumeRenamePermissions that expects RESOURCE_ALREADY_EXISTS, and the "requests with the current name" sentence in auth.md, need to change with it.
There was a problem hiding this comment.
done. same-name requests use the rename checks now. updated the tests and removed the old docs wording.
| (!#strict_privilege_checks || #new_name == null || | ||
| #new_name == #full_name.substring(#full_name.lastIndexOf('.') + 1) || | ||
| #authorize(#principal, #schema, OWNER) || | ||
| #authorizeAll(#principal, #schema, USE_SCHEMA, CREATE_VOLUME)) |
There was a problem hiding this comment.
[AI Assisted] This copies the schema part of createVolume's rule (#authorize(#principal, #schema, OWNER) || #authorizeAll(#principal, #schema, USE_SCHEMA, CREATE_VOLUME)). If the create rule changes later, rename will quietly drift from it. Could it be a shared fragment in AuthorizeExpressions, next to UPDATE_SCHEMA?
There was a problem hiding this comment.
[AI Assisted] Ping on this. There is a precedent: AuthorizeExpressions.RENAME_TABLE composes DELETE_TABLE with a create-in-schema check. Volume rename could follow the same shape (an UPDATE_VOLUME constant plus the create-in-schema part), which also keeps the #strict_privilege_checks term as one piece that is easy to drop when the flag is removed.
There was a problem hiding this comment.
i'd prefer to keep this inline. the shared check is two lines in the same class, and i find both annotations easier to follow this way.
There was a problem hiding this comment.
@yili-db up to you if you'd prefer we have it extracted. this is your proposal:
--- a/server/src/main/java/io/unitycatalog/server/auth/AuthorizeExpressions.java
+++ b/server/src/main/java/io/unitycatalog/server/auth/AuthorizeExpressions.java
@@
public static final String DELETE_SCHEMA = UPDATE_SCHEMA;
+ /** Schema permissions shared by volume creation and rename. */
+ public static final String CREATE_VOLUME_IN_SCHEMA =
+ """
+ (#authorize(#principal, #schema, OWNER) ||
+ #authorizeAll(#principal, #schema, USE_SCHEMA, CREATE_VOLUME))
+ """;
+
--- a/server/src/main/java/io/unitycatalog/server/service/VolumeService.java
+++ b/server/src/main/java/io/unitycatalog/server/service/VolumeService.java
@@
import com.linecorp.armeria.server.annotation.Post;
+import io.unitycatalog.server.auth.AuthorizeExpressions;
import io.unitycatalog.server.auth.UnityCatalogAuthorizer;
@@
@Post("")
@AuthorizeExpression(
- """
- #authorizeAny(#principal, #catalog, OWNER, USE_CATALOG) &&
- (#authorize(#principal, #schema, OWNER) ||
- #authorizeAll(#principal, #schema, USE_SCHEMA, CREATE_VOLUME)) &&
- (#volume_type != 'EXTERNAL' ||
- (#no_overlap_with_data_securable &&
- (#external_location == null ||
- #authorizeAny(#principal, #external_location, OWNER, CREATE_EXTERNAL_VOLUME))))
- """)
+ "#authorizeAny(#principal, #catalog, OWNER, USE_CATALOG) && "
+ + AuthorizeExpressions.CREATE_VOLUME_IN_SCHEMA
+ + """
+ && (#volume_type != 'EXTERNAL' ||
+ (#no_overlap_with_data_securable &&
+ (#external_location == null ||
+ #authorizeAny(#principal, #external_location, OWNER, CREATE_EXTERNAL_VOLUME))))
+ """)
@@
#authorize(#principal, #schema, USE_SCHEMA) &&
#authorize(#principal, #volume, OWNER))) &&
(!#strict_privilege_checks || #new_name == null ||
- #authorize(#principal, #schema, OWNER) ||
- #authorizeAll(#principal, #schema, USE_SCHEMA, CREATE_VOLUME))
- """)
+ """
+ + AuthorizeExpressions.CREATE_VOLUME_IN_SCHEMA
+ + ")")| "VOLUME, true, false, SCHEMA, false, false", | ||
| "SCHEMA, true, false, , true, true", | ||
| "SCHEMA, false, false, , false, false", | ||
| "CATALOG, false, false, , true, false", |
There was a problem hiding this comment.
[AI Assisted] These CATALOG, false, ... rows don't test what they say. setupCommonCatalogAndSchema() grants PRINCIPAL_1 USE_CATALOG on cat_pr1, and the revoke block below only removes grants from PRINCIPAL_2 and REGULAR_1. So useCatalog=false is never actually true for the catalog owner. Can you also revoke USE_CATALOG from PRINCIPAL_1 there?
There was a problem hiding this comment.
done. the setup now revokes USE_CATALOG from PRINCIPAL_1 too.
| TestUtils.SCHEMA_FULL_NAME, | ||
| Privileges.USE_SCHEMA, | ||
| Privileges.CREATE_VOLUME); | ||
| VolumeInfo original = |
There was a problem hiding this comment.
[AI Assisted] nit: this "create the volume as REGULAR_1, then revoke its catalog and schema grants" setup is almost the same as the one in SdkVolumeAccessControlCRUDTest.testVolumeRenamePermissions. Can we move it into a helper in SdkAccessControlBaseCRUDTest and call it from both?
There was a problem hiding this comment.
[AI Assisted] Ping on this one too.
There was a problem hiding this comment.
i'd keep this setup in the two test classes. the legacy test will go away with the flag, so i don't think we need to move it into the common base.
822cc4e to
78064bb
Compare
|
/review |
| ", true, true, SCHEMA, false, false" | ||
| }) | ||
| @SneakyThrows | ||
| public void testVolumeRenamePermissions( |
There was a problem hiding this comment.
Can we change this to a plain @Test, like NormalizedURLTest.testToStandardizedURIString? A small helper plus one call per case reads much better than positional CSV rows, where it's hard to tell which column means what.
There was a problem hiding this comment.
done. switched to a plain @Test with a helper. the loops cover all 60 combinations, with a separate catalog for each case.
58551a8 to
90bdb7e
Compare
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
90bdb7e to
750e926
Compare
|
/review |
|
last ai review run: https://github.com/unitycatalog/unitycatalog/pull/2017/checks?check_run_id=123071554061 i didnt find the nits to be too meaningful. skipping them. |
PR Checklist
docsis updatedDescription of changes
Require permission to create volumes in the containing schema before renaming a volume. Check any request with
new_name, including the current name. Comment-only updates keep the existing checks.This is the default, so a rename that works today returns 403 unless the caller also owns the schema or has
USE SCHEMAandCREATE VOLUMEon it. This includes requests whosenew_nameis the current name. Setserver.authorization.strict-privilege-checks=falseto keep the old behavior.Tests:
SdkVolumeAccessControlCRUDTest(strict mode, all owner and grant combinations),SdkVolumeRenameLegacyAccessControlTest(flag off), andSdkVolumeCRUDTestpass; formatting passed.