Skip to content

Conversation

@nodece
Copy link
Member

@nodece nodece commented Feb 8, 2023

Motivation

#6428 adds allowTopicOperationAsync() to check the topic authz abilities, it is a good solution, but this PR doesn't deprecate the old methods:

  • canProduceAsync
  • canConsumeAsync
  • canLookupAsync

When users customize their own AuthorizationProvider, they will be confused, so I decided to deprecate the old methods.

Modifications

  • Deprecate canProduceAsync, canConsumeAsync, and canLookupAsync in the AuthorizationProvider, and add a default implementation
  • Add back compatibility to allowTopicOperationAsync to call the deprecated method
  • Uniformly use allowTopicOperationAsync to check permissions in the AuthorizationService
  • Fix failure tests

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Feb 8, 2023
…eck permissions

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
@nodece nodece force-pushed the cleanup-check-topic-permission branch from 5b441c5 to 897daba Compare February 8, 2023 09:51
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great proposal! I think this is a good direction for Pulsar's authorization framework. I will need to come back to this tomorrow or Monday to give it a more thorough review.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Mar 30, 2023
@nodece
Copy link
Member Author

nodece commented Apr 12, 2023

ping @michaeljmarshall, do you have time to review this PR?

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodece - I completely agree that we should clean up these abstractions and make it easier for contributors and extension maintainers to know how to integrate with the AuthorizationService. I left some initial feedback. Let me know what you think. Thanks!

Comment on lines +150 to +153
default CompletableFuture<Boolean> canLookupAsync(TopicName topicName, String role,
AuthenticationDataSource authenticationData) {
return CompletableFuture.completedFuture(false);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of providing a default implementation, I think we should just deprecate these methods. Then, in the PulsarAuthorizationProvider class, we can remove the @Override annotation and those methods become internal implementation details instead of top level methods on the interface.

Comment on lines -348 to -350
return FutureUtil.failedFuture(
new IllegalStateException("TopicOperation [" + operation.name() + "] is not supported by the Authorization"
+ "provider you are using."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to explain a bit more why this is required for backwards compatibility? I think we should be able to leave this here and leave the switch statement in the PulsarAuthorizationProvider.

Comment on lines 281 to +284
if (isSuperUser) {
return CompletableFuture.completedFuture(true);
} else {
return provider.canLookupAsync(topicName, role, authenticationData);
return provider.allowTopicOperationAsync(topicName, role, TopicOperation.LOOKUP, authenticationData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only tangentially related to your PR, but it seems like a broken abstraction that the AuthorizationService decides that the superuser privilege supersedes the AuthenticationProvider implementaiton. Instead, I think we could just call provider.allowTopicOperationAsync(topicName, role, TopicOperation.LOOKUP, authenticationData);, as you've done here.

My goal is to move that logic into the provider so that plugin implementations do not need to deal with the complexity of when to check for super user and when not to. All of this logic should be delegated to the provider, in my opinion.

That change is probably worth its own PR, though.

Comment on lines -194 to +202
return provider.canConsumeAsync(topicName, role, authenticationData, subscription);
AuthenticationDataSource subscriptionDataSource;
if (authenticationData instanceof AuthenticationDataSubscription) {
subscriptionDataSource = authenticationData;
} else {
subscriptionDataSource = new AuthenticationDataSubscription(authenticationData, subscription);
}
return provider.allowTopicOperationAsync(topicName, role, TopicOperation.CONSUME,
subscriptionDataSource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deprecate this canConsumeAsync method? It seems like the same kind of logic that we're deprecating in the AuthorizationProvider.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label May 15, 2023
@Technoboy- Technoboy- added this to the 3.2.0 milestone Jul 31, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 14, 2024
@coderzc coderzc modified the milestones: 4.1.0, 4.2.0 Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants