-
Notifications
You must be signed in to change notification settings - Fork 933
Add ValkeyModule_ACLCheckCommandPermissionsForCurrentUser API #2690
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
base: unstable
Are you sure you want to change the base?
Changes from 7 commits
ac171ad
71ce27c
5111bd4
8238124
cfc47a6
0273be0
ac071e6
f65208b
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 |
|---|---|---|
|
|
@@ -70,6 +70,7 @@ | |
| #include "io_threads.h" | ||
| #include "scripting_engine.h" | ||
| #include "cluster_migrateslots.h" | ||
| #include <cerrno> | ||
| #include <dlfcn.h> | ||
| #include <sys/stat.h> | ||
| #include <sys/wait.h> | ||
|
|
@@ -9993,6 +9994,40 @@ int VM_ACLCheckCommandPermissions(ValkeyModuleUser *user, ValkeyModuleString **a | |
| return VALKEYMODULE_OK; | ||
| } | ||
|
|
||
| /* Checks if the command can be executed by the module context user, according to the ACLs | ||
| * associated with it. | ||
| * | ||
| * On success a VALKEYMODULE_OK is returned, otherwise | ||
| * VALKEYMODULE_ERR is returned and errno is set to the following values: | ||
| * | ||
| * * ENOENT: Specified command does not exist. | ||
| * * EACCES: Command cannot be executed, according to ACL rules; or the user is not authenticated. | ||
| * * EINVAL: Invalid module context. | ||
| * * ENOTSUP: There is no user associated with this module context. | ||
| */ | ||
| int VM_ACLCheckCommandPermissionsForCurrentUser(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { | ||
| if (ctx == NULL) { | ||
| errno = EINVAL; | ||
| return VALKEYMODULE_ERR; | ||
| } else if (ctx->user == NULL && (ctx->client == NULL || ctx->client->user == NULL)) { | ||
| errno = ENOTSUP; | ||
| return VALKEYMODULE_ERR; | ||
| } | ||
|
|
||
| /* If the ctx->user was set by VM_SetContextUser then use that user instead | ||
| * of the ctx->client->user. */ | ||
| if (ctx->user) { | ||
| return VM_ACLCheckCommandPermissions((ValkeyModuleUser *)ctx->user, argv, argc); | ||
| } | ||
|
|
||
| ValkeyModuleUser user = { | ||
| .user = ctx->client->user, | ||
| .free_user = 0, | ||
| }; | ||
|
Comment on lines
+10022
to
+10025
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. This entire API is because we're trying to bypass the allocation and do it on the stack here. When the API was written, we cared more about abstraction then performance. If we think performance is so critical, I would rather just ditch the abstraction and directly return the user from the module APIs. Glancing through the code I don't see any incompatibility with that. 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. Are you proposing to make In that case we would probably need to add a field in the 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.
Yes. We don't expect a large number of users, so adding an extra field should be safe. I think we even have a bit field we could use if we wanted to avoid adding any memory at all. |
||
|
|
||
| return VM_ACLCheckCommandPermissions(&user, argv, argc); | ||
| } | ||
|
|
||
| /* Check if the key can be accessed by the user according to the ACLs attached to the user | ||
| * and the flags representing the key access. The flags are the same that are used in the | ||
| * keyspec for logical operations. These flags are documented in ValkeyModule_SetCommandInfo as | ||
|
|
@@ -14330,6 +14365,7 @@ void moduleRegisterCoreAPI(void) { | |
| REGISTER_API(GetCurrentUserName); | ||
| REGISTER_API(GetModuleUserFromUserName); | ||
| REGISTER_API(ACLCheckCommandPermissions); | ||
| REGISTER_API(ACLCheckCommandPermissionsForCurrentUser); | ||
| REGISTER_API(ACLCheckKeyPermissions); | ||
| REGISTER_API(ACLCheckChannelPermissions); | ||
| REGISTER_API(ACLAddLogEntry); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.