Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][sec][branch-2.11] Align some namespace level policy authorisation check (#21640) #22248

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,8 @@ protected void internalSetPublishRate(PublishRate maxPublishMessageRate) {

protected CompletableFuture<Void> internalSetPublishRateAsync(PublishRate maxPublishMessageRate) {
log.info("[{}] Set namespace publish-rate {}/{}", clientAppId(), namespaceName, maxPublishMessageRate);
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.publishMaxMessageRate.put(pulsar().getConfiguration().getClusterName(), maxPublishMessageRate);
log.info("[{}] Successfully updated the publish_max_message_rate for cluster on namespace {}",
clientAppId(), namespaceName);
Expand Down Expand Up @@ -1378,7 +1379,8 @@ protected void internalRemovePublishRate() {

protected CompletableFuture<Void> internalRemovePublishRateAsync() {
log.info("[{}] Remove namespace publish-rate {}/{}", clientAppId(), namespaceName, topicName);
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
if (policies.publishMaxMessageRate != null) {
policies.publishMaxMessageRate.remove(pulsar().getConfiguration().getClusterName());
}
Expand Down Expand Up @@ -1417,7 +1419,8 @@ protected void internalSetTopicDispatchRate(DispatchRateImpl dispatchRate) {
@SuppressWarnings("deprecation")
protected CompletableFuture<Void> internalSetTopicDispatchRateAsync(DispatchRateImpl dispatchRate) {
log.info("[{}] Set namespace dispatch-rate {}/{}", clientAppId(), namespaceName, dispatchRate);
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.topicDispatchRate.put(pulsar().getConfiguration().getClusterName(), dispatchRate);
policies.clusterDispatchRate.put(pulsar().getConfiguration().getClusterName(), dispatchRate);
log.info("[{}] Successfully updated the dispatchRate for cluster on namespace {}", clientAppId(),
Expand All @@ -1444,7 +1447,8 @@ protected void internalDeleteTopicDispatchRate() {
}

protected CompletableFuture<Void> internalDeleteTopicDispatchRateAsync() {
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.topicDispatchRate.remove(pulsar().getConfiguration().getClusterName());
policies.clusterDispatchRate.remove(pulsar().getConfiguration().getClusterName());
log.info("[{}] Successfully delete the dispatchRate for cluster on namespace {}", clientAppId(),
Expand All @@ -1461,7 +1465,7 @@ protected CompletableFuture<DispatchRate> internalGetTopicDispatchRateAsync() {
}

protected CompletableFuture<Void> internalSetSubscriptionDispatchRateAsync(DispatchRateImpl dispatchRate) {
return validateSuperUserAccessAsync()
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.subscriptionDispatchRate.put(pulsar().getConfiguration().getClusterName(), dispatchRate);
log.info("[{}] Successfully updated the subscriptionDispatchRate for cluster on namespace {}",
Expand All @@ -1471,7 +1475,7 @@ protected CompletableFuture<Void> internalSetSubscriptionDispatchRateAsync(Dispa
}

protected CompletableFuture<Void> internalDeleteSubscriptionDispatchRateAsync() {
return validateSuperUserAccessAsync()
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.subscriptionDispatchRate.remove(pulsar().getConfiguration().getClusterName());
log.info("[{}] Successfully delete the subscriptionDispatchRate for cluster on namespace {}",
Expand All @@ -1489,7 +1493,8 @@ protected CompletableFuture<DispatchRate> internalGetSubscriptionDispatchRateAsy

protected CompletableFuture<Void> internalSetSubscribeRateAsync(SubscribeRate subscribeRate) {
log.info("[{}] Set namespace subscribe-rate {}/{}", clientAppId(), namespaceName, subscribeRate);
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.clusterSubscribeRate.put(pulsar().getConfiguration().getClusterName(), subscribeRate);
log.info("[{}] Successfully updated the subscribeRate for cluster on namespace {}", clientAppId(),
namespaceName);
Expand All @@ -1498,7 +1503,8 @@ protected CompletableFuture<Void> internalSetSubscribeRateAsync(SubscribeRate su
}

protected CompletableFuture<Void> internalDeleteSubscribeRateAsync() {
return validateSuperUserAccessAsync().thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
return validateNamespacePolicyOperationAsync(namespaceName, PolicyName.RATE, PolicyOperation.WRITE)
.thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {
policies.clusterSubscribeRate.remove(pulsar().getConfiguration().getClusterName());
log.info("[{}] Successfully delete the subscribeRate for cluster on namespace {}", clientAppId(),
namespaceName);
Expand All @@ -1514,7 +1520,7 @@ protected CompletableFuture<SubscribeRate> internalGetSubscribeRateAsync() {
}

protected void internalRemoveReplicatorDispatchRate() {
validateSuperUserAccess();
validateNamespacePolicyOperation(namespaceName, PolicyName.REPLICATION_RATE, PolicyOperation.WRITE);
try {
updatePolicies(namespaceName, policies -> {
policies.replicatorDispatchRate.remove(pulsar().getConfiguration().getClusterName());
Expand All @@ -1530,7 +1536,7 @@ protected void internalRemoveReplicatorDispatchRate() {
}

protected void internalSetReplicatorDispatchRate(DispatchRateImpl dispatchRate) {
validateSuperUserAccess();
validateNamespacePolicyOperation(namespaceName, PolicyName.REPLICATION_RATE, PolicyOperation.WRITE);
log.info("[{}] Set namespace replicator dispatch-rate {}/{}", clientAppId(), namespaceName, dispatchRate);
try {
updatePolicies(namespaceName, policies -> {
Expand Down Expand Up @@ -1906,7 +1912,7 @@ protected Boolean internalGetEncryptionRequired() {
}

protected void internalSetInactiveTopic(InactiveTopicPolicies inactiveTopicPolicies) {
validateSuperUserAccess();
validateNamespacePolicyOperation(namespaceName, PolicyName.INACTIVE_TOPIC, PolicyOperation.WRITE);
validatePoliciesReadOnlyAccess();
internalSetPolicies("inactive_topic_policies", inactiveTopicPolicies);
}
Expand Down Expand Up @@ -2322,7 +2328,7 @@ protected void internalSetMaxUnackedMessagesPerConsumer(Integer maxUnackedMessag
}

protected void internalSetMaxSubscriptionsPerTopic(Integer maxSubscriptionsPerTopic){
validateSuperUserAccess();
validateNamespacePolicyOperation(namespaceName, PolicyName.MAX_SUBSCRIPTIONS, PolicyOperation.WRITE);
validatePoliciesReadOnlyAccess();
if (maxSubscriptionsPerTopic != null && maxSubscriptionsPerTopic < 0) {
throw new RestException(Status.PRECONDITION_FAILED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ public void getSubscriptionExpirationTime(@Suspended AsyncResponse asyncResponse
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
validateAdminAccessForTenantAsync(tenant)
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.SUBSCRIPTION_EXPIRATION_TIME,
PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.subscription_expiration_time_minutes))
.exceptionally(ex -> {
Expand Down
Loading