-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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:pika support acl #2013
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释不用保留了吧,已经调用RemovePassword了
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.
可以去掉
} 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里面是否需要调用 SetUser(clearselectors)? 我看redis文档中,reset需要清空selector
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.
效果都是一样的吧, 这里的selectors_.clear()
把 selectors_ 这个链表清空了
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.
在 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果只需要单向遍历的话,是否使用std::forward_list比list有更好的空间利用率?
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.
一开始没考虑那么多直接用了 list, 后来想换成 std::forward_list 的时候 发现了两个问题
- std::forward_list 不能 push_back, 这个问题不大
- std::forward_list 不能 for (:) 遍历, 改动的地方挺多的
考虑到这两个差别不大 就一直没改, 如果性能性能 空间 差距 较大的话 可以改了
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.
行,这个数据量不大的情况下就不改了吧
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的逻辑是不是写反了?顺序检查所有的Selector,如果符合一个Selector,直接就返回OK了,后面的Selector都没有执行检查。
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.
这里的逻辑是不是写反了?顺序检查所有的Selector,如果符合一个Selector,直接就返回OK了,后面的Selector都没有执行检查。
这个逻辑应该就是这样的, 多个 selector中,有一个 符合就可以通过
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.
奥,好的
已经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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个配置怎么注释了?
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.
这段配置全用默认就行,所以就没开
pika的配置文件风格是什么?
return; | ||
} | ||
|
||
PikaCmdArgsType args; |
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.
# 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
include/pika_conf.h
Outdated
std::shared_lock l(rwlock_); | ||
return user_blacklist_; | ||
} | ||
// std::string userpass() { |
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.
怎么还有这种注释代码?如果不需要,可以删除
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.
好的
include/pika_conf.h
Outdated
} | ||
} | ||
void SetSlotMigrate(const std::string &value) { | ||
// void SetUserPass(const std::string& value) { |
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.
如上
src/pika_slot_command.cc
Outdated
return nullptr; | ||
} | ||
} | ||
// std::string userpass = g_pika_conf->userpass(); |
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.
这些代码留着是为了什么?
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.
这些都是在改原来代码的时候,先注释原来的,然后再改的, 后面就一直没有删, 等会我统一删了
} | ||
} | ||
|
||
# test on local machine is passed |
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.
这个测试注释掉,是为何?
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.
这个是因为这个测试很慢, 有时候重启pika会有问题, 我本地测试没问题后就去掉了
b7f6c58
into
OpenAtomFoundation:unstable
copy from redis acl --------- Co-authored-by: Chengyu Liu <[email protected]>
copy from redis acl --------- Co-authored-by: Chengyu Liu <[email protected]>
copy from redis acl --------- Co-authored-by: Chengyu Liu <[email protected]>
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
中