Skip to content

Conversation

@michaeljmarshall
Copy link
Member

PIP: #12105
Fixes: #19311

Motivation

Implement asynchronous authentication for the ServerCnx class.

Modifications

  • Update authentication of primary auth data to use the authenticateAsync method instead of authenticate. The callbacks are all handled on the context's event loop to ensure thread safety.
  • Update the order in which the ServerCnx validates proxied authentication data. The issue is described here [Broker] ServerCnx should not respond with Success until verifying originalAuthData #19311. Now, we authenticate the proxy's auth data, then the client's auth data, and then reply with the Connected command.
  • Add failure scenario to the ServerCnx so that it correctly fails authentication when a proxy's original auth method triggers multistaged authentication.
  • Clean up error handling. This results in some slightly different error messages to clients when authentication fails. There is no real contract here, so I think this is a safe change.

Verifying this change

Several new tests are added and some existing tests are updated.

Does this pull request potentially affect one of the following parts:

  • Send an error to the proxy if the client's auth data triggers an auth challenge.
  • Change certain protocol string messages when authentication fails.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: michaeljmarshall#23

@michaeljmarshall michaeljmarshall added type/feature The PR added a new feature or issue requested a new feature area/broker doc-not-needed Your PR changes do not impact docs labels Feb 2, 2023
@michaeljmarshall michaeljmarshall added this to the 3.0.0 milestone Feb 2, 2023
@michaeljmarshall michaeljmarshall self-assigned this Feb 2, 2023
@michaeljmarshall
Copy link
Member Author

Looks like PersistentTopicTest#testGetReplicationClusters is failing. It hasn't been reported as a flaky test, but it seems unrelated to my changes. I'll look closer tomorrow.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

Good work @michaeljmarshall

@lhotari
Copy link
Member

lhotari commented Feb 3, 2023

@michaeljmarshall is this a real failure? https://github.com/apache/pulsar/actions/runs/4085441211/jobs/7043646144#step:11:1102

  Error:  Tests run: 14, Failures: 1, Errors: 0, Skipped: 13, Time elapsed: 0.872 s <<< FAILURE! - in org.apache.pulsar.broker.service.ServerCnxAuthorizationTest
  Error:  testVerifyAuthRoleAndAuthDataFromDirectConnectionBroker(org.apache.pulsar.broker.service.ServerCnxAuthorizationTest)  Time elapsed: 0.063 s  <<< FAILURE!
  java.lang.NullPointerException: Cannot invoke "io.netty.channel.ChannelFuture.addListener(io.netty.util.concurrent.GenericFutureListener)" because the return value of "io.netty.channel.ChannelOutboundInvoker.writeAndFlush(Object)" is null
  	at org.apache.pulsar.common.util.netty.NettyChannelUtil.writeAndFlushWithClosePromise(NettyChannelUtil.java:60)
  	at org.apache.pulsar.broker.service.ServerCnx.authenticationFailed(ServerCnx.java:838)
  	at org.apache.pulsar.broker.service.ServerCnx.handleConnect(ServerCnx.java:1027)
  	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
  	at java.base/java.lang.Thread.run(Thread.java:833)
  

@lhotari
Copy link
Member

lhotari commented Feb 3, 2023

@michaeljmarshall The test class ServerCnxAuthorizationTest is doing extensive mocking of Netty classes, which is a bad solution. The ServerCnxTest has a better solution based on a real class, EmbeddedChannel . Article: https://www.baeldung.com/testing-netty-embedded-channel

protected void resetChannel() throws Exception {
int MaxMessageSize = 5 * 1024 * 1024;
if (channel != null && channel.isActive()) {
serverCnx.close();
channel.close().get();
}
serverCnx = new ServerCnx(pulsar);
serverCnx.setAuthRole("");
channel = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(
MaxMessageSize,
0,
4,
0,
4),
(ChannelHandler) serverCnx);
}

Instead of adding more mocking to ServerCnxAuthorizationTest, I think it's better to refactor it to use EmbeddedChannel.

@michaeljmarshall
Copy link
Member Author

@lhotari - I completely agree that we should just move the test to the ServerCnxTest. I am working on that now.

@michaeljmarshall
Copy link
Member Author

I can't seem to run the TestPulsarSQLAuth suite locally. I see errors related to missing certificates. Instead of troubleshooting, I am pushed changes that should get the tests into a better spot.

@michaeljmarshall
Copy link
Member Author

Looks like those changes made the SQL integration tests pass. I am pushing one more commit to add a test that explicitly covers the bug that made the SQL tests fail 539ad03.

@lhotari
Copy link
Member

lhotari commented Feb 4, 2023

I can't seem to run the TestPulsarSQLAuth suite locally. I see errors related to missing certificates. Instead of troubleshooting, I am pushed changes that should get the tests into a better spot.

The missing cert issue gets fixed by running the maven build (for core-modules) once. It copies the certs to the expected location somewhere.

michaeljmarshall added a commit that referenced this pull request Feb 15, 2023
### Motivation

I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from #19409, without taking the async logic.

### Modifications

* Make changes to `ServerCnx` to make tests pass

### Verifying this change

Tests are currently failing, so passing tests will show that this solution is correct.

### Documentation

- [x] `doc-not-needed`
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from apache#19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from apache#19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
michaeljmarshall added a commit that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from #19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
(cherry picked from commit 15e4198)
michaeljmarshall added a commit that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from #19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
(cherry picked from commit 15e4198)
(cherry picked from commit 6132b46)
michaeljmarshall added a commit that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from #19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
(cherry picked from commit 15e4198)
(cherry picked from commit 6132b46)
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request Feb 15, 2023
I broke all release branches when I cherry picked 2847dd1 to them. This change takes some of the underlying logic from apache#19409, without taking the async logic.

* Make changes to `ServerCnx` to make tests pass

Tests are currently failing, so passing tests will show that this solution is correct.

- [x] `doc-not-needed`

(cherry picked from commit 8246da2)
(cherry picked from commit 15e4198)
(cherry picked from commit 6132b46)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 16, 2023
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 17, 2023
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request Feb 17, 2023
(cherry picked from commit 2225361)
(cherry picked from commit fb0d8bb)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 17, 2023
(cherry picked from commit 2225361)
(cherry picked from commit 557b72d)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 22, 2023
(cherry picked from commit 2225361)
(cherry picked from commit 557b72d)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 23, 2023
(cherry picked from commit 2225361)
(cherry picked from commit 557b72d)
(cherry picked from commit 9330092)
hangc0276 added a commit to hangc0276/pulsar that referenced this pull request Mar 15, 2023
hangc0276 added a commit to hangc0276/pulsar that referenced this pull request Mar 15, 2023
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Apr 19, 2023
michaeljmarshall added a commit that referenced this pull request May 8, 2023
Fixes #20236 
PIP: #19409 

### Motivation

In the `AuthenticationService`, we are currently using the deprecated `authenticate` methods. As a result, we hit the `Not Implemented` exception when using the `AuthenticationProviderOpenID`. This PR updates the implementation so that we're able 

This solution isn't ideal for two reasons.

1. We are not using the `authenticationHttpRequest` method, which seems like the right method for the WebSocket proxy. However, this is not a viable option, as I documented in #20237.
2. We are calling `.get()` on a future. However, it is expected that the `AuthenticationProvider` not block forever, so I think this is acceptable for now. Please let me know if you disagree.

### Modifications

* Replace `authenticate` with `authenticateAsync`.

### Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

### Documentation

- [x] `doc-not-needed`

Note that I do have documentation showing that 3.0.x does not support OIDC in the WebSocket Proxy. The `next` docs don't need that limitation since this PR fixes that and targets 3.1.0. apache/pulsar-site#558

### Matching PR in forked repository

PR in forked repository: skipping for this trivial PR
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request May 8, 2023
Fixes apache#20236
PIP: apache#19409

### Motivation

In the `AuthenticationService`, we are currently using the deprecated `authenticate` methods. As a result, we hit the `Not Implemented` exception when using the `AuthenticationProviderOpenID`. This PR updates the implementation so that we're able

This solution isn't ideal for two reasons.

1. We are not using the `authenticationHttpRequest` method, which seems like the right method for the WebSocket proxy. However, this is not a viable option, as I documented in apache#20237.
2. We are calling `.get()` on a future. However, it is expected that the `AuthenticationProvider` not block forever, so I think this is acceptable for now. Please let me know if you disagree.

### Modifications

* Replace `authenticate` with `authenticateAsync`.

### Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

### Documentation

- [x] `doc-not-needed`

Note that I do have documentation showing that 3.0.x does not support OIDC in the WebSocket Proxy. The `next` docs don't need that limitation since this PR fixes that and targets 3.1.0. apache/pulsar-site#558

### Matching PR in forked repository

PR in forked repository: skipping for this trivial PR

(cherry picked from commit 03dc3db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker doc-not-needed Your PR changes do not impact docs type/feature The PR added a new feature or issue requested a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Broker] ServerCnx should not respond with Success until verifying originalAuthData

2 participants