
Integrating an external identity provider (IdP) with Kubernetes allows you to centralize user authentication and leverage existing identity management workflows. OpenID Connect (OIDC) is the standard protocol for this integration, enabling secure authentication against providers like Okta. By using Okta, you can enforce consistent security policies, manage user access from a single dashboard, and give a seamless Single Sign-on (SSO) experience for developers accessing your Vultr Kubernetes Engine (VKE).
This guide explains how to automate the entire integration process using Terraform. You will configure an OIDC application in Okta, deploy a VKE cluster with OIDC authentication enabled, and set up the necessary kubectl plugins to authenticate users with their Okta credentials.
Before you begin, you need to:
This section provides the steps to provision the Okta OIDC application using a pre-configured Terraform project from a Git repository. This automates the creation of the necessary resources in Okta, ensuring your configuration is repeatable and version-controlled.
Clone the Terraform manifests repository from GitHub.
Edit the terraform.tfvars and set your Okta credentials.
Update the following variables:
Save and close the file.
For example, if your Okta domain is trial-9859852.okta.com, then use the following values:
trial-9859852 - This is the subdomain part of your Okta URL.okta.com - This is the root domain used across all Okta tenants.Initialize Terraform to download the Okta provider.
Validate the manifest file to check for syntax errors and ensure that the manifest is correct.
This above command should display a success output confirming that the configuration is valid.
Review the execution plan to see the resources Terraform will create.
Apply the manifest to create the Okta application and related resources.
When prompted, enter yes to allow Terraform to create the following resources:
k8s-admins: A group for users who will have admin access to the VKE Cluster.k8s-restricted-users: A group for users who will have limited access.k8s-auth is created which is linked to the VKE OIDC application.k8s-.After the command completes, Terraform will display the output with the credentials for your OIDC application, save these credentials for later use:
In this section, you will provision a VKE cluster by making a direct API call using curl. This approach allows you to include the OIDC configuration retrieved from Okta, enabling secure authentication integration between your VKE cluster and Okta's identity provider.
Set environment variables for your Vultr API Key and the OIDC values from the Terraform output.
In the above commands, replace YOUR_VULTR_API_KEY with your Vultr API Key, YOUR_ISSUER_URL with your Okta Authorization Server Issuer URL, YOUR_CLIENT_ID with your Okta Client ID provided by Terraform output.
Run the following curl command to create the VKE cluster. It sends a POST request to the Vultr API with your cluster definition, including the OIDC configuration.
This request provisions a VKE cluster with the following settings:
v1.33.0+1 is deployed. To use the latest available version, send a GET request to list all supported Kubernetes versions.ewr region. This refers to Vultr's New Jersey (EWR) region. You can list all available regions by sending a GET request.issuer_url: The base URL of your OIDC provider's discovery document. Kubernetes uses this to fetch metadata and validate ID tokens.client_id: The Client ID of your registered OIDC application. It ensures that the tokens are issued for this Kubernetes cluster.username_claim: The claim from the ID token that Kubernetes will use as the username. Typically set to sub, which is a unique and immutable user ID.groups_claim: The claim in the ID token that lists the user's groups. Used to assign RBAC roles in Kubernetes.4 nodes with autoscaling enabled between 4 and 8 nodes.vhp-2c-4gb-amd compute plan for each node. Modify the configuration as needed to match your infrastructure requirements. The response includes a id, which you can use to check the cluster status by sending a GET request.
After the cluster is provisioned, download the kubeconfig.yml file from the Vultr Console.
Move the kubeconfig.yml file to the default Kubernetes configuration directory and rename it to config.
Replace /path/to/kubeconfig.yml with the actual path to the file you downloaded. If you already have a ~/.kube/config file, back it up first to avoid overwriting existing configurations:
Verify that your system can communicate with the VKE API server by running the following command.
This above command returns the number of nodes available in the VKE Cluster.
Use the following steps to install Krew, the plugin manager for kubectl, and the oidc-login plugin, which enables authentication via Okta OIDC.
Create a file named install-krew.sh.
Add the following script to the file.
Save and exit the file.
Give the executable permission to the file.
Execute the script to install the krew plugin manager.
Add the krew's installation directory to your PATH.
Add the above line to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc) to persist it across sessions.
Install the oidc-login plugin using Krew.
This plugin enables kubectl to authenticate with Kubernetes clusters using the OIDC login flow provided by Okta.
To clear the saved OIDC authentication cache, run the following command:
In this section, you define the RBAC roles and create separate kubectl contexts for your admin and restricted users. This allows you to test the OIDC integration and verify that the correct permissions are applied based on Okta group membership.
Use the following pre-created YAML files located in the k8s/ directory to configure role-based access for your Okta user groups:
k8s-admins-CRB.yaml: Grants full cluster-wide administrative access to users in the k8s-admins group by binding it to the built-in cluster-admin role.k8s-restricted-users-CR.yaml: Creates a custom ClusterRole named restricted-pod-access that allows basic pod operations such as listing, creating, updating, and deleting. This role is designed for users with limited access needs.k8s-restricted-users-CRB.yaml: Binds the k8s-restricted-users group to the restricted-pod-access role, enforcing scoped access within the cluster for non-admin users.Apply all RBAC configurations using:
This command provisions the necessary permissions for both admin and restricted users based on group membership defined in your Okta configuration.
Use the following steps to configure Kubernetes access for users in the k8s-admins group.
Clear any cached OIDC authentication tokens.
Export your OIDC credentials and cluster name as environment variables.
Replace each placeholder with the appropriate value:
Use the following command to retrieve the value for the client secret k8s_oidc_client_secret:
Other credentials like OIDC_ISSUER_URL and OIDC_CLIENT_ID can be retrived by running terraform output.
To identify the cluster name, run:
The output lists all available contexts. Use the value in the NAME column that corresponds to your VKE cluster.
Set the OIDC login credentials for the admin user.
The Terraform manifest used in this guide configures the Okta OIDC application with the Application Type set to Web. As a result, you must include the --oidc-client-secret flag in the above command. If you manually configured the application using the native application type, omit the --oidc-client-secret flag or the authentication will fail.
Create and use the admin context.
Run a test command to authenticate and verify access.
This above command opens a browser window for Okta login and after successful authentication, kubectl returns a list of number of nodes in the cluster.
In this guide, you integrated Okta OIDC with VKE to enable secure, centralized authentication for your clusters. You used Terraform to configure the OIDC application in Okta, then deployed a VKE cluster with OIDC authentication enabled via the Vultr API. After downloading and setting up the kubeconfig file, you installed the required CLI tools including kubectl, krew, and the oidc-login plugin. You applied RBAC roles to manage access for admin and restricted users, created separate Kubernetes configurations for each group, and verified access to ensure the correct permissions were enforced through Okta-based authentication.
0 Comments
Be the first to comment and share your perspective with the community.