如何停止对redis数据库的匿名访问



我用docker compose运行redis镜像
我通过了redis.conf(redis说"已加载配置"(
redis.conf中我添加了用户

user pytest ><password> ~pytest/* on @set @get

但我可以匿名与redis交流即使使用未注释的字符串

requirepass <password>

Redis文档主题:安全性和ACL没有回答如何限制每个人的访问。也许我根本不了解一些事情。

我的码头组合

version: '3'
services:
  redis:
    image: redis:latest
    ports:
      - 6379:6379
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 6000s
      timeout: 30s
      retries: 50
    restart: always
    volumes:
      - redis-db:/data
      - redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf" ]

volumes:
  redis-db:
  redis.conf:

然而,即使使用未注释的字符串,我也可以以匿名身份与redis通信

因为有一个默认用户,而你没有禁用它。如果你想完全禁用匿名访问,你应该在redis.conf中添加以下内容:

user default off

其次,用户"pytest"的配置不正确。如果您只想允许用户"pytest"在给定的密钥模式上有setget命令,您应该按如下方式配置它:

user pytest ><password> ~pytest/* on +set +get

您还需要确保docker compose正在使用您的配置文件。假设redis.confdocker-compose.yml位于同一目录中,则服务声明中的"volumes"部分将为.

  - ./redis.conf:/usr/local/etc/redis/redis.conf

并且还删除底部中的命名卷声明

redis.conf:

用户可以连接到Redis,但如果没有AUTH,如果您启用,他们将无法执行任何操作

requirepass <password>

限制密钥pytest/*上的GET、SET操作的正确方法是

user pytest ><password> ~pytest/* on +set +get

最新更新