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

WebSocket proxy should not make a consumer/producer when authorization is failed #448

Merged
merged 2 commits into from
Jun 12, 2017

Conversation

yush1ga
Copy link
Contributor

@yush1ga yush1ga commented Jun 6, 2017

Motivation

Now, websocket proxy make an internal consumer/producer by using a super user role even if authorization is failed. (Although websocket connection is closed.)
It causes some problems.

Modifications

  • Changed isAuthorized() to synchronized
  • Made producer/consumer creation abstract

Result

Websocket proxy no longer make consumers/producers for unauthorized users.

@yush1ga yush1ga changed the title Websocket proxy should not make a consumer/producer when authorization is failed. WebSocket proxy should not make a consumer/producer when authorization is failed Jun 6, 2017
if(!isAuthorized) {
log.warn("[{}] WebSocket Client [{}] is not authorized on topic {}", session.getRemoteAddress(), role,
try {
if(!isAuthorized(authRole)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

actually idea behind keeping isAuthorized async to avoid blocking-thread on authorization check. So, can we keep it async and on future-complete we can call createClient(session) so, we can still keep it async and avoid creation of producer/consumer on authorization failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I returned isAuthorized() to asynchronized and put createClient() in thenApply block.

@yush1ga yush1ga force-pushed the websocket-unauthorized branch from 4cdfa3c to 7e6b6a0 Compare June 7, 2017 07:48
@yush1ga
Copy link
Contributor Author

yush1ga commented Jun 7, 2017

Some tests were failed.
I'm going to cope with it.
The local test has been passed.

@yush1ga yush1ga force-pushed the websocket-unauthorized branch 2 times, most recently from 5e4aed7 to dee7e51 Compare June 7, 2017 08:52
@@ -81,10 +81,14 @@ public void onWebSocketConnect(Session session) {
log.warn("[{}] WebSocket Client [{}] is not authorized on topic {}", session.getRemoteAddress(), role,
topic);
close(WebSocketError.NotAuthorizedError);
} else {
createClient(session);
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think it make sense to complete handshake super.onWebSocketConnect(session); after successfully authenticating client, means after calling createClient(session)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned here, onWebSocketConnect seems to be called after handshake is completed and super.onWebSocketConnect(session) seems to only set member variables.
In addition, as you stated in #98, onWebSocketText(..) gets triggered at server only when server releases thread from onWebSocketConnect().
I think we need not move super.onWebSocketConnect(session).
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

onWebSocketText(..) gets triggered only when server releases thread from onWebSocketConnect()

It means if we do authorization async then there could be a chance that producer start producing messages even before authorization completed. So, we can keep your previous commit where we do authorization synchronously and it should be faster because we fetch it from ZkCache and get from zk only once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed isAuthorized into synchronized again.

@yush1ga yush1ga force-pushed the websocket-unauthorized branch from dee7e51 to bbebf82 Compare June 9, 2017 02:59
Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

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

👍

@yush1ga
Copy link
Contributor Author

yush1ga commented Jun 12, 2017

@merlimat @saandrews
Will you please take a look ?

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

👍

@merlimat merlimat added the type/bug The PR fixed a bug or issue reported a bug label Jun 12, 2017
@merlimat merlimat added this to the 1.18 milestone Jun 12, 2017
@merlimat merlimat merged commit 10ac6c1 into apache:master Jun 12, 2017
hangc0276 added a commit to hangc0276/pulsar that referenced this pull request May 26, 2021
### Changes
Bump pulsar to 2.8.0-rc-202104202206 and fix the incompatible interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants