当前位置: 首页 > news >正文

ETCD 权限配置

直接使用
docker exec -it etcd1 etcdctl --endpoints=地址 --user=root:123456 role add test_role && \
docker exec etcd1 etcdctl --endpoints=地址 --user=root:123456 role grant-permission test_role readwrite /test --prefix=true && \
docker exec etcd1 etcdctl --endpoints=地址 --user=root:123456 user add testuser:test_password_123456 && \
docker exec etcd1 etcdctl --endpoints=地址9 --user=root:123456 user grant-role testuser test_role

#!/bin/bash

# etcd 用户权限配置脚本

# 用途:配置 etcd 访问用户和权限

set -e

# 配置参数

ETCD_ENDPOINTS=""

ROOT_PASSWORD=""

APP_USER=""

APP_PASSWORD=""

# 颜色输出

RED='\033[0;31m'

GREEN='\033[0;32m'

YELLOW='\033[1;33m'

NC='\033[0m'

echo -e "${GREEN}========================================${NC}"

echo -e "${GREEN}etcd 用户权限配置脚本${NC}"

echo -e "${GREEN}========================================${NC}"

# 等待集群就绪

echo -e "${YELLOW}[1/8] 等待 etcd 集群就绪...${NC}"

sleep 5

# 检查集群状态

echo -e "${YELLOW}[2/8] 检查集群状态...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} endpoint status --write-out=table

echo -e "${GREEN}✓ 集群运行正常${NC}"

# 创建 root 用户

echo -e "${YELLOW}[3/8] 创建 root 用户...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} user add root:${ROOT_PASSWORD} || echo "root 用户可能已存在"

echo -e "${GREEN}✓ root 用户已配置${NC}"

# 创建应用用户

echo -e "${YELLOW}[4/8] 创建应用用户 (${APP_USER})...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} user add ${APP_USER}:${APP_PASSWORD} || echo "${APP_USER} 用户可能已存在"

echo -e "${GREEN}✓ ${APP_USER} 用户已创建${NC}"

# 创建角色

echo -e "${YELLOW}[5/8] 创建角色...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} role add readwrite || echo "readwrite 角色可能已存在"

echo -e "${GREEN}✓ readwrite 角色已创建${NC}"

# 授予权限(读写所有 key)

echo -e "${YELLOW}[6/8] 授予权限...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} role grant-permission readwrite readwrite '' --prefix=true

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} role grant-permission readwrite read '' --prefix=true

echo -e "${GREEN}✓ 权限已授予${NC}"

# 将用户绑定到角色

echo -e "${YELLOW}[7/8] 绑定用户到角色...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} user grant-role ${APP_USER} readwrite

echo -e "${GREEN}✓ 用户角色绑定完成${NC}"

# 启用认证

echo -e "${YELLOW}[8/8] 启用认证...${NC}"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} auth enable || echo "认证可能已启用"

echo -e "${GREEN}✓ 认证已启用${NC}"

# 测试认证

echo -e "${YELLOW}[测试] 测试认证...${NC}"

echo -e "使用 root 用户测试:"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} --user=root:${ROOT_PASSWORD} put /test/auth "authentication works"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} --user=root:${ROOT_PASSWORD} get /test/auth

echo -e ""

echo -e "使用 ${APP_USER} 用户测试:"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} --user=${APP_USER}:${APP_PASSWORD} put /test/${APP_USER} "app user works"

docker exec etcd1 etcdctl --endpoints=${ETCD_ENDPOINTS} --user=${APP_USER}:${APP_PASSWORD} get /test/${APP_USER}

echo -e ""

echo -e "${GREEN}========================================${NC}"

echo -e "${GREEN}用户权限配置完成!${NC}"

echo -e "${GREEN}========================================${NC}"

echo -e "Root 用户: root"

echo -e "Root 密码: ${ROOT_PASSWORD}"

echo -e ""

echo -e "应用用户: ${APP_USER}"

echo -e "应用密码: ${APP_PASSWORD}"

echo -e ""

echo -e "${YELLOW}重要提示:${NC}"

echo -e "1. 请妥善保管这些密码"

echo -e "2. 建议修改密码: etcdctl user passwd <username>"

echo -e "3. 连接字符串: ${ETCD_ENDPOINTS}"

echo -e ""

echo -e "使用示例:"

echo -e " etcdctl --endpoints=${ETCD_ENDPOINTS} --user=${APP_USER}:${APP_PASSWORD} get / --prefix"

echo -e "${GREEN}========================================${NC}"

http://www.dtcms.com/a/577785.html

相关文章:

  • 数据结构(c++版):深入理解哈希表
  • HIKVISION前端一面面经整理
  • Rocky9基于MySQL安装Zabbix7
  • 安庆网站制作1688阿里巴巴国际站首页
  • 阿里云微服务引擎 MSE 及 API 网关 2025 年 10 月产品动态
  • 太原网站建设内蒙古建设工程造价信息网官网中项网
  • Oracle 19C RAC下TRUNCATE TABLE的REUSE STORAGE选项作用和风险浅析!
  • CentOS 7 Oracle 11g RAC+DataGuard 分阶段静默部署脚本
  • 索牛网站建设江苏省建设厅官网网站首页
  • 三网合一网站系统晋城市网站建设
  • 智慧幼儿园管理系统-幼儿园多园区管理小程序的技术架构与应用实践:重构幼教领域数字化管理范式-幼儿园小程序开发-幼儿园软件开发-幼儿园系统开发定制
  • 精准招聘新纪元:AI 重构选才逻辑
  • 超聚变联手英特尔打造边缘智算一体机,重构工作站市场格局
  • 英国服务器Windows系统远程桌面安装与优化
  • 青岛做网站优化大屏网站模板
  • 多项分布 (Multinomial Distribution)
  • 网站gif横幅广告怎么做网站开发人员篡改客户数据
  • 大模型-vllm的知识点记录-1
  • 哪些网站是用织梦做的php做的直播网站
  • 为云原生加速:深入解析PoleFS分布式缓存系统BlobCache
  • xml方式实现AOP
  • XML签名
  • 云原生基石的试金石:基于 openEuler 部署 Docker 与 Nginx 的全景实录
  • 浏阳网站建设卷云网络南和网站seo
  • postgresql pg_upgrade源码阅读--doing
  • oracle导出 导入
  • 如何自己做个简单网站wordpress 中国提速
  • 程序安装包在ubuntu安装教程,以opencv安装为例
  • Linux 服务器内存监控与优化指南
  • APP应用怎么选择游戏盾