You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "NihalJain (via GitHub)" <gi...@apache.org> on 2025/12/01 17:25:33 UTC
[PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
NihalJain opened a new pull request, #17295:
URL: https://github.com/apache/pinot/pull/17295
This commit extends Row-Level Security (RLS) functionality to ZooKeeper-based authentication (`ZkBasicAuthAccessControlFactory`), enabling dynamic user management with table-level filter controls via REST API.
Previously, RLS filters were only supported with file-based `BasicAuth` configuration. ZK-based authentication passed empty RLS filter maps, preventing users from applying row-level restrictions when using ZooKeeper for user management.
Changes:
- Extended UserConfig to store RLS filters per table (`Map<String, List<String>>`)
- Updated `AccessControlUserConfigUtils` to serialize/deserialize RLS filters to/from `ZNRecord`
- Modified `BasicAuthUtils` to extract RLS filters from `UserConfig` and pass to `ZkBasicAuthPrincipal`
- Implemented `getRowColFilters()` in `ZkBasicAuthAccessControlFactory` to return RLS filters
- Updated `UserConfigBuilder` to support RLS filter configuration
- Added comprehensive unit tests for `UserConfig`, `UserConfigBuilder`, and `AccessControlUserConfigUtils`
- Added integration tests for ZkAuth RLS scenarios by extracting base class from existing `BasicAuth` tests
API Example:
```
POST /users
{
"username": "user",
"password": "secret",
"component": "BROKER",
"role": "USER",
"tables": ["table1", "table2"],
"permissions": ["READ"],
"rlsFilters": {
"table1": ["country='US'"],
"table2": ["department='Engineering'", "level='Senior'"]
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578088629
##########
pinot-common/src/main/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtils.java:
##########
@@ -48,13 +56,32 @@ public static UserConfig fromZNRecord(ZNRecord znRecord) {
List<String> tableList = znRecord.getListField(UserConfig.TABLES_KEY);
List<String> excludeTableList = znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY);
- List<String> permissionListFromZNRecord = znRecord.getListField(UserConfig.PERMISSIONS_KEY);
+ List<String> permissionListFromZNRecord = znRecord.getListField(
+ UserConfig.PERMISSIONS_KEY);
List<AccessType> permissionList = null;
if (permissionListFromZNRecord != null) {
permissionList = permissionListFromZNRecord.stream()
- .map(x -> AccessType.valueOf(x)).collect(Collectors.toList());
+ .map(x -> AccessType.valueOf(x))
+ .collect(Collectors.toList());
+ }
+
+ // Extract RLS filters from simple fields (stored as JSON)
+ Map<String, List<String>> rlsFilters = null;
+ String rlsFiltersJson = simpleFields.get(UserConfig.RLS_FILTERS_KEY);
+ if (rlsFiltersJson != null && !rlsFiltersJson.isEmpty()) {
+ try {
+ rlsFilters = JsonUtils.stringToObject(
+ rlsFiltersJson, new TypeReference<Map<String, List<String>>>() {
+ }
+ );
+ } catch (IOException e) {
+ // Log error but continue - RLS filters are optional
+ LOGGER.error("Failed to deserialize RLS filters for user: {}", username, e);
Review Comment:
is this fair assumption or should we fail here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3645256710
Hi team could you please provide some feedback, I need to start re-work on https://github.com/apache/pinot/pull/15861 after this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3598127363
## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/17295?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `73.17073%` with `11 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 55.69%. Comparing base ([`4e3599c`](https://app.codecov.io/gh/apache/pinot/commit/4e3599ceabdb02524d3a5f283d4f6e8966876fbf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`40a39c7`](https://app.codecov.io/gh/apache/pinot/commit/40a39c7cb3a54265f09d8feaf865923098555b74?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 2 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/17295?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...a/org/apache/pinot/spi/config/user/UserConfig.java](https://app.codecov.io/gh/apache/pinot/pull/17295?src=pr&el=tree&filepath=pinot-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fspi%2Fconfig%2Fuser%2FUserConfig.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3VzZXIvVXNlckNvbmZpZy5qYXZh) | 52.38% | [2 Missing and 8 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/17295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...mon/utils/config/AccessControlUserConfigUtils.java](https://app.codecov.io/gh/apache/pinot/pull/17295?src=pr&el=tree&filepath=pinot-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcommon%2Futils%2Fconfig%2FAccessControlUserConfigUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdXRpbHMvY29uZmlnL0FjY2Vzc0NvbnRyb2xVc2VyQ29uZmlnVXRpbHMuamF2YQ==) | 93.75% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/17295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (4e3599c) and HEAD (40a39c7). Click for more details.
>
> <details><summary>HEAD has 32 uploads less than BASE</summary>
>
>| Flag | BASE (4e3599c) | HEAD (40a39c7) |
>|------|------|------|
>|java-21|4|1|
>|unittests1|2|1|
>|unittests|3|1|
>|temurin|9|1|
>|java-11|5|0|
>|unittests2|1|0|
>|integration|6|0|
>|integration2|2|0|
>|integration1|2|0|
>|custom-integration1|2|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #17295 +/- ##
============================================
- Coverage 63.23% 55.69% -7.54%
+ Complexity 1433 702 -731
============================================
Files 3133 2446 -687
Lines 186131 137806 -48325
Branches 28408 21900 -6508
============================================
- Hits 117704 76755 -40949
+ Misses 59363 54617 -4746
+ Partials 9064 6434 -2630
```
| [Flag](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration1](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration2](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-11](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-21](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.69% <73.17%> (+0.08%)` | :arrow_up: |
| [temurin](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.69% <73.17%> (-7.54%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.69% <73.17%> (-7.54%)` | :arrow_down: |
| [unittests1](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.69% <73.17%> (+0.03%)` | :arrow_up: |
| [unittests2](https://app.codecov.io/gh/apache/pinot/pull/17295/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/pinot/pull/17295?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3598374158
Please review @Jackie-Jiang @vrajat @9aman @yashmayya
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578121555
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/user/UserConfig.java:
##########
@@ -59,26 +61,72 @@ public class UserConfig extends BaseJsonConfig {
@JsonPropertyDescription("The table permission of User")
private List<AccessType> _permissions;
+ @JsonPropertyDescription("The RLS filters for User per table")
+ private Map<String, List<String>> _rlsFilters;
+
@JsonCreator
public UserConfig(@JsonProperty(value = USERNAME_KEY, required = true) String username,
@JsonProperty(value = PASSWORD_KEY, required = true) String password,
@JsonProperty(value = COMPONET_KEY, required = true) String component,
@JsonProperty(value = ROLE_KEY, required = true) String role,
@JsonProperty(value = TABLES_KEY) @Nullable List<String> tableList,
@JsonProperty(value = EXCLUDE_TABLES_KEY) @Nullable List<String> excludeTableList,
- @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList
+ @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList,
+ @JsonProperty(value = RLS_FILTERS_KEY) @Nullable Map<String, List<String>> rlsFilters
) {
- Preconditions.checkArgument(username != null, "'username' must be configured");
- Preconditions.checkArgument(password != null, "'password' must be configured");
+ this(username, password, component, role, tableList, excludeTableList, permissionList, rlsFilters, true);
+ }
+
+ /**
+ * Constructor for backward compatibility without RLS filters.
+ * This allows existing code to continue working without modification.
+ */
+ public UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList) {
+ this(username, password, component, role, tableList, excludeTableList, permissionList, null, true);
+ }
+
+ private UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList,
+ Map<String, List<String>> rlsFilters, boolean validate) {
+ if (validate) {
+ Preconditions.checkArgument(username != null, "'username' must be configured");
+ Preconditions.checkArgument(!username.isEmpty(), "'username' must not be empty");
+ Preconditions.checkArgument(password != null, "'password' must be configured");
+ Preconditions.checkArgument(!password.isEmpty(), "'password' must not be empty");
+ }
// NOTE: Handle lower case table type and raw table name for backward-compatibility
_username = username;
_password = password;
_componentType = ComponentType.valueOf(component.toUpperCase());
_roleType = RoleType.valueOf(role.toUpperCase());
+
+ if (tableList != null) {
Review Comment:
let me do as another commit to keep this pr clean, will revert this change here in next commit!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2613239574
##########
pinot-core/src/main/java/org/apache/pinot/core/auth/BasicAuthUtils.java:
##########
@@ -122,10 +122,14 @@ public static List<ZkBasicAuthPrincipal> extractBasicAuthPrincipals(List<UserCon
.orElseGet(() -> Collections.emptyList())
.stream().map(x -> x.toString())
.collect(Collectors.toSet());
- //todo: Handle RLS filters properly
+
+ // Extract RLS filters from UserConfig
Review Comment:
Consider adding a brief inline comment explaining that RLS filters are now being extracted from UserConfig, since this is a key change from the previous implementation where an empty map was passed. This would help future readers understand the significance of this change.
```suggestion
// Extract RLS filters from UserConfig.
// Note: This is a key change from the previous implementation where an empty map was always passed.
```
##########
pinot-broker/src/main/java/org/apache/pinot/broker/broker/ZkBasicAuthAccessControlFactory.java:
##########
@@ -120,6 +124,26 @@ public TableAuthorizationResult authorize(RequesterIdentity requesterIdentity, S
return new TableAuthorizationResult(failedTables);
}
+ @Override
+ public TableRowColAccessResult getRowColFilters(RequesterIdentity requesterIdentity, String table) {
+ Optional<ZkBasicAuthPrincipal> principalOpt = getPrincipalAuth(requesterIdentity);
+
+ Preconditions.checkState(principalOpt.isPresent(), "Principal is not authorized");
+ Preconditions.checkState(table != null, "Table cannot be null");
+
+ TableRowColAccessResult tableRowColAccessResult = new TableRowColAccessResultImpl();
+ ZkBasicAuthPrincipal principal = principalOpt.get();
+
+ //precondition: The principal should have the table.
Review Comment:
The comment has a typo: 'precondition' should be capitalized and formatted consistently with the Preconditions.checkArgument below it. Consider changing this to a standard Javadoc comment or removing it since the Preconditions.checkArgument already expresses this requirement clearly.
```suggestion
```
##########
pinot-common/src/main/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtils.java:
##########
@@ -48,13 +56,32 @@ public static UserConfig fromZNRecord(ZNRecord znRecord) {
List<String> tableList = znRecord.getListField(UserConfig.TABLES_KEY);
List<String> excludeTableList = znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY);
- List<String> permissionListFromZNRecord = znRecord.getListField(UserConfig.PERMISSIONS_KEY);
+ List<String> permissionListFromZNRecord = znRecord.getListField(
+ UserConfig.PERMISSIONS_KEY);
List<AccessType> permissionList = null;
if (permissionListFromZNRecord != null) {
permissionList = permissionListFromZNRecord.stream()
- .map(x -> AccessType.valueOf(x)).collect(Collectors.toList());
+ .map(x -> AccessType.valueOf(x))
+ .collect(Collectors.toList());
+ }
+
+ // Extract RLS filters from simple fields (stored as JSON)
+ Map<String, List<String>> rlsFilters = null;
+ String rlsFiltersJson = simpleFields.get(UserConfig.RLS_FILTERS_KEY);
+ if (rlsFiltersJson != null && !rlsFiltersJson.isEmpty()) {
+ try {
+ rlsFilters = JsonUtils.stringToObject(
+ rlsFiltersJson, new TypeReference<Map<String, List<String>>>() {
+ }
+ );
+ } catch (IOException e) {
+ // Log error but continue - RLS filters are optional
+ LOGGER.error("Failed to deserialize RLS filters for user: {}", username, e);
+ }
}
Review Comment:
Consider adding a comment explaining why RLS filters are stored as JSON in simple fields rather than using list fields like other list-based data. This design decision would be helpful for future maintainers to understand the serialization approach.
##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/RowLevelSecurityZkAuthIntegrationTest.java:
##########
@@ -0,0 +1,209 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.integration.tests;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.Map;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Row Level Security integration test using ZkAuth (ZooKeeper-based authentication).
+ * Users and permissions are created dynamically via REST API calls to the controller.
+ * This approach allows for dynamic user management without requiring cluster restarts.
+ */
+public class RowLevelSecurityZkAuthIntegrationTest extends RowLevelSecurityIntegrationTestBase {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RowLevelSecurityZkAuthIntegrationTest.class);
+
+ @Override
+ protected void overrideControllerConf(Map<String, Object> properties) {
+ properties.put("controller.segment.fetcher.auth.token", AUTH_TOKEN);
+ properties.put("controller.admin.access.control.factory.class",
+ "org.apache.pinot.controller.api.access.ZkBasicAuthAccessControlFactory");
+ properties.put("access.control.init.username", ADMIN_USER);
+ properties.put("access.control.init.password", ADMIN_PASSWORD);
+ }
+
+ @Override
+ protected void overrideBrokerConf(PinotConfiguration brokerConf) {
+ brokerConf.setProperty("pinot.broker.enable.row.column.level.auth", "true");
+ brokerConf.setProperty("pinot.broker.access.control.class",
+ "org.apache.pinot.broker.broker.ZkBasicAuthAccessControlFactory");
+ }
+
+ @Override
+ protected void overrideServerConf(PinotConfiguration serverConf) {
+ serverConf.setProperty("pinot.server.segment.fetcher.auth.token", AUTH_TOKEN);
+ serverConf.setProperty("pinot.server.segment.uploader.auth.token", AUTH_TOKEN);
+ serverConf.setProperty("pinot.server.instance.auth.token", AUTH_TOKEN);
+ }
+
+ /**
+ * Initialize users via REST API after the cluster has started.
+ * This creates the same users with the same permissions and RLS filters as BasicAuth test.
+ */
+ @Override
+ protected void initializeUsers()
+ throws Exception {
+ LOGGER.info("Initializing users via REST API for ZkAuth test");
+
+ // Wait for controller to be ready
+ waitForControllerReady();
+
+ // Create users for BROKER component with RLS filters
+ createBrokerUsers();
+
+ // Create users for CONTROLLER component
+ createControllerUsers();
+
+ // Create users for SERVER component
+ createServerUsers();
+
+ LOGGER.info("Successfully initialized all users for ZkAuth test");
+ }
+
+ private void waitForControllerReady()
+ throws Exception {
+ int maxRetries = 30;
+ int retryCount = 0;
+ String healthUrl = "http://localhost:" + getControllerPort() + "/health";
+ while (retryCount < maxRetries) {
+ try {
+ String response = sendGetRequest(healthUrl);
+ if (response != null && !response.isEmpty()) {
+ LOGGER.info("Controller is ready");
+ return;
+ }
+ } catch (Exception e) {
+ // Controller not ready yet
Review Comment:
Consider logging the exception message to help with debugging when the controller fails to become ready. This would provide more context about why the health check failed.
```suggestion
// Controller not ready yet
LOGGER.debug("Controller health check failed on attempt {}: {}", retryCount + 1, e.getMessage(), e);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3597916618
Manual testing:
1) Tested REST API create/update/get operations with RLS filters
- POST
```
curl -X 'POST' \
'http://localhost:9001/users' \
-H 'accept: application/json' \
-H 'Authorization: Basic YWRtaW46dmVyeXNlY3JldA==' \
-H 'Content-Type: application/json' \
-d '{
"username": "userRLS_Simple",
"password": "secretSimple",
"component": "BROKER",
"role": "USER",
"tables": ["airlineStats"],
"permissions": ["READ"],
"rlsFilters": {"airlineStats": ["AirlineID='\''19805'\''"]}
}'
```
```
{
"status": "User userRLS_Simple_BROKER has been successfully added!"
}
```
- GET
```
curl -X 'GET' \
'http://localhost:9001/users/userRLS_Simple?component=BROKER' \
-H 'accept: application/json' \
-H 'Authorization: Basic YWRtaW46dmVyeXNlY3JldA=='
```
```
{
"userRLS_Simple_BROKER": {
"username": "userRLS_Simple",
"password": "$2a$10$lA8P0gGKpG66Ype3wTmrp.2Bel8jHbQNglf8g/Cai7DHUbY/LZnzS",
"component": "BROKER",
"role": "USER",
"tables": [
"airlineStats"
],
"permissions": [
"READ"
],
"rlsFilters": {
"airlineStats": [
"AirlineID='19805'"
]
},
"usernameWithComponent": "userRLS_Simple_BROKER"
}
}```
- DELETE
```
curl -X 'DELETE' \
'http://localhost:9001/users/userRLS_Simple?component=BROKER' \
-H 'accept: application/json' \
-H 'Authorization: Basic YWRtaW46dmVyeXNlY3JldA=='
```
```
{
"status": "User: userRLS_Simple_BROKER has been successfully deleted"
}
```
2) Tested queries work as expected with rls for the ZK-based authentication
```
▸ Row-Level Security (RLS) Testing
Testing: RLS filter application on airlineStats:
DEBUG: curl -s -w \n%{http_code} -u admin:verysecret -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[289]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":2,"requestId":"97156851000000116","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":1,"totalDocs":289,"numEntriesScannedInFilter":0,"numEntriesScannedPostFilter":1,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeNs"
:0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":false,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ Admin sees all rows (no RLS, count=289) → 200 OK, count=289
DEBUG: curl -s -w \n%{http_code} -u userRLS:secretRLS -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[45]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":3,"requestId":"97156851000000117","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":45,"totalDocs":289,"numEntriesScannedInFilter":289,"numEntriesScannedPostFilter":0,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeN
s":0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS sees only TX rows (RLS applied, count=45) → 200 OK, count=45
DEBUG: curl -s -w \n%{http_code} -u userRLS:secretRLS -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats WHERE OriginState='TX' LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[45]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":3,"requestId":"97156851000000118","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":45,"totalDocs":289,"numEntriesScannedInFilter":334,"numEntriesScannedPostFilter":0,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeN
s":0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS explicit TX query (count=45) → 200 OK, count=45
DEBUG: curl -s -w \n%{http_code} -u userRLS:secretRLS -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats WHERE OriginState='CA' LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[0]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":3,"requestId":"97156851000000119","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":0,"totalDocs":289,"numEntriesScannedInFilter":313,"numEntriesScannedPostFilter":0,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":0,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeNs"
:0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS CA query returns 0 (RLS blocks CA, count=0) → 200 OK, count=0
Testing: RLS Simple filter (AirlineID='19805'):
DEBUG: curl -s -w \n%{http_code} -u userRLS_Simple:secretSimple -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[40]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":3,"requestId":"97156851000000120","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":1,"totalDocs":289,"numEntriesScannedInFilter":0,"numEntriesScannedPostFilter":1,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeNs":
0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS_Simple sees filtered rows (RLS applied, count=40) → 200 OK, count=40
Testing: RLS AND filter (OriginState='TX' AND AirlineID='19805'):
DEBUG: curl -s -w \n%{http_code} -u userRLS_And:secretAnd -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[14]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":3,"requestId":"97156851000000121","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":14,"totalDocs":289,"numEntriesScannedInFilter":304,"numEntriesScannedPostFilter":0,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeN
s":0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS_And sees filtered rows (RLS applied, count=14) → 200 OK, count=14
Testing: RLS OR filter (OriginState='TX' OR OriginState='CA'):
DEBUG: curl -s -w \n%{http_code} -u userRLS_Or:secretOr -X POST -H Content-Type: application/json -d {"sql":"SELECT COUNT(*) FROM airlineStats LIMIT 1"} http://localhost:8099/query/sql
DEBUG: Response body: {"resultTable":{"dataSchema":{"columnNames":["count(*)"],"columnDataTypes":["LONG"]},"rows":[[84]]},"numRowsResultSet":1,"partialResult":false,"exceptions":[],"numGroupsLimitReached":false,"numGroupsWarningLimitReached":false,"timeUsedMs":6,"requestId":"97156851000000122","clientRequestId":null,"brokerId":"Broker_localhost_8099","numDocsScanned":84,"totalDocs":289,"numEntriesScannedInFilter":578,"numEntriesScannedPostFilter":0,"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numConsumingSegmentsProcessed":0,"numConsumingSegmentsMatched":0,"minConsumingFreshnessTimeMs":0,"numSegmentsPrunedByBroker":0,"numSegmentsPrunedByServer":0,"numSegmentsPrunedInvalid":0,"numSegmentsPrunedByLimit":0,"numSegmentsPrunedByValue":0,"brokerReduceTimeMs":0,"offlineThreadCpuTimeNs":0,"realtimeThreadCpuTimeNs":0,"offlineSystemActivitiesCpuTimeNs":0,"realtimeSystemActivitiesCpuTimeN
s":0,"offlineResponseSerializationCpuTimeNs":0,"realtimeResponseSerializationCpuTimeNs":0,"offlineTotalCpuTimeNs":0,"realtimeTotalCpuTimeNs":0,"explainPlanNumEmptyFilterSegments":0,"explainPlanNumMatchAllFilterSegments":0,"traceInfo":{},"tablesQueried":["airlineStats"],"offlineThreadMemAllocatedBytes":0,"realtimeThreadMemAllocatedBytes":0,"offlineResponseSerMemAllocatedBytes":0,"realtimeResponseSerMemAllocatedBytes":0,"offlineTotalMemAllocatedBytes":0,"realtimeTotalMemAllocatedBytes":0,"pools":[-1],"rlsFiltersApplied":true,"groupsTrimmed":false}
DEBUG: Response status: 200
✓ UserRLS_Or sees filtered rows (RLS applied, count=84) → 200 OK, count=84
```
PS: This was done with a bash script which I plan to contribute later with another PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2584025982
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
Review Comment:
Corrected spelling of 'getPermissios' to 'getPermissions'.
```suggestion
Assert.assertNull(userConfig.getPermissions(), "Permissions should be null when not set");
```
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null when not set");
+ }
+
+ @Test
+ public void testUserConfigWithTableList() {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testUserConfigWithExcludeTableList() {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testUserConfigWithPermissionList() {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testUserConfigWithRlsFilters() {
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+ rlsFilters.put("table2", Arrays.asList("filter3"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.PROXY)
+ .setRoleType(RoleType.USER)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ Assert.assertEquals(userConfig.getRlsFilters(), rlsFilters, "RLS filters should match");
+ Assert.assertEquals(userConfig.getRlsFilters().size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table2"), "Should contain table2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").size(), 2, "table1 should have 2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").size(), 1, "table2 should have 1 filter");
+ }
+
+ @Test
+ public void testUserConfigWithAllFields() {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.UPDATE, AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername("adminUser")
+ .setPassword("adminPass123")
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), "adminUser", "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), "adminPass123", "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.ADMIN, "Role type should match");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
Review Comment:
Corrected spelling of 'getPermissios' to 'getPermissions'.
```suggestion
Assert.assertEquals(userConfig.getPermissions(), permissionList, "Permission list should match");
```
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null when not set");
+ }
+
+ @Test
+ public void testUserConfigWithTableList() {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testUserConfigWithExcludeTableList() {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testUserConfigWithPermissionList() {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
Review Comment:
Multiple occurrences of 'getPermissios' should be corrected to 'getPermissions'.
```suggestion
Assert.assertNotNull(userConfig.getPermissions(), "Permissions should not be null");
Assert.assertEquals(userConfig.getPermissions(), permissionList, "Permission list should match");
Assert.assertEquals(userConfig.getPermissions().size(), 3, "Permission list size should be 3");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.READ), "Should contain READ permission");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.CREATE), "Should contain CREATE permission");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.UPDATE), "Should contain UPDATE permission");
```
##########
pinot-common/src/test/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtilsTest.java:
##########
@@ -0,0 +1,559 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.UserConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link AccessControlUserConfigUtils}
+ */
+public class AccessControlUserConfigUtilsTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testFromZNRecordWithMandatoryFieldsOnly() {
+ // Create ZNRecord with only mandatory fields
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null");
+ }
+
+ @Test
+ public void testFromZNRecordWithTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.CONTROLLER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testFromZNRecordWithExcludeTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.SERVER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testFromZNRecordWithPermissionList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.MINION.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> permissionListStr = Arrays.asList("READ", "CREATE", "UPDATE");
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
Review Comment:
Multiple occurrences of 'getPermissios' should be corrected to 'getPermissions'.
```suggestion
Assert.assertNotNull(userConfig.getPermissions(), "Permissions should not be null");
Assert.assertEquals(userConfig.getPermissions().size(), 3, "Permission list size should be 3");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.READ), "Should contain READ permission");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.CREATE), "Should contain CREATE permission");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.UPDATE), "Should contain UPDATE permission");
```
##########
pinot-common/src/test/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtilsTest.java:
##########
@@ -0,0 +1,559 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.UserConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link AccessControlUserConfigUtils}
+ */
+public class AccessControlUserConfigUtilsTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testFromZNRecordWithMandatoryFieldsOnly() {
+ // Create ZNRecord with only mandatory fields
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null");
Review Comment:
Corrected spelling of 'getPermissios' to 'getPermissions'.
```suggestion
Assert.assertNull(userConfig.getPermissions(), "Permissions should be null");
```
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null when not set");
+ }
+
+ @Test
+ public void testUserConfigWithTableList() {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testUserConfigWithExcludeTableList() {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testUserConfigWithPermissionList() {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testUserConfigWithRlsFilters() {
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+ rlsFilters.put("table2", Arrays.asList("filter3"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.PROXY)
+ .setRoleType(RoleType.USER)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ Assert.assertEquals(userConfig.getRlsFilters(), rlsFilters, "RLS filters should match");
+ Assert.assertEquals(userConfig.getRlsFilters().size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table2"), "Should contain table2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").size(), 2, "table1 should have 2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").size(), 1, "table2 should have 1 filter");
+ }
+
+ @Test
+ public void testUserConfigWithAllFields() {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.UPDATE, AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername("adminUser")
+ .setPassword("adminPass123")
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), "adminUser", "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), "adminPass123", "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.ADMIN, "Role type should match");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
+ Assert.assertEquals(userConfig.getRlsFilters(), rlsFilters, "RLS filters should match");
+ }
+
+ @Test
+ public void testBuilderChaining() {
+ UserConfigBuilder builder = new UserConfigBuilder();
+
+ // Verify that each setter returns the builder instance for chaining
+ UserConfigBuilder result1 = builder.setUsername(TEST_USERNAME);
+ Assert.assertSame(result1, builder, "setUsername should return the builder instance");
+
+ UserConfigBuilder result2 = builder.setPassword(TEST_PASSWORD);
+ Assert.assertSame(result2, builder, "setPassword should return the builder instance");
+
+ UserConfigBuilder result3 = builder.setComponentType(ComponentType.BROKER);
+ Assert.assertSame(result3, builder, "setComponentType should return the builder instance");
+
+ UserConfigBuilder result4 = builder.setRoleType(RoleType.USER);
+ Assert.assertSame(result4, builder, "setRoleType should return the builder instance");
+
+ UserConfigBuilder result5 = builder.setTableList(Arrays.asList("table1"));
+ Assert.assertSame(result5, builder, "setTableList should return the builder instance");
+
+ UserConfigBuilder result6 = builder.setExcludeTableList(Arrays.asList("excludeTable1"));
+ Assert.assertSame(result6, builder, "setExcludeTableList should return the builder instance");
+
+ UserConfigBuilder result7 = builder.setPermissionList(Arrays.asList(AccessType.READ));
+ Assert.assertSame(result7, builder, "setPermissionList should return the builder instance");
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1"));
+ UserConfigBuilder result8 = builder.setRlsFilters(rlsFilters);
+ Assert.assertSame(result8, builder, "setRlsFilters should return the builder instance");
+ }
+
+ @Test
+ public void testMultipleComponentTypes() {
+ // Test with different component types
+ ComponentType[] componentTypes = {
+ ComponentType.CONTROLLER, ComponentType.BROKER, ComponentType.SERVER,
+ ComponentType.MINION, ComponentType.PROXY
+ };
+
+ for (ComponentType componentType : componentTypes) {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(componentType)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertEquals(userConfig.getComponentType(), componentType,
+ "Component type should match for " + componentType);
+ }
+ }
+
+ @Test
+ public void testMultipleRoleTypes() {
+ // Test with different role types
+ RoleType[] roleTypes = {RoleType.ADMIN, RoleType.USER};
+
+ for (RoleType roleType : roleTypes) {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(roleType)
+ .build();
+
+ Assert.assertEquals(userConfig.getRoleType(), roleType,
+ "Role type should match for " + roleType);
+ }
+ }
+
+ @Test
+ public void testAllAccessTypes() {
+ // Test with all access types
+ List<AccessType> allPermissions = Arrays.asList(
+ AccessType.CREATE, AccessType.READ, AccessType.UPDATE, AccessType.DELETE
+ );
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(allPermissions)
+ .build();
+
+ Assert.assertEquals(userConfig.getPermissios().size(), 4, "Should have all 4 access types");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.DELETE), "Should contain DELETE");
Review Comment:
Multiple occurrences of 'getPermissios' should be corrected to 'getPermissions'.
```suggestion
Assert.assertEquals(userConfig.getPermissions().size(), 4, "Should have all 4 access types");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.CREATE), "Should contain CREATE");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.READ), "Should contain READ");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.UPDATE), "Should contain UPDATE");
Assert.assertTrue(userConfig.getPermissions().contains(AccessType.DELETE), "Should contain DELETE");
```
##########
pinot-common/src/test/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtilsTest.java:
##########
@@ -0,0 +1,559 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.UserConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link AccessControlUserConfigUtils}
+ */
+public class AccessControlUserConfigUtilsTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testFromZNRecordWithMandatoryFieldsOnly() {
+ // Create ZNRecord with only mandatory fields
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null");
+ }
+
+ @Test
+ public void testFromZNRecordWithTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.CONTROLLER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testFromZNRecordWithExcludeTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.SERVER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testFromZNRecordWithPermissionList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.MINION.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> permissionListStr = Arrays.asList("READ", "CREATE", "UPDATE");
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testFromZNRecordWithRlsFilters() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ Assert.assertEquals(userConfig.getRlsFilters().size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table2"), "Should contain table2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").size(), 2, "table1 should have 2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").size(), 1, "table2 should have 1 filter");
+ // Verify actual filter values
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(0), "country='US'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testFromZNRecordWithMalformedRlsFilters() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, "invalid-json-{malformed");
+ znRecord.setSimpleFields(simpleFields);
+
+ // Should not throw exception, but log error and continue
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null due to malformed JSON");
+ }
+
+ @Test
+ public void testFromZNRecordWithAllFields() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, "adminUser");
+ simpleFields.put(UserConfig.PASSWORD_KEY, "adminPass123");
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.PROXY.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<String> permissionListStr = Arrays.asList("READ", "UPDATE", "DELETE");
+
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), "adminUser", "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), "adminPass123", "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.PROXY, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.ADMIN, "Role type should match");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should match");
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ }
+
+ @Test
+ public void testToZNRecordWithMandatoryFieldsOnly() throws JsonProcessingException {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord, "ZNRecord should not be null");
+ Assert.assertEquals(znRecord.getId(), TEST_USERNAME, "ZNRecord ID should match username");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.USERNAME_KEY), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.PASSWORD_KEY), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.COMPONET_KEY), ComponentType.BROKER.toString(),
+ "Component type should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.ROLE_KEY), RoleType.USER.toString(),
+ "Role type should match");
+ Assert.assertNull(znRecord.getListField(UserConfig.TABLES_KEY), "Tables should be null");
+ Assert.assertNull(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), "Exclude tables should be null");
+ Assert.assertNull(znRecord.getListField(UserConfig.PERMISSIONS_KEY), "Permissions should be null");
+ Assert.assertNull(znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY), "RLS filters should be null");
+ }
+
+ @Test
+ public void testToZNRecordWithTableList() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord.getListField(UserConfig.TABLES_KEY), "Tables should not be null");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY), tableList, "Table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY).size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testToZNRecordWithExcludeTableList() throws JsonProcessingException {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), "Exclude tables should not be null");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), excludeTableList,
+ "Exclude table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY).size(), 2,
+ "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testToZNRecordWithPermissionList() throws JsonProcessingException {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ List<String> permissionListStr = znRecord.getListField(UserConfig.PERMISSIONS_KEY);
+ Assert.assertNotNull(permissionListStr, "Permissions should not be null");
+ Assert.assertEquals(permissionListStr.size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(permissionListStr.contains("READ"), "Should contain READ permission");
+ Assert.assertTrue(permissionListStr.contains("CREATE"), "Should contain CREATE permission");
+ Assert.assertTrue(permissionListStr.contains("UPDATE"), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testToZNRecordWithRlsFilters() throws IOException {
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ String rlsFiltersJson = znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY);
+ Assert.assertNotNull(rlsFiltersJson, "RLS filters should not be null");
+
+ // Deserialize and verify
+ Map<String, List<String>> deserializedFilters = JsonUtils.stringToObject(
+ rlsFiltersJson, new com.fasterxml.jackson.core.type.TypeReference<Map<String, List<String>>>() {
+ }
+ );
+ Assert.assertEquals(deserializedFilters.size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(deserializedFilters.containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(deserializedFilters.containsKey("table2"), "Should contain table2 filters");
+ // Verify actual filter values
+ Assert.assertEquals(deserializedFilters.get("table1").get(0), "country='US'");
+ Assert.assertEquals(deserializedFilters.get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(deserializedFilters.get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testToZNRecordWithAllFields() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.UPDATE, AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername("adminUser")
+ .setPassword("adminPass123")
+ .setComponentType(ComponentType.PROXY)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord, "ZNRecord should not be null");
+ Assert.assertEquals(znRecord.getId(), "adminUser", "ZNRecord ID should match username");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.USERNAME_KEY), "adminUser", "Username should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.PASSWORD_KEY), "adminPass123", "Password should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.COMPONET_KEY), ComponentType.PROXY.toString(),
+ "Component type should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.ROLE_KEY), RoleType.ADMIN.toString(),
+ "Role type should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY), tableList, "Table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), excludeTableList,
+ "Exclude table list should match");
+ Assert.assertNotNull(znRecord.getListField(UserConfig.PERMISSIONS_KEY), "Permissions should not be null");
+ Assert.assertNotNull(znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY), "RLS filters should not be null");
+ }
+
+ @Test
+ public void testRoundTripConversionWithMandatoryFields() throws JsonProcessingException {
+ UserConfig originalConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(originalConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getUserName(), originalConfig.getUserName(),
+ "Username should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPassword(), originalConfig.getPassword(),
+ "Password should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getComponentType(), originalConfig.getComponentType(),
+ "Component type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRoleType(), originalConfig.getRoleType(),
+ "Role type should match after round-trip");
+ }
+
+ @Test
+ public void testRoundTripConversionWithAllFields() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.CREATE, AccessType.READ, AccessType.UPDATE,
+ AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+
+ UserConfig originalConfig = new UserConfigBuilder()
+ .setUsername("fullTestUser")
+ .setPassword("fullTestPassword")
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(originalConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getUserName(), originalConfig.getUserName(),
+ "Username should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPassword(), originalConfig.getPassword(),
+ "Password should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getComponentType(), originalConfig.getComponentType(),
+ "Component type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRoleType(), originalConfig.getRoleType(),
+ "Role type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getTables(), originalConfig.getTables(),
+ "Tables should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getExcludeTables(), originalConfig.getExcludeTables(),
+ "Exclude tables should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPermissios().size(), originalConfig.getPermissios().size(),
Review Comment:
Multiple occurrences of 'getPermissios' should be corrected to 'getPermissions'.
```suggestion
Assert.assertEquals(reconstructedConfig.getPermissions().size(), originalConfig.getPermissions().size(),
```
##########
pinot-common/src/test/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtilsTest.java:
##########
@@ -0,0 +1,559 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.UserConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link AccessControlUserConfigUtils}
+ */
+public class AccessControlUserConfigUtilsTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testFromZNRecordWithMandatoryFieldsOnly() {
+ // Create ZNRecord with only mandatory fields
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null");
+ }
+
+ @Test
+ public void testFromZNRecordWithTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.CONTROLLER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testFromZNRecordWithExcludeTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.SERVER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testFromZNRecordWithPermissionList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.MINION.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> permissionListStr = Arrays.asList("READ", "CREATE", "UPDATE");
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testFromZNRecordWithRlsFilters() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ Assert.assertEquals(userConfig.getRlsFilters().size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table2"), "Should contain table2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").size(), 2, "table1 should have 2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").size(), 1, "table2 should have 1 filter");
+ // Verify actual filter values
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(0), "country='US'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testFromZNRecordWithMalformedRlsFilters() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, "invalid-json-{malformed");
+ znRecord.setSimpleFields(simpleFields);
+
+ // Should not throw exception, but log error and continue
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null due to malformed JSON");
+ }
+
+ @Test
+ public void testFromZNRecordWithAllFields() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, "adminUser");
+ simpleFields.put(UserConfig.PASSWORD_KEY, "adminPass123");
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.PROXY.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<String> permissionListStr = Arrays.asList("READ", "UPDATE", "DELETE");
+
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), "adminUser", "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), "adminPass123", "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.PROXY, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.ADMIN, "Role type should match");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should match");
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ }
+
+ @Test
+ public void testToZNRecordWithMandatoryFieldsOnly() throws JsonProcessingException {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord, "ZNRecord should not be null");
+ Assert.assertEquals(znRecord.getId(), TEST_USERNAME, "ZNRecord ID should match username");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.USERNAME_KEY), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.PASSWORD_KEY), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.COMPONET_KEY), ComponentType.BROKER.toString(),
+ "Component type should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.ROLE_KEY), RoleType.USER.toString(),
+ "Role type should match");
+ Assert.assertNull(znRecord.getListField(UserConfig.TABLES_KEY), "Tables should be null");
+ Assert.assertNull(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), "Exclude tables should be null");
+ Assert.assertNull(znRecord.getListField(UserConfig.PERMISSIONS_KEY), "Permissions should be null");
+ Assert.assertNull(znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY), "RLS filters should be null");
+ }
+
+ @Test
+ public void testToZNRecordWithTableList() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord.getListField(UserConfig.TABLES_KEY), "Tables should not be null");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY), tableList, "Table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY).size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testToZNRecordWithExcludeTableList() throws JsonProcessingException {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), "Exclude tables should not be null");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), excludeTableList,
+ "Exclude table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY).size(), 2,
+ "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testToZNRecordWithPermissionList() throws JsonProcessingException {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ List<String> permissionListStr = znRecord.getListField(UserConfig.PERMISSIONS_KEY);
+ Assert.assertNotNull(permissionListStr, "Permissions should not be null");
+ Assert.assertEquals(permissionListStr.size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(permissionListStr.contains("READ"), "Should contain READ permission");
+ Assert.assertTrue(permissionListStr.contains("CREATE"), "Should contain CREATE permission");
+ Assert.assertTrue(permissionListStr.contains("UPDATE"), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testToZNRecordWithRlsFilters() throws IOException {
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ String rlsFiltersJson = znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY);
+ Assert.assertNotNull(rlsFiltersJson, "RLS filters should not be null");
+
+ // Deserialize and verify
+ Map<String, List<String>> deserializedFilters = JsonUtils.stringToObject(
+ rlsFiltersJson, new com.fasterxml.jackson.core.type.TypeReference<Map<String, List<String>>>() {
+ }
+ );
+ Assert.assertEquals(deserializedFilters.size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(deserializedFilters.containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(deserializedFilters.containsKey("table2"), "Should contain table2 filters");
+ // Verify actual filter values
+ Assert.assertEquals(deserializedFilters.get("table1").get(0), "country='US'");
+ Assert.assertEquals(deserializedFilters.get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(deserializedFilters.get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testToZNRecordWithAllFields() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.UPDATE, AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername("adminUser")
+ .setPassword("adminPass123")
+ .setComponentType(ComponentType.PROXY)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+
+ Assert.assertNotNull(znRecord, "ZNRecord should not be null");
+ Assert.assertEquals(znRecord.getId(), "adminUser", "ZNRecord ID should match username");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.USERNAME_KEY), "adminUser", "Username should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.PASSWORD_KEY), "adminPass123", "Password should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.COMPONET_KEY), ComponentType.PROXY.toString(),
+ "Component type should match");
+ Assert.assertEquals(znRecord.getSimpleField(UserConfig.ROLE_KEY), RoleType.ADMIN.toString(),
+ "Role type should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.TABLES_KEY), tableList, "Table list should match");
+ Assert.assertEquals(znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY), excludeTableList,
+ "Exclude table list should match");
+ Assert.assertNotNull(znRecord.getListField(UserConfig.PERMISSIONS_KEY), "Permissions should not be null");
+ Assert.assertNotNull(znRecord.getSimpleField(UserConfig.RLS_FILTERS_KEY), "RLS filters should not be null");
+ }
+
+ @Test
+ public void testRoundTripConversionWithMandatoryFields() throws JsonProcessingException {
+ UserConfig originalConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(originalConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getUserName(), originalConfig.getUserName(),
+ "Username should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPassword(), originalConfig.getPassword(),
+ "Password should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getComponentType(), originalConfig.getComponentType(),
+ "Component type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRoleType(), originalConfig.getRoleType(),
+ "Role type should match after round-trip");
+ }
+
+ @Test
+ public void testRoundTripConversionWithAllFields() throws JsonProcessingException {
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<AccessType> permissionList = Arrays.asList(AccessType.CREATE, AccessType.READ, AccessType.UPDATE,
+ AccessType.DELETE);
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+
+ UserConfig originalConfig = new UserConfigBuilder()
+ .setUsername("fullTestUser")
+ .setPassword("fullTestPassword")
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .setExcludeTableList(excludeTableList)
+ .setPermissionList(permissionList)
+ .setRlsFilters(rlsFilters)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(originalConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getUserName(), originalConfig.getUserName(),
+ "Username should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPassword(), originalConfig.getPassword(),
+ "Password should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getComponentType(), originalConfig.getComponentType(),
+ "Component type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRoleType(), originalConfig.getRoleType(),
+ "Role type should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getTables(), originalConfig.getTables(),
+ "Tables should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getExcludeTables(), originalConfig.getExcludeTables(),
+ "Exclude tables should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getPermissios().size(), originalConfig.getPermissios().size(),
+ "Permissions size should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().size(), originalConfig.getRlsFilters().size(),
+ "RLS filters size should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().get("table1"),
+ originalConfig.getRlsFilters().get("table1"), "RLS filters for table1 should match after round-trip");
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().get("table2"),
+ originalConfig.getRlsFilters().get("table2"), "RLS filters for table2 should match after round-trip");
+ // Verify actual filter values
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().get("table1").get(0), "country='US'");
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(reconstructedConfig.getRlsFilters().get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testDifferentComponentTypes() throws JsonProcessingException {
+ ComponentType[] componentTypes = {
+ ComponentType.CONTROLLER, ComponentType.BROKER, ComponentType.SERVER,
+ ComponentType.MINION, ComponentType.PROXY
+ };
+
+ for (ComponentType componentType : componentTypes) {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(componentType)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getComponentType(), componentType,
+ "Component type should match for " + componentType);
+ }
+ }
+
+ @Test
+ public void testDifferentRoleTypes() throws JsonProcessingException {
+ RoleType[] roleTypes = {RoleType.ADMIN, RoleType.USER};
+
+ for (RoleType roleType : roleTypes) {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(roleType)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getRoleType(), roleType, "Role type should match for " + roleType);
+ }
+ }
+
+ @Test
+ public void testAllAccessTypes() throws JsonProcessingException {
+ List<AccessType> allPermissions = Arrays.asList(
+ AccessType.CREATE, AccessType.READ, AccessType.UPDATE, AccessType.DELETE
+ );
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(allPermissions)
+ .build();
+
+ ZNRecord znRecord = AccessControlUserConfigUtils.toZNRecord(userConfig);
+ UserConfig reconstructedConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertEquals(reconstructedConfig.getPermissios().size(), 4, "Should have all 4 access types");
+ Assert.assertTrue(reconstructedConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE");
+ Assert.assertTrue(reconstructedConfig.getPermissios().contains(AccessType.READ), "Should contain READ");
+ Assert.assertTrue(reconstructedConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE");
+ Assert.assertTrue(reconstructedConfig.getPermissios().contains(AccessType.DELETE), "Should contain DELETE");
Review Comment:
Multiple occurrences of 'getPermissios' should be corrected to 'getPermissions'.
```suggestion
Assert.assertEquals(reconstructedConfig.getPermissions().size(), 4, "Should have all 4 access types");
Assert.assertTrue(reconstructedConfig.getPermissions().contains(AccessType.CREATE), "Should contain CREATE");
Assert.assertTrue(reconstructedConfig.getPermissions().contains(AccessType.READ), "Should contain READ");
Assert.assertTrue(reconstructedConfig.getPermissions().contains(AccessType.UPDATE), "Should contain UPDATE");
Assert.assertTrue(reconstructedConfig.getPermissions().contains(AccessType.DELETE), "Should contain DELETE");
```
##########
pinot-common/src/test/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtilsTest.java:
##########
@@ -0,0 +1,559 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.UserConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link AccessControlUserConfigUtils}
+ */
+public class AccessControlUserConfigUtilsTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testFromZNRecordWithMandatoryFieldsOnly() {
+ // Create ZNRecord with only mandatory fields
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null");
+ }
+
+ @Test
+ public void testFromZNRecordWithTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.CONTROLLER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testFromZNRecordWithExcludeTableList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.SERVER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testFromZNRecordWithPermissionList() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.MINION.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> permissionListStr = Arrays.asList("READ", "CREATE", "UPDATE");
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
+ }
+
+ @Test
+ public void testFromZNRecordWithRlsFilters() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("country='US'", "department='Engineering'"));
+ rlsFilters.put("table2", Arrays.asList("region='WEST'"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+
+ znRecord.setSimpleFields(simpleFields);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig.getRlsFilters(), "RLS filters should not be null");
+ Assert.assertEquals(userConfig.getRlsFilters().size(), 2, "RLS filters map size should be 2");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table1"), "Should contain table1 filters");
+ Assert.assertTrue(userConfig.getRlsFilters().containsKey("table2"), "Should contain table2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").size(), 2, "table1 should have 2 filters");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").size(), 1, "table2 should have 1 filter");
+ // Verify actual filter values
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(0), "country='US'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table1").get(1), "department='Engineering'");
+ Assert.assertEquals(userConfig.getRlsFilters().get("table2").get(0), "region='WEST'");
+ }
+
+ @Test
+ public void testFromZNRecordWithMalformedRlsFilters() {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, TEST_USERNAME);
+ simpleFields.put(UserConfig.PASSWORD_KEY, TEST_PASSWORD);
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.BROKER.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.USER.toString());
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, "invalid-json-{malformed");
+ znRecord.setSimpleFields(simpleFields);
+
+ // Should not throw exception, but log error and continue
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null due to malformed JSON");
+ }
+
+ @Test
+ public void testFromZNRecordWithAllFields() throws JsonProcessingException {
+ ZNRecord znRecord = new ZNRecord(TEST_USERNAME);
+ Map<String, String> simpleFields = new HashMap<>();
+ simpleFields.put(UserConfig.USERNAME_KEY, "adminUser");
+ simpleFields.put(UserConfig.PASSWORD_KEY, "adminPass123");
+ simpleFields.put(UserConfig.COMPONET_KEY, ComponentType.PROXY.toString());
+ simpleFields.put(UserConfig.ROLE_KEY, RoleType.ADMIN.toString());
+
+ Map<String, List<String>> rlsFilters = new HashMap<>();
+ rlsFilters.put("table1", Arrays.asList("filter1", "filter2"));
+ simpleFields.put(UserConfig.RLS_FILTERS_KEY, JsonUtils.objectToString(rlsFilters));
+ znRecord.setSimpleFields(simpleFields);
+
+ List<String> tableList = Arrays.asList("table1", "table2");
+ List<String> excludeTableList = Arrays.asList("excludeTable1");
+ List<String> permissionListStr = Arrays.asList("READ", "UPDATE", "DELETE");
+
+ znRecord.setListField(UserConfig.TABLES_KEY, tableList);
+ znRecord.setListField(UserConfig.EXCLUDE_TABLES_KEY, excludeTableList);
+ znRecord.setListField(UserConfig.PERMISSIONS_KEY, permissionListStr);
+
+ UserConfig userConfig = AccessControlUserConfigUtils.fromZNRecord(znRecord);
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), "adminUser", "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), "adminPass123", "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.PROXY, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.ADMIN, "Role type should match");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should match");
Review Comment:
Corrected spelling of 'getPermissios' to 'getPermissions'.
```suggestion
Assert.assertEquals(userConfig.getPermissions().size(), 3, "Permission list size should match");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578024533
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/user/UserConfig.java:
##########
@@ -59,26 +61,72 @@ public class UserConfig extends BaseJsonConfig {
@JsonPropertyDescription("The table permission of User")
private List<AccessType> _permissions;
+ @JsonPropertyDescription("The RLS filters for User per table")
+ private Map<String, List<String>> _rlsFilters;
+
@JsonCreator
public UserConfig(@JsonProperty(value = USERNAME_KEY, required = true) String username,
@JsonProperty(value = PASSWORD_KEY, required = true) String password,
@JsonProperty(value = COMPONET_KEY, required = true) String component,
@JsonProperty(value = ROLE_KEY, required = true) String role,
@JsonProperty(value = TABLES_KEY) @Nullable List<String> tableList,
@JsonProperty(value = EXCLUDE_TABLES_KEY) @Nullable List<String> excludeTableList,
- @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList
+ @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList,
+ @JsonProperty(value = RLS_FILTERS_KEY) @Nullable Map<String, List<String>> rlsFilters
) {
- Preconditions.checkArgument(username != null, "'username' must be configured");
- Preconditions.checkArgument(password != null, "'password' must be configured");
+ this(username, password, component, role, tableList, excludeTableList, permissionList, rlsFilters, true);
+ }
+
+ /**
+ * Constructor for backward compatibility without RLS filters.
+ * This allows existing code to continue working without modification.
+ */
+ public UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList) {
+ this(username, password, component, role, tableList, excludeTableList, permissionList, null, true);
+ }
+
+ private UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList,
+ Map<String, List<String>> rlsFilters, boolean validate) {
+ if (validate) {
+ Preconditions.checkArgument(username != null, "'username' must be configured");
+ Preconditions.checkArgument(!username.isEmpty(), "'username' must not be empty");
+ Preconditions.checkArgument(password != null, "'password' must be configured");
+ Preconditions.checkArgument(!password.isEmpty(), "'password' must not be empty");
+ }
// NOTE: Handle lower case table type and raw table name for backward-compatibility
_username = username;
_password = password;
_componentType = ComponentType.valueOf(component.toUpperCase());
_roleType = RoleType.valueOf(role.toUpperCase());
+
+ if (tableList != null) {
Review Comment:
are these check fine or should i drop them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3605215897
Failure is not related.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578121555
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/user/UserConfig.java:
##########
@@ -59,26 +61,72 @@ public class UserConfig extends BaseJsonConfig {
@JsonPropertyDescription("The table permission of User")
private List<AccessType> _permissions;
+ @JsonPropertyDescription("The RLS filters for User per table")
+ private Map<String, List<String>> _rlsFilters;
+
@JsonCreator
public UserConfig(@JsonProperty(value = USERNAME_KEY, required = true) String username,
@JsonProperty(value = PASSWORD_KEY, required = true) String password,
@JsonProperty(value = COMPONET_KEY, required = true) String component,
@JsonProperty(value = ROLE_KEY, required = true) String role,
@JsonProperty(value = TABLES_KEY) @Nullable List<String> tableList,
@JsonProperty(value = EXCLUDE_TABLES_KEY) @Nullable List<String> excludeTableList,
- @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList
+ @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList,
+ @JsonProperty(value = RLS_FILTERS_KEY) @Nullable Map<String, List<String>> rlsFilters
) {
- Preconditions.checkArgument(username != null, "'username' must be configured");
- Preconditions.checkArgument(password != null, "'password' must be configured");
+ this(username, password, component, role, tableList, excludeTableList, permissionList, rlsFilters, true);
+ }
+
+ /**
+ * Constructor for backward compatibility without RLS filters.
+ * This allows existing code to continue working without modification.
+ */
+ public UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList) {
+ this(username, password, component, role, tableList, excludeTableList, permissionList, null, true);
+ }
+
+ private UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList,
+ Map<String, List<String>> rlsFilters, boolean validate) {
+ if (validate) {
+ Preconditions.checkArgument(username != null, "'username' must be configured");
+ Preconditions.checkArgument(!username.isEmpty(), "'username' must not be empty");
+ Preconditions.checkArgument(password != null, "'password' must be configured");
+ Preconditions.checkArgument(!password.isEmpty(), "'password' must not be empty");
+ }
// NOTE: Handle lower case table type and raw table name for backward-compatibility
_username = username;
_password = password;
_componentType = ComponentType.valueOf(component.toUpperCase());
_roleType = RoleType.valueOf(role.toUpperCase());
+
+ if (tableList != null) {
Review Comment:
let me do as another commit to keep this pr clean
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3598779291
Ok so the test failures are due to tests added in this pr. i reverted the unrelated user config change but forgot to remove the test which requires that change and hence the failure. will remove this test in next commit and add as part of user config validation enhancement pr later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-4164291948
Superceded by https://github.com/apache/pinot/pull/18051
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2584871527
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
Review Comment:
typo in method name, raised https://github.com/apache/pinot/issues/17307 for fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on PR #17295:
URL: https://github.com/apache/pinot/pull/17295#issuecomment-3721308780
@9aman Can you help review this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578088629
##########
pinot-common/src/main/java/org/apache/pinot/common/utils/config/AccessControlUserConfigUtils.java:
##########
@@ -48,13 +56,32 @@ public static UserConfig fromZNRecord(ZNRecord znRecord) {
List<String> tableList = znRecord.getListField(UserConfig.TABLES_KEY);
List<String> excludeTableList = znRecord.getListField(UserConfig.EXCLUDE_TABLES_KEY);
- List<String> permissionListFromZNRecord = znRecord.getListField(UserConfig.PERMISSIONS_KEY);
+ List<String> permissionListFromZNRecord = znRecord.getListField(
+ UserConfig.PERMISSIONS_KEY);
List<AccessType> permissionList = null;
if (permissionListFromZNRecord != null) {
permissionList = permissionListFromZNRecord.stream()
- .map(x -> AccessType.valueOf(x)).collect(Collectors.toList());
+ .map(x -> AccessType.valueOf(x))
+ .collect(Collectors.toList());
+ }
+
+ // Extract RLS filters from simple fields (stored as JSON)
+ Map<String, List<String>> rlsFilters = null;
+ String rlsFiltersJson = simpleFields.get(UserConfig.RLS_FILTERS_KEY);
+ if (rlsFiltersJson != null && !rlsFiltersJson.isEmpty()) {
+ try {
+ rlsFilters = JsonUtils.stringToObject(
+ rlsFiltersJson, new TypeReference<Map<String, List<String>>>() {
+ }
+ );
+ } catch (IOException e) {
+ // Log error but continue - RLS filters are optional
+ LOGGER.error("Failed to deserialize RLS filters for user: {}", username, e);
Review Comment:
should we fail here? although this is unlikely to happen
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2578027661
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/user/UserConfig.java:
##########
@@ -59,26 +61,72 @@ public class UserConfig extends BaseJsonConfig {
@JsonPropertyDescription("The table permission of User")
private List<AccessType> _permissions;
+ @JsonPropertyDescription("The RLS filters for User per table")
+ private Map<String, List<String>> _rlsFilters;
+
@JsonCreator
public UserConfig(@JsonProperty(value = USERNAME_KEY, required = true) String username,
@JsonProperty(value = PASSWORD_KEY, required = true) String password,
@JsonProperty(value = COMPONET_KEY, required = true) String component,
@JsonProperty(value = ROLE_KEY, required = true) String role,
@JsonProperty(value = TABLES_KEY) @Nullable List<String> tableList,
@JsonProperty(value = EXCLUDE_TABLES_KEY) @Nullable List<String> excludeTableList,
- @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList
+ @JsonProperty(value = PERMISSIONS_KEY) @Nullable List<AccessType> permissionList,
+ @JsonProperty(value = RLS_FILTERS_KEY) @Nullable Map<String, List<String>> rlsFilters
) {
- Preconditions.checkArgument(username != null, "'username' must be configured");
- Preconditions.checkArgument(password != null, "'password' must be configured");
+ this(username, password, component, role, tableList, excludeTableList, permissionList, rlsFilters, true);
+ }
+
+ /**
+ * Constructor for backward compatibility without RLS filters.
+ * This allows existing code to continue working without modification.
+ */
+ public UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList) {
+ this(username, password, component, role, tableList, excludeTableList, permissionList, null, true);
+ }
+
+ private UserConfig(String username, String password, String component, String role,
+ List<String> tableList, List<String> excludeTableList, List<AccessType> permissionList,
+ Map<String, List<String>> rlsFilters, boolean validate) {
+ if (validate) {
Review Comment:
cant recall why i added this flag, drop?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain closed pull request #17295: Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220)
URL: https://github.com/apache/pinot/pull/17295
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2584871527
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
Review Comment:
typo in existing method name, raised https://github.com/apache/pinot/issues/17307 for fix
##########
pinot-spi/src/test/java/org/apache/pinot/spi/utils/builder/UserConfigBuilderTest.java:
##########
@@ -0,0 +1,261 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.spi.utils.builder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.config.user.AccessType;
+import org.apache.pinot.spi.config.user.ComponentType;
+import org.apache.pinot.spi.config.user.RoleType;
+import org.apache.pinot.spi.config.user.UserConfig;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@link UserConfigBuilder}
+ */
+public class UserConfigBuilderTest {
+
+ private static final String TEST_USERNAME = "testUser";
+ private static final String TEST_PASSWORD = "testPassword";
+
+ @Test
+ public void testBasicUserConfigBuild() {
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.BROKER)
+ .setRoleType(RoleType.USER)
+ .build();
+
+ Assert.assertNotNull(userConfig, "UserConfig should not be null");
+ Assert.assertEquals(userConfig.getUserName(), TEST_USERNAME, "Username should match");
+ Assert.assertEquals(userConfig.getPassword(), TEST_PASSWORD, "Password should match");
+ Assert.assertEquals(userConfig.getComponentType(), ComponentType.BROKER, "Component type should match");
+ Assert.assertEquals(userConfig.getRoleType(), RoleType.USER, "Role type should match");
+ Assert.assertNull(userConfig.getTables(), "Tables should be null when not set");
+ Assert.assertNull(userConfig.getExcludeTables(), "Exclude tables should be null when not set");
+ Assert.assertNull(userConfig.getPermissios(), "Permissions should be null when not set");
+ Assert.assertNull(userConfig.getRlsFilters(), "RLS filters should be null when not set");
+ }
+
+ @Test
+ public void testUserConfigWithTableList() {
+ List<String> tableList = Arrays.asList("table1", "table2", "table3");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.CONTROLLER)
+ .setRoleType(RoleType.ADMIN)
+ .setTableList(tableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getTables(), "Tables should not be null");
+ Assert.assertEquals(userConfig.getTables(), tableList, "Table list should match");
+ Assert.assertEquals(userConfig.getTables().size(), 3, "Table list size should be 3");
+ }
+
+ @Test
+ public void testUserConfigWithExcludeTableList() {
+ List<String> excludeTableList = Arrays.asList("excludeTable1", "excludeTable2");
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.SERVER)
+ .setRoleType(RoleType.USER)
+ .setExcludeTableList(excludeTableList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getExcludeTables(), "Exclude tables should not be null");
+ Assert.assertEquals(userConfig.getExcludeTables(), excludeTableList, "Exclude table list should match");
+ Assert.assertEquals(userConfig.getExcludeTables().size(), 2, "Exclude table list size should be 2");
+ }
+
+ @Test
+ public void testUserConfigWithPermissionList() {
+ List<AccessType> permissionList = Arrays.asList(AccessType.READ, AccessType.CREATE, AccessType.UPDATE);
+
+ UserConfig userConfig = new UserConfigBuilder()
+ .setUsername(TEST_USERNAME)
+ .setPassword(TEST_PASSWORD)
+ .setComponentType(ComponentType.MINION)
+ .setRoleType(RoleType.ADMIN)
+ .setPermissionList(permissionList)
+ .build();
+
+ Assert.assertNotNull(userConfig.getPermissios(), "Permissions should not be null");
+ Assert.assertEquals(userConfig.getPermissios(), permissionList, "Permission list should match");
+ Assert.assertEquals(userConfig.getPermissios().size(), 3, "Permission list size should be 3");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.READ), "Should contain READ permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.CREATE), "Should contain CREATE permission");
+ Assert.assertTrue(userConfig.getPermissios().contains(AccessType.UPDATE), "Should contain UPDATE permission");
Review Comment:
typo in existing method name, raised https://github.com/apache/pinot/issues/17307 for fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Add Row-Level Security (RLS) Support for ZooKeeper-Based Authentication (#17220) [pinot]
Posted by "NihalJain (via GitHub)" <gi...@apache.org>.
NihalJain commented on code in PR #17295:
URL: https://github.com/apache/pinot/pull/17295#discussion_r2617995376
##########
pinot-broker/src/main/java/org/apache/pinot/broker/broker/ZkBasicAuthAccessControlFactory.java:
##########
@@ -120,6 +124,26 @@ public TableAuthorizationResult authorize(RequesterIdentity requesterIdentity, S
return new TableAuthorizationResult(failedTables);
}
+ @Override
+ public TableRowColAccessResult getRowColFilters(RequesterIdentity requesterIdentity, String table) {
+ Optional<ZkBasicAuthPrincipal> principalOpt = getPrincipalAuth(requesterIdentity);
+
+ Preconditions.checkState(principalOpt.isPresent(), "Principal is not authorized");
+ Preconditions.checkState(table != null, "Table cannot be null");
+
+ TableRowColAccessResult tableRowColAccessResult = new TableRowColAccessResultImpl();
+ ZkBasicAuthPrincipal principal = principalOpt.get();
+
+ //precondition: The principal should have the table.
Review Comment:
code is copied from existing method, will fix when we refactor both into a single copy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org