Kubernetes

Tokenless Authentication to Kubernetes using SAML.to

Introduction

The SAML.to Command Line Interface or Assume AWS Role Action can be used for authentication to the Kubernetes Control Plane and be used with any tool that supports a kubeconfig file (such as kubectl, helm, k9s, etc.).

This document will detail how to use SAML.to to authenticate to the Kubernetes Control Plane for Tokenless authentication.

This page is focused for AWS EKS, however if you've manually provisioned your own cluster, you'll need to first set up the AWS IAM Authenticator on your Kubernetes cluster.

Prerequisites

Create a Kubernetes Admin Role

Create a kubernetes-admin role (or whatever name you prefer) that has a Trust Relationship to SAML.to.

At a minimum, the role needs permission to eks:DescribeCluster:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "eks:DescribeCluster",
      "Resource": "arn:aws:eks:*:*:cluster/*"
    }
  ]
}

Then, in saml-to.yml, grant access to GitHub Users to assume that role:

Ensure the role is functional:

Edit the Config Map

If the system was provisioned by AWS EKS, you should have an aws-auth ConfigMap in the kube-system namespace:

Add a section to mapRoles allowing the desired role access to the system:masters group:

Connect to Kubernetes Using the Role

With The SAML.to CLI

Optional: Create or Update .kubeconfig

Using the SAML.to CLI with the --headless flag will update your Terminal Session with temporary AWS Session Tokens:

Run saml-to before kubectl commands as you normally would:

Kubernetes will do the rest of the work and map the active role in the Terminal Session to a group permission level as defined in mapRoles!

Running $(saml-to ...) before every Kubectl command is unnecessary.

The credentials will stay valid in your Terminal Session for how-ever long is defined in saml-to.yml the property value of https://aws.amazon.com/SAML/Attributes/SessionDuration, which defaults to 1 hour.

If the session expires, simply run the saml-to assume ... --headless command again!

Within GitHub Actions

A repository can also be granted access to the role. In your user's or organizations saml-to.yml, grant access for the Repository to gain access to the role:

Then, in the GitHub action, use the Assume AWS Role Action to assume the role:

Questions/Comments/Issues?

Contact us!

Last updated