如何使用 acl 限制对 redis pubsub 中某些主题的访问?
How do I restrict access to certain topics in redis pubsub with acl?
我希望某些客户端无法订阅 Redis pubsub 中的某些主题。这可以用 redis acl 实现吗?
是的,这就是您如何使用 ACL 将客户端限制为 "foo" 主题:
$ redis-cli
127.0.0.1:6379> ACL SETUSER limitedpubsub on nopass -@all +subscribe|foo
OK
127.0.0.1:6379> AUTH limitedpubsub ""
OK
127.0.0.1:6379> SUBSCRIBE bar
Reading messages... (press Ctrl-C to quit)
(error) NOPERM this user has no permissions to run the 'subscribe' command or its subcommand
^C
$ redis-cli
127.0.0.1:6379> AUTH limitedpubsub ""
OK
127.0.0.1:6379> SUBSCRIBE foo
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "foo"
3) (integer) 1
我希望某些客户端无法订阅 Redis pubsub 中的某些主题。这可以用 redis acl 实现吗?
是的,这就是您如何使用 ACL 将客户端限制为 "foo" 主题:
$ redis-cli
127.0.0.1:6379> ACL SETUSER limitedpubsub on nopass -@all +subscribe|foo
OK
127.0.0.1:6379> AUTH limitedpubsub ""
OK
127.0.0.1:6379> SUBSCRIBE bar
Reading messages... (press Ctrl-C to quit)
(error) NOPERM this user has no permissions to run the 'subscribe' command or its subcommand
^C
$ redis-cli
127.0.0.1:6379> AUTH limitedpubsub ""
OK
127.0.0.1:6379> SUBSCRIBE foo
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "foo"
3) (integer) 1