管理 Redis Enterprise 集群 (REC) 凭证

Redis Enterprise for Kubernetes 使用名为 的自定义资源RedisEnterpriseCluster来创建 Redis Enterprise 集群 (REC)。在创建过程中,它会生成随机凭据供操作员使用。凭据保存在 Kubernetes (K8s) secret中。secret 名称默认为集群的名称。

笔记:
此过程仅支持操作员版本 6.0.20-12 及以上版本。

检索当前用户名和密码

凭证可用于访问 Redis Enterprise 管理控制台或 API。必须使用适当的服务(或端口转发)配置与 REC pod 的连接。

  1. 使用命令检查操作员在创建过程中创建的随机用户名和密码kubectl get secret

    kubectl get secret rec -o jsonpath='{.data}'
    

    该命令输出编码的密码和用户名,类似于下面的示例。

    map[password:MTIzNDU2NzgK username:ZGVtb0BleGFtcGxlLmNvbQo=]
    
  2. echo使用上一步中的命令和密码解码密码和用户名。

    echo MTIzNDU2NzgK | base64 --decode
    

    这将以纯文本形式输出密码和用户名。在此示例中,纯文本密码为12345678,用户名为demo@example.com

更改 Redis Enterprise 集群 (REC) 凭证

更改当前用户名的 REC 密码

  1. 访问运行 Redis Enterprise 集群的pod 。

    kubectl exec -it <rec-resource-name>-0 bash
    
  2. 为现有用户添加新密码。

     REC_USER="`cat /opt/redislabs/credentials/username`" \
     REC_PASSWORD="`cat /opt/redislabs/credentials/password`" \
     curl -k --request POST \
       --url https://localhost:9443/v1/users/password \
       -u "$REC_USER:$REC_PASSWORD" \
       --header 'Content-Type: application/json' \
       --data "{\"username\":\"$REC_USER\", \
     \"old_password\":\"$REC_PASSWORD\", \
     \"new_password\":\"<NEW PASSWORD>\"}"
    
  3. 从 pod 外部更新 REC 凭证机密。

    1. 将现有用户名保存到文本文件。

      echo -n "<current_username>" > username 
      
    2. 将新密码保存到文本文件。

      echo -n "<new_password>" > password
      
    3. 更新 REC 凭证机密。

      kubectl create secret generic <cluster_secret_name> \
        --from-file=./username \
        --from-file=./password --dry-run \
        -o yaml
      kubectl apply -f 
      
  4. 等待五分钟,让所有组件从更新的密钥中读取新密码。如果您过早进行下一步,帐户可能会被锁定。

  5. 再次访问运行 Redis Enterprise 集群的 pod。

    kubectl exec -it <rec-resource-name>-0 bash
    
  6. 删除以前的密码以确保只有新密码适用。

    REC_USER="`cat /opt/redislabs/credentials/username`"; \
    REC_PASSWORD="`cat /opt/redislabs/credentials/password`"; \
    curl -k --request DELETE \ 
      --url https://localhost:9443/v1/users/password \
      -u "$REC_USER:$REC_PASSWORD" \
      --header 'Content-Type: application/json' \
      --data "{\"username\":\"$REC_USER\", \
      \"old_password\":\"<OLD PASSWORD\"}"
    
    笔记:
    K8s 机密的用户名是 Redis Enterprise 管理控制台上显示的电子邮件。

更改 REC 用户名和密码

  1. 连接到管理控制台

  2. 添加另一个管理员用户并选择一个新密码。

  3. username在REC 自定义资源规范的字段中指定新用户名。

  4. 更新 REC 凭证机密:

    1. 将现有用户名保存到文本文件。

      echo -n "<current_username>" > username
      
    2. 将新密码保存到文本文件。

      echo -n "<new_password>" > password
      
    3. 更新 REC 凭证机密。

      kubectl create secret generic <cluster_secret_name> \
        --from-file=./username \
        --from-file=./password --dry-run \
        -o yaml
      kubectl apply -f 
      
  5. 等待五分钟,让所有组件从更新的密钥中读取新密码。如果您过早进行下一步,帐户可能会被锁定。

  6. 从集群中删除以前的管理员用户。

笔记:
操作员可能会在更新 REC 规范中的用户名和秘密更新之间的时间内记录错误。

更新 Vault 中的凭据机密

如果您使用 Hashicorp Vault 存储机密,请使用以下键值对更新 REC 凭证的机密:

username:<desired_username>, password:<desired_password>

有关 Vault 与 Redis Enterprise Cluster 集成的更多信息,请参阅将 Redis Enterprise for Kubernetes 与 Hashicorp Vault 集成

给此页面评分
返回顶部 ↑