Allow specifying ACL reason for module log entry (#10559)
Allow specifying an ACL log reason, which is shown in the log. Right now it always shows "unknown", which is a little bit cryptic. This is a breaking change, but this API was added as part of 7 so it seems ok to stabilize it still.
This commit is contained in:
+12
-2
@@ -8699,8 +8699,18 @@ int RM_ACLCheckChannelPermissions(RedisModuleUser *user, RedisModuleString *ch,
|
||||
* Returns REDISMODULE_OK on success and REDISMODULE_ERR on error.
|
||||
*
|
||||
* For more information about ACL log, please refer to https://redis.io/commands/acl-log */
|
||||
void RM_ACLAddLogEntry(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModuleString *object) {
|
||||
addACLLogEntry(ctx->client, 0, ACL_LOG_CTX_MODULE, -1, user->user->name, sdsdup(object->ptr));
|
||||
int RM_ACLAddLogEntry(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModuleString *object, RedisModuleACLLogEntryReason reason) {
|
||||
int acl_reason;
|
||||
switch (reason) {
|
||||
case REDISMODULE_ACL_LOG_AUTH: acl_reason = ACL_DENIED_AUTH; break;
|
||||
case REDISMODULE_ACL_LOG_KEY: acl_reason = ACL_DENIED_KEY; break;
|
||||
case REDISMODULE_ACL_LOG_CHANNEL: acl_reason = ACL_DENIED_CHANNEL; break;
|
||||
case REDISMODULE_ACL_LOG_CMD: acl_reason = ACL_DENIED_CMD; break;
|
||||
default: return REDISMODULE_ERR;
|
||||
}
|
||||
|
||||
addACLLogEntry(ctx->client, acl_reason, ACL_LOG_CTX_MODULE, -1, user->user->name, sdsdup(object->ptr));
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
/* Authenticate the client associated with the context with
|
||||
|
||||
+8
-1
@@ -735,6 +735,13 @@ typedef struct RedisModuleSwapDbInfo {
|
||||
|
||||
#define RedisModuleSwapDbInfo RedisModuleSwapDbInfoV1
|
||||
|
||||
typedef enum {
|
||||
REDISMODULE_ACL_LOG_AUTH = 0, /* Authentication failure */
|
||||
REDISMODULE_ACL_LOG_CMD, /* Command authorization failure */
|
||||
REDISMODULE_ACL_LOG_KEY, /* Key authorization failure */
|
||||
REDISMODULE_ACL_LOG_CHANNEL /* Channel authorization failure */
|
||||
} RedisModuleACLLogEntryReason;
|
||||
|
||||
/* ------------------------- End of common defines ------------------------ */
|
||||
|
||||
#ifndef REDISMODULE_CORE
|
||||
@@ -1158,7 +1165,7 @@ REDISMODULE_API RedisModuleUser * (*RedisModule_GetModuleUserFromUserName)(Redis
|
||||
REDISMODULE_API int (*RedisModule_ACLCheckCommandPermissions)(RedisModuleUser *user, RedisModuleString **argv, int argc) REDISMODULE_ATTR;
|
||||
REDISMODULE_API int (*RedisModule_ACLCheckKeyPermissions)(RedisModuleUser *user, RedisModuleString *key, int flags) REDISMODULE_ATTR;
|
||||
REDISMODULE_API int (*RedisModule_ACLCheckChannelPermissions)(RedisModuleUser *user, RedisModuleString *ch, int literal) REDISMODULE_ATTR;
|
||||
REDISMODULE_API void (*RedisModule_ACLAddLogEntry)(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModuleString *object) REDISMODULE_ATTR;
|
||||
REDISMODULE_API void (*RedisModule_ACLAddLogEntry)(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModuleString *object, RedisModuleACLLogEntryReason reason) REDISMODULE_ATTR;
|
||||
REDISMODULE_API int (*RedisModule_AuthenticateClientWithACLUser)(RedisModuleCtx *ctx, const char *name, size_t len, RedisModuleUserChangedFunc callback, void *privdata, uint64_t *client_id) REDISMODULE_ATTR;
|
||||
REDISMODULE_API int (*RedisModule_AuthenticateClientWithUser)(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModuleUserChangedFunc callback, void *privdata, uint64_t *client_id) REDISMODULE_ATTR;
|
||||
REDISMODULE_API int (*RedisModule_DeauthenticateAndCloseClient)(RedisModuleCtx *ctx, uint64_t client_id) REDISMODULE_ATTR;
|
||||
|
||||
@@ -92,7 +92,7 @@ int rm_call_aclcheck_cmd(RedisModuleCtx *ctx, RedisModuleUser *user, RedisModule
|
||||
if (ret != 0) {
|
||||
RedisModule_ReplyWithError(ctx, "DENIED CMD");
|
||||
/* Add entry to ACL log */
|
||||
RedisModule_ACLAddLogEntry(ctx, user, argv[1]);
|
||||
RedisModule_ACLAddLogEntry(ctx, user, argv[1], REDISMODULE_ACL_LOG_CMD);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ start_server {tags {"modules acl"}} {
|
||||
assert {[dict get $entry username] eq {default}}
|
||||
assert {[dict get $entry context] eq {module}}
|
||||
assert {[dict get $entry object] eq {set}}
|
||||
assert {[dict get $entry reason] eq {command}}
|
||||
}
|
||||
|
||||
test {test module check acl for key perm} {
|
||||
@@ -75,6 +76,7 @@ start_server {tags {"modules acl"}} {
|
||||
assert {[dict get $entry username] eq {default}}
|
||||
assert {[dict get $entry context] eq {module}}
|
||||
assert {[dict get $entry object] eq {z}}
|
||||
assert {[dict get $entry reason] eq {key}}
|
||||
|
||||
# rm call check for command permission
|
||||
r acl setuser default -set
|
||||
@@ -88,6 +90,7 @@ start_server {tags {"modules acl"}} {
|
||||
assert {[dict get $entry username] eq {default}}
|
||||
assert {[dict get $entry context] eq {module}}
|
||||
assert {[dict get $entry object] eq {set}}
|
||||
assert {[dict get $entry reason] eq {command}}
|
||||
}
|
||||
|
||||
test "Unload the module - aclcheck" {
|
||||
|
||||
Reference in New Issue
Block a user