kubernetes-notes
  • 目录
    • 序言
  • 云原生体系
    • 12-Factor
    • K8S知识体系
  • 安装与配置
    • 部署k8s集群
      • 使用kubeadm安装生产环境kubernetes
      • 使用kubespray安装kubernetes
      • 使用minikube安装kubernetes
      • 使用kind安装kubernetes
    • k8s证书及秘钥
    • k8s版本说明
  • 基本概念
    • kubernetes架构
      • Kubernetes总架构图
      • 基于Docker及Kubernetes技术构建容器云(PaaS)平台概述
    • kubernetes对象
      • 理解kubernetes对象
      • kubernetes常用对象说明
    • Pod
      • Pod介绍
      • Pod定义文件
      • Pod生命周期
      • Pod健康检查
      • Pod存储卷
      • Pod控制器
      • Pod伸缩与升级
    • 配置
      • ConfigMap
    • Workload
  • 核心原理
    • 核心组件
      • Api Server
      • Controller Manager
      • Scheduler
      • Kubelet
    • 流程图
      • Pod创建流程
      • PVC创建流程
  • 容器网络
    • Docker网络
    • K8S网络
    • 网络插件
      • Flannel介绍
    • CNI
      • CNI接口介绍
      • Macvlan介绍
  • 容器存储
    • 存储卷概念
      • Volume
      • Persistent Volume
      • Persistent Volume Claim
      • Storage Class
      • Dynamic Volume Provisioning
    • CSI
      • csi-cephfs-plugin
      • 部署csi-cephfs
      • 部署cephfs-provisioner
      • FlexVolume介绍
  • 资源隔离
    • 资源配额
    • Pod限额
    • 资源服务质量
    • Lxcfs资源视图隔离
  • 运维指南
    • kubectl工具
      • kubectl安装与配置
      • kubectl命令说明
      • kubectl命令别名
    • kubernetes集群问题排查
    • 节点调度
      • 安全迁移节点
      • 指定Node调度与隔离
    • 镜像仓库配置
      • 配置私有的镜像仓库
      • 拉取私有镜像
  • 开发指南
    • client-go的使用及源码分析
    • CSI插件开发
      • nfs-client-provisioner源码分析
      • csi-provisioner源码分析
    • operator开发
      • kubebuilder的使用
  • 问题排查
    • 节点相关问题
      • keycreate permission denied
      • Cgroup不支持pid资源
      • Cgroup子系统无法挂载
    • Pod驱逐
    • 镜像拉取失败问题
    • PVC Terminating
  • 源码分析
    • Kubernetes源码分析笔记
    • kubelet
      • NewKubeletCommand
      • NewMainKubelet
      • startKubelet
      • syncLoopIteration
      • syncPod
    • kube-controller-manager
      • NewControllerManagerCommand
      • DeploymentController
      • Informer机制
    • kube-scheduler
      • NewSchedulerCommand
      • registerAlgorithmProvider
      • scheduleOne
      • findNodesThatFit
      • PrioritizeNodes
      • preempt
    • kube-apiserver
      • NewAPIServerCommand
  • Runtime
    • Runtime
      • Runc和Containerd概述
    • Containerd
      • 安装Containerd
    • Docker
      • Docker学习笔记
    • Kata Container
      • kata容器简介
      • kata配置
    • GPU
      • nvidia-device-plugin介绍
  • Etcd
    • Etcd介绍
    • Raft算法
    • Etcd启动配置参数
    • Etcd访问控制
    • etcdctl命令工具
      • etcdctl命令工具-V3
      • etcdctl命令工具-V2
    • Etcd中的k8s数据
    • Etcd-Operator的使用
  • 多集群管理
    • k8s多集群管理的思考
    • Virtual Kubelet
      • Virtual Kubelet介绍
      • Virtual Kubelet 命令
    • Karmada
      • Karmada介绍
  • 边缘容器
    • KubeEdge介绍
    • KubeEdge源码分析
      • cloudcore
      • edgecore
    • OpenYurt部署
  • 虚拟化
    • 虚拟化相关概念
    • KubeVirt
      • KubeVirt的介绍
      • KubeVirt的使用
  • 监控体系
    • 监控体系介绍
    • cAdvisor介绍
    • Heapster介绍
    • Influxdb介绍
由 GitBook 提供支持

www.huweihuang.com

在本页
  • 1. ETCD资源类型
  • 2. 权限资源
  • 3. ETCD访问控制
  • 3.1. 访问控制相关命令
  • 3.2. user相关命令
  • 3.2.1. 添加root用户并设置密码
  • 3.2.2. 添加非root用户并设置密码
  • 3.2.3. 查看当前所有用户
  • 3.2.4. 将用户添加到对应角色
  • 3.2.5. 查看用户拥有哪些角色
  • 3.3. role相关命令
  • 3.3.1. 添加角色
  • 3.3.2. 查看所有角色
  • 3.3.3. 给角色分配权限
  • 3.3.4. 查看角色所拥有的权限
  • 3.4. auth相关操作
  • 3.4.1. 开启认证
  • 4. 访问控制设置步骤
  • 5. 访问认证的API调用

这有帮助吗?

在GitHub上编辑
  1. Etcd

Etcd访问控制

1. ETCD资源类型

There are three types of resources in etcd

  • permission resources: users and roles in the user store

  • key-value resources: key-value pairs in the key-value store

  • settings resources: security settings, auth settings, and dynamic etcd cluster settings (election/heartbeat)

2. 权限资源

Users:user用来设置身份认证(user:passwd),一个用户可以拥有多个角色,每个角色被分配一定的权限(只读、只写、可读写),用户分为root用户和非root用户。

Roles:角色用来关联权限,角色主要三类:root角色。默认创建root用户时即创建了root角色,该角色拥有所有权限;guest角色,默认自动创建,主要用于非认证使用。普通角色,由root用户创建角色,并分配指定权限。

注意:如果没有指定任何验证方式,即没显示指定以什么用户进行访问,那么默认会设定为 guest 角色。默认情况下 guest 也是具有全局访问权限的。如果不希望未授权就获取或修改etcd的数据,则可收回guest角色的权限或删除该角色,etcdctl role revoke 。

Permissions:权限分为只读、只写、可读写三种权限,权限即对指定目录或key的读写权限。

3. ETCD访问控制

3.1. 访问控制相关命令

NAME:
   etcdctl - A simple command line client for etcd.
USAGE:
   etcdctl [global options] command [command options] [arguments...]
VERSION:
   2.2.0
COMMANDS:
   user         user add, grant and revoke subcommands
   role         role add, grant and revoke subcommands
   auth         overall auth controls  
GLOBAL OPTIONS:
   --peers, -C          a comma-delimited list of machine addresses in the cluster (default: "http://127.0.0.1:4001,http://127.0.0.1:2379")
   --endpoint           a comma-delimited list of machine addresses in the cluster (default: "http://127.0.0.1:4001,http://127.0.0.1:2379")
   --cert-file          identify HTTPS client using this SSL certificate file
   --key-file           identify HTTPS client using this SSL key file
   --ca-file            verify certificates of HTTPS-enabled servers using this CA bundle
   --username, -u       provide username[:password] and prompt if password is not supplied.
   --timeout '1s'       connection timeout per request

3.2. user相关命令

[root@localhost etcd]# etcdctl user --help
NAME:
   etcdctl user - user add, grant and revoke subcommands
USAGE:
   etcdctl user command [command options] [arguments...]
COMMANDS:
   add      add a new user for the etcd cluster
   get      get details for a user
   list     list all current users
   remove   remove a user for the etcd cluster
   grant    grant roles to an etcd user
   revoke   revoke roles for an etcd user
   passwd   change password for a user
   help, h  Shows a list of commands or help for one command
    
OPTIONS:
   --help, -h   show help

3.2.1. 添加root用户并设置密码

3.2.2. 添加非root用户并设置密码

3.2.3. 查看当前所有用户

3.2.4. 将用户添加到对应角色

3.2.5. 查看用户拥有哪些角色

3.3. role相关命令

[root@localhost etcd]# etcdctl role --help
NAME:
   etcdctl role - role add, grant and revoke subcommands
USAGE:
   etcdctl role command [command options] [arguments...]
COMMANDS:
   add      add a new role for the etcd cluster
   get      get details for a role
   list     list all roles
   remove   remove a role from the etcd cluster
   grant    grant path matches to an etcd role
   revoke   revoke path matches for an etcd role
   help, h  Shows a list of commands or help for one command
    
OPTIONS:
   --help, -h   show help

3.3.1. 添加角色

3.3.2. 查看所有角色

3.3.3. 给角色分配权限

[root@localhost etcd]# etcdctl role grant --help
NAME:
   grant - grant path matches to an etcd role
USAGE:
   command grant [command options] [arguments...]
OPTIONS:
   --path   Path granted for the role to access
   --read   Grant read-only access
   --write  Grant write-only access
   --readwrite  Grant read-write access

3.3.4. 查看角色所拥有的权限

3.4. auth相关操作

[root@localhost etcd]# etcdctl auth --help
NAME:
   etcdctl auth - overall auth controls
USAGE:
   etcdctl auth command [command options] [arguments...]
COMMANDS:
   enable   enable auth access controls
   disable  disable auth access controls
   help, h  Shows a list of commands or help for one command
    
OPTIONS:
   --help, -h   show help

3.4.1. 开启认证

4. 访问控制设置步骤

顺序
步骤
命令

1

添加root用户

etcdctl --endpoints http://: user add root

2

开启认证

etcdctl --endpoints http://: auth enable

3

添加非root用户

etcdctl --endpoints http://: –username root: user add

4

添加角色

etcdctl --endpoints http://: –username root: role add

5

给角色授权(只读、只写、可读写)

etcdctl --endpoints http://: –username root: role grant --readwrite --path

6

给用户分配角色(即分配了角色对应的权限)

etcdctl --endpoints http://: –username root: user grant --roles

5. 访问认证的API调用

更多参考

  • https://coreos.com/etcd/docs/latest/v2/auth_api.html

  • https://coreos.com/etcd/docs/latest/v2/authentication.html

上一页Etcd启动配置参数下一页etcdctl命令工具

最后更新于2年前

这有帮助吗?

etcdctl --endpoints user add root

etcdctl --endpoints --username root:123 user add huwh

etcdctl --endpoints --username root:123 user list

etcdctl --endpoints --username root:123 user grant --roles test1 phpor

etcdctl --endpoints --username root:123 user get phpor

etcdctl --endpoints --username root:2379 role add test1

etcdctl --endpoints --username root:123 role list

1、只包含目录 etcdctl --endpoints --username root:123 role grant --readwrite --path /test1 test1

2、包括目录和子目录或文件 etcdctl --endpoints --username root:123 role grant --readwrite --path /test1/* test1

etcdctl --endpoints --username root:2379 role get test1

etcdctl --endpoints auth enable

http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379
http://172.16.22.36:2379