You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "mattisonchao (via GitHub)" <gi...@apache.org> on 2024/11/25 10:00:53 UTC

[PR] [feat][broker]: support missing broker level fine-granted permissions [pulsar]

mattisonchao opened a new pull request, #23637:
URL: https://github.com/apache/pulsar/pull/23637

   ### Motivation
   
   support missing broker-level fine-granted permissions.
   
   ### Modifications
   
   - Introduce Broker level operations
   - Add `allowBrokerOperationAsync` method for `AuthorizationProvider`.
   - Keep compatibility for existing endpoints. 
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   ### Documentation
   
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on PR #23637:
URL: https://github.com/apache/pulsar/pull/23637#issuecomment-2507338830

   oh, sure. let me add one. 


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #23637:
URL: https://github.com/apache/pulsar/pull/23637#discussion_r1862886179


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java:
##########
@@ -614,5 +629,34 @@ private CompletableFuture<Void> doShutDownBrokerGracefullyAsync(int maxConcurren
         pulsar().getBrokerService().unloadNamespaceBundlesGracefully(maxConcurrentUnloadPerSec, forcedTerminateTopic);
         return pulsar().closeAsync();
     }
+
+
+    private CompletableFuture<Void> validateBrokerOperationAsync(String cluster, String brokerId,
+                                                                 BrokerOperation operation) {
+        final var pulsar = pulsar();
+        if (pulsar.getBrokerService().isAuthenticationEnabled()
+            && pulsar.getBrokerService().isAuthorizationEnabled()) {
+            return pulsar.getBrokerService().getAuthorizationService()
+                    .allowBrokerOperationAsync(cluster, brokerId, operation, originalPrincipal(),
+                            clientAppId(), clientAuthData())
+                    .thenAccept(isAuthorized -> {
+                        if (!isAuthorized) {
+                            throw new RestException(Status.UNAUTHORIZED,
+                                    String.format("Unauthorized to validateBrokerOperation for"
+                                                  + " originalPrincipal [%s] and clientAppId [%s] "
+                                                  + "about operation [%s] on broker [%s]",
+                                            originalPrincipal(), clientAppId(), operation.toString(), brokerId));
+                        }
+                    }).exceptionallyCompose(ex -> {
+                        // Fallback to superuser validation for compatibility purposes.
+                        final var rc = FutureUtil.unwrapCompletionException(ex);
+                        if (rc instanceof UnsupportedOperationException) {

Review Comment:
   fixed.



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #23637:
URL: https://github.com/apache/pulsar/pull/23637#issuecomment-2507335755

   > * Fix admin `backlogQuotaCheck` HTTP request path.
   
   @mattisonchao It seems that it hasn't been tested before if it was broken. Could you please add a functional test to ensure that it works?


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao merged PR #23637:
URL: https://github.com/apache/pulsar/pull/23637


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao closed pull request #23637: [feat][broker]: support missing broker level fine-granted permissions
URL: https://github.com/apache/pulsar/pull/23637


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23637:
URL: https://github.com/apache/pulsar/pull/23637#issuecomment-2507000758

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/23637?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `75.86207%` with `14 lines` in your changes missing coverage. Please review.
   > Project coverage is 74.41%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`59ea0b8`)](https://app.codecov.io/gh/apache/pulsar/commit/59ea0b865989bfa721b05cd0c0ff054b48190510?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 760 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/23637?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...sar/broker/authorization/AuthorizationService.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-broker-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fauthorization%2FAuthorizationService.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3B1bHNhci9icm9rZXIvYXV0aG9yaXphdGlvbi9BdXRob3JpemF0aW9uU2VydmljZS5qYXZh) | 12.50% | [5 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...g/apache/pulsar/broker/admin/impl/BrokersBase.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fadmin%2Fimpl%2FBrokersBase.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi9pbXBsL0Jyb2tlcnNCYXNlLmphdmE=) | 80.00% | [5 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/23637/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #23637      +/-   ##
   ============================================
   + Coverage     73.57%   74.41%   +0.83%     
   - Complexity    32624    35041    +2417     
   ============================================
     Files          1877     1945      +68     
     Lines        139502   147286    +7784     
     Branches      15299    16254     +955     
   ============================================
   + Hits         102638   109598    +6960     
   - Misses        28908    29234     +326     
   - Partials       7956     8454     +498     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pulsar/pull/23637/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [inttests](https://app.codecov.io/gh/apache/pulsar/pull/23637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `27.32% <31.03%> (+2.73%)` | :arrow_up: |
   | [systests](https://app.codecov.io/gh/apache/pulsar/pull/23637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `24.35% <27.58%> (+0.02%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pulsar/pull/23637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.80% <75.86%> (+0.95%)` | :arrow_up: |
   
   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.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/23637?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...ar/broker/authorization/AuthorizationProvider.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-broker-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fauthorization%2FAuthorizationProvider.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3B1bHNhci9icm9rZXIvYXV0aG9yaXphdGlvbi9BdXRob3JpemF0aW9uUHJvdmlkZXIuamF2YQ==) | `18.75% <100.00%> (+0.23%)` | :arrow_up: |
   | [...ache/pulsar/client/admin/internal/BrokersImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-client-admin%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fclient%2Fadmin%2Finternal%2FBrokersImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNsaWVudC1hZG1pbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9hZG1pbi9pbnRlcm5hbC9Ccm9rZXJzSW1wbC5qYXZh) | `88.23% <100.00%> (+0.73%)` | :arrow_up: |
   | [...e/pulsar/common/policies/data/BrokerOperation.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcommon%2Fpolicies%2Fdata%2FBrokerOperation.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbW1vbi9wb2xpY2llcy9kYXRhL0Jyb2tlck9wZXJhdGlvbi5qYXZh) | `100.00% <100.00%> (ø)` | |
   | [...sar/broker/authorization/AuthorizationService.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-broker-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fauthorization%2FAuthorizationService.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3B1bHNhci9icm9rZXIvYXV0aG9yaXphdGlvbi9BdXRob3JpemF0aW9uU2VydmljZS5qYXZh) | `57.14% <12.50%> (-1.07%)` | :arrow_down: |
   | [...g/apache/pulsar/broker/admin/impl/BrokersBase.java](https://app.codecov.io/gh/apache/pulsar/pull/23637?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fadmin%2Fimpl%2FBrokersBase.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi9pbXBsL0Jyb2tlcnNCYXNlLmphdmE=) | `85.01% <80.00%> (+12.56%)` | :arrow_up: |
   
   ... and [669 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/23637/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker]: support missing broker level fine-granted permissions [pulsar]

Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- commented on code in PR #23637:
URL: https://github.com/apache/pulsar/pull/23637#discussion_r1862867044


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java:
##########
@@ -614,5 +629,34 @@ private CompletableFuture<Void> doShutDownBrokerGracefullyAsync(int maxConcurren
         pulsar().getBrokerService().unloadNamespaceBundlesGracefully(maxConcurrentUnloadPerSec, forcedTerminateTopic);
         return pulsar().closeAsync();
     }
+
+
+    private CompletableFuture<Void> validateBrokerOperationAsync(String cluster, String brokerId,
+                                                                 BrokerOperation operation) {
+        final var pulsar = pulsar();
+        if (pulsar.getBrokerService().isAuthenticationEnabled()
+            && pulsar.getBrokerService().isAuthorizationEnabled()) {
+            return pulsar.getBrokerService().getAuthorizationService()
+                    .allowBrokerOperationAsync(cluster, brokerId, operation, originalPrincipal(),
+                            clientAppId(), clientAuthData())
+                    .thenAccept(isAuthorized -> {
+                        if (!isAuthorized) {
+                            throw new RestException(Status.UNAUTHORIZED,
+                                    String.format("Unauthorized to validateBrokerOperation for"
+                                                  + " originalPrincipal [%s] and clientAppId [%s] "
+                                                  + "about operation [%s] on broker [%s]",
+                                            originalPrincipal(), clientAppId(), operation.toString(), brokerId));
+                        }
+                    }).exceptionallyCompose(ex -> {
+                        // Fallback to superuser validation for compatibility purposes.
+                        final var rc = FutureUtil.unwrapCompletionException(ex);
+                        if (rc instanceof UnsupportedOperationException) {

Review Comment:
   Here, we need to discuss if we can check `validateSuperUserAccessAsync` first.
   @codelipenghui WDYT?



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org