Containers
Fine-grained IAM roles for Red Hat OpenShift Service on AWS (ROSA) workloads with STS
Red Hat OpenShift Service on AWS (ROSA) is a fully managed OpenShift service, jointly supported by both Red Hat and Amazon Web Services (AWS) and managed by the Red Hat SRE team. This relieves customers of cluster lifecycle management, allowing them to focus on building applications rather than maintaining the OpenShift clusters.
ROSA has recently been integrated with the AWS Security Token Service (AWS STS). AWS STS is an AWS service that allows AWS users, authenticated via AWS Identity and Access Management (IAM) or Federation, to request temporary security credentials for your AWS resources. ROSA users can allocate administrative permissions on demand. The temporary security credentials work exactly like regular long-term security access key credentials allocated to IAM users, except the lifecycle of the access credentials is shorter. Additionally, the temporary credentials are not stored with the user and instead are generated dynamically and provided to the user on demand. When the temporary credentials expire, the user can simply request new ones.
IAM supports federated identities using an OpenID Connect (OIDC) identity provider. This feature allows customers to authenticate AWS API calls with supported identity providers and receive a valid OIDC JSON web token (JWT). PODs can request and pass this token to the AWS STS AssumeRoleWithWebIdentity
API operation and receive temporary IAM role credentials.
Currently, you can create a ROSA cluster using the AWS STS service, using the rosa create cluster --sts
option. This will be discussed in greater detail later. During cluster creation, the operator IAM roles and the OpenID Connect (OIDC) identity provider are created. The operator IAM roles and endpoint are mapped to OpenShift resources within the ROSA cluster and use the OIDC to authenticate.
In this blog post, we will discuss how to use the OIDC identity provider created during cluster installation and use it with IAM roles for service accounts (IRSA). IRSA allows us to associate an IAM role with a Kubernetes service account, which can then be used by pods for authentication and fine-grained permissions.
Using IRSA has the benefit of using the least privileged recommendation and credential isolations, meaning that the container within the pod can only retrieve credentials for the IAM role associated with the service account to which the pod belongs. We can also get better auditing, having access and event logging available through AWS CloudTrail.
Walkthrough
In the following section, we demonstrate how ROSA with STS enabled can use IAM roles for service accounts to provide access for a Kubernetes pod to an Amazon Simple Storage Service (Amazon S3) bucket. The guide will not walk through the creation of a ROSA cluster with STS enabled. For more detail on how to provision a ROSA cluster using STS, see the documentation.
Prerequisites
- AWS account
- The AWS, rosa, and oc CLI
- ROSA enabled in the AWS account
- A ROSA cluster with STS enabled
Step 1. Set working variables
We are going to reuse the existing OIDC endpoint created during the ROSA STS cluster deployment. To do this, we are going to create a set of variables for items that will be reused later, then connect to the OpenShift cluster using the oc
CLI.
Step 2. Get the OIDC endpoint URL of the cluster
We will now use the oc
CLI to connect to the ROSA cluster and get the existing OIDC endpoint details. In the documentation we will find how to connect to the cluster using oc
CLI in more detail. Once connected, we can collect the endpoint details.
Step 3. Create the application namespace and service account
Step 4. Create an IAM role for the application service account
Step 5. Attach IAM policy to the IAM role
Attach the required Amazon S3 policy and apply them to the newly created IRSA role.
Note: You can choose to attach to the user custom or specific policies required by your needs.
Step 6. Associate the IAM role created to the service account
For the moment, the Amazon Resource Name (ARN) of the IAM role created is not yet an annotation for the service account. Use the following command to associate an IAM role to the service account.
Let’s describe the service account
Step 7. Application deployment
Next, we will deploy a sample application onto the ROSA cluster. For simplicity, we will deploy a single container in a deployment called awscli
. This container will have the AWS CLI binary preinstalled and will allow us to demonstrate accessing cloud services from ROSA using fine-grained IAM roles.
When AWS clients or SDKs connect to AWS APIs, they look for credentials in a variety of different places, such as an ~/.aws/config
file or an AWS_ACCESS_KEY_ID
environment variable. When using a Web Identity, the AWS clients and SDKs look for environment variables called AWS_WEB_IDENTITY_TOKEN_FILE
and AWS_ROLE_ARN
. For the Python Boto3 SDK, this is documented here.
The EKS Pod Identity Webhook running in the OpenShift cluster can place these variables within a running pod for us as long as a service account with an IAM role defined has been attached to your pod. For the demonstration workload running in our ROSA cluster, we can see these variables have been successfully inserted into the pod by running:
Note also TokenExpirationSeconds
in the Volumes section of the pod:
Step 8. Create an S3 bucket
Outside of the ROSA cluster, we can use the AWS CLI on our workstation to create an S3 bucket.
Step 9. Verify the solution
Verify the solution by starting a remote shell into the running pod and then use the AWS CLI to write to the S3 bucket.
List the bucket using awscli
Create a file, upload it into the S3 bucket, and check the content of the S3 bucket.
Summary
In this blog post, we have explored how to use RBAC for implementing IAM roles for service accounts in a ROSA cluster to provide fine-grained permissions to pods and access AWS API securely. For more information and getting started with Red Hat OpenShift Service on AWS (ROSA) as well as other Red Hat solutions on AWS, see the AWS Red Hat partner page.