Role-based access control is a method to regulate access of individuals and services to compute and network resources.
We distinguish in: i) namespaced (e.g. pods) and ii) non-namespaced resources (e.g. nodes, persistent volumes). You can check them with:
kubectl api-resources --namespaced=true
Namespaced and non-namespaced resources are respectively handled by RBAC via namespaced Roles and non-namespaced clusterRoles. Roles and ClusterRoles define a set of permissions available (applicable) on resources, whereas role- and clusterrole- bindings specify who gets the permissions, i.e. the actual application of permissions, on either one namespace or all namespaces (both current and future created ones).
For instance, to see default roles in k8s - https://kubernetes.io/docs/reference/access-authn-authz/rbac/.
You can create a role with:
kubectl -n <ns> create role <name> --verb=<verb> --resource=<res> -o yaml
Bindings are additive and specify what is allowed, so everything else is denied by default. Similarly:
kubectl -n <ns> create rolebinding <name> --role=<role-name> --user=<user> -o yaml
You can use the auth command to verify whethere a user can perform specific verb on resource:
- kubectl auth can-i <verb> <resource>
- kubectl auth can-i list pods --all-namespaces
- kubectl auth can-i <verb> <resource> --as <user>
Also, you can check bindings for a user in openshift - https://docs.openshift.com/container-platform/3.7/admin_guide/manage_rbac.html
In K8s, there are 2 types of accounts: i) regular Users and ii) ServiceAccounts. The latter are a specific k8s resource and are managed by the k8s API, whereas users are not a specific resource, rather somebody with a client certificate that can connect to the cluster:
- the client cert is a certificate signed by the cluster certificate authority (CA) and has a specified username under the common name "/CN=<username>" in the certificate
- to get a signed cert, the client perform a certificate signing request to the kube api, and upon successfull login the k8s kube api uses its CA to sign the cert, update the signing request to include the cert and let the client download it and use it;
No comments:
Post a Comment