How to Use AWS Services from EKS with Fine-grained Access Control

Gertjan Assies
AWS in Plain English
2 min readNov 2, 2021

--

At my company, where I am part of the SRE team, we are using EKS (Amazon’s managed Kubernetes service) to run our applications and services.
We also use it to deploy those applications and services and increasingly serverless stacks with cloud formation or terraform.

But how do we keep our systems secure and stable while allowing the dev teams to build, deploy, monitor and debug their applications as they see fit?

Kubernetes has the concept of service accounts. these are k8s resources that allow other k8s resources like pods for instance to interact with k8s and external services.

EKS allows you to bind those service accounts to IAM Roles allowing fine-grained control on what AWS Services a k8s resource can interact with.
This is possible as EKS can authenticate by using an OIDC Provider (follow the link to see how that connects Service accounts and IAM Roles.)

For us, this means we can give development teams the possibility to deploy their k8s deployments, cloud formation stacks and big data jobs through CI/CD pipelines in their namespaces without having to give them extensive access to the AWS Console.

How that all works in detail is for another blog entry, what I want to show here is that if you want to interact with AWS services from within your application or job, you need to be able to assume that role that is bound to that service account.

The example I'm showing uses Python and the Boto3 library, but this should be possible in any language that has an AWS client library or SDK that support STS (Secure Token Service)

As you can see once the service account role bindings are set up the following environment variables are available:

Hopefully, I’ve given you some ideas on how to run AWS workloads in EKS.

Thanks for reading.

More content at plainenglish.io

--

--

Polyglot Functional Software Engineer, currently working as a Site Reliability Software Engineer