Openshift 管理员令牌
Openshift Admin Token
我正在尝试创建一个每 15 分钟记录一次项目资源的脚本。如何使用 Openshift API 进行身份验证?我可以使用对所有命名空间具有读取权限的令牌吗?如何创建可以访问所有命名空间的服务帐户?
您需要创建一个具有资源读取权限的 ClusterRole,并使用 ClusterRoleBinding 将 ServiceAccount 关联到该 ClusterRole。粗略的例子,未经测试但应该可以工作:
# creates the service account "ns-reader"
apiVersion: v1
kind: ServiceAccount
metadata:
name: ns-reader
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: global-reader
rules:
- apiGroups: [""]
# add other rescources you wish to read
resources: ["pods", "secrets"]
verbs: ["get", "watch", "list"]
---
# This cluster role binding allows service account "ns-reader" to read pods in all available namespace
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-ns
subjects:
- kind: ServiceAccount
name: ns-reader
namespace: default
roleRef:
kind: ClusterRole
name: global-reader
apiGroup: rbac.authorization.k8s.io
设置 ServiceAccount 时,会自动创建与其关联的许多机密。其中一些秘密持有一个令牌,然后可以在直接使用 REST API 或使用 oc
时使用。在 ServiceAccount 上使用 oc describe
查看令牌的 Secret 名称。然后在其中一个 Secret 上使用 oc describe
来查看令牌。
我正在尝试创建一个每 15 分钟记录一次项目资源的脚本。如何使用 Openshift API 进行身份验证?我可以使用对所有命名空间具有读取权限的令牌吗?如何创建可以访问所有命名空间的服务帐户?
您需要创建一个具有资源读取权限的 ClusterRole,并使用 ClusterRoleBinding 将 ServiceAccount 关联到该 ClusterRole。粗略的例子,未经测试但应该可以工作:
# creates the service account "ns-reader"
apiVersion: v1
kind: ServiceAccount
metadata:
name: ns-reader
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: global-reader
rules:
- apiGroups: [""]
# add other rescources you wish to read
resources: ["pods", "secrets"]
verbs: ["get", "watch", "list"]
---
# This cluster role binding allows service account "ns-reader" to read pods in all available namespace
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-ns
subjects:
- kind: ServiceAccount
name: ns-reader
namespace: default
roleRef:
kind: ClusterRole
name: global-reader
apiGroup: rbac.authorization.k8s.io
设置 ServiceAccount 时,会自动创建与其关联的许多机密。其中一些秘密持有一个令牌,然后可以在直接使用 REST API 或使用 oc
时使用。在 ServiceAccount 上使用 oc describe
查看令牌的 Secret 名称。然后在其中一个 Secret 上使用 oc describe
来查看令牌。