aws-samples / eks-aws-auth-configmap

This repository provides sample code that uses programmatic way for applying aws-auth ConfigMap in Amazon EKS (Programmatic Amazon EKS Cluster permission for IAM User/Role) and for accessing Kubernetes Objects like list pods and read daemonset (accessing/updating Kubernetes objects through Kubernetes client api)
MIT No Attribution
13 stars 10 forks source link
authentication aws-auth configmap eks

Amazon Elastic Kubernetes Service eks-aws-auth-configmap-api

This package provides code(api/programmatic way) for

Code can be run without installing or depending on aws commnd line interface (cli) and kubectl cli. Code uses AWS SDK for Python (Boto3), AWS Security Token Service API and Kubernetes(k8s) API to achieve this.

Scenario

For security reasons, when you create an Amazon EKS cluster, only the IAM entity user or role, such as a federated user that creates the cluster, is granted permissions in the cluster's RBAC configuration in the control plane. User or role that created cluster has to login through kubectl to provide cluster access to additional users/roles.

Issue

For automation like build pipeline or infrastructure as code, there is a dependency on kubectl, aws cli to apply aws auth ConfigMap. Also for a scenario where we need to standup large number of EKS clusters for training/learning purpose or for DR automation one has to automate with dependency on kubectl cli.

Approach to solve the problem/used in this sample

Create custom http request/api that generates token/sts signed url for EKS and generating kubeconfig in temporary folder. This way, automation can be done in lambda or any other automation tools/application without need to have CLI dependency or invoking through command line interface.

Use Cases where this can be used

Code Flow

Refer standalone/test.py file for available functions & its flow. Read function comments.

Installation & Run

Standalone python

Pre requisites:

  Python 3.7

  pip3

Installation:

  cd standalone

  pip3 install -r requirements.txt

Configuration:

Attention!

For demo purpose, access key and secret access keys are exported as environment variables in this sample. Folow security best practice to read access key and secret access keys from secrets manager or from vault when integrating into build pipeline or application code.

Run:

  python3 test.py

AWS Lambda

Pre requisites:

Packaging steps:

Note:

References

https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html

FAQ

License

This library is licensed under the MIT-0 License. See the LICENSE file.