Kubernetes RBAC Integration
Overview
Kublr provides a convenient UI for Kubernetes RBAC management. This article described how access to certain Kubernetes namespaces
can be restricted using this UI. A common use-case is to provide developers with read-only permissions to your production
environment (aka namespace in Kubernetes).
Setup
- Open the Kublr Platform (or, if you don’t have one yet, create one. Please refer to Kublr installation manuals for instructions).
- Go to Keycloak.
![Open Keycloak Screen](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvcmJhYy11aS9vcGVuLWtleWNsb2FrLXNjcmVlbi5wbmcjbm9tYXJnaW4ucG5n&__proxy_form=0)
- In the main Keycloak screen, go to “User” (left menu) and create a new user named “developer” (disable temporary, set email verified). Set a password and add the user to the read-only group named “KublrReadOnlyUsers”.
![Add_read_only](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvYWRkX3RvX2dyb3VwLnBuZw==&__proxy_form=0)
- Go to the Kublr UI, create a space, and name it “production”.
![Add_read_only](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvY3JlYXRlX3NwYWNlLnBuZw==&__proxy_form=0)
- Now, go to the Roles tab and add a new role.
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvY3JlYXRlX3JvbGUucG5n&__proxy_form=0)
- Specify the role parameters, as shown in these screenshots.
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvY3JlYXRlX3J1bGUzLnBuZw==&__proxy_form=0)
- On “KublrReadOnlyUsers,” click “add role binging” to assign the group (e.g., all users named “developer”) to the “production” space and grant them access. These users can now observe clusters in prod without being able to execute any actions. You can find more details about Kublr spaces here Kublr RBAC UI
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvYWRkX3JvbGVfYmluZGluZ18xLnBuZw==&__proxy_form=0)
- Now, switch to the “production” space (top-left menu) and create a cluster (refer to installation manuals for more information).
- Once you created a cluster in the “production” space, go to the cluster overview page and click on the “Open Web Console” link. This will open a terminal with the embedded kubectl. Use it to create a Kubernetes namespace and name it “production”.
![web_console](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvY3JlYXRlX25hbWVzcGFjZS5wbmc=&__proxy_form=0)
- In the newly created cluster, go to the
ADMINISTRATION
tab, which will allow you to manage Kubernetes RBAC. - Use the ROLE BINDING sub-tab.
- Click ADD NEW ROLE BINDING.
![Add New Role Binding](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvYWRkX25ld19yb2xlX2JpbmRpbmcucG5n&__proxy_form=0)
- Fill in the parameters (namespace - production, select role - view), add a subject for the “KublrReadOnlyUsers” group, and assign it a Kubernetes role in Keycloak (and all users in the group). That way, all “developer” users will have a “view role” in the “production” namespace of the cluster.
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvYWRkX25ld19yb2xlX2JpbmRpbmczLnBuZw==&__proxy_form=0)
- Now you’ll need to create an additional Kubernetes role binding to allow users to see all namespaces in the Kubernetes cluster, including those they don’t have access to. Go to “Roles” and create a new role. Then, assign that role to the subject “KublrReadOnlyUsers”
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvY3JlYXRlX2JpbmRpbmdfbnNfcmVhZGVyLnBuZw==&__proxy_form=0)
Your setup is ready. Logout as admin and in again as “developer”. Go to the cluster overview page and click on the “Open Dashboard” link.
You’ll see a list of all resources under the “production” namespace. But if you try to delete something, you’ll get this message:
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvZGV2ZWxvcGVyX2luX3Byb2R1Y3Rpb25fdmlldy5wbmc=&__proxy_form=0)
Additionally, you won’t be able to list resources in any other namespace.
![Add_role](./?url=aHR0cHM6Ly9kb2NzLmt1YmxyLmNvbS9pbWFnZXMvazhzLXJiYWMvZ29fdG9fZGFzaGJvYWRyX2t1YmVfc3lzdGVtLnBuZw==&__proxy_form=0)