使用 Redis AUTH 命令进行身份验证
通过使用 Redis 身份验证令牌(或密码),Redis 可以在允许客户端运行命令之前要求提供密码,从而提高了数据安全性。
主题
ElastiCache for Redis 中 AUTH 的概览
在将 Redis AUTH 与 ElastiCache for Redis 集群一起使用时,需要进行一些优化。
特别是,在将 AUTH 与 ElastiCache for Redis 一起使用时,请注意以下 AUTH 令牌(或密码)限制:
-
令牌(或密码)必须是 16-128 个可打印字符。
-
非字母数字字符仅限使用 !、&、#、$、^、<、>、-。
-
只能为启用了传输中加密的 ElastiCache for Redis 集群启用 AUTH。
要设置增强令牌,我们建议您遵循严格的密码策略,例如,要求满足以下条件:
-
令牌(或密码)必须包含至少三种以下字符类型:
-
大写字符
-
小写字符
-
数字
-
非字母数字字符(
!
、&
、#
、$
、^
、<
、>
、-
)
-
-
令牌(或密码)不能包含词典单词或稍微修改的词典单词。
-
令牌(或密码)不能与最近使用的令牌相同或相似。
对 ElastiCache for Redis 集群应用身份验证
您可以要求用户在受令牌保护的 Redis 服务器上输入令牌(密码)。为此,在创建复制组或集群时,请在 --auth-token
参数(API:AuthToken
)中包含正确的令牌。还要在复制组或集群的所有后续命令中包含该令牌。
以下 Amazon CLI 操作创建一个启用了传输中加密(TLS)并具有 AUTH 令牌
的复制组。用已存在的子网组替换子网组 This-is-a-sample-token
sng-test
。
关键参数
-
--engine
– 必须为redis
。 -
--engine-version
– 必须是 3.2.6、4.0.10 或更高版本。 -
--transit-encryption-enabled
– 对于身份验证和 HIPAA 资格是必需的。 -
--auth-token
– 对于 HIPAA 资格是必需的。该值必须是该受令牌保护的 Redis 服务器的正确令牌。 -
--cache-subnet-group
– 对于 HIPAA 资格是必需的。
对于 Linux、macOS 或 Unix:
aws elasticache create-replication-group \ --replication-group-id
authtestgroup
\ --replication-group-descriptionauthtest
\ --engineredis
\ --cache-node-typecache.m4.large
\ --num-node-groups1
\ --replicas-per-node-group2
\ --transit-encryption-enabled \ --auth-tokenThis-is-a-sample-token
\ --cache-subnet-groupsng-test
对于 Windows:
aws elasticache create-replication-group ^ --replication-group-id
authtestgroup
^ --replication-group-descriptionauthtest
^ --engineredis
^ --cache-node-typecache.m4.large
^ --num-node-groups1
^ --replicas-per-node-group2
^ --transit-encryption-enabled ^ --auth-tokenThis-is-a-sample-token
^ --cache-subnet-groupsng-test
修改现有 ElastiCache for Redis 集群上的 AUTH 令牌
为了简化更新身份验证的过程,您可以修改在 ElastiCache for Redis 集群上使用的 AUTH 令牌。如果引擎版本为 5.0.5 或更高版本,并且 ElastiCache for Redis 启用了传输中加密,您可以进行该修改。
修改 AUTH 令牌支持两种策略:ROTATE 和 SET。ROTATE 策略将一个额外的 AUTH 令牌添加到服务器中,同时保留以前的令牌。SET 策略更新服务器以仅支持单个 AUTH 令牌。请使用 --apply-immediately
参数进行这些修改调用以立即应用更改。
轮换 AUTH 令牌
要使用新的 AUTH 令牌更新 Redis 服务器,请调用 ModifyReplicationGroup
API,将 --auth-token
参数作为新的 AUTH 令牌并将 --auth-token-update-strategy
值设置为 ROTATE。在修改完成后,除了 auth-token
参数中指定的 AUTH 令牌以外,集群还支持以前的 AUTH 令牌。
如果您之前未配置 AUTH 令牌,则修改完成后,除在 auth-token 参数中指定的一个令牌外,集群将不支持任何 AUTH 令牌。
如果该修改是在已支持两个 AUTH 令牌的服务器上执行的,还会在该操作期间删除最早的 AUTH 令牌,从而使服务器在给定时间最多支持两个最新的 AUTH 令牌。
此时,您可以继续更新客户端以使用最新的 AUTH 令牌。在更新客户端后,您可以使用 SET 策略轮换 AUTH 令牌(在下一节中说明)以开始使用唯一的新令牌。
以下 Amazon CLI 操作修改复制组以轮换 AUTH 令牌
。This-is-the-rotated-token
对于 Linux、macOS 或 Unix:
aws elasticache modify-replication-group \ --replication-group-id
authtestgroup
\ --auth-tokenThis-is-the-rotated-token
\ --auth-token-update-strategy ROTATE \ --apply-immediately
对于 Windows:
aws elasticache modify-replication-group ^ --replication-group-id
authtestgroup
^ --auth-tokenThis-is-the-rotated-token
^ --auth-token-update-strategy ROTATE ^ --apply-immediately
设置 AUTH 令牌
要更新具有两个 AUTH 令牌的 Redis 服务器以支持单个 AUTH 令牌,请调用 ModifyReplicationGroup
API 操作。调用 ModifyReplicationGroup
,将 --auth-token
参数作为新 AUTH 令牌,并将 --auth-token-update-strategy
参数值设置为 SET。auth-token
参数值必须与上次轮换的 AUTH 令牌相同。在修改完成后,Redis 服务器仅支持 auth-token
参数中指定的 AUTH 令牌。
以下 Amazon CLI 操作修改复制组以将 AUTH 令牌设置为
。This-is-the-set-token
对于 Linux、macOS 或 Unix:
aws elasticache modify-replication-group \ --replication-group-id
authtestgroup
\ --auth-tokenThis-is-the-set-token
\ --auth-token-update-strategy SET \ --apply-immediately
对于 Windows:
aws elasticache modify-replication-group ^ --replication-group-id
authtestgroup
^ --auth-tokenThis-is-the-set-token
^ --auth-token-update-strategy SET ^ --apply-immediately
在现有 ElastiCache for Redis 集群上启用身份验证
要在现有 Redis 服务器上启用身份验证,请调用 ModifyReplicationGroup
API 操作。调用 ModifyReplicationGroup
,将 --auth-token
参数作为新令牌,并将 --auth-token-update-strategy
参数值设置为 ROTATE。
在修改完成后,除了支持未进行身份验证的连接以外,集群还支持 auth-token
参数中指定的 AUTH 令牌。仅在启用了传输中加密(TLS)的 Redis 服务器上支持启用身份验证。
从 RBAC 迁移到 Redis AUTH
如果您使用 Redis 基于角色的访问控制(RBAC)对用户进行身份验证,如使用基于角色的访问控制(RBAC)对用户进行身份验证中所述,并希望迁移到 Redis AUTH,请使用以下过程。您可以使用控制台或 CLI 进行迁移。
使用控制台从 RBAC 迁移到 Redis AUTH
登录 Amazon Web Services Management Console 并打开 ElastiCache 控制台(https://console.aws.amazon.com/elasticache/
)。 -
从右上角的列表中,选择要修改的集群所在的 Amazon 区域。
-
在导航窗格中,选择在您要修改的集群上运行的引擎。
此时会显示选定引擎的集群列表。
-
在集群列表中,对于要修改的集群,选择其名称。
-
对于 Actions(操作),选择 Modify(修改)。
Modify Cluster(修改集群)窗口随即出现。
-
对于 Access Control Option(访问控制选项),选择 Redis AUTH Default User(Redis AUTH 默认用户)。
-
在 AUTH token(AUTH 令牌)下,接受 No change(无更改),转动现有令牌或设置新令牌。
-
选择 Modify(修改)。
使用 Amazon CLI 从 RBAC 迁移到 Redis AUTH
-
使用以下命令之一。
对于 Linux、macOS 或 Unix:
aws elasticache modify-replication-group \ --replication-group-id test \ --remove-user-groups \ --auth-token password \ --auth-token-update-strategy SET \ --apply-immediately
对于 Windows:
aws elasticache modify-replication-group ^ --replication-group-id test ^ --remove-user-groups ^ --auth-token password ^ --auth-token-update-strategy SET ^ --apply-immediately
有关使用 AUTH 的更多信息,请参阅 redis .io 网站上的 AUTH 令牌