Chr*_*ell 10 kubernetes kubernetes-security
我正在尝试以最小许可的方式配置Kubernetes RBAC,我想将角色的范围限定于特定资源和子资源。我浏览了文档,找不到资源及其子资源的简明清单。
我对支配Deployment规范的一部分的子资源(容器映像)特别感兴趣。
Doc*_*tor 15
使用kubectl api-resources -o wide
显示所有资源,动词和关联的API-group。
$ kubectl api-resources -o wide
NAME SHORTNAMES APIGROUP NAMESPACED KIND VERBS
bindings true Binding [create]
componentstatuses cs false ComponentStatus [get list]
configmaps cm true ConfigMap [create delete deletecollection get list patch update watch]
endpoints ep true Endpoints [create delete deletecollection get list patch update watch]
events ev true Event [create delete deletecollection get list patch update watch]
limitranges limits true LimitRange [create delete deletecollection get list patch update watch]
namespaces ns false Namespace [create delete get list patch update watch]
nodes no false Node [create delete deletecollection get list patch update watch]
persistentvolumeclaims pvc true PersistentVolumeClaim [create delete deletecollection get list patch update watch]
persistentvolumes pv false PersistentVolume [create delete deletecollection get list patch update watch]
pods po true Pod [create delete deletecollection get list patch update watch]
statefulsets sts apps true StatefulSet [create delete deletecollection get list patch update watch]
meshpolicies authentication.istio.io false MeshPolicy [delete deletecollection get list patch create update watch]
policies authentication.istio.io true Policy [delete deletecollection get list patch create update watch]
...
...
Run Code Online (Sandbox Code Playgroud)
我想您可以使用它来创建RBAC配置中所需的资源列表
定义RBAC角色所需的资源,子资源和动词未记录在静态列表中的任何位置。它们可在发现文档中找到,即通过API获得,例如/api/apps/v1
。
以下bash脚本将以以下格式列出所有资源,子资源和动词:
api_version resource: [verb]
Run Code Online (Sandbox Code Playgroud)
哪里api-version
是core
核心资源,应该""
在您的角色定义中替换为(带引号的空字符串)。
例如,core pods/status: get patch update
。
该脚本需要jq。
#!/bin/bash
SERVER="localhost:8080"
APIS=$(curl -s $SERVER/apis | jq -r '[.groups | .[].name] | join(" ")')
# do core resources first, which are at a separate api location
api="core"
curl -s $SERVER/api/v1 | jq -r --arg api "$api" '.resources | .[] | "\($api) \(.name): \(.verbs | join(" "))"'
# now do non-core resources
for api in $APIS; do
version=$(curl -s $SERVER/apis/$api | jq -r '.preferredVersion.version')
curl -s $SERVER/apis/$api/$version | jq -r --arg api "$api" '.resources | .[]? | "\($api) \(.name): \(.verbs | join(" "))"'
done
Run Code Online (Sandbox Code Playgroud)
警告:请注意,如果没有通过api列出动词,则输出将仅显示api版本和资源,例如
core pods/exec:
Run Code Online (Sandbox Code Playgroud)
在以下资源的特定实例中,没有通过api显示任何动词,这是错误的(Kubernetes错误#65421,由#65518修复):
nodes/proxy
pods/attach
pods/exec
pods/portforward
pods/proxy
services/proxy
Run Code Online (Sandbox Code Playgroud)
这些资源支持的动词如下:
nodes/proxy: create delete get patch update
pods/attach: create get
pods/exec: create get
pods/portforward: create get
pods/proxy: create delete get patch update
services/proxy: create delete get patch update
Run Code Online (Sandbox Code Playgroud)
警告2:有时Kubernetes使用此处未列出的专用动词检查其他权限。例如,bind
动词是API组中的roles
和clusterroles
资源所必需的rbac.authorization.k8s.io
。这些专用动词的详细信息可以在此处的文档中找到。
for kind in `kubectl api-resources | tail +2 | awk '{ print $1 }' | sort`; do kubectl explain $kind ; done | grep -e "KIND:" -e "VERSION:" | awk '{print $2}' | paste -sd' \n'
Run Code Online (Sandbox Code Playgroud)
您可以从这里找到 Kubernetes v1.26 的资源列表: https: //kubernetes.io/docs/reference/ generated/kubernetes-api/v1.26 / 。对于其他 K8s 版本,请查看https://kubernetes.io/docs/reference/kubernetes-api/
查看左侧的目录,例如,“Workloads”是 Container、Deployment、CronJob 等基本资源类型的高级概述。而“Container、Deployment、CronJob”等子资源是典型的基本资源类型。 Kubernetes API 资源。
您可以通过 kubectl 访问这些基本资源,因此https://kubernetes.io/docs/reference/kubectl/cheatsheet/中还提供了“资源类型”列表
但是我在你的陈述“管理部署规范的一部分的子资源——容器映像”中感到困惑,如果你试图管理容器映像的权限,你应该在你的映像注册表上执行它,但是不在 Kubernetes 这边。例如,您的注册表应该有一个访问控制器,用于在用户拉取镜像时进行身份验证。
我什至犹豫是否将其作为“答案”,但对于评论来说肯定太长了
对于资源列表,您是否知道$HOME/.kube/cache/discovery
Swagger JSON 文件通过与其封闭的apiVersion
. 这是我能找到的最快的链接(查看“发现和使用 CRD”标题)但ls -la ~/.kube/cached/discovery
会显示我的意思。这些 Swagger JSON 文件apiVersion
以一种我发现比 API 参考网站更易于访问的方式列举了所有主要参与者。
我面前没有这些文件来知道它们是否包含子资源定义,所以希望其他人可以对此进行权衡。
“权重”部分的小星号是,根据我对 RBAC 文档和 1.9 API 参考所做的浏览,我没有得到子资源是对其父资源的“字段级访问”的印象。例如,v1beta1/Evictions是一个 Pod 子资源/evictions
,据我所知,它不是其中的一个字段PodSpec
所以,如果你有兴趣做RBAC约束部署的形象,你可能会很大,与快乐的网络挂接模式,其中一个可以有无限的差不多的业务逻辑应用到尝试的请求。
归档时间: |
|
查看次数: |
6862 次 |
最近记录: |