Find out about the permissions required to access clusters you've created using Kubernetes Engine (OKE).
To perform operations on a Kubernetes cluster, you must have appropriate permissions to access the cluster.
For most operations on Kubernetes clusters created and managed by Kubernetes Engine, Oracle Cloud Infrastructure Identity and Access Management (IAM) provides access control. A user's permissions to access clusters comes from the IAM groups (including dynamic groups) to which they belong. The permissions for a group are defined by policies. Policies define what actions members of a group can perform, and in which compartments. Users can then access clusters and perform operations based on the policies set for the groups they are members of.
IAM provides control over:
SeePolicy Configuration for Cluster Creation and Deployment.
In addition to IAM, the Kubernetes RBAC Authorizer can enforce additional fine-grained access control for users on specific clusters via Kubernetes RBAC roles and clusterroles. A Kubernetes RBAC role is a collection of permissions. For example, a role might include read permission on pods and list permission for pods. A Kubernetes RBAC clusterrole is just like a role, but can be used anywhere in the cluster. A Kubernetes RBAC rolebinding maps a role to a user or group, granting that role's permissions to the user or group for resources in that namespace. Similarly, a Kubernetes RBAC clusterrolebinding maps a clusterrole to a user or group, granting that clusterrole's permissions to the user or group across the entire cluster.
IAM and the Kubernetes RBAC Authorizer work together to enable users who have been successfully authorized by at least one of them to complete the requested Kubernetes operation. You can use OCIDs to map Kubernetes RBAC rolebindings and clusterrolebindings to IAM users and groups (including dynamic groups).
When a user attempts to perform any operation on a cluster (except for create role and create clusterrole operations), IAM first determines whether a group (or dynamic group) to which the user belongs has the appropriate and sufficient permissions. If so, the operation succeeds. If the attempted operation also requires additional permissions granted via a Kubernetes RBAC role or clusterrole, the Kubernetes RBAC Authorizer then determines whether the user or group has been granted the appropriate Kubernetes role or clusterrole.
Typically, you'll want to define your own Kubernetes RBAC roles and clusterroles when deploying a Kubernetes cluster to provide additional fine-grained control. When you attempt to perform a create role or create clusterrole operation, the Kubernetes RBAC Authorizer first determines whether you have sufficient Kubernetes privileges. To create a role or clusterrole, you must have been assigned an existing Kubernetes RBAC role (or clusterrole) that has at least the same or higher privileges as the new role (or clusterrole) you're attempting to create.
By default, users are not assigned any Kubernetes RBAC roles (or clusterroles) by default. So before attempting to create a new role (or clusterrole), you must be assigned an appropriately privileged role (or clusterrole). A number of such roles and clusterroles are always created by default, including the cluster-admin clusterrole (for a full list, seeDefault Roles and Role Bindings in the Kubernetes documentation). The cluster-admin clusterrole essentially confers super-user privileges. A user granted the cluster-admin clusterrole can perform any operation across all namespaces in a given cluster.
Note that Oracle Cloud Infrastructure tenancy administrators already have sufficient privileges, and do not require the cluster-admin clusterrole.
The following instructions assume:
Follow these steps to grant a user who is not a tenancy administrator the Kubernetes RBAC cluster-admin clusterrole on a cluster deployed on Oracle Cloud Infrastructure:
In a terminal window, grant the Kubernetes RBAC cluster-admin clusterrole to the user by entering:
kubectl create clusterrolebinding <my-cluster-admin-binding> --clusterrole=cluster-admin --user=<user_OCID>where:
<my-cluster-admin-binding> is a string of your choice to be used as the name for the binding between the user and the Kubernetes RBAC cluster-admin clusterrole. For example,jdoe_clst_adm<user_OCID> is the user's OCID (obtained from the Console ). For example,ocid1.user.oc1..aaaaa...zutq (abbreviated for readability).For example:
kubectl create clusterrolebinding jdoe_clst_adm --clusterrole=cluster-admin --user=ocid1.user.oc1..aaaaa...zutqFollow these steps to give a non-administrator user the necessary Oracle Cloud Infrastructure and Kubernetes RBAC permissions to view pods running on a Kubernetes cluster. In this example, a non-administrator user is given explicit access to the cluster (rather than as a member of a group).
ocid1.user.oc1..aa______tx5a, abbreviated for readability).acme-developer-group), and add the new IAM user account to the group. SeeTo create a group.Allow group acme-developer-group to use clusters in <location>In the above policy statement, replace<location> with eithertenancy (if you are creating the policy in the tenancy's root compartment) orcompartment <compartment-name> (if you are creating the policy in an individual compartment). SeeTo create a policy.
Note that if a group is not in the default identity domain, prefix the group name with the identity domain name, in the formatgroup '<identity-domain-name>'/'group-name'. You can also specify a group using its OCID, in the formatgroup id <group-ocid>.
pod-reader-user.yaml) to define a Kubernetes RBAC role and role binding to enable the new IAM user account to list pods in the kube-system namespace:kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: pod-reader-ks namespace: kube-systemrules:- apiGroups: [""] resources: ["pods"] verbs: ["get", "watch", "list"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: pod-reader-ks-role-binding namespace: kube-systemsubjects:- kind: User name: <user-ocid> apiGroup: rbac.authorization.k8s.ioroleRef: kind: Role name: pod-reader-ks apiGroup: rbac.authorization.k8s.iowherename: <user-ocid> specifies the OCID of the new IAM user account you created previously. For example,name: ocid1.user.oc1..aa______tx5a
kubectl apply -f pod-reader-user.ymlkubectl get pods -n kube-systemFollow these steps to give non-administrator users in a group the necessary Oracle Cloud Infrastructure and Kubernetes RBAC permissions to view pods running on a Kubernetes cluster. In this example, non-administrator users are given access to the cluster as members of an IAM group (you could specify a dynamic group instead).
acme-developer-group), and add the new IAM user account to the group. SeeTo create a group.ocid1.group.oc1..aa______m7dt, abbreviated for readability).Allow group acme-developer-group to use clusters in <location>In the above policy statement, replace<location> with eithertenancy (if you are creating the policy in the tenancy's root compartment) orcompartment <compartment-name> (if you are creating the policy in an individual compartment). SeeTo create a policy.
Note that if a group is not in the default identity domain, prefix the group name with the identity domain name, in the formatgroup '<identity-domain-name>'/'group-name'. You can also specify a group using its OCID, in the formatgroup id <group-ocid>.
pod-reader-group.yaml) to define a Kubernetes RBAC role and role binding to enable users in the new IAM group to list pods in the kube-system namespace:kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: pod-reader-ks namespace: kube-systemrules:- apiGroups: [""] resources: ["pods"] verbs: ["get", "watch", "list"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: pod-reader-ks-role-binding namespace: kube-systemsubjects:- kind: Group name: <group-ocid> apiGroup: rbac.authorization.k8s.ioroleRef: kind: Role name: pod-reader-ks apiGroup: rbac.authorization.k8s.iowherename: <group-ocid> specifies the OCID of the new IAM group you created previously. For example,name: ocid1.group.oc1..aa______m7dt
kubectl apply -f pod-reader-group.ymlkubectl get pods -n kube-systemFollow these steps to give non-administrator users in a group the necessary Oracle Cloud Infrastructure and Kubernetes RBAC permissions to view pods running on a Kubernetes cluster. In this example, a non-administrator user is given access to the cluster either explicitly or as member of an IAM group (you could specify a dynamic group instead).
ocid1.user.oc1..aa______4gs6, abbreviated for readability).acme-developer-group), and add the new IAM user account to the group. SeeTo create a group.ocid1.group.oc1..aa______e26f, abbreviated for readability).Allow group acme-developer-group to use clusters in <location>In the above policy statement, replace<location> with eithertenancy (if you are creating the policy in the tenancy's root compartment) orcompartment <compartment-name> (if you are creating the policy in an individual compartment). SeeTo create a policy.
Note that if a group is not in the default identity domain, prefix the group name with the identity domain name, in the formatgroup '<identity-domain-name>'/'group-name'. You can also specify a group using its OCID, in the formatgroup id <group-ocid>.
secrets-reader.yaml):apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: secret-readerrules:- apiGroups: [""] resources: ["secrets"] verbs: ["get", "watch", "list"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: read-secrets-globalsubjects:- kind: User name: <user-ocid> apiGroup: rbac.authorization.k8s.ioroleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.iowherename: <user-ocid> specifies the OCID of the new IAM user you created previously. For example,name: ocid1.user.oc1..aa______4gs6
secrets-reader.yaml):apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: secret-readerrules:- apiGroups: [""] resources: ["secrets"] verbs: ["get", "watch", "list"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: read-secrets-globalsubjects:- kind: Group name: <group-ocid> apiGroup: rbac.authorization.k8s.ioroleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.iowherename: <group-ocid> is the OCID of the new IAM group you created previously. For example,ocid1.group.oc1..aa______e26f
kubectl apply -f secret-reader.ymlkubectl get secrets --all-namespaces