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

[fix][authentication] Store the original authentication data #19519

Merged
merged 4 commits into from
Feb 16, 2023

Conversation

nodece
Copy link
Member

@nodece nodece commented Feb 14, 2023

Motivation

In the authentication:

  • With the proxy, the broker stores the client authentication to the originalAuthData and originalPrincipal, and stores the proxy authentication to the authenticationData and authRole.
  • Without the proxy, the broker stores the authentication to the authenticationData and authRole

When with the proxy, the broker only checks whether originalAuthData is expired. If true, the broker sends AuthChallenge to the client, then the client sends CommandAuthResponse.

In handleAuthResponse logic, the broker always stores the authentication to authenticationData and authRole, without considering the proxy case. When the authorization provider checks the role and authentication data, it is unmatched, this is incorrect behavior, so we need to distinguish whether have the proxy and then store the authentication data and role correctly.

More context: #18130

Modifications

  • Fix storing the authentication in the authChallengeSuccessCallback
  • Add MockMutableAuthenticationProvider and MockMutableAuthenticationState to refresh the role and datasource
  • Make MockAlwaysExpiredAuthenticationState extends MockMutableAuthenticationState to avoid the code duplication, and override the isExpired

Verifying this change

  • Make sure that the change passes the CI checks.

Added testRefreshOriginalPrincipalWithAuthDataForwardedFromProxy test

Documentation

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

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
@nodece nodece self-assigned this Feb 14, 2023
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Feb 14, 2023
@nodece nodece added this to the 3.0.0 milestone Feb 14, 2023
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.

It looks like this PR is partially addressing #19332. It won't solve that issue because this PR doesn't address the fact that we cannot refresh both of the AuthData objects.

@@ -1030,6 +1030,55 @@ public void testVerifyAuthRoleAndAuthDataFromDirectConnectionBroker() throws Exc
}));
}

@Test
public void testRefreshOriginalPrincipalWithAuthDataForwardedFromProxy() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Note that the tests that comment about https://github.com/apache/pulsar/issues/19332 should fail because they make assertions on the current behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

For current design, it works fine.

Copy link
Member

Choose a reason for hiding this comment

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

I must not have written some of the assertions I thought I did. You're right that those tests all pass. It might be worth removing the comments that reference #19332 because your PR will make them incorrect.

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
@nodece
Copy link
Member Author

nodece commented Feb 15, 2023

Hi @michaeljmarshall, I updated this PR.

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
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.

LGTM, great work @nodece

@nodece
Copy link
Member Author

nodece commented Feb 16, 2023

/pulsarbot rerun-failure-checks

1 similar comment
@nodece
Copy link
Member Author

nodece commented Feb 16, 2023

/pulsarbot rerun-failure-checks

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
@nodece nodece merged commit 2d90089 into apache:master Feb 16, 2023
@michaeljmarshall
Copy link
Member

@nodece - I think this is a bug, so we can back port it to the older release branches, if you would like. However, I am finishing up cherry picking some of this PR's dependencies, so it will be easiest to delay cherry-picking by a day or two.

@nodece
Copy link
Member Author

nodece commented Feb 17, 2023

@michaeljmarshall Thank you for your work! I look forward to your contribution!

@michaeljmarshall
Copy link
Member

@nodece - just so you know, I finished cherry picking my changes to the older branches.

nodece added a commit to nodece/pulsar that referenced this pull request Mar 2, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>

(cherry picked from commit 2d90089)
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
nodece added a commit to nodece/pulsar that referenced this pull request Mar 2, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>

(cherry picked from commit 2d90089)
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
nodece added a commit that referenced this pull request Mar 13, 2023
Signed-off-by: Zixuan Liu <nodeces@gmail.com>

(cherry picked from commit 2d90089)
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
nodece added a commit to nodece/pulsar that referenced this pull request Mar 13, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>

(cherry picked from commit 2d90089)
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
michaeljmarshall added a commit that referenced this pull request Mar 18, 2023
When #19519 was
cherry-picked to branch-2.11, it did not implement the
authenticate method in the MockMutableAuthenticationState,
which led to several test failures in the ServerCnxTest class.
This commit fixes those tests.

Note that the issue is only in the test code.
@michaeljmarshall
Copy link
Member

@nodece - just letting you know there was a minor issue when cherry picking this to branch-2.11. Some of the ServerCnxTest tests were failing. I fixed it with ad06fac.

michaeljmarshall pushed a commit to michaeljmarshall/pulsar that referenced this pull request Apr 20, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
(cherry picked from commit 2d90089)
gaoran10 pushed a commit to gaoran10/pulsar that referenced this pull request Dec 2, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
(cherry picked from commit 2d90089)
gaoran10 pushed a commit to gaoran10/pulsar that referenced this pull request Dec 8, 2023
…19519)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
(cherry picked from commit 2d90089)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants