-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Use explicit auth ops for namespace properties endpoints #25552
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2759,7 +2759,7 @@ protected void internalSetMaxTopicsPerNamespace(Integer maxTopicsPerNamespace) { | |
| } | ||
|
|
||
| protected void internalSetProperty(String key, String value, AsyncResponse asyncResponse) { | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.UPDATE_PROPERTIES) | ||
| .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync()) | ||
| .thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> { | ||
| policies.properties.put(key, value); | ||
|
|
@@ -2779,7 +2779,7 @@ protected void internalSetProperty(String key, String value, AsyncResponse async | |
| } | ||
|
|
||
| protected void internalSetProperties(Map<String, String> properties, AsyncResponse asyncResponse) { | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.UPDATE_PROPERTIES) | ||
| .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync()) | ||
| .thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> { | ||
| policies.properties.putAll(properties); | ||
|
|
@@ -2799,7 +2799,7 @@ protected void internalSetProperties(Map<String, String> properties, AsyncRespon | |
| } | ||
|
|
||
| protected void internalGetProperty(String key, AsyncResponse asyncResponse) { | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.GET_PROPERTIES) | ||
| .thenCompose(__ -> getNamespacePoliciesAsync(namespaceName)) | ||
| .thenAccept(policies -> asyncResponse.resume(policies.properties.get(key))) | ||
| .exceptionally(ex -> { | ||
|
|
@@ -2812,7 +2812,7 @@ protected void internalGetProperty(String key, AsyncResponse asyncResponse) { | |
| } | ||
|
|
||
| protected void internalGetProperties(AsyncResponse asyncResponse) { | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.GET_PROPERTIES) | ||
| .thenCompose(__ -> getNamespacePoliciesAsync(namespaceName)) | ||
| .thenAccept(policies -> asyncResponse.resume(policies.properties)) | ||
| .exceptionally(ex -> { | ||
|
|
@@ -2825,7 +2825,7 @@ protected void internalGetProperties(AsyncResponse asyncResponse) { | |
|
|
||
| protected void internalRemoveProperty(String key, AsyncResponse asyncResponse) { | ||
| AtomicReference<String> oldVal = new AtomicReference<>(null); | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.DELETE_PROPERTIES) | ||
| .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync()) | ||
| .thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> { | ||
| oldVal.set(policies.properties.remove(key)); | ||
|
|
@@ -2845,7 +2845,7 @@ protected void internalRemoveProperty(String key, AsyncResponse asyncResponse) { | |
|
|
||
| protected void internalClearProperties(AsyncResponse asyncResponse) { | ||
| AtomicReference<Integer> clearedCount = new AtomicReference<>(0); | ||
| validateAdminAccessForTenantAsync(namespaceName.getTenant()) | ||
| validateBothAdminAccessForTenantAndNamespaceOperationAsync(namespaceName, NamespaceOperation.DELETE_PROPERTIES) | ||
| .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync()) | ||
| .thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> { | ||
| clearedCount.set(policies.properties.size()); | ||
|
|
@@ -3206,4 +3206,41 @@ private CompletableFuture<BundlesData> getDefaultBundleDataAsync() { | |
| getBundles(config().getDefaultNumberOfNamespaceBundles())); | ||
| } | ||
|
|
||
|
|
||
| protected CompletableFuture<Void> validateBothAdminAccessForTenantAndNamespaceOperationAsync( | ||
| NamespaceName namespaceName, NamespaceOperation operation) { | ||
| final var tenantAdminValidation = validateAdminAccessForTenantAsync(namespaceName.getTenant()); | ||
| final var namespaceOperationValidation = validateNamespaceOperationAsync(namespaceName, operation); | ||
| return FutureUtil.waitForAll(List.of(tenantAdminValidation, namespaceOperationValidation)) | ||
| .handle((result, err) -> { | ||
| if (!tenantAdminValidation.isCompletedExceptionally() | ||
| || !namespaceOperationValidation.isCompletedExceptionally()) { | ||
| return null; | ||
| } | ||
| if (log.isDebugEnabled()) { | ||
| Throwable tenantAdminValidationException = null; | ||
| try { | ||
| tenantAdminValidation.join(); | ||
| } catch (Throwable ex) { | ||
| tenantAdminValidationException = FutureUtil.unwrapCompletionException(ex); | ||
| } | ||
| Throwable namespaceOperationValidationException = null; | ||
| try { | ||
| namespaceOperationValidation.join(); | ||
| } catch (Throwable ex) { | ||
| namespaceOperationValidationException = FutureUtil.unwrapCompletionException(ex); | ||
| } | ||
| log.debug("validateBothAdminAccessForTenantAndNamespaceOperationAsync failed." | ||
| + " originalPrincipal={} clientAppId={} operation={} namespace={} " | ||
| + "tenantAdminValidationError={} namespaceOperationValidationError={}", | ||
| originalPrincipal(), clientAppId(), operation.toString(), namespaceName, | ||
| tenantAdminValidationException, namespaceOperationValidationException); | ||
| } | ||
| throw new RestException(Status.UNAUTHORIZED, | ||
| String.format("Unauthorized to validateBothAdminAccessForTenantAndNamespaceOperationAsync" | ||
| + " for originalPrincipal [%s] and clientAppId [%s] about operation [%s]" | ||
| + " on namespace [%s]", | ||
| originalPrincipal(), clientAppId(), operation.toString(), namespaceName)); | ||
| }); | ||
|
Comment on lines
+3239
to
+3244
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |||
| import java.net.URI; | ||||
| import java.net.URL; | ||||
| import java.time.Duration; | ||||
| import java.util.List; | ||||
|
||||
| import java.util.List; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,9 @@ public enum NamespaceOperation { | |
| GET_PERMISSION, | ||
| GRANT_PERMISSION, | ||
| REVOKE_PERMISSION, | ||
| GET_PROPERTIES, | ||
| UPDATE_PROPERTIES, | ||
| DELETE_PROPERTIES, | ||
|
Comment on lines
+37
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering if adding new enums breaks existing 3rd party AuthorizationProviders which many Pulsar users use currently in production? |
||
|
|
||
| CLEAR_BACKLOG, | ||
| UNSUBSCRIBE, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateBothAdminAccessForTenantAndNamespaceOperationAsyncalways starts both authorization checks and waits for both to complete, even if the tenant-admin check succeeds. This adds extra auth traffic/latency to every namespace properties request and can make the endpoint as slow as the slower of the two checks. Consider short-circuiting on the first successful validation (and only running the second path if the first fails).