-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
if(!isAuthorized) { | ||
log.warn("[{}] WebSocket Client [{}] is not authorized on topic {}", session.getRemoteAddress(), role, | ||
try { | ||
if(!isAuthorized(authRole)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
4cdfa3c
to
7e6b6a0
Compare
|
5e4aed7
to
dee7e51
Compare
@@ -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); |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
dee7e51
to
bbebf82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@merlimat @saandrews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
### Changes Bump pulsar to 2.8.0-rc-202104202206 and fix the incompatible interface.
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
isAuthorized()
to synchronizedResult
Websocket proxy no longer make consumers/producers for unauthorized users.