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

ISSUE 568 : Synchronize Kerberos ticket renewal for non-renewable ticket #581

Merged
merged 4 commits into from
Aug 14, 2019

Conversation

raju-saravanan
Copy link
Collaborator

@raju-saravanan raju-saravanan commented Aug 7, 2019

Fixes #568

@raju-saravanan raju-saravanan requested a review from guruchai August 7, 2019 08:40
@@ -246,6 +260,26 @@ private KerberosTicket getTGT() {
return null;
}

private void synchronizeReLogin() throws LoginException {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see any point having relogin and synchronizeReLogin. Please rename this as relogin and delete the other.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The code in try {} block and in else {} block have same lines of code which has been abstracted out as reLogin(). Its better to keep this abstracted out, as synchronizedReLogin() is wrapper over reLogin() which hold the actual logic to reLogin() while synchornizedReLogin() simply provides a synchronization on top of it.

KerberosLogin kerberosLogin = new KerberosLogin();
kerberosSynchronizationLock = new ReentrantReadWriteLock(true);
Lock kerberosTGTRenewalLock = kerberosSynchronizationLock.writeLock();
KerberosLogin kerberosLogin = new KerberosLogin(kerberosTGTRenewalLock, KERBEROS_SYNCHRONIZATION_TIMEOUT_MS);
Copy link
Contributor

Choose a reason for hiding this comment

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

KERBEROS_SYNCHRONIZATION_TIMEOUT_MS does not belong here. And sharing the lock does not appear so elegant. How about this

  1. Create a ReentrantReadWriteLock in KerberosLogin.
  2. Use writelock in relogin method.
  3. Push the synchronizedDoAction to KerberosLogin and use readlock for that.

You will limit the moving parts of KerberosLogin class.

@raju-saravanan
Copy link
Collaborator Author

@guruchai: I have exposed NOOPLogin class which will abstract out the login
() / doAction() mechanism in the schema registry.

Copy link
Contributor

@guruchai guruchai left a comment

Choose a reason for hiding this comment

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

LGTM...

food for thought: Can we do away with all the additional checks for locks in KerberosLogin? relogin ideally should be an atomic operation. Almost all the KerberosLogin impls have their relogin wrapped inside a lock.
https://github.com/hortonworks/kafka/blob/bd037de41b621a6984a0577ab59e13c27c225931/clients/src/main/java/org/apache/kafka/common/security/kerberos/KerberosLogin.java#L359
https://github.com/apache/zookeeper/blob/d84b7a682eb4601005db9fac886079b1a9a4d4b0/zookeeper-server/src/main/java/org/apache/zookeeper/Login.java#L409

Similarly, on read lock side, no implementation would want to do an action without lock. So lets make that explicit by creating lock always. This simplifies the code and removes repititive checks. We can assume an indefinite timeout in default case.

@raju-saravanan
Copy link
Collaborator Author

We can't have reLogin() wrapped in a synchronized block as you have referenced in the previous comment. In the schema registry, we don't have a connection pool, we open up a new connection for every request made, so if we open a new connection between logout() and login() of reLogin() the server will throw 401. Zookeeper and Kafka the connection is reused after the request is over and hence it making a call between logout() and login() works as it still the cookie from the previous call.
In NOOPLogin where we want to use a plain connection to the server, we don't want a lock for every doAction() call. That is why I have not abstracted out the locking mechanism to its abstract class.

@guruchai
Copy link
Contributor

@raju-saravanan
We can't have reLogin() wrapped in a synchronized block as you have referenced in the previous comment. In the schema registry, we don't have a connection pool, we open up a new connection for every request made, so if we open a new connection between logout() and login() of reLogin() the server will throw 401.

I am asking you to have only the synrchronizedRelogin method instead of both relogin and synrchronizedRelogin methods. You may use the WriteLock. synchronized as you said does not make sense. To me, relogin should be treated like an atomic operation.

Zookeeper and Kafka the connection is reused after the request is over and hence it making a call between logout() and login() works as it still the cookie from the previous call.

Connection reuse aside. The point is that we will not be able to make calls between logout and login, for any time, irrespective of presence of cookie or not.

@guruchai guruchai merged commit 77932b9 into hortonworks:master Aug 14, 2019
@guruchai
Copy link
Contributor

Thanks for the PR!

gcsaba2 pushed a commit that referenced this pull request Apr 30, 2020
…ket (#581)

*  ISSUE 568 : Synchronize Kerberos ticket renewal for non-renewable ticket

*   Handle doAction as a part of Login class

*   Remove references to Schema Registry in KerberosLogin class.

*   With default constructor of KerberosLogin create a read/write lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronize Kerberos ticket renewal for non-renewable ticket
2 participants