Skip to content

[#11095] feat(client-python): add Role CRUD and authorization data structures#11210

Merged
jerryshao merged 3 commits into
apache:mainfrom
sunyuhan1998:feature/python-sdk-auth-role-crud
May 27, 2026
Merged

[#11095] feat(client-python): add Role CRUD and authorization data structures#11210
jerryshao merged 3 commits into
apache:mainfrom
sunyuhan1998:feature/python-sdk-auth-role-crud

Conversation

@sunyuhan1998

@sunyuhan1998 sunyuhan1998 commented May 25, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add Role CRUD operations and authorization data structures to the Python client SDK:

  • DTOs: PrivilegeDTO, SecurableObjectDTO, RoleDTO with JSON serialization support
  • Role CRUD: create_role, get_role, delete_role, list_role_names on GravitinoMetalake and GravitinoClient
  • DTOConverters: to/from_privilege_dto and to/from_securable_object_dto conversion methods
  • Fix: GenericPrivilege.__eq__ now checks isinstance(value, Privilege) for PrivilegeDTO compatibility
  • Tests: Unit tests (DTO, response, client delegate, error handler) and integration tests against a live server

Why are the changes needed?

This is the Role authorization piece of issue #10782. User (#11058) and Group (#11094) management are already merged. Role CRUD is a prerequisite for Grant/Revoke operations, which will follow in a separate PR.

Fix: #11095

Does this PR introduce any user-facing change?

Yes — new public APIs on GravitinoClient and GravitinoMetalake:

  • create_role(role_name, properties=None, securable_objects=None)
  • get_role(role_name)
  • delete_role(role_name) -> bool
  • list_role_names() -> list[str]

How was this patch tested?

  • Unit tests: all passed
  • Integration tests: 4 passed against a live Gravitino server with authorization enabled
  • Linting: ruff check clean, pylint 10/10

…ata structures

- Add PrivilegeDTO, SecurableObjectDTO, RoleDTO data transfer objects
- Add Role CRUD operations: create_role, get_role, delete_role, list_role_names
- Fix GenericPrivilege.__eq__ for PrivilegeDTO compatibility
- Add DTOConverters for privilege and securable object conversion
- Add unit tests and integration tests for Role CRUD
@sunyuhan1998

Copy link
Copy Markdown
Contributor Author

Hi @jerryshao , I've split the CRUD part of role into a separate PR, do you think this is appropriate?

@github-actions

github-actions Bot commented May 25, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 66.51% +0.22% 🟢
Files changed 71.47% 🟢

Module Coverage
aliyun 1.72% 🔴
api 46.82% 🟢
authorization-common 85.96% 🟢
aws 2.66% 🔴
azure 2.47% 🔴
catalog-common 10.2% 🔴
catalog-fileset 80.02% 🟢
catalog-glue 66.08% 🟢
catalog-hive 79.75% -2.18% 🟢
catalog-jdbc-clickhouse 80.02% 🟢
catalog-jdbc-common 44.46% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.17% 🟢
catalog-jdbc-starrocks 78.27% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 44.89% -10.32% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.64% 🟢
catalog-lakehouse-paimon 79.29% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.94% 🟢
common 49.99% 🟢
core 82.39% +0.42% 🟢
filesystem-hadoop3 76.97% 🟢
flink 0.0% 🔴
flink-common 43.17% -9.92% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 53.26% 🟢
iceberg-common 54.98% 🟢
iceberg-rest-server 69.72% +0.51% 🟢
idp-basic 89.26% +0.37% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 20.9% -5.18% 🔴
lance-rest-server 62.78% +24.11% 🟢
lineage 53.02% 🟢
optimizer 82.95% 🟢
optimizer-api 21.95% 🔴
server 85.1% 🟢
server-common 72.85% 🟢
spark 32.79% 🔴
spark-common 39.09% 🔴
trino-connector 39.28% 🔴
Files
Module File Coverage
catalog-hive HiveCatalogOperations.java 81.84% 🟢
HiveViewCatalogOperations.java 75.11% 🟢
HiveView.java 69.23% 🟢
catalog-lakehouse-generic LanceTableDelegator.java 100.0% 🟢
LanceTableOperations.java 28.24% 🔴
core FilesetVersionBaseSQLProvider.java 100.0% 🟢
FunctionVersionMetaBaseSQLProvider.java 100.0% 🟢
ModelVersionAliasRelBaseSQLProvider.java 100.0% 🟢
ModelVersionMetaBaseSQLProvider.java 100.0% 🟢
SecurableObjectBaseSQLProvider.java 100.0% 🟢
StatisticBaseSQLProvider.java 100.0% 🟢
TableColumnBaseSQLProvider.java 100.0% 🟢
TagMetadataObjectRelBaseSQLProvider.java 100.0% 🟢
FilesetMetaPostgreSQLProvider.java 100.0% 🟢
FilesetVersionPostgreSQLProvider.java 100.0% 🟢
FunctionMetaPostgreSQLProvider.java 100.0% 🟢
FunctionVersionMetaPostgreSQLProvider.java 100.0% 🟢
ModelMetaPostgreSQLProvider.java 100.0% 🟢
ModelVersionAliasRelPostgreSQLProvider.java 100.0% 🟢
ModelVersionMetaPostgreSQLProvider.java 100.0% 🟢
OwnerMetaPostgreSQLProvider.java 100.0% 🟢
SecurableObjectPostgreSQLProvider.java 100.0% 🟢
TableColumnPostgreSQLProvider.java 100.0% 🟢
TableMetaPostgreSQLProvider.java 100.0% 🟢
TagMetadataObjectRelPostgreSQLProvider.java 100.0% 🟢
ViewMetaPostgreSQLProvider.java 100.0% 🟢
SchemaMetaService.java 99.34% 🟢
HierarchicalConversionPOStorageOps.java 97.22% 🟢
LancePartitionStatisticStorage.java 96.68% 🟢
FilesetMetaSQLProviderFactory.java 96.55% 🟢
TagMetadataObjectRelSQLProviderFactory.java 96.15% 🟢
ModelVersionMetaSQLProviderFactory.java 95.65% 🟢
TableColumnSQLProviderFactory.java 95.65% 🟢
ModelVersionAliasSQLProviderFactory.java 95.45% 🟢
FilesetVersionSQLProviderFactory.java 95.24% 🟢
FunctionVersionMetaSQLProviderFactory.java 95.24% 🟢
SecurableObjectSQLProviderFactory.java 95.0% 🟢
StatisticSQLProviderFactory.java 95.0% 🟢
FilesetMetaBaseSQLProvider.java 94.74% 🟢
OwnerMetaBaseSQLProvider.java 93.75% 🟢
OwnerMetaSQLProviderFactory.java 93.33% 🟢
TopicMetaPostgreSQLProvider.java 87.5% 🟢
ModelMetaSQLProviderFactory.java 83.33% 🟢
PolicyMetadataObjectRelSQLProviderFactory.java 82.76% 🟢
FunctionMetaSQLProviderFactory.java 80.77% 🟢
ViewMetaSQLProviderFactory.java 80.77% 🟢
SchemaOperationDispatcher.java 79.8% 🟢
TopicMetaSQLProviderFactory.java 79.31% 🟢
TableMetaSQLProviderFactory.java 78.57% 🟢
PolicyMetadataObjectRelBaseSQLProvider.java 76.92% 🟢
ModelMetaBaseSQLProvider.java 75.0% 🟢
SchemaMetaPostgreSQLProvider.java 75.0% 🟢
FunctionMetaBaseSQLProvider.java 70.59% 🟢
ViewMetaBaseSQLProvider.java 70.59% 🟢
SchemaMetaSQLProviderFactory.java 70.0% 🟢
TableMetaBaseSQLProvider.java 70.0% 🟢
PolicyMetadataObjectRelPostgreSQLProvider.java 70.0% 🟢
TopicMetaBaseSQLProvider.java 68.42% 🟢
SchemaMetaBaseSQLProvider.java 61.9% 🟢
SchemaPOStorageOps.java 60.0% 🟢
BasePOStorageOps.java 5.0% 🔴
FilesetMetaMapper.java 0.0% 🔴
FilesetVersionMapper.java 0.0% 🔴
FunctionMetaMapper.java 0.0% 🔴
FunctionVersionMetaMapper.java 0.0% 🔴
ModelMetaMapper.java 0.0% 🔴
ModelVersionAliasRelMapper.java 0.0% 🔴
ModelVersionMetaMapper.java 0.0% 🔴
OwnerMetaMapper.java 0.0% 🔴
PolicyMetadataObjectRelMapper.java 0.0% 🔴
SchemaMetaMapper.java 0.0% 🔴
SecurableObjectMapper.java 0.0% 🔴
StatisticMetaMapper.java 0.0% 🔴
TableColumnMapper.java 0.0% 🔴
TableMetaMapper.java 0.0% 🔴
TagMetadataObjectRelMapper.java 0.0% 🔴
TopicMetaMapper.java 0.0% 🔴
ViewMetaMapper.java 0.0% 🔴
flink-common BaseCatalog.java 27.3% 🔴
GravitinoHiveCatalog.java 0.0% 🔴
iceberg-rest-server IcebergNamespaceHookDispatcher.java 90.0% 🟢
idp-basic IdpUserGroupManager.java 100.0% 🟢
IdpUserMetaBaseSQLProvider.java 100.0% 🟢
IdpUserMetaService.java 96.3% 🟢
IdpGroupMetaService.java 95.12% 🟢
IdpGroup.java 42.86% 🔴
IdpUser.java 42.86% 🔴
lance-common LancePropertiesUtils.java 83.33% 🟢
LanceTableOperations.java 0.0% 🔴
GravitinoLanceTableOperations.java 0.0% 🔴
LanceConstants.java 0.0% 🔴
lance-rest-server LanceTableOperations.java 96.88% 🟢

Copilot AI 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.

Pull request overview

This PR adds Role authorization management to the Python client SDK by introducing Role/Privilege/SecurableObject DTOs plus create/get/delete/list role APIs on GravitinoMetalake and GravitinoClient, along with unit + integration test coverage.

Changes:

  • Added authorization DTOs: PrivilegeDTO, SecurableObjectDTO, RoleDTO (JSON serialization + converters).
  • Added Role CRUD APIs on GravitinoMetalake and delegated equivalents on GravitinoClient.
  • Added new request/response DTOs and expanded unit/integration tests + REST error handler coverage.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
clients/client-python/gravitino/api/authorization/privileges.py Adjusts GenericPrivilege.__eq__ to compare against any Privilege implementation.
clients/client-python/gravitino/client/dto_converters.py Adds converters to/from PrivilegeDTO and SecurableObjectDTO.
clients/client-python/gravitino/client/gravitino_client.py Adds Role CRUD delegate methods on GravitinoClient.
clients/client-python/gravitino/client/gravitino_metalake.py Implements Role CRUD operations against REST endpoints on GravitinoMetalake.
clients/client-python/gravitino/dto/authorization/init.py Exports new authorization DTOs from the package.
clients/client-python/gravitino/dto/authorization/privilege_dto.py Introduces PrivilegeDTO with JSON serialization and equality/hash.
clients/client-python/gravitino/dto/authorization/role_dto.py Introduces RoleDTO with builder, JSON serialization, equality/hash.
clients/client-python/gravitino/dto/authorization/securable_object_dto.py Introduces SecurableObjectDTO with JSON serialization and derived name/parent.
clients/client-python/gravitino/dto/requests/role_create_request.py Adds RoleCreateRequest for role creation payloads.
clients/client-python/gravitino/dto/responses/role_response.py Adds RoleResponse and RoleNamesListResponse response DTOs.
clients/client-python/tests/integration/test_role_management.py Adds live-server integration tests for role CRUD.
clients/client-python/tests/unittests/client/test_metalake_role_operations.py Adds mock-based unit tests for role endpoints + client delegation.
clients/client-python/tests/unittests/dto/responses/test_role_response.py Adds unit tests for role response DTO validation + JSON roundtrip.
clients/client-python/tests/unittests/dto/test_privilege_dto.py Adds unit tests for PrivilegeDTO.
clients/client-python/tests/unittests/dto/test_role_dto.py Adds unit tests for RoleDTO.
clients/client-python/tests/unittests/dto/test_securable_object_dto.py Adds unit tests for SecurableObjectDTO.
clients/client-python/tests/unittests/test_error_handler.py Extends error-handler tests to cover role error mapping.

Comment thread clients/client-python/gravitino/dto/authorization/role_dto.py
Comment thread clients/client-python/gravitino/dto/authorization/privilege_dto.py
Comment thread clients/client-python/tests/unittests/dto/test_privilege_dto.py
…to concrete privilege

PrivilegeDTO.can_bind_to now delegates to the concrete Privilege subclass
via Privileges.allow/deny, matching the Java DTO behavior.
@sunyuhan1998

Copy link
Copy Markdown
Contributor Author

Hi! @jerryshao , I have addressed all the feedback from Copilot. Please help review it again when you have time. Thank you!

Comment thread clients/client-python/gravitino/client/dto_converters.py Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Comment thread clients/client-python/gravitino/client/dto_converters.py Outdated
Comment thread clients/client-python/gravitino/client/dto_converters.py Outdated
… methods

Remove from_privilege_dto and from_securable_object_dto which have no
callers in this PR. They can be added in the follow-up Grant/Revoke PR.
@sunyuhan1998

Copy link
Copy Markdown
Contributor Author

@jerryshao , all known issues have been resolved, please help review it again, thank you!

@jerryshao
jerryshao merged commit 7990fb1 into apache:main May 27, 2026
28 checks passed
jerryshao pushed a commit that referenced this pull request Jun 2, 2026
…ns (#11274)

### What changes were proposed in this pull request?

Add Grant/Revoke authorization operations to the Python client SDK:

- **PermissionErrorHandler**: Error handler for grant/revoke REST API
calls
- **Grant/Revoke roles**: `grant_roles_to_user`,
`revoke_roles_from_user`, `grant_roles_to_group`,
`revoke_roles_from_group`
- **Grant/Revoke privileges**: `grant_privileges_to_role`,
`revoke_privileges_from_role`
- **Input validation**: All grant/revoke methods validate parameters
with `Precondition.check_string_not_empty`

### Why are the changes needed?

This completes the Role authorization piece of issue #10782, building on
top of PR #11210 (Role CRUD) which is already merged.

Fix: #11096

### Does this PR introduce _any_ user-facing change?

Yes — new public APIs on `GravitinoClient` and `GravitinoMetalake`:
- `grant_roles_to_user(role_names, user_name)`
- `revoke_roles_from_user(role_names, user_name)`
- `grant_roles_to_group(role_names, group_name)`
- `revoke_roles_from_group(role_names, group_name)`
- `grant_privileges_to_role(role_name, securable_object, privileges)`
- `revoke_privileges_from_role(role_name, securable_object, privileges)`

### How was this patch tested?

- Unit tests: 6 grant/revoke mock tests, 6 client delegate tests, 13
permission error handler assertions
- Integration tests: 3 tests against a live Gravitino server
(grant/revoke roles to user, grant/revoke roles to group, grant/revoke
privileges to role)
- Linting: `ruff check` clean, `pylint` 10/10

---------

Co-authored-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
danhuawang pushed a commit to danhuawang/gravitino that referenced this pull request Jun 8, 2026
…ata structures (apache#11210)

### What changes were proposed in this pull request?

Add Role CRUD operations and authorization data structures to the Python
client SDK:

- **DTOs**: `PrivilegeDTO`, `SecurableObjectDTO`, `RoleDTO` with JSON
serialization support
- **Role CRUD**: `create_role`, `get_role`, `delete_role`,
`list_role_names` on `GravitinoMetalake` and `GravitinoClient`
- **DTOConverters**: `to/from_privilege_dto` and
`to/from_securable_object_dto` conversion methods
- **Fix**: `GenericPrivilege.__eq__` now checks `isinstance(value,
Privilege)` for `PrivilegeDTO` compatibility
- **Tests**: Unit tests (DTO, response, client delegate, error handler)
and integration tests against a live server

### Why are the changes needed?

This is the Role authorization piece of issue apache#10782. User (apache#11058) and
Group (apache#11094) management are already merged. Role CRUD is a
prerequisite for Grant/Revoke operations, which will follow in a
separate PR.

Fix: apache#11095

### Does this PR introduce _any_ user-facing change?

Yes — new public APIs on `GravitinoClient` and `GravitinoMetalake`:
- `create_role(role_name, properties=None, securable_objects=None)`
- `get_role(role_name)`
- `delete_role(role_name) -> bool`
- `list_role_names() -> list[str]`

### How was this patch tested?

- Unit tests: all passed
- Integration tests: 4 passed against a live Gravitino server with
authorization enabled
- Linting: `ruff check` clean, `pylint` 10/10

---------

Co-authored-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
danhuawang pushed a commit to danhuawang/gravitino that referenced this pull request Jun 8, 2026
…erations (apache#11274)

### What changes were proposed in this pull request?

Add Grant/Revoke authorization operations to the Python client SDK:

- **PermissionErrorHandler**: Error handler for grant/revoke REST API
calls
- **Grant/Revoke roles**: `grant_roles_to_user`,
`revoke_roles_from_user`, `grant_roles_to_group`,
`revoke_roles_from_group`
- **Grant/Revoke privileges**: `grant_privileges_to_role`,
`revoke_privileges_from_role`
- **Input validation**: All grant/revoke methods validate parameters
with `Precondition.check_string_not_empty`

### Why are the changes needed?

This completes the Role authorization piece of issue apache#10782, building on
top of PR apache#11210 (Role CRUD) which is already merged.

Fix: apache#11096

### Does this PR introduce _any_ user-facing change?

Yes — new public APIs on `GravitinoClient` and `GravitinoMetalake`:
- `grant_roles_to_user(role_names, user_name)`
- `revoke_roles_from_user(role_names, user_name)`
- `grant_roles_to_group(role_names, group_name)`
- `revoke_roles_from_group(role_names, group_name)`
- `grant_privileges_to_role(role_name, securable_object, privileges)`
- `revoke_privileges_from_role(role_name, securable_object, privileges)`

### How was this patch tested?

- Unit tests: 6 grant/revoke mock tests, 6 client delegate tests, 13
permission error handler assertions
- Integration tests: 3 tests against a live Gravitino server
(grant/revoke roles to user, grant/revoke roles to group, grant/revoke
privileges to role)
- Linting: `ruff check` clean, `pylint` 10/10

---------

Co-authored-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
danhuawang pushed a commit to danhuawang/gravitino that referenced this pull request Jun 9, 2026
…ata structures (apache#11210)

### What changes were proposed in this pull request?

Add Role CRUD operations and authorization data structures to the Python
client SDK:

- **DTOs**: `PrivilegeDTO`, `SecurableObjectDTO`, `RoleDTO` with JSON
serialization support
- **Role CRUD**: `create_role`, `get_role`, `delete_role`,
`list_role_names` on `GravitinoMetalake` and `GravitinoClient`
- **DTOConverters**: `to/from_privilege_dto` and
`to/from_securable_object_dto` conversion methods
- **Fix**: `GenericPrivilege.__eq__` now checks `isinstance(value,
Privilege)` for `PrivilegeDTO` compatibility
- **Tests**: Unit tests (DTO, response, client delegate, error handler)
and integration tests against a live server

### Why are the changes needed?

This is the Role authorization piece of issue apache#10782. User (apache#11058) and
Group (apache#11094) management are already merged. Role CRUD is a
prerequisite for Grant/Revoke operations, which will follow in a
separate PR.

Fix: apache#11095

### Does this PR introduce _any_ user-facing change?

Yes — new public APIs on `GravitinoClient` and `GravitinoMetalake`:
- `create_role(role_name, properties=None, securable_objects=None)`
- `get_role(role_name)`
- `delete_role(role_name) -> bool`
- `list_role_names() -> list[str]`

### How was this patch tested?

- Unit tests: all passed
- Integration tests: 4 passed against a live Gravitino server with
authorization enabled
- Linting: `ruff check` clean, `pylint` 10/10

---------

Co-authored-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
danhuawang pushed a commit to danhuawang/gravitino that referenced this pull request Jun 9, 2026
…erations (apache#11274)

### What changes were proposed in this pull request?

Add Grant/Revoke authorization operations to the Python client SDK:

- **PermissionErrorHandler**: Error handler for grant/revoke REST API
calls
- **Grant/Revoke roles**: `grant_roles_to_user`,
`revoke_roles_from_user`, `grant_roles_to_group`,
`revoke_roles_from_group`
- **Grant/Revoke privileges**: `grant_privileges_to_role`,
`revoke_privileges_from_role`
- **Input validation**: All grant/revoke methods validate parameters
with `Precondition.check_string_not_empty`

### Why are the changes needed?

This completes the Role authorization piece of issue apache#10782, building on
top of PR apache#11210 (Role CRUD) which is already merged.

Fix: apache#11096

### Does this PR introduce _any_ user-facing change?

Yes — new public APIs on `GravitinoClient` and `GravitinoMetalake`:
- `grant_roles_to_user(role_names, user_name)`
- `revoke_roles_from_user(role_names, user_name)`
- `grant_roles_to_group(role_names, group_name)`
- `revoke_roles_from_group(role_names, group_name)`
- `grant_privileges_to_role(role_name, securable_object, privileges)`
- `revoke_privileges_from_role(role_name, securable_object, privileges)`

### How was this patch tested?

- Unit tests: 6 grant/revoke mock tests, 6 client delegate tests, 13
permission error handler assertions
- Integration tests: 3 tests against a live Gravitino server
(grant/revoke roles to user, grant/revoke roles to group, grant/revoke
privileges to role)
- Linting: `ruff check` clean, `pylint` 10/10

---------

Co-authored-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
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.

[Subtask] Add Role authorization management to Python client

3 participants