feat:pika support acl - #2013
Conversation
|
这个实现作为 3.5.3。先把 ci 失败处理了。 |
好的 在看失败原因了 |
# Conflicts: # src/pika_server.cc
# Conflicts: # include/pika_server.h # src/pika_server.cc
| } | ||
| delpass = op.data() + 1; | ||
| } | ||
| // passwords_.erase(delpass); |
There was a problem hiding this comment.
这个注释不用保留了吧,已经调用RemovePassword了
| } else if (!strcasecmp(op.data(), "clearselectors")) { | ||
| selectors_.clear(); | ||
| return pstd::Status::OK(); | ||
| } else if (!strcasecmp(op.data(), "reset")) { |
There was a problem hiding this comment.
这里面是否需要调用 SetUser(clearselectors)? 我看redis文档中,reset需要清空selector
There was a problem hiding this comment.
效果都是一样的吧, 这里的selectors_.clear() 把 selectors_ 这个链表清空了
There was a problem hiding this comment.
在 131行, 调用了status = SetUser("-@all"); 把 selector 设置为 -@all 了,所以不用 clean, redis也是这样处理的
|
|
||
| std::set<std::string> passwords_; // passwords for this user | ||
|
|
||
| std::list<std::shared_ptr<AclSelector>> selectors_; /* A set of selectors this user validates commands |
There was a problem hiding this comment.
如果只需要单向遍历的话,是否使用std::forward_list比list有更好的空间利用率?
There was a problem hiding this comment.
一开始没考虑那么多直接用了 list, 后来想换成 std::forward_list 的时候 发现了两个问题
- std::forward_list 不能 push_back, 这个问题不大
- std::forward_list 不能 for (:) 遍历, 改动的地方挺多的
考虑到这两个差别不大 就一直没改, 如果性能性能 空间 差距 较大的话 可以改了
There was a problem hiding this comment.
行,这个数据量不大的情况下就不改了吧
|
@lqxhub pls merge latest codes |
| AclDeniedCmd res = AclDeniedCmd::OK; | ||
| for (const auto& selector : selectors_) { | ||
| res = selector->CheckCanExecCmd(cmd, subCmdIndex, keys, errKey); | ||
| if (res == AclDeniedCmd::OK) { |
There was a problem hiding this comment.
这里的逻辑是不是写反了?顺序检查所有的Selector,如果符合一个Selector,直接就返回OK了,后面的Selector都没有执行检查。
There was a problem hiding this comment.
这里的逻辑是不是写反了?顺序检查所有的Selector,如果符合一个Selector,直接就返回OK了,后面的Selector都没有执行检查。
这个逻辑应该就是这样的, 多个 selector中,有一个 符合就可以通过
已经merge了, 因为测试不通过 我还没有提交, 等 我修复缓存的那个pr合了再提吧 |
| # resetchannels: revokes access to all Pub/Sub channels | ||
| # | ||
| # acl-pubsub-default defaults to 'resetchannels' permission. | ||
| # acl-pubsub-default : resetchannels |
There was a problem hiding this comment.
这段配置全用默认就行,所以就没开
pika的配置文件风格是什么?
| return; | ||
| } | ||
|
|
||
| PikaCmdArgsType args; |
# Conflicts: # include/pika_admin.h # include/pika_bit.h # include/pika_command.h # include/pika_geo.h # include/pika_hash.h # include/pika_kv.h # include/pika_list.h # include/pika_pubsub.h # include/pika_set.h # include/pika_transaction.h # include/pika_zset.h # src/pika_command.cc
# Conflicts: # include/pika_conf.h
| std::shared_lock l(rwlock_); | ||
| return user_blacklist_; | ||
| } | ||
| // std::string userpass() { |
| } | ||
| } | ||
| void SetSlotMigrate(const std::string &value) { | ||
| // void SetUserPass(const std::string& value) { |
| return nullptr; | ||
| } | ||
| } | ||
| // std::string userpass = g_pika_conf->userpass(); |
There was a problem hiding this comment.
这些都是在改原来代码的时候,先注释原来的,然后再改的, 后面就一直没有删, 等会我统一删了
| } | ||
| } | ||
|
|
||
| # test on local machine is passed |
There was a problem hiding this comment.
这个是因为这个测试很慢, 有时候重启pika会有问题, 我本地测试没问题后就去掉了
copy from redis acl --------- Co-authored-by: Chengyu Liu <chengyu_l@126.com>
copy from redis acl --------- Co-authored-by: Chengyu Liu <chengyu_l@126.com>
copy from redis acl --------- Co-authored-by: Chengyu Liu <chengyu_l@126.com>






related issue #2190
这个是 pika 支持 Redis acl的功能, 目前 redis 的 acl相关测试已经跑通
把上次的review发现的问题已经修复
在这个pr中, 把
hello命令的问题一起解决了 #2190目前根据Redis的分类标准,对命令做了简单分类,但是有一个问题。Redis中 ,
config get和config set属于两个命令,这个两个命令可以属于不同的分类(category),但是在pika中, 这两个命令属于同一个命令,然后根据不同的参数做了区分,执行不同的逻辑,所以在pika中 只能属于同一个分类. 类似的还有ACL相关的命令等等 有子命令的命令。如果对这个部分有建议和不用的看法 还请不吝赐教
有关 pika ACL 相关的讨论在这个issue下 #1284
对以前的改动:
userpass,只保留requirepass配置, 和redis保持相同GetConfStrMulti函数,实现多行读取 https://github.com/OpenAtomFoundation/pika/pull/2013/files#diff-02ec4106d4dadab327423f6791330502cb6365957d105a74f43018266c7f43baR234pstd::StringTrim函数错误,并加单测 https://github.com/OpenAtomFoundation/pika/pull/2013/files#diff-7880ecffec99b660051b9ca83b4fb3f624a29f2ff91465e447abb58f846d21e2R719flag做了补充,加入了ACL需要的参数CmdFlags做了修改 https://github.com/OpenAtomFoundation/pika/pull/2013/files#diff-96b2e654cfee5e668db837f1c01c4cbaea767b949413087a1093e0327f8f4438R243CmdRes做了修改 https://github.com/OpenAtomFoundation/pika/pull/2013/files#diff-96b2e654cfee5e668db837f1c01c4cbaea767b949413087a1093e0327f8f4438L274ACL的主要实现逻辑在
acl.h和acl.cc文件中, acl命令处理在pika_acl.h和pika_acl.cc中