AWS Identity Federation Token Generation and Resource Retrieval
This document outlines the process of generating temporary security credentials using AWS CLI to assume an IAM role in a specified AWS account, using the credentials to retrieve EC2 instances, and configuring the Cloud Builder role for organization-wide scanning in AWS, GCP, and Azure. The process was completed on June 23, 2025, at 07:42 PM IST, with updates for the Cloud Builder role and simplified credential generation added on July 1, 2025.Purpose
To enable secure access to AWS resources using IAM role assumption and to configure the Cloud Builder role to collect audit logs, cost data, and resource information across AWS, GCP, and Azure at the account, organization, or resource level.Scope
This document covers:- Generating temporary security credentials in AWS using IAM role assumption to access EC2 instances.
- Creating and assigning the Cloud Builder role in AWS, GCP, and Azure for Steampipe scanning, with options to scope permissions to account, organization, or resource levels.
- Applicable to users managing cloud resources in a single AWS account or across an AWS organization.
Assumptions
- The user has administrative access to the AWS account, Google Cloud project, and Azure subscription.
- The
aws,gcloud, andazCLIs are installed and authenticated with sufficient permissions. - The user has basic knowledge of IAM roles and cloud resource management.
- An IAM role with appropriate permissions is available for assumption.
Best Practices for Identity Federation
- Use Short-Lived Credentials: Generate temporary credentials with a short duration (e.g., 1 hour) to minimize security risks.
- Least Privilege: Assign only the necessary permissions to the IAM role to reduce the attack surface.
- Secure Role Access: Restrict access to IAM roles used for assumption.
- Audit and Monitor: Regularly audit IAM policies and monitor credential usage to detect unauthorized access.
- Scope Permissions Appropriately: Assign the Cloud Builder role at the organization level for broad scanning, or at the account/resource level for granular control.
- Use Managed Authentication: Prefer
aws stscommands for credential generation to simplify the process and reduce manual key management.
Prerequisites
- AWS CLI installed and authenticated with a user or role with sufficient permissions (e.g.,
IAMFullAccess,EC2FullAccess). gcloudCLI installed and authenticated for GCP operations.azCLI installed and authenticated for Azure operations.- AWS Account:
your-aws-account-id. - Google Cloud Project:
your-project-name(Project Number:your-project-number). - Azure Subscription:
your-azure-subscription-id. - IAM Role:
your-iam-role.
Step-by-Step Guide to Temporary Credential Creation
The following steps outline the process to generate temporary security credentials via IAM role assumption, use them to access AWS resources, and configure the Cloud Builder role.Step 1: Create an IAM Role for Assumption
Create a new IAM role (your-iam-role) that can be assumed by an authenticated user or role.
1.1 Create the IAM Role
assume-role-trust-policy.json:
1.2 Attach a Policy for EC2 Access
Outcome:
- IAM role created and granted read-only access to EC2.
Step 2: Create and Assign Cloud Builder Roles
The Cloud Builder role provides read-only access to collect cost, audit, and resource data. Below are instructions for creating and assigning this role in AWS, GCP, and Azure, with options to scope permissions to account, organization, or resource levels.2.1 AWS: Create and Assign the Cloud Builder Role
Create the IAM Role
cloud-builder-trust-policy.json:
Create and Attach the Policy
cloud-builder-policy.json:
Assign the Role to a Service
- The Cloud Builder role can be assumed by the Steampipe service or user for scanning:
Outcome:
- The Cloud Builder role is created in AWS with permissions equivalent to those in GCP and Azure, assigned to the Steampipe service via role assumption.
2.2 GCP: Create and Assign the Cloud Builder Role
Create the Custom Role
Assign the Role
- Organization Level:
- Folder Level:
- Project Level:
Outcome:
- The Cloud Builder role is created in GCP and assigned to the service account
your-steampipe-svc@your-project-name.iam.gserviceaccount.comat the desired scope.
2.3 Azure: Create and Assign the Cloud Builder Role
Create the Custom Role
cloud-builder-role.json:
Assign the Role
- Subscription Level:
- Management Group Level:
- Resource Group Level:
Outcome:
- The Cloud Builder role is created in Azure and assigned to the service principal
your-steampipe-svc@your-tenant.onmicrosoft.comat the desired scope.
Step 3: Generate Temporary Security Credentials
Useaws sts assume-role to generate temporary credentials by assuming the IAM role.
3.1 Authenticate with AWS CLI
Ensure the AWS CLI is configured with a user or role that has permission to assumeyour-iam-role:
3.2 Assume the IAM Role
Outcome:
- Received temporary credentials, e.g.:
- Extract the
AccessKeyId,SecretAccessKey, andSessionTokenfor use asYOUR_ACCESS_KEY_ID,YOUR_SECRET_ACCESS_KEY, andYOUR_SESSION_TOKEN.
Summary
- IAM Role:
your-iam-role - Cloud Builder Role:
CloudBuilder - Temporary Credentials:
ASIAEXAMPLE,wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY,IQoJb3JpZ2luX2... - Resource Retrieved: EC2 instances in
your-region. - Cloud Builder Role: Created and assigned in AWS, GCP, and Azure for Steampipe scanning, with permissions scoped to organization, account/project, or resource group levels as needed.