sijie commented on a change in pull request #7523:
URL: https://github.com/apache/pulsar/pull/7523#discussion_r483377081
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationProvider.java
##########
@@ -489,4 +490,36 @@ default Boolean allowTopicOperation(TopicName topicName,
throw new RestException(e.getCause());
}
}
+
+ /**
+ * Check if a given <tt>role</tt> is allowed to execute a given topic
<tt>operation</tt> on topic's <tt>policy</tt>.
+ *
+ * @param topic topic name
+ * @param role role name
+ * @param operation topic operation
+ * @param authData authenticated data
+ * @return CompletableFuture<Boolean>
+ */
+ default CompletableFuture<Boolean>
allowTopicPolicyOperationAsync(TopicName topic,
+ String
role,
+
PolicyName policy,
+
PolicyOperation operation,
+
AuthenticationDataSource authData) {
+ return FutureUtil.failedFuture(
Review comment:
Can you make the default implementation to use the existing method? If
people wrote its own plugin, it will fail all the topic policy operations when
it upgrades to a newer version of Pulsar.
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
Review comment:
compact should be an admin operation, correct?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case PEEK_MESSAGES: isAuthorizedFuture =
canConsumeAsync(topicName, role, authData, authData.getSubscription());
+ break;
+ case RESET_CURSOR: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case SKIP: isAuthorizedFuture = canConsumeAsync(topicName, role,
authData, authData.getSubscription());
+ break;
+ case TERMINATE: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case UNLOAD: isAuthorizedFuture = canProduceAsync(topicName, role,
authData);
+ break;
+ case ADD_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case GET_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case DELETE_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
Review comment:
admin?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
Review comment:
admin?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
Review comment:
expire messages is a consume operation, correct?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationService.java
##########
@@ -364,13 +353,11 @@ private boolean isProxyRole(String role) {
* Grant authorization-action permission on a tenant to the given client
*
* @param tenantName tenant name
- * @param operation tenant operation
- * @param role role name
- * @param authData
- * additional authdata in json for targeted authorization
provider
+ * @param operation tenant operation
Review comment:
Can you avoid formatting the file with other changes?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case PEEK_MESSAGES: isAuthorizedFuture =
canConsumeAsync(topicName, role, authData, authData.getSubscription());
+ break;
+ case RESET_CURSOR: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case SKIP: isAuthorizedFuture = canConsumeAsync(topicName, role,
authData, authData.getSubscription());
+ break;
+ case TERMINATE: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case UNLOAD: isAuthorizedFuture = canProduceAsync(topicName, role,
authData);
+ break;
+ case ADD_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
Review comment:
admin?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case PEEK_MESSAGES: isAuthorizedFuture =
canConsumeAsync(topicName, role, authData, authData.getSubscription());
+ break;
+ case RESET_CURSOR: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case SKIP: isAuthorizedFuture = canConsumeAsync(topicName, role,
authData, authData.getSubscription());
+ break;
+ case TERMINATE: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case UNLOAD: isAuthorizedFuture = canProduceAsync(topicName, role,
authData);
Review comment:
admin?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case PEEK_MESSAGES: isAuthorizedFuture =
canConsumeAsync(topicName, role, authData, authData.getSubscription());
+ break;
+ case RESET_CURSOR: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
Review comment:
consume?
##########
File path:
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
##########
@@ -564,6 +564,36 @@ private void validatePoliciesReadOnlyAccess() {
break;
case CONSUME: isAuthorizedFuture = canConsumeAsync(topicName,
role, authData, authData.getSubscription());
break;
+ case COMPACT: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case EXPIRE_MESSAGES: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case OFFLOAD: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case PEEK_MESSAGES: isAuthorizedFuture =
canConsumeAsync(topicName, role, authData, authData.getSubscription());
+ break;
+ case RESET_CURSOR: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case SKIP: isAuthorizedFuture = canConsumeAsync(topicName, role,
authData, authData.getSubscription());
+ break;
+ case TERMINATE: isAuthorizedFuture = canProduceAsync(topicName,
role, authData);
+ break;
+ case UNLOAD: isAuthorizedFuture = canProduceAsync(topicName, role,
authData);
+ break;
+ case ADD_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
+ break;
+ case GET_BUNDLE_RANGE: isAuthorizedFuture =
canProduceAsync(topicName, role, authData);
Review comment:
admin?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]