Skip to content

Add an access control test to verify that user can't claim staging table created by other users. - #1138

Merged
tdas merged 4 commits into
unitycatalog:mainfrom
yili-db:staging_table_access_test
Nov 10, 2025
Merged

tdas merged 4 commits into
unitycatalog:mainfrom
yili-db:staging_table_access_test

Conversation

@yili-db

@yili-db yili-db commented Oct 29, 2025 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • 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.
  • 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

Add an access control test to verify that user can't claim staging table created by other users.

Related issue is: #1143

@yili-db
yili-db force-pushed the staging_table_access_test branch 5 times, most recently from 6d3004b to eff7c18 Compare October 30, 2025 05:28
@yili-db
yili-db marked this pull request as draft October 31, 2025 20:06
@yili-db
yili-db force-pushed the staging_table_access_test branch 2 times, most recently from 3263ae4 to 1a9a21a Compare November 5, 2025 07:15
@yili-db yili-db mentioned this pull request Nov 5, 2025
2 of 4 tasks
@yili-db
yili-db marked this pull request as ready for review November 5, 2025 07:23
@yili-db yili-db changed the title [Managed table 5] Add an access control test to verify that user can't claim staging table created by other users. Add an access control test to verify that user can't claim staging table created by other users. Nov 5, 2025
@yili-db
yili-db force-pushed the staging_table_access_test branch 4 times, most recently from 9b9c090 to 15598c6 Compare November 6, 2025 00:16
* <li>Automatic cleanup of created users and granted permissions
* </ul>
*/
public abstract class SdkAccessControlBaseCRUDTest extends BaseAccessControlCRUDTest {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Previously the access control tests are only done via CLI. They are based on CliAccessControlBaseCrudTest which uses CLI to setup users and permissions. That won't allow us to do fine grain test between staging table and actual table because CLI can only do a table creation as a whole.
This new base class is just based on SDK and supports the user/permission setup.

new SdkSchemaOperations(TestUtils.createApiClient(adminConfig));

CreateCatalog createCatalog =
new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT);

@yili-db yili-db Nov 6, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The catalog, along with everything under it, is cleaned up by BaseCRUDTest

@yili-db
yili-db force-pushed the staging_table_access_test branch 2 times, most recently from 8b88de6 to 47d3157 Compare November 6, 2025 19:13
@yili-db
yili-db force-pushed the staging_table_access_test branch 4 times, most recently from e5473cd to 1bce207 Compare November 6, 2025 19:53
@yili-db yili-db mentioned this pull request Nov 6, 2025
2 of 4 tasks
@yili-db
yili-db force-pushed the staging_table_access_test branch from 1bce207 to 3b7be70 Compare November 6, 2025 20:50
Comment thread build.sbt
// Server and control models are added as provided to avoid them being added as maven dependencies
// This is because the server and control models are included in the server jar
.dependsOn(serverModels % "provided", controlModels % "provided")
.dependsOn(controlApi % "test->compile")

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.

why is this needed? which class?

@yili-db yili-db Nov 7, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The access control test base class SdkAccessControlBaseCRUDTest.java needs the following imports in order to create test users:

io.unitycatalog.control.api.UsersApi;
io.unitycatalog.control.ApiClient
io.unitycatalog.control.ApiException

@yili-db
yili-db requested a review from tdas November 7, 2025 19:55
@yili-db yili-db closed this Nov 7, 2025
@yili-db yili-db reopened this Nov 7, 2025
@yili-db
yili-db force-pushed the staging_table_access_test branch from 3b7be70 to 003b10d Compare November 10, 2025 09:05
* functionality for SDK-based access control tests, including user management, permission
* management, and resource setup.
*/
public class SdkStagingTableAccessControlCRUDTest extends SdkAccessControlBaseCRUDTest {

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.

technically this test is not testing CRUD (create, read, update, delete) as staging table cannot be updated or deleted.

private final List<PermissionGrant> grantedPermissions = new ArrayList<>();

/** Helper class to track granted permissions for cleanup. */
private record PermissionGrant(

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.

Seems like it's JDK 16+ language syntax , right ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just checked. It's from Java 14. We are using Java 17. So it should be fine?


@Override
protected CatalogOperations createCatalogOperations(ServerConfig config) {
return new SdkCatalogOperations(TestUtils.createApiClient(config));

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.

Could you please file an issue to track that we need to reuse the ApiClient construction that we've already used in ApiClientFactory . Also @timothyw553 is helping to build the retry policy for it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Created #1181

* @param config Server configuration including URL and auth token
* @return A TableOperations instance
*/
protected TableOperations createTableOperations(ServerConfig config) {

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.

nit: no usage for this method, could you please remove it ?

Comment on lines +179 to +187
java.net.URI uri = java.net.URI.create(config.getServerUrl());
int port = uri.getPort();
controlApiClient.setHost(uri.getHost());
controlApiClient.setPort(port);
controlApiClient.setScheme(uri.getScheme());
if (config.getAuthToken() != null && !config.getAuthToken().isEmpty()) {
controlApiClient.setRequestInterceptor(
request -> request.header("Authorization", "Bearer " + config.getAuthToken()));
}

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.

I've seen lots of places are trying to constrcut the api client by themselves. Actually we need to unify them into one place, because:

  1. Retry policy.
  2. need to care about this issue: Allow providing base path for UC API Client #1130

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the control api client. It looks similar to io.unitycatalog.client.ApiClient but it's actually a different class generated by openapi with no common base class.

Signed-off-by: Yi Li <[email protected]>
@yili-db
yili-db requested review from openinx and tdas November 10, 2025 19:50

@openinx openinx left a comment

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.

LGTM overall, thanks @yili-db for the great work !

@tdas tdas 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.

LGTM. good test!

@tdas
tdas merged commit e62eabb into unitycatalog:main Nov 10, 2025
yili-db added a commit to yili-db/unitycatalog that referenced this pull request Nov 19, 2025
…ble created by other users. (unitycatalog#1138)

## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/1138/files) to
review incremental changes.
-
[**staging_table_access_test**](unitycatalog#1138)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/1138/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.
- [ ] 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

Add an access control test to verify that user can't claim staging table
created by other users.
<!-- Please state what you've changed and how it might affect the users.
-->
Related issue is:
unitycatalog#1143

---------

Signed-off-by: Yi Li <[email protected]>
Sign up for free to 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.

3 participants