-
Notifications
You must be signed in to change notification settings - Fork 968
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
feat(acl): add support of multiple passwords #3189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,13 +160,22 @@ std::optional<ParseKeyResult> MaybeParseAclKey(std::string_view command) { | |
return ParseKeyResult{std::string(key), op}; | ||
} | ||
|
||
std::optional<std::string> MaybeParsePassword(std::string_view command, bool hashed) { | ||
std::optional<User::UpdatePass> MaybeParsePassword(std::string_view command, bool hashed) { | ||
using UpPass = User::UpdatePass; | ||
if (command == "nopass") { | ||
return std::string(command); | ||
return UpPass{"", false, true}; | ||
} | ||
|
||
if (command == "resetpass") { | ||
return UpPass{"", false, false, true}; | ||
} | ||
|
||
if (command[0] == '>' || (hashed && command[0] == '#')) { | ||
return std::string(command.substr(1)); | ||
return UpPass{std::string(command.substr(1))}; | ||
} | ||
|
||
if (command[0] == '<') { | ||
return UpPass{std::string(command.substr(1)), true}; | ||
} | ||
|
||
return {}; | ||
|
@@ -261,10 +270,8 @@ std::variant<User::UpdateRequest, ErrorReply> ParseAclSetUser(facade::ArgRange a | |
|
||
for (std::string_view arg : args) { | ||
if (auto pass = MaybeParsePassword(facade::ToSV(arg), hashed); pass) { | ||
if (req.password) { | ||
return ErrorReply("Only one password is allowed"); | ||
} | ||
req.password = std::move(pass); | ||
req.passwords.push_back(std::move(*pass)); | ||
|
||
if (hashed && absl::StartsWith(facade::ToSV(arg), "#")) { | ||
req.is_hashed = hashed; | ||
} | ||
|
@@ -346,4 +353,16 @@ std::string AclKeysToString(const AclKeys& keys) { | |
return result; | ||
} | ||
|
||
std::string PasswordsToString(const absl::flat_hash_set<std::string>& passwords, bool nopass, | ||
bool full_sha) { | ||
if (nopass) { | ||
return "nopass "; | ||
} | ||
std::string result; | ||
for (const auto& pass : passwords) { | ||
absl::StrAppend(&result, "#", PrettyPrintSha(pass, full_sha), " "); | ||
} | ||
|
||
return result; | ||
} | ||
Comment on lines
+356
to
+367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it can very well be that a user doesn't have nopass set, but it's password set is empty. Maybe we should print some kind of warning in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am following redis/valkey here :) If there is no |
||
} // namespace dfly::acl |
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.
A little bit unusual interface with the leftover space 🙂 But yes, it's only used twice, so not important
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.
Soooo, it's used in 3 places and two of them needed the extra space, so I thought this was the minimal set of changes required 🤣 I promise I will clean this, just like the other two places that almost have identical printing (acl list and when we serialize the registry to write it via acl save)