Security and scalability are paramount in modern cloud architectures. Amazon Web Services (AWS) Identity and Access Management is a critical tool that helps you manage users, permissions, and access control across AWS services. While Identity and Access Management (IAM) users have traditionally been the go-to approach for granting access to resources, there are significant advantages to moving to IAM roles.
This article will explore why transitioning to roles is a good idea and how to implement that transition, including integrating Okta as your Identity Provider (IdP) and enabling OpenID Connect (OIDC) for user management. We’ll also walk through how to integrate Okta with Github, Atlantis, and AWS for Terraform deployments.
IAM users are tied directly to specific credentials (username/password or access keys) for authentication. Over time, managing these users can lead to security risks, such as unmonitored access keys or weak passwords. IAM roles, on the other hand, are temporary and are used with AWS services, which reduces the attack surface area. Roles don’t require permanent access credentials, improving security.
Managing IAM users becomes cumbersome at scale, especially when you have large numbers of developers, administrators, or automated processes needing varying levels of access. IAM roles allow you to easily scale user permissions across teams, departments, or even external partners without having to create and manage separate IAM users for each.
By using IAM roles in combination with identity federation services like Okta, you can simplify the management of external users or teams that require access to your AWS resources. Okta provides an Identity-as-a-Service (IDaaS) solution, which allows for centralized user management and security policies across all your applications, including AWS.
To implement the transition from IAM users to roles in AWS using Okta as an Identity Provider (IdP) with Terraform, you'll need to define the necessary resources for AWS IAM, Okta, and identity federation in a Terraform configuration file.
Prior to following the steps outlined below, be sure that the following applies to your environment:
We'll configure Okta to be used as an OIDC provider for AWS in Terraform. In this step, you will create the OIDC identity provider in AWS using Okta's issuer URL.
|
Next, you’ll define the IAM role in AWS that users will assume after being authenticated via Okta’s OIDC tokens. This role will include a trust policy allowing users from Okta to assume the role.
|
For this example, we will create a policy granting full S3 access, which can be adjusted according to your use case.
|
While this part is mainly handled by Okta, the key step here is to ensure that your Okta application for OIDC is configured to issue tokens that AWS can understand. Make sure the Client ID and Client Secret from Okta match the details used in the OIDC provider configuration in AWS.
In Okta, the users will authenticate using the OIDC app you created, and AWS will allow those authenticated users to assume the OktaRole.
The IAM role is now ready to be assumed by authenticated Okta users. In practice, Okta users will authenticate through the OIDC flow and, upon success, receive temporary credentials that they can use to interact with AWS resources according to the permissions of the role they assumed.
In your application or script, users would authenticate against Okta and assume the AWS role programmatically. Here's how you might handle the role assumption with aws sts assume-role-with-web-identity using the AWS CLI or SDK.
aws sts assume-role-with-web-identity \ --role-arn arn:aws:iam::<AWS_ACCOUNT_ID>:role/OktaRole \ --role-session-name OktaSession \ --web-identity-token <okta-id-token> |
This command will return temporary credentials (access key, secret key, and session token), which can be used to interact with AWS resources according to the role’s permissions.
Here’s the complete Terraform configuration putting everything together:
|
By using Okta as an Identity Provider (IdP) for federated access to AWS, and by leveraging IAM roles instead of IAM users, you can significantly improve your security and scalability. Terraform makes the management of your AWS resources more efficient and repeatable, and you can easily integrate Okta to authenticate and manage users.
This setup ensures that your users never need to have long-lived AWS IAM credentials, while still having the necessary permissions to work with AWS resources in a secure, scalable way.
Now lets take this a step further by integrating Okta with AWS IAM roles. This provides several benefits especially for use with tools like GitHub and Atlantis, and it can significantly improve the security, scalability, and automation of your infrastructure deployments.
In this section, we'll explore how this setup can help streamline continuous integration and continuous deployment (CI/CD) workflows, specifically with Terraform and Atlantis for Infrastructure as Code (IaC) on AWS.
By using Okta as your identity provider (IdP), you can centralize user management for GitHub and Atlantis, ensuring that access is streamlined across your AWS infrastructure. With Okta federated authentication, you can authenticate users and manage permissions through Okta, ensuring only authorized personnel can deploy and modify infrastructure in AWS via Atlantis.
Instead of embedding permanent AWS IAM credentials in the Atlantis or GitHub environment, roles can be assumed dynamically, providing temporary credentials for specific tasks. This reduces the risk of credential leakage or misuse while maintaining the principle of least privilege for each action performed on AWS.
Okta users will authenticate through the OpenID Connect (OIDC) integration, automatically assuming the appropriate IAM roles with minimal configuration. These roles define the permissions needed to deploy infrastructure (such as S3, EC2, Lambda, etc.) in AWS. When combined with Atlantis, Okta authentication provides an effective security model for automating deployments with Terraform.
To successfully integrate Okta with GitHub, Atlantis, and AWS, follow these steps:
As we discussed in the previous section, first you need to set up Okta as an OpenID Connect (OIDC) provider in AWS. This step ensures that Okta users can authenticate and assume IAM roles for accessing AWS resources.
Example of a GitHub Actions workflow:
|
In this example:
sts:assume-role-with-web-identity
operation.Atlantis is a tool that automates Terraform workflows for pull requests. It integrates directly with GitHub to trigger Terraform commands (like terraform plan
and terraform apply
) when a pull request is opened, updated, or merged.
1. Install Atlantis:
First, you'll need to install Atlantis on a server. There are a variety of options for deploying Atlantis (such as using Docker or a pre-configured VM).
2. Configure Atlantis with GitHub:
Atlantis will need access to GitHub, so you’ll configure it to listen to GitHub events. This is done by setting up webhooks in GitHub and providing Atlantis with a GitHub token (which can be securely managed in Okta if necessary).
3. Atlantis Configuration for Terraform:
Once Atlantis is set up, you can configure it to run Terraform commands using IAM roles. Here’s how you can set it up for Okta-based federated authentication:
Atlantis Config Example (atlantis.yaml
):
vpc_id: "${env.VPC_ID}" # Example of using environment variables |
4. Atlantis Integration with Okta:
The complete workflow will look like this:
main
branch).terraform plan
and terraform apply
if the pull request is approved.Using Okta for federated authentication with AWS IAM roles in conjunction with GitHub and Atlantis creates a secure and automated deployment pipeline for Infrastructure as Code (IaC) using Terraform. This integration provides centralized user management, seamless role assumption, and enhanced security by using short-lived, temporary credentials.
With this setup, your infrastructure deployment pipeline becomes more secure, scalable, and easier to manage, ensuring that only authorized users and actions are able to modify your cloud infrastructure.
Interested in reading more from our Platform team? Check out this recent article: Platform, Fires, and You: Navigating the Fine Line Between Operations and Development