How can I create a Kubernetes role in which a users can create namespaces in which they can do anything?

10/11/2019

I have created a role, below is definition the role:

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: ${SERVICE_ACCOUNT_NAME}-full-access-role
  namespace: ${NAMESPACE}
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]
- apiGroups: ["batch"]
  resources:
  - jobs
  - cronjobs
  verbs: ["*"]

Using this role a user can create, list and delete any resource in a namespace but problem is it can also list all namespaces in cluster.

I want to enable users to create namespaces and can perform any action in it as well but also they can't list any resource even other namespaces that are't created by the user.

-- Anurag Tamrakar
kubernetes
role-base-authorization
roles

2 Answers

10/11/2019

It would help if you can tell us which cloud platform you are on. To my knowledge, different cloud platforms handle Role based access differently.

With that being said, I believe there should be predefined roles for the specific level of access you want. Usually role based authorization trickles down. If you grant someone access to a resource at the folder level, the user will be able to access all resources in that folder. Since you want to grant access to any resource in an namespace, I would grant the user access at that level.

-- panda
Source: StackOverflow

10/14/2019

I think you cannot deny user access right to list all namespaces and give them the access you need at the same. At least not in the bare metal kubernetes. Read the following GH issue, it's about the similar issue that you encounter.

-- RafaƂ Leszko
Source: StackOverflow