Skip to content
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

[improve][broker] ServerCnx: go to Failed state when auth fails #19312

Conversation

michaeljmarshall
Copy link
Member

@michaeljmarshall michaeljmarshall commented Jan 23, 2023

PIP: #12105

Motivation

When authentication fails in the ServerCnx, the state is left in Start if the primary authData fails authentication and in Connecting or Connected if the originalAuthData authentication fails. To prevent any kind of unexpected behavior, we should go to Failed state.

Note that the tests verify the current behavior where a failed originalAuthData results first in a Connected command from the broker and then an Error command. I documented that I think this is sub optimal here #19311.

Modifications

  • Update ServerCnx state to Failed when there is an authentication exception during handleConnect and during handleAuthResponse.
  • Update handleAuthResponse reply to "Unable to authenticate" instead of the AuthenticationState exception.

Verifying this change

A new test is added. The added test covers the change made in #19295 where we updated ServerCnx so that we call AuthState#authenticate instead of relying on the implementation detail that the initialization calls authenticate. That PR should have added a test.

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

This is not a breaking change.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: michaeljmarshall#18

@michaeljmarshall michaeljmarshall added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/broker labels Jan 23, 2023
@michaeljmarshall michaeljmarshall added this to the 2.12.0 milestone Jan 23, 2023
@michaeljmarshall michaeljmarshall self-assigned this Jan 23, 2023
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jan 23, 2023
@lhotari
Copy link
Member

lhotari commented Jan 24, 2023

/pulsarbot rerun-failure-checks

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

it looks like we have the same issue in the handleAuthResponse method.
It's fine to create a separated pull request

@michaeljmarshall
Copy link
Member Author

Great suggestion @nicoloboschi. I updated this PR since it fits well within the scope. I also extended the tests to cover this part of the protocol.

@codecov-commenter
Copy link

Codecov Report

Merging #19312 (6fecb6f) into master (8d81392) will decrease coverage by 0.44%.
The diff coverage is 91.17%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #19312      +/-   ##
============================================
- Coverage     63.93%   63.49%   -0.44%     
- Complexity     3470    25900   +22430     
============================================
  Files          1818     1818              
  Lines        133061   133079      +18     
  Branches      14637    14637              
============================================
- Hits          85067    84499     -568     
- Misses        40270    40818     +548     
- Partials       7724     7762      +38     
Flag Coverage Δ
inttests 24.88% <0.00%> (-0.07%) ⬇️
systests 25.62% <8.82%> (-0.08%) ⬇️
unittests 60.85% <91.17%> (-0.46%) ⬇️

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

Impacted Files Coverage Δ
...va/org/apache/pulsar/broker/service/ServerCnx.java 52.98% <72.72%> (-1.94%) ⬇️
...er/authentication/OneStageAuthenticationState.java 100.00% <100.00%> (ø)
...ain/java/org/apache/pulsar/broker/rest/Topics.java 0.00% <0.00%> (-100.00%) ⬇️
...apache/pulsar/broker/web/ProcessHandlerFilter.java 0.00% <0.00%> (-83.34%) ⬇️
...apache/pulsar/broker/web/MaxRequestSizeFilter.java 0.00% <0.00%> (-82.36%) ⬇️
.../pulsar/broker/rest/RestMessagePublishContext.java 0.00% <0.00%> (-77.78%) ⬇️
...pache/pulsar/broker/tools/GenerateDocsCommand.java 0.00% <0.00%> (-77.28%) ⬇️
...apache/pulsar/websocket/data/ProducerMessages.java 0.00% <0.00%> (-75.00%) ⬇️
.../pulsar/broker/service/SharedConsumerAssignor.java 5.55% <0.00%> (-74.08%) ⬇️
...ava/org/apache/pulsar/broker/tools/BrokerTool.java 0.00% <0.00%> (-71.43%) ⬇️
... and 196 more

@michaeljmarshall michaeljmarshall merged commit 8049690 into apache:master Jan 25, 2023
@michaeljmarshall michaeljmarshall deleted the pip-97-call-authenticate-on-auth-state branch January 25, 2023 03:38
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 15, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 16, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 17, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request Feb 17, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: michaeljmarshall#18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
(cherry picked from commit 168aa6a)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 17, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
(cherry picked from commit 467cd32)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 22, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
(cherry picked from commit 467cd32)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Feb 23, 2023
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
(cherry picked from commit 3ef3bf1)
(cherry picked from commit 467cd32)
(cherry picked from commit 1fab71b)
@michaeljmarshall michaeljmarshall added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Feb 27, 2023
@michaeljmarshall
Copy link
Member Author

I cherry picked this because it added some important tests that other important bug fixes relied on.

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
…he#19312)

PIP: apache#12105

When authentication fails in the `ServerCnx`, the state is left in `Start` if the primary `authData` fails authentication and in `Connecting` or `Connected` if the `originalAuthData` authentication fails. To prevent any kind of unexpected behavior, we should go to `Failed` state.

Note that the tests verify the current behavior where a failed `originalAuthData` results first in a `Connected` command from the broker and then an `Error` command. I documented that I think this is sub optimal here apache#19311.

* Update `ServerCnx` state to `Failed` when there is an authentication exception during `handleConnect` and during `handleAuthResponse`.
* Update `handleAuthResponse` reply to `"Unable to authenticate"` instead of the `AuthenticationState` exception.

A new test is added. The added test covers the change made in apache#19295 where we updated `ServerCnx` so that we call `AuthState#authenticate` instead of relying on the implementation detail that the initialization calls `authenticate`. That PR should have added a test.

This is not a breaking change.

- [x] `doc-not-needed`

PR in forked repository: #18

(cherry picked from commit 8049690)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs release/2.8.5 release/2.9.5 release/2.10.5 release/2.11.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants