permission-manager

概述

Permission ManagerSIGHUP开发的一个应用程序,它可以为 Kubernetes提供超级简单和用户友好的RBAC 管理。如果您正在寻找一种简单直观的方式来管理 Kubernetes 集群中的用户,那么这里就是您的最佳选择。

使用 Permission Manager,您可以创建用户、分配命名空间/权限,并通过简单易用的 Web UI 分发 Kubeconfig YAML 文件

GitHub 源码地址

链接:https://github.com/sighupio/permission-manager

注意事项

作者测试时,最新版本为:v1.7.1-rc1。

在测试时发现有问题,所以安装的 v1.6.0,该版本可以正常使用;

安装

# 创建命名空间
kubectl create namespace permission-manager
# 使用此内容创建一个秘密并相应地更新
cat <<EOF | kubectl apply -f -
---
apiVersion: v1
kind: Secret
metadata:
  name: permission-manager
  namespace: permission-manager
type: Opaque
stringData:
  PORT: "4000" # port where server is exposed
  CLUSTER_NAME: "my-cluster" # name of the cluster to use in the generated kubeconfig file
  CONTROL_PLANE_ADDRESS: "https://172.17.0.3:6443" # full address of the control plane to use in the generated kubeconfig file
  BASIC_AUTH_PASSWORD: "changeMe" # password used by basic auth (username is `admin`)
EOF

部署

kubectl apply -f https://github.com/sighupio/permission-manager/releases/download/v1.6.0/crd.yml
kubectl apply -f https://github.com/sighupio/permission-manager/releases/download/v1.6.0/deploy.yml
kubectl apply -f https://github.com/sighupio/permission-manager/releases/download/v1.6.0/seed.yml

访问应用程序

kubectl port-forward svc/permission-manager 4000 --namespace permission-manager

用户名是admin密码作为秘密安装BASIC_AUTH_PASSWORD

权限分配讲解

permission-manager 创建了 ClusterRole,ClusterRole中分配了权限;在授权的namespace中创建了 RoleBinding 绑定了 ClusterRole;

所以,如果需要给不同的ns授权不同的权限。需要创建不同的 ClusterRole,针对每个 ns 绑定不同的 ClusterRole;

如图:

image-20221226171025004

图中的 TEMPLATE 为我们创建的 ClusterRole

权限分配实操

创建一个 ClusterRole

cat << EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  # ClusterRole 命名规则为 template-namespaced-resources___ + 名称;如下将被识别为 logs-terminal
  name: template-namespaced-resources___logs-terminal
rules:
  - apiGroups:
      - "*"
    resources:
      - "componentstatuses"
      - "namespaces"
      - "nodes"
      - "persistentvolumes"
      - "mutatingwebhookconfigurations"
      - "validatingwebhookconfigurations"
      - "customresourcedefinitions"
      - "apiservices"
      - "tokenreviews"
      - "selfsubjectaccessreviews"
      - "selfsubjectrulesreviews"
      - "subjectaccessreviews"
      - "certificatesigningrequests"
      - "runtimeclasses"
      - "podsecuritypolicies"
      - "clusterrolebindings"
      - "clusterroles"
      - "priorityclasses"
      - "csidrivers"
      - "csinodes"
      - "storageclasses"
      - "volumeattachment"
      - "pods"
      - "pods/log"
      - "pods/portforward"
      - "pods/exec"
      - "podtemplates"
      - "deployments"
    # verbs: ["*"]
    verbs: ["get", "list", "watch", "create"]
EOF

分配权限

image-20221226171338687

这里给不同的 ns(etek-pre、default)分配了不同的 TEMPLATE(ClusterRole);实现了不同ns的不同权限的分配;