Skip to content

Conversation

@michaeljmarshall
Copy link
Member

@michaeljmarshall michaeljmarshall commented Apr 19, 2023

Fixes: #20066

Motivation

In #20068 we changed the way that the AuthorizationService is implemented. I think we should change the Consumer and the Producer logic to call the correct AuthorizationService method.

Given that our goal is to deprecate the AuthorizationService methods for canProduce and canConsume, this change helps us move in the right direction.

Modifications

  • Update Producer and Consumer in broker to call the AuthorizationService#allowTopicOperationAsync method.

Verifying this change

This change is trivial.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: Skipping PR as I ran tests locally.

@michaeljmarshall michaeljmarshall added type/bug The PR fixed a bug or issue reported a bug doc-not-needed Your PR changes do not impact docs ready-to-test area/authz labels Apr 19, 2023
@michaeljmarshall michaeljmarshall added this to the 3.1.0 milestone Apr 19, 2023
@michaeljmarshall michaeljmarshall self-assigned this Apr 19, 2023
@nodece
Copy link
Member

nodece commented Apr 19, 2023

#20068 is the correct implementation, I don't suggest we revert that.

I suggest we just update the Producer.java and Consumer.java to call the AuthorizationService#allowTopicOperationAsync method, and we also can add the @Deprecated to AuthorizationService#canProduceAsync, AuthorizationService#canConsumeAsync.

BTW, the canLookupAsync should also be deprecated.

@michaeljmarshall
Copy link
Member Author

#20068 is the correct implementation, I don't suggest we revert that.

What is the purpose of changing the implementation of an abstraction that we are deprecating?

@nodece
Copy link
Member

nodece commented Apr 19, 2023

#20068 is the correct implementation, I don't suggest we revert that.

What is the purpose of changing the implementation of an abstraction that we are deprecating?

Make sure this logic/behavior is correct.

Maybe this affects the commit history, but I still suggest we keep #20068.

@michaeljmarshall
Copy link
Member Author

#20068 is the correct implementation, I don't suggest we revert that.

What is the purpose of changing the implementation of an abstraction that we are deprecating?

Make sure this logic is correct.

The logic has been there for a long time. It's likely extensions built on top of those methods already account for the short coming, which is why I said that solution could have unintended consequences.

The problem described by #20066 is that the Producer and Consumer use the wrong method in the AuthorizationService. In my opinion, the right fix is to fix which method those classes use.

Maybe this affects the commit history, but I still suggest we keep #20068.

That's a fair point. I will break this PR into two PRs to make the discussion clearer.

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

LGTM

@michaeljmarshall
Copy link
Member Author

@nodece - I'll open a PR to deprecate those methods.

@michaeljmarshall michaeljmarshall added type/cleanup Code or doc cleanups e.g. remove the outdated documentation or remove the code no longer in use and removed type/bug The PR fixed a bug or issue reported a bug labels Apr 19, 2023
Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

I rethought this PR, if the custom authorization provider didn't handle the TopicOperation, which introduces unintended consequences.

@michaeljmarshall
Copy link
Member Author

I rethought this PR, if the custom authorization provider didn't handle the TopicOperation, which introduces unintended consequences.

@nodece - by that same logic, #20068 is invalid. The default for the provider is to fail, so it is a safe change:

default CompletableFuture<Boolean> allowTopicOperationAsync(TopicName topic,
String role,
TopicOperation operation,
AuthenticationDataSource authData) {
return FutureUtil.failedFuture(
new IllegalStateException("TopicOperation [" + operation.name() + "] is not supported by the Authorization"
+ "provider you are using."));
}

Further, the allowTopicOperationAsync has been used by ServerCnx for a while.

@nodece
Copy link
Member

nodece commented Apr 19, 2023

I rethought this PR, if the custom authorization provider didn't handle the TopicOperation, which introduces unintended consequences.

@nodece - by that same logic, #20068 is invalid. The default for the provider is to fail, so it is a safe change:

default CompletableFuture<Boolean> allowTopicOperationAsync(TopicName topic,
String role,
TopicOperation operation,
AuthenticationDataSource authData) {
return FutureUtil.failedFuture(
new IllegalStateException("TopicOperation [" + operation.name() + "] is not supported by the Authorization"
+ "provider you are using."));
}

Further, the allowTopicOperationAsync has been used by ServerCnx for a while.

I know we've been using allowTopicOperationAsync for a long time, but I'm still concerned about compatibility issues.

If we allow for this change, I think #20068 is also safe, is it right?

@michaeljmarshall
Copy link
Member Author

If we allow for this change, I think #20068 is also safe, is it right?

My concern for #20068 is not with the AuthorizationProvider implementation but rather with pulsar extensions running in the broker that call the AuthorizationService#canProduceAsync and AuthorizationService#canConsumeAsync. My primary argument is that there is no compelling reason to change the AuthorizationService implementation because there is already a "correct" alternative to use. As such, I want to leave those methods unchanged and to update the broker code to use the newer method to get the correct behavior.

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

Thank you for your explanation, we focus on different points, so different ideas emerge.
In my opinion, both #20142 and #20068 PRs are able to solve #20066, and in order to solve the issue completely I submitted #20145.

#20068 can also be reverted.

@codecov-commenter
Copy link

Codecov Report

Merging #20142 (f757419) into master (9b72302) will increase coverage by 39.78%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #20142       +/-   ##
=============================================
+ Coverage     33.17%   72.96%   +39.78%     
- Complexity    12236    31927    +19691     
=============================================
  Files          1499     1868      +369     
  Lines        114413   138402    +23989     
  Branches      12431    15236     +2805     
=============================================
+ Hits          37962   100986    +63024     
+ Misses        71499    29397    -42102     
- Partials       4952     8019     +3067     
Flag Coverage Δ
inttests 24.25% <50.00%> (?)
systests 24.84% <62.50%> (?)
unittests 72.26% <100.00%> (+39.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...sar/broker/authorization/AuthorizationService.java 58.92% <100.00%> (+48.92%) ⬆️
...ava/org/apache/pulsar/broker/service/Consumer.java 86.64% <100.00%> (+26.85%) ⬆️
...ava/org/apache/pulsar/broker/service/Producer.java 82.46% <100.00%> (+25.20%) ⬆️

... and 1538 files with indirect coverage changes

@michaeljmarshall michaeljmarshall merged commit dc5e497 into apache:master Apr 20, 2023
@michaeljmarshall michaeljmarshall deleted the fix-authz branch April 20, 2023 05:17
michaeljmarshall added a commit that referenced this pull request Apr 20, 2023
…#20143)

This reverts commit fc17c1d.

### Motivation

In #20068 we changed the way that the `AuthorizationService` is implemented. I think this approach could have unintended consequences. Instead, I think we should change the `Consumer` and the `Producer` logic to call the correct `AuthorizationService` method. I propose an update to the `Consumer` and `Producer` logic here #20142.

Given that our goal is to deprecate the `AuthorizationService` methods for `canProduce` and `canConsume`, I think we should not change their implementations.

### Modifications

* Revert #20068

### Verifying this change

This change is trivial. It removes certain test changes that were only made to make the previous PR work.

### Documentation

- [x] `doc-not-needed`

### Matching PR in forked repository

PR in forked repository: Skipping PR as I ran tests locally.
@poorbarcode
Copy link
Contributor

poorbarcode commented May 7, 2023

poorbarcode pushed a commit that referenced this pull request May 7, 2023
…20142)

Fixes: #20066

### Motivation

In #20068 we changed the way that the `AuthorizationService` is implemented. I think we should change the `Consumer` and the `Producer` logic to call the correct `AuthorizationService` method.

Given that our goal is to deprecate the `AuthorizationService` methods for `canProduce` and `canConsume`, this change helps us move in the right direction.

### Modifications

* Update `Producer` and `Consumer` in broker to call the `AuthorizationService#allowTopicOperationAsync` method.

### Verifying this change

This change is trivial.

### Documentation

- [x] `doc-not-needed`

### Matching PR in forked repository

PR in forked repository: Skipping PR as I ran tests locally.

(cherry picked from commit dc5e497)
poorbarcode pushed a commit that referenced this pull request May 7, 2023
…#20143)

This reverts commit fc17c1d.

### Motivation

In #20068 we changed the way that the `AuthorizationService` is implemented. I think this approach could have unintended consequences. Instead, I think we should change the `Consumer` and the `Producer` logic to call the correct `AuthorizationService` method. I propose an update to the `Consumer` and `Producer` logic here #20142.

Given that our goal is to deprecate the `AuthorizationService` methods for `canProduce` and `canConsume`, I think we should not change their implementations.

### Modifications

* Revert #20068

### Verifying this change

This change is trivial. It removes certain test changes that were only made to make the previous PR work.

### Documentation

- [x] `doc-not-needed`

### Matching PR in forked repository

PR in forked repository: Skipping PR as I ran tests locally.

(cherry picked from commit 00dc7a0)
michaeljmarshall added a commit that referenced this pull request May 18, 2023
Similar to: #20142

### Motivation

In #20142 we changed the `Consumer` and the `Producer` logic to call the correct `AuthorizationService` method.

Our goal is to deprecate the `AuthorizationService` methods for `canProduce` and `canConsume`, so this change helps us move in the right direction.

This PR follows the same logic and updates the WebSocket proxy to remove all calls to the `can*` methods in the `AuthorizationService`

### Modifications

* Update `ProducerHandler`,  `ConsumerHandler`, and `ReaderHander` in the WebSocket Proxy to call the `AuthorizationService#allowTopicOperationAsync` method.

### Verifying this change

This change is trivial.

### Documentation

- [x] `doc-not-needed`

### Matching PR in forked repository

PR in forked repository: Skipping PR as I ran tests locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/authz area/broker cherry-picked/branch-3.0 doc-not-needed Your PR changes do not impact docs ready-to-test release/3.0.1 type/cleanup Code or doc cleanups e.g. remove the outdated documentation or remove the code no longer in use

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [broker] Producer and consumer will all be disconnected while using tenant admin to produce/consume

5 participants