Adfolks LLC has formally joined the ZainTECH family Learn more
Blogs How to give permission to AWS Code build to access EKS cluster using a role
banner adfolks
blog adfolks
Adfolks
Cloud, AWS,

How to give permission to AWS Code build to access EKS cluster using a role

Posted:

TL;DR β€” This is for DevOps who have working knowledge on AWS Codebuild, IAM roles, EKS cluster and AWS CLI

1_8JKd7QbuS-g1HE1f0RF6Zg_3659f8b2f5.jpeg

It is very common practice to use roles for making AWS services talk to each other. It’s the best practice rather than sharing credentials with developers. Credentials can be leaked out and get your environment compromised.

Here I am gonna explain how we can give permission to AWS CodeBuild service to access AWS EKS environment securely without storing kubeconfig file anywhere. I have seen many people storing there EKS cluster kubeconfig file in S3 bucket or in their git repo, which is very frightening 😱.

Here is the recipe πŸ€—

The Workflow consists of 4 steps,

1 β€” Create IAM Role with trust relationship from CodeBuild Service Role

In my example, the CODEBUILD role is service-role/codebuild-BUILD222-service-role, this is auto-generated when you create a CodeBuild.

2 β€” Configure aws-auth configmap to authenticate in the cluster using the role created in step1

3 β€” Create a Policy and attach to CodeBuild Service Role, to perform STS:assumerole and permission to READ in EKS:* to the role created in step 1

4 β€” Using aws eks update-kubeconfig with the argument β€” role-arn , you will be able to authenticate in the EKS cluster. Below is a sample buildspec file which you can try ✌️

Now you can manually trigger a build to test it. If everything is configured as I mentioned in above steps, kubectl commands against the EKS cluster will execute successfully and it can be verified in build logs. Hope you find this article useful and helped in building a secure CICD pipeline πŸ‘