Skip to content
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

Merged
merged 31 commits into from
Jan 10, 2024
Merged

feat:pika support acl #2013

merged 31 commits into from
Jan 10, 2024

Conversation

lqxhub
Copy link
Collaborator

@lqxhub lqxhub commented Sep 22, 2023

related issue #2190

这个是 pika 支持 Redis acl的功能, 目前 redis 的 acl相关测试已经跑通

把上次的review发现的问题已经修复

在这个pr中, 把 hello 命令的问题一起解决了 #2190

目前根据Redis的分类标准,对命令做了简单分类,但是有一个问题。Redis中 , config getconfig set 属于两个命令,这个两个命令可以属于不同的分类(category),但是在pika中, 这两个命令属于同一个命令,然后根据不同的参数做了区分,执行不同的逻辑,所以在pika中 只能属于同一个分类. 类似的还有 ACL 相关的命令等等 有子命令的命令。

如果对这个部分有建议和不用的看法 还请不吝赐教

有关 pika ACL 相关的讨论在这个issue下 #1284

对以前的改动:

ACL的主要实现逻辑在 acl.hacl.cc文件中, acl命令处理在 pika_acl.hpika_acl.cc

@AlexStocks
Copy link
Collaborator

这个实现作为 3.5.3。先把 ci 失败处理了。

@lqxhub
Copy link
Collaborator Author

lqxhub commented Sep 23, 2023

这个实现作为 3.5.3。先把 ci 失败处理了。

好的 在看失败原因了

@lqxhub lqxhub marked this pull request as ready for review November 9, 2023 01:33
@lqxhub lqxhub changed the title pika support acl feat:pika support acl Nov 24, 2023
@lqxhub lqxhub linked an issue Nov 24, 2023 that may be closed by this pull request
}
delpass = op.data() + 1;
}
// passwords_.erase(delpass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个注释不用保留了吧,已经调用RemovePassword了

Copy link
Collaborator Author

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")) {
Copy link
Collaborator

@dingxiaoshuai123 dingxiaoshuai123 Dec 18, 2023

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

效果都是一样的吧, 这里的selectors_.clear() 把 selectors_ 这个链表清空了

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只需要单向遍历的话,是否使用std::forward_list比list有更好的空间利用率?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一开始没考虑那么多直接用了 list, 后来想换成 std::forward_list 的时候 发现了两个问题

  1. std::forward_list 不能 push_back, 这个问题不大
  2. std::forward_list 不能 for (:) 遍历, 改动的地方挺多的

考虑到这两个差别不大 就一直没改, 如果性能性能 空间 差距 较大的话 可以改了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

行,这个数据量不大的情况下就不改了吧

@AlexStocks
Copy link
Collaborator

@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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的逻辑是不是写反了?顺序检查所有的Selector,如果符合一个Selector,直接就返回OK了,后面的Selector都没有执行检查。

Copy link
Collaborator Author

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中,有一个 符合就可以通过

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

奥,好的

@lqxhub
Copy link
Collaborator Author

lqxhub commented Dec 18, 2023

@lqxhub pls merge latest codes

已经merge了, 因为测试不通过 我还没有提交, 等 我修复缓存的那个pr合了再提吧

# resetchannels: revokes access to all Pub/Sub channels
#
# acl-pubsub-default defaults to 'resetchannels' permission.
# acl-pubsub-default : resetchannels
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个配置怎么注释了?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段配置全用默认就行,所以就没开

pika的配置文件风格是什么?

return;
}

PikaCmdArgsType args;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
下面是redis

@dingxiaoshuai123
Copy link
Collaborator

dingxiaoshuai123 commented Dec 20, 2023

在添加channel的规则的时候,会先检查key pattern,如果已经存在,那就不会将channel的规则添加到channels中,所以导致channel命令没有权限。上图为pika,下图为redis
image
image

# 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
@lqxhub
Copy link
Collaborator Author

lqxhub commented Dec 30, 2023

在添加channel的规则的时候,会先检查key pattern,如果已经存在,那就不会将channel的规则添加到channels中,所以导致channel命令没有权限。上图为pika,下图为redis image image

image
done

std::shared_lock l(rwlock_);
return user_blacklist_;
}
// std::string userpass() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

怎么还有这种注释代码?如果不需要,可以删除

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

}
}
void SetSlotMigrate(const std::string &value) {
// void SetUserPass(const std::string& value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如上

return nullptr;
}
}
// std::string userpass = g_pika_conf->userpass();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些代码留着是为了什么?

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个测试注释掉,是为何?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是因为这个测试很慢, 有时候重启pika会有问题, 我本地测试没问题后就去掉了

@chengyu-l chengyu-l merged commit b7f6c58 into OpenAtomFoundation:unstable Jan 10, 2024
10 of 13 checks passed
KKorpse pushed a commit to KKorpse/pika that referenced this pull request Jan 11, 2024
copy from redis acl
---------

Co-authored-by: Chengyu Liu <[email protected]>
bigdaronlee163 pushed a commit to bigdaronlee163/pika that referenced this pull request Jun 8, 2024
copy from redis acl
---------

Co-authored-by: Chengyu Liu <[email protected]>
cheniujh pushed a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
copy from redis acl
---------

Co-authored-by: Chengyu Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.5.3 ✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pika 支持 ACL 多租户功能
4 participants