AWS Setup: OIDC and a Read-Only IAM Role
This guide sets up OIDC authentication between GitHub Actions and AWS. No IAM access keys are stored in your repository: GitHub Actions requests a short-lived token for each scan.
Prerequisites
- An AWS account with resources to scan
- Permission to create IAM roles and OIDC providers
- A GitHub repository with LeftSize installed
Step 1: Create the OIDC provider
If your AWS account doesn’t have a GitHub Actions OIDC provider yet, create one:
- Go to the IAM Console > Identity providers > Add provider
- Select OpenID Connect
- Configure:
- Provider URL:
https://token.actions.githubusercontent.com - Audience:
sts.amazonaws.com
- Provider URL:
- Click Add provider
If you already use GitHub Actions OIDC for other workflows, skip this step. The existing provider works for LeftSize too.
Step 2: Create an IAM role
- Go to IAM > Roles > Create role
- Select Web identity as the trusted entity type
- Choose the GitHub OIDC provider and audience
sts.amazonaws.com - Click Next
- Attach the ReadOnlyAccess managed policy
- Name the role, for example
LeftSize-GitHub-Action - Click Create role
Restrict the trust policy
Edit the role’s trust policy so only the default branch of your repository can assume it:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:YOUR_ORG/YOUR_REPO:ref:refs/heads/main"
}
}
}
]
}
Replace ACCOUNT_ID with your AWS account ID and YOUR_ORG/YOUR_REPO with your repository. Scheduled runs use the default branch, so if yours isn’t main, change the branch name. To also allow manual runs from other branches, use StringLike with repo:YOUR_ORG/YOUR_REPO:*.
Step 3: Add secrets and variables to GitHub
In your repository, go to Settings > Secrets and variables > Actions.
Secrets
| Secret | Value |
|---|---|
AWS_ROLE_ARN_MAIN |
The ARN of the IAM role (for example arn:aws:iam::123456789012:role/LeftSize-GitHub-Action) |
LEFTSIZE_INSTALLATION_ID |
Provided during LeftSize onboarding |
LEFTSIZE_REPOSITORY_TOKEN |
Provided during LeftSize onboarding |
Variables
| Variable | Value |
|---|---|
AWS_REGIONS |
Regions to scan, comma-separated (for example us-east-1,eu-west-1,ap-southeast-1), or all for every region enabled in the account |
If AWS_REGIONS is empty, LeftSize scans only the region of the login step, which is us-east-1 in the generated workflow. IAM users and other global resources are checked once, in the first region. S3 buckets are reported under the first region’s scope and listed once per issue, whichever regions you scan (action version 1.0.30 and later).
Scanning multiple AWS accounts
Use the matrix in the workflow, with one entry per account:
strategy:
fail-fast: false
matrix:
environment: [MAIN, PROD, DEV]
For each environment, create a matching secret:
AWS_ROLE_ARN_PROD: role ARN in your production accountAWS_ROLE_ARN_DEV: role ARN in your development account
Each account needs its own IAM role with the OIDC trust policy and ReadOnlyAccess. Findings are grouped per account and region, so issues from different accounts never mix.
Other ways to authenticate
OIDC is the recommended setup: nothing secret is stored, and every run gets credentials that expire within the hour. The LeftSize action itself doesn’t care how you sign in. It uses whatever credentials the earlier step in the job sets up, so these also work:
- Access keys of an IAM user stored as GitHub secrets, passed to
aws-actions/configure-aws-credentialsasaws-access-key-idandaws-secret-access-key(optionally withrole-to-assumeto switch to the read-only role). - A self-hosted runner with an instance profile or other credentials already configured.
The permissions are the same: ReadOnlyAccess or the narrower read-only policy. Access keys are long-lived credentials that you need to protect and rotate, which is why OIDC is recommended.
Verifying the setup
- Go to your repository’s Actions tab
- Select LeftSize Cost Optimization Scan
- Click Run workflow
- Check that the AWS Login (OIDC) step succeeds and the job summary lists the scan results
If authentication fails, check that:
- The OIDC provider exists in your AWS account
- The IAM role trust policy names the right repository and branch
- The role has
ReadOnlyAccessattached - The
AWS_ROLE_ARN_MAINsecret contains the full ARN
Using a narrower policy than ReadOnlyAccess
ReadOnlyAccess is the supported setup. If you need something narrower, the role still needs read access (Describe*, List* and the relevant Get* actions) to everything the rules check:
- EC2 (instances, volumes, snapshots, AMIs, Elastic IPs, NAT gateways, VPCs, VPC endpoints, security groups), Auto Scaling, Elastic Load Balancing
- RDS, DynamoDB, ElastiCache, DocumentDB and Neptune (through RDS), OpenSearch, Timestream
- S3 bucket settings (location, policy, ACL, encryption, versioning, logging, lifecycle, public access block)
- Lambda, ECS, EKS (clusters, node groups and Fargate profiles), ECR, Elastic Beanstalk, Batch
- EFS, EMR, Glue, MSK (Kafka), DMS, MWAA (Airflow), Kendra, CloudSearch, Pinpoint
- WorkSpaces, Directory Service, Cloud Directory, Route 53 ARC readiness checks
- IAM users and access keys, ACM, Secrets Manager, CloudWatch Logs
- CloudWatch metrics (
cloudwatch:GetMetricStatistics,cloudwatch:GetMetricData,cloudwatch:ListMetrics),tag:GetResourcesandsts:GetCallerIdentity - The account-level S3 Block Public Access setting (
s3:GetAccountPublicAccessBlock). Without it,leftsize-public-s3-accessreports no buckets, and the job summary lists it under “Incomplete scan”. - The account name and alias, used to tell production from non-production accounts (
account:GetAccountInformation,iam:ListAccountAliases). Without them, LeftSize decides the environment from tags and names only.
A rule whose permissions are missing fails without stopping the scan, and its findings are missing. The job summary lists such rules under “Incomplete scan” and the failed-policies output has them too. To see the error of each rule, set LEFTSIZE_DEBUG: true on the scan step (see Troubleshooting).
What LeftSize reads
- Resource configuration through the AWS APIs
- CloudWatch metrics for usage
- Never creates, changes or deletes resources
- Never reads the data inside your resources (no S3 objects, no database contents)
Was this article helpful?