-
Notifications
You must be signed in to change notification settings - Fork 994
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
Add support for external user identity / authentication management #1916
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.lettuce.core; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Value object representing credentials used to authenticate with Redis. | ||
* | ||
* @author Jon Iantosca | ||
* @since 6.2 | ||
*/ | ||
public class Credentials { | ||
|
||
private String username; | ||
|
||
private char[] password; | ||
|
||
public Credentials(char[] password) { | ||
this(null, password); | ||
} | ||
|
||
public Credentials(String username, char[] password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public boolean hasUsername() { | ||
return username != null && !username.isEmpty(); | ||
} | ||
|
||
public char[] getPassword() { | ||
return password; | ||
} | ||
|
||
public boolean hasPassword() { | ||
return password != null && password.length > 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof Credentials)) { | ||
return false; | ||
} | ||
Credentials credentials = (Credentials) o; | ||
|
||
return Objects.equals(username, credentials.username) && Arrays.equals(password, credentials.password); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(username) + Arrays.hashCode(password); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/io/lettuce/core/DefaultCredentialsSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.lettuce.core; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Internal {@link Supplier<Credentials>} with support to delegate to a client supplied {@link Supplier<Credentials>}. | ||
* | ||
* @author Jon Iantosca | ||
* @since 6.2 | ||
*/ | ||
class DefaultCredentialsSupplier implements Supplier<Credentials> { | ||
|
||
private String username; | ||
|
||
private char[] password; | ||
|
||
private Supplier<Credentials> delegate; | ||
|
||
DefaultCredentialsSupplier() { | ||
} | ||
|
||
DefaultCredentialsSupplier(char[] password) { | ||
this(null, password); | ||
} | ||
|
||
DefaultCredentialsSupplier(String username, char[] password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public Credentials get() { | ||
return hasDelegate() ? delegate.get() : new Credentials(this.username, this.password); | ||
} | ||
|
||
void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
void setPassword(char[] password) { | ||
this.password = password; | ||
} | ||
|
||
Supplier<Credentials> getCredentialsSupplier() { | ||
return hasDelegate() ? delegate : this; | ||
} | ||
|
||
void setDelegate(Supplier<Credentials> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
boolean hasDelegate() { | ||
return delegate != null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In the case which this.credentialsSupplier has a delegate which takes the passwd from another service: after sending an AUTH query to the server, we override the credentialsSupplier that has delegate with a new DefaultCredentialsSupplier which holds only the passwd at the time of the query.
In the case of a passwd rotation, the passwd at the time of the AUTH query will be expired.
I think there is supposed to be a check for existence credentialsSupplier and only if it does not exists, then to set it.
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.
That's intended if the Redis connection is authenticated manually. In an arrangement where credentials are supplied externally, there's no need to call
AUTH
from a client application.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.
Hi @mp911de, we're looking into adding support for recurring authentication using ephemeral passwords.
This will mean that the client will need to repeatedly reauthenticate, and on each reauthentication attempt receive a fresh password from the credentials supplier.
Overwriting the credentials supplier will mean that this flow will break after the first reauthentication.
I can see 2 option to come over it.
The 1st:
To check if the this.credentialsSupplier is of type DefaultCredentialsSupplier, meaning there is no delegate by the customer.
In order to be sure the customer didn't create a new CredentialsSupplier which inherits from DefaultCredentialsSupplier, we put DefaultCredentialsSupplier as final so no inheritance from it.
The 2nd:
To set this.credentialsSupplier using the DefaultCredentialsSupplier itself from the RedisUri , and then to check if it has delegate or not, if there is delegate, meaning the user/passwd is supplied externally and not supposed be to be overridden by any auth command.
Anyway, I think we should change this function name as it doesn't always change the username/passwd anymore and also not on all cases
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.
When you add or remove a password on the Redis ACL, does that affect connected clients?
Generally as I understand the scenario, you want to call AUTH yourself so there doesn't seem to be need to have a credentials provider at all.