-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Authorization] Use AuthorizationService#grantPermissionAsync to gran… #12515
[Authorization] Use AuthorizationService#grantPermissionAsync to gran… #12515
Conversation
5dfec7a
to
867cecd
Compare
|
||
String topicUri = topicName.toString(); | ||
try { | ||
pulsarResources.getNamespaceResources().setPolicies(topicName.getNamespaceObject(), policies -> { |
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.
the setPolicies()
would be a blocking call here. Instead we should use setPoliciesAsync()
and use that future.
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.
Great catch. It looks like grantPermissionAsync(NamespaceName namespaceName, Set<AuthAction> actions, String role, String authDataJson)
has the same issue. I'll follow up with an update to that method separately. Further, I'd like to update the calling methods to be asynchronous instead of calling .get
on the future.
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.
I've updated it to use the same logic found in the updateSubscriptionPermissionAsync
method.
@merlimat - it looks like the /**
* Grant authorization-action permission on a topic to the given client
*
* @param topicName
* @param role
* @param authDataJson
* additional authdata in json format
* @return CompletableFuture
* @completesWith <br/>
* IllegalArgumentException when namespace not found<br/>
* IllegalStateException when failed to grant permission
*/
CompletableFuture<Void> grantPermissionAsync(TopicName topicName, Set<AuthAction> actions, String role,
String authDataJson); Based on inspecting the Since we're already fully in on PIP-45, I think we should just update these Javadocs and make sure that the changes are mentioned in the release notes for 2.10. Let me know how you think we should proceed. I'm happy to open up a PR to update the Javadocs. |
d15897f
to
919d053
Compare
@merlimat - PTAL. Sorry, I pushed with force, so the history is gone. It's mostly a small change though, so hopefully it isn't too hard to review. Thanks! |
@merlimat, @eolivelli, @codelipenghui, @freeznet, @lhotari - PTAL |
…13897) ### Motivation This PR is based on an observation from #12515. The content is essentially the same, and the goal is to make an async method _actually_ asynchronous. ### Modifications * Make `PulsarAuthorizationProvider#grantPermissionAsync` actually async * Update the exception handling to ensure correctness * Switch from `thenRun` to `whenComplete` for handling future completion in several methods in `PulsarAuthorizationProvider`.
…pache#13897) ### Motivation This PR is based on an observation from apache#12515. The content is essentially the same, and the goal is to make an async method _actually_ asynchronous. ### Modifications * Make `PulsarAuthorizationProvider#grantPermissionAsync` actually async * Update the exception handling to ensure correctness * Switch from `thenRun` to `whenComplete` for handling future completion in several methods in `PulsarAuthorizationProvider`.
…t topic permission
Motivation
There are several motivating factors here.
AuthorizationProvider
interface has a method to grant permission for a role to a topic. However, that method is not currently used. The other methods in the interface for granting permission on namespaces and on subscriptions are used. This PR seeks to bring the implementation into alignment. Without this change, a custom authorization provider would not be able to create custom logic for topic level permissions.PulsarAuthorizationProvider#grantPermissionAsync(TopicName topicName, Set<AuthAction> actions, String role, String authDataJson)
is surprising. It currently sets permissions using the namespace method instead of setting the permissions at the topic level. This could result in granting more permission than intended. However, the method is not actually called right now, so this unexpected behavior is irrelevant.Modifications
PulsarAuthorizationProvider
. This change closely resembles the existing code in theNamespacesBase
class.Verifying this change
There are already tests that cover the granting of permission at a topic level. For example,
PersistentTopicsTest
tests this. Existing test coverage should be sufficient for validating this change.Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changesDocumentation
Check the box below and label this PR (if you have committer privilege).
Need to update docs?
doc-required
(If you need help on updating docs, create a doc issue)
no-need-doc
No behavior is changed here. The fundamental change is to rely on the
AuthorizationProvider
interface when granting topic level permissions.doc
(If this PR contains doc changes)