我试图在AWS集群中创建一个命名空间,并不断地得到一个错误。
我可以使用默认的名称空间来做我想做的任何事情,但是当我尝试创建一个新的名称空间名称时,我是被禁止的。
这肯定是我对用户“thera”做错了一些事情。也许是角色约束?
看起来我给了角色访问所有东西的权限,因为在规则中我给了它*通配符。
我用的命令是-
kubectl create namespace ernie
我所犯的错误是-
Error from server (Forbidden): namespaces is forbidden: User "thera-eks" cannot create resource "namespaces" in API group "" at the cluster scope
我的role.yaml是:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: full_access
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
我的rolebinding.yaml是:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: full_access_role_binding
subjects:
- kind: User
name: thera-eks
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: full_access
apiGroup: rbac.authorization.k8s.io
auth配置映射是:
data:
mapRoles: |
- groups:
- system:bootstrappers
- system:nodes
rolearn: arn:aws:iam::9967xxxxxxxx:role/eksctl-ops-nodegroup-linux-ng-sys-NodeInstanceRole-346VJPTOXI7L
username: system:node:{{EC2PrivateDNSName}}
- groups:
- eks-role
- system:master
rolearn: arn:aws:iam::9967xxxxxxxx:role/thera-eks
username: thera-eks
mapUsers: |
- userarn: arn:aws:iam::9967xxxxxxxx:user/test-ecr
username: test-ecr
groups:
- eks-role
角色“thera”的AWS IAM权限JSON是-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:ListImages",
"ecr:PutImage",
"ecr:UploadLayerPart",
"ecr:GetAuthorizationToken"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"eks:*",
"iam:ListRoles",
"sts:AssumeRole"
],
"Resource": "*"
}
]
}
发布于 2020-11-17 10:25:58
@mdaniel和@PEkambaram是对的,但为了更好地理解,我想扩展并支持官方文件:
RBAC
Role
或ClusterRole
包含表示一组权限的规则。权限纯粹是加性的(没有“拒绝”规则)。Role
总是在特定的名称空间中设置权限;创建Role
时,必须指定它所属的名称空间。 相比之下,ClusterRole
是一个非命名空间的资源。资源有不同的名称(Role
和ClusterRole
),因为Kubernetes对象总是必须有名称空间或没有名称空间;不能两者兼而有之。ClusterRoles
有几个用途。您可以使用ClusterRole
来:
如果要在命名空间中定义角色,请使用Role
**;(如果要定义角色集群范围内的角色),使用** ClusterRole
**.**。
您还将找到一个ClusterRole示例。
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: secret-reader
rules:
- apiGroups: [""]
#
# at the HTTP level, the name of the resource for accessing Secret
# objects is "secrets"
resources: ["secrets"]
verbs: ["get", "watch", "list"]
apiVersion: rbac.authorization.k8s.io/v1
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
kind: ClusterRoleBinding
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: manager # Name is case sensitive
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
链接的文档将通过示例向您展示所有必要的细节,这些示例将帮助您理解和设置RBAC。
发布于 2020-11-17 07:08:33
用户“thera”没有创建命名空间的权限。
使用下面的命令检查是否允许创建命名空间
kubectl auth can-i create namespace
创建命名空间对象需要具有群集级别的权限。定义集群角色并在集群绑定中映射用户
https://stackoverflow.com/questions/64866349
复制相似问题