Set up user sign-in to a CMK cluster with OIDC
OpenID Connect (OIDC) sign-in lets people access a Crusoe Managed Kubernetes (CMK) cluster with their own accounts in your identity provider in place of shared admin credentials. You control what each person can do with Kubernetes role-based access control (RBAC) rules that match the groups that the person belongs to in the identity provider.
OIDC sign-in controls kubectl access to a CMK cluster. It doesn't control sign-in to the Crusoe Cloud console, which uses a separate setup. For the console, see Log in to Crusoe Cloud with Single Sign-On (SSO).
CMK uses standard OIDC settings. This page uses Okta as an example, but settings aren't specific to Okta. For other identity providers, use the provider's matching settings.
How sign-in works
When a person runs kubectl against a cluster with OIDC sign-in, these steps happen:
kubectlreads the person's kubeconfig, which tells it to run the kubelogin plugin to get a token.- kubelogin opens the person's browser at the identity provider's sign-in page.
- The person signs in. The identity provider returns a signed ID token that holds the person's identity and a groups claim. A claim is a named field in the token. The groups claim lists the groups that the person belongs to.
- kubelogin checks the token's signature and caches the token on the person's computer. Later
kubectlcommands use the cached token until it expires. kubectlsends the token to the CMK API server with each request.- The API server checks the token's signature with the identity provider's public keys, then reads the groups claim.
- The API server looks for an RBAC rule that gives one of those groups permission for the request. If it finds one, it runs the request. If it doesn't, it returns a
Forbiddenerror.
In step 7, the API server compares group names as exact strings. The group name in each RBAC rule must match the group name in the token exactly, including case.
Prerequisites
Before you start, make sure that you have the following:
- A Crusoe Cloud project and permission to create CMK clusters in it.
- An OIDC application in your identity provider, with its client ID and issuer URL. In Okta, this is an OIDC app integration.
- A group in your identity provider that holds the people who need access to the cluster.
- The name of the claim in your ID tokens that lists group membership, for example
groups. - The Crusoe CLI and
kubectl. - The kubelogin plugin (
kubectl oidc-login) on the computer of each person who signs in, installed separately from the Crusoe CLI.
OIDC sign-in works on every Kubernetes version that CMK supports, 1.34 and later. To see the versions that you can create a cluster with, run crusoe kubernetes versions list.
1. Create a cluster with OIDC sign-in
You can turn on OIDC sign-in only when you create a cluster. To create the cluster, pass your identity provider's details to the --oidc-provider flag:
crusoe kubernetes clusters create \
--name my-oidc-cluster \
--project-id <project-id> \
--location <location> \
--cluster-version 1.35 \
--oidc-provider client-id=<client-id>,issuer-url=<issuer-url>,groups-claim=groups
CMK v2 uses the latest supported patch of the minor version that you specify, such as 1.35. In locations that still create CMK v1 clusters, use a full version from crusoe kubernetes versions list. For these locations, see What's new in CMK v2. To see the available locations, run crusoe locations list.
The --oidc-provider flag takes comma-separated key-value pairs. This example uses 3 keys:
| Key | Value |
|---|---|
client-id | The client ID of your OIDC application |
issuer-url | The issuer URL of your identity provider. In Okta, this is the URL of the authorization server. |
groups-claim | The name of the token claim that lists the person's groups |
If you leave out groups-claim, the API server reads no groups from the token, so the group-based RBAC rules in step 2 never match. For the other optional keys, run crusoe kubernetes clusters create --help.
2. Grant permissions to groups
A new cluster starts without any RBAC rules for your groups, so OIDC users can't read or modify resources until you provide RBAC rules for access. To add rules, use the cluster's admin credentials:
-
Get admin credentials for the cluster. This command adds them to your kubeconfig:
crusoe kubernetes clusters get-credentials my-oidc-cluster --auth-type=admin_cert -
Create a file named
rbac.yamlwith the following content:rbac.yamlapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: k8s-oidc-limitedrules:- apiGroups: [""]resources: ["nodes", "pods"]verbs: ["get", "list", "watch"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: k8s-oidc-limited-bindingsubjects:- kind: Groupname: k8s-CMK-OIDC # Must match the group name in the token exactlyapiGroup: rbac.authorization.k8s.ioroleRef:kind: ClusterRolename: k8s-oidc-limitedapiGroup: rbac.authorization.k8s.ioThe
ClusterRolelets its holder read nodes and pods across the whole cluster. TheClusterRoleBindinggives that role to the groupk8s-CMK-OIDC. Replacek8s-CMK-OIDCwith the name of your group. -
Apply the file to the cluster:
kubectl apply -f rbac.yamlThe output confirms that both objects exist:
clusterrole.rbac.authorization.k8s.io/k8s-oidc-limited createdclusterrolebinding.rbac.authorization.k8s.io/k8s-oidc-limited-binding created
3. Get OIDC credentials
People who sign in through your identity provider need a kubeconfig that uses OIDC sign-in in place of the admin credentials. To get this kubeconfig, run the following command:
crusoe kubernetes clusters get-credentials my-oidc-cluster --auth-type=oidc
For more about cluster credentials, see Get cluster credentials.
4. Check access
Check that a member of the group can only do what the role allows. If the OIDC credentials aren't in your default kubeconfig, add --kubeconfig <path> to each command.
To check access, run these commands as a member of the group:
-
List the nodes:
kubectl get nodesBecause kubelogin has no cached token yet, this command opens your browser at the identity provider's sign-in page. After you sign in, the command lists the nodes:
NAME STATUS ROLES AGE VERSIONnp-f3fae51e-1.eu-iceland1-a.compute.internal Ready <none> 18h v1.35.8 -
List the pods in all namespaces:
kubectl get pods -ANAMESPACE NAME READY STATUS RESTARTS AGEkube-system cilium-bxv9t 1/1 Running 0 18hkube-system cilium-operator-7ffb994f45-5vx7g 1/1 Running 0 25h -
Request a resource that the role doesn't cover, such as storage classes:
kubectl get storageclassThe API server refuses the request with a
Forbiddenerror:Error from server (Forbidden): storageclasses.storage.k8s.io is forbidden: User "https://<okta-domain>/oauth2/<server-id>#<okta-user-id>" cannot list resource "storageclasses" in API group "storage.k8s.io" at the cluster scopeThe username in the error is the issuer URL, then
#, then the person's user ID from the token. This example shows an Okta issuer URL. The username shows that the API server took the identity from the identity provider's token.