Introduction
Authenticating to AWS EKS (Elastic Kubernetes Service) using AWS IAM (Identity and Access Management) credentials is a crucial aspect of managing and securing these clusters. However, IAM is not the only option when it comes to authenticating with these clusters. You can also configure additional IDP (identity providers) for this purpose. In this post today, I’ll explain the steps necessary to authenticate with Okta.
Pre-requisities
Before diving into the specifics, please ensure you have the following -
- An Okta app, with it’s corresponding client id/secret.
- Terraform configs which create the cluster, and have admin level access to configure the cluster.
Configuring the EKS OIDC IDP Module
Use this module in your Terraform configuration, specifying the required input variables such as cluster name, cluster email, IDP client ID, issuer URL, group claims, username claims, and admin/readonly groups and users. A sample config will look like this -
1module eks_oidc_idp { 2 source = "git::ssh://git@github.com/abiydv/aws-eks-okta-auth.git?ref=v1.0.0" 3 4 cluster_name = "my-cluster" 5 cluster_email = "user" 6 idp_client_id = "client-id" 7 idp_config_name = "okta" 8 idp_issuer_url = "https://example.okta.com" 9 idp_group_claim = "groups" 10 idp_username_claim = "username" 11 idp_cluster_admin_groups = ["okta-admins"] 12 idp_cluster_admin_users = ["user1", "user2"] 13 idp_cluster_readonly_groups = ["okta-devs"] 14 idp_cluster_readonly_users = ["user3", "user4"] 15 tags = var.tags 16}
Apply the Terraform configuration to provision the OIDC provider for your EKS cluster. This might take upto 20 mins to complete.
Installing the Kubelogin Plugin
To authenticate with Okta, we need to install the Kubelogin plugin. Follow these steps:
- Install the Kubelogin plugin using the appropriate package manager for your system.
- Verify the installation by running the
kubectl oidc-login --help
command.
Configuring the Kubectl User
In the ~/.kube/config
file, add a new user configuration under the users section, specifying the necessary details such as name, exec command, OIDC issuer URL, client ID, client secret, and additional scopes.
1- name: okta
2 user:
3 exec:
4 apiVersion: client.authentication.k8s.io/v1beta1
5 args:
6 - oidc-login
7 - get-token
8 - --oidc-issuer-url=https://okta.com/oauth2/
9 - --oidc-client-id=clientid
10 - --oidc-client-secret=clientsecret
11 - --oidc-extra-scope=profile
12 command: kubectl
13 env: null
14 provideClusterInfo: false
Testing Access
To test the access to your EKS cluster using Okta authentication, execute any kubectl command. For example, run kubectl get svc
to retrieve information about the cluster’s services. If the command executes successfully, it means you have authenticated successfully with Okta as the IDP.
Conclusion
In this blog post, we have learned how to authenticate to an AWS EKS cluster using Okta as the IDP. By leveraging Okta’s secure authentication capabilities and the flexibility of AWS EKS, you can ensure robust access control and streamlined management of your Kubernetes clusters. Implementing Okta as the IDP enhances the security and ease of use for developers and administrators working with your EKS infrastructure.
Note: Code mentioned above is here