LeftSize scans your AWS, Azure and Cloudflare accounts with read-only access and opens GitHub issues for idle and orphaned resources, upcoming service retirements, and security and governance gaps. Each issue lists the affected resources, the estimated impact and the fix, so the team that owns the resources can act on it like any other issue.
This repository is the open-source (MIT) GitHub Action that runs the scan. It uses Cloud Custodian under the hood and runs on your GitHub Actions runner: cloud credentials never leave it.
- Website: leftsize.com
- Rule catalog: leftsize.com/rules: every check, what it detects and how to fix it
- Install: LeftSize GitHub App
- Compare: vs Azure Advisor, AWS Trusted Advisor, Infracost and Cloud Custodian
A scheduled scan turns each finding group into an issue that is updated on every run. For example:
[COST] 3 idle VMs (≈ $350.40/mo)
We've identified 3 VMs with minimal activity (≤5% CPU over 7+ days), wasting ≈$350.40/month.
Affected resources
vm-build-agent-02in rg-dev (≈ $140.16/mo)vm-test-runnerin rg-dev (≈ $140.16/mo)vm-demo-oldin rg-dev (≈ $70.08/mo)Quick fix:
az vm deallocate --name "vm-build-agent-02" --resource-group "rg-dev"…Comment
@leftsize explain,@leftsize howto,@leftsize script azure-cli,@leftsize impact,@leftsize alternatives,@leftsize snooze 14dor@leftsize ignore reason="..."on the issue.
| Free | Team | Business | |
|---|---|---|---|
| Repositories | 3 | 10 | Unlimited |
| Cost optimization rules (AWS, Azure, Cloudflare) | ✅ All | ✅ All | ✅ All |
| Deprecation & retirement alerts | – | ✅ | ✅ |
| Security & governance rules | – | ✅ | ✅ |
| Support | Docs | Priority email | |
| Price per GitHub organization | $0 | $79/month or $790/year | $249/month or $2,490/year |
Early-access prices; see leftsize.com/#pricing. To get a paid plan, contact hi@leftsize.com.
- 🔍 Read-only - Scans with Reader / ReadOnlyAccess / a read-only Cloudflare API token; never changes your infrastructure
- ☁️ AWS, Azure and Cloudflare - One workflow for all three clouds, one job per cloud (example)
- 🐙 GitHub issues - Findings land in the repository of the team that owns the resources
- 🔐 OIDC - Keyless sign-in to AWS and Azure from your runner; no cloud secrets stored by LeftSize (Cloudflare has no OIDC, so it uses a read-only API token kept in a GitHub secret)
- 📅 Retirements - Retiring VM sizes, end-of-support runtimes and engines, with dates
- 🎯 Customizable - Include or exclude policy categories
- Install the LeftSize GitHub App
- Complete onboarding to get your
installation-idandrepository-token - Configure cloud provider authentication (Azure, AWS or Cloudflare)
name: LeftSize Cost Optimization Scan
on:
schedule:
- cron: '0 0 * * *' # Daily at midnight
workflow_dispatch: # Manual trigger
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- name: Azure Login (OIDC)
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run LeftSize Scan
uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}permissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- name: AWS Login (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Run LeftSize Scan
uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: awsCloudflare has no OIDC for API tokens, so pass a read-only API token from a secret. No login step and no id-token: write are needed.
permissions:
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- name: Run LeftSize Scan
uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: cloudflare
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-ids: ${{ vars.CLOUDFLARE_ACCOUNT_IDS }} # optional; empty = every account the token can readSee Cloudflare Setup for the token permissions.
| Input | Required | Default | Description |
|---|---|---|---|
installation-id |
✅ Yes | - | GitHub App installation ID from LeftSize onboarding |
repository-token |
✅ Yes | - | Secure repository token from LeftSize onboarding |
backend-url |
No | https://api.leftsize.com |
LeftSize backend API URL (https, LeftSize domains only: the repository token is sent to it) |
cloud-provider |
No | azure |
Cloud provider: azure, aws or cloudflare (any case). One cloud per step; use one job per cloud to scan several |
azure-subscription-ids |
No | Login subscription | Subscription ID used for scoping and currency detection. The scan covers the subscription selected by azure/login; scan more subscriptions with a matrix (one job per subscription). |
aws-regions |
No | Login region | Comma-separated AWS regions to scan, or all for every enabled region |
cloudflare-api-token |
For Cloudflare | - | Read-only Cloudflare API token; pass it from a secret (${{ secrets.CLOUDFLARE_API_TOKEN }}). See Cloudflare Setup for the permissions |
cloudflare-account-ids |
No | Every account the token can read | Comma-separated Cloudflare account IDs to scan (32 hex characters each) |
include-policies |
No | All | Rule categories: cost-optimization, deprecation, governance, security |
exclude-policies |
No | None | Rule names to skip (comma-separated, with or without the leftsize- prefix) |
auto-close |
No | true |
Let LeftSize close an issue once its problem is gone (after a warning comment and a week's grace); false to close issues yourself |
environment-name |
No | Detected per resource | Environment of the scanned resources: one value for the whole scan (Production), or name=environment pairs for a subscription with several environments (Freelance-NG-A=acceptance, Freelance-NG-P=production). Values that aren't an environment (such as a matrix label MAIN) are ignored. See Production vs non-production. |
verbose |
No | false |
Debug logging for LeftSize itself (library logs such as botocore stay at warning level) |
| Output | Description |
|---|---|
findings-count |
Total number of findings detected |
findings-submitted |
Whether findings were successfully submitted (true/false) |
findings-json |
JSON string of all findings for custom processing; an empty array when it would exceed 512 KB (GitHub limits step outputs to 1 MB) |
findings-file |
Path of a JSON file with all findings, whatever the size |
failed-policies |
JSON array of checks that didn't run, for example because of a missing read permission; [] when the scan was complete |
limit-exceeded |
true when findings weren't submitted because the plan's repository limit was reached |
The step fails (exit code 1) when no policy file could run at all, for example because cloud credentials are missing or expired, or every file timed out; a scan without results is never reported as clean. AWS credentials are checked with sts:GetCallerIdentity before the scan starts. When only some checks fail (a missing permission, throttling), the scan continues and the job summary lists what didn't run under Incomplete scan.
Submitting findings is retried on network errors and server errors (three attempts). When the daily submission limit is reached, the step stays green and the summary says the findings weren't submitted.
Per finding: the rule, the resource ID and name, the region, resource group or Cloudflare account, the environment LeftSize detected, the fields its issues and savings estimates need (size, SKU, instance type, creation date and similar), and the names of the resource's tags. Tag values are never sent. On Cloudflare, the Zero Trust seat and two-factor rules send the email addresses of the users and members they flag; the API token, Worker variable and secret values and certificate files are never sent. Custodian runs with --dry-run and the policies' actions: are removed before it runs, so the action can't change anything in your cloud.
Some rules only apply to non-production resources, such as shutting down dev VMs at night or dropping Multi-AZ on test databases. LeftSize decides the environment per resource, using the first of these signals that applies:
- The
environment-nameinput, if it names an environment (PROD,DEV,acceptance, …) - An
Environment,EnvorStagetag on the resource, then on its Azure resource group - Words in the resource name or resource group name:
prod,prd,live→ production;acc,uat,preprod→ acceptance;stg,staging;test,tst,qa;dev;sandbox;nonprod - A one-letter last word in the resource group name:
-P,-A,-T,-D(for exampleShop-NG-A) - The account the resource is in, for setups with one account per environment: the AWS account name or alias, or the Azure subscription name or its
Environmenttag (for exampleshop-acc)
Any production signal wins, and a resource without positive non-production evidence is never treated as non-production. Each issue shows the environment and what it was based on.
Each job scans the subscription it logs in to, so use a matrix with one entry per subscription:
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
strategy:
matrix:
environment: [PROD, DEV]
steps:
- uses: azure/login@v2
with:
client-id: ${{ secrets[format('AZURE_CLIENT_ID_{0}', matrix.environment)] }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets[format('AZURE_SUBSCRIPTION_ID_{0}', matrix.environment)] }}
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
environment-name: ${{ matrix.environment }}permissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: aws
aws-regions: "us-east-1,eu-west-1,ap-southeast-1"Each run of the action scans one cloud. Give each cloud its own job; the jobs run in parallel and each submits its own findings. Only the AWS and Azure jobs need id-token: write, so set permissions per job. A scan of one cloud never closes findings of another cloud. Each job counts as one of the 20 findings submissions an installation can make per day (UTC).
name: LeftSize
on:
schedule:
- cron: '17 6 * * *'
workflow_dispatch:
permissions:
contents: read
jobs:
aws:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: AWS Login (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: aws
aws-regions: ${{ vars.AWS_REGIONS }}
azure:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Azure Login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: azure
cloudflare:
runs-on: ubuntu-latest
steps:
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: cloudflare
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}The same as a matrix, with one list of steps. A matrix shares one permissions block, so the Cloudflare entry also gets id-token: write (unused); fail-fast: false keeps one failing cloud from cancelling the others. Add an include entry per extra AWS account or Azure subscription (e.g. cloud: aws with environment: PROD, secrets ending in _PROD). See Scanning several clouds from one workflow.
jobs:
leftsize:
name: Scan ${{ matrix.cloud }} ${{ matrix.environment }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- { cloud: aws, environment: MAIN }
- { cloud: azure, environment: MAIN }
- { cloud: cloudflare, environment: MAIN }
steps:
- name: AWS Login (OIDC)
if: matrix.cloud == 'aws'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets[format('AWS_ROLE_ARN_{0}', matrix.environment)] }}
aws-region: us-east-1
- name: Azure Login (OIDC)
if: matrix.cloud == 'azure'
uses: azure/login@v2
with:
client-id: ${{ secrets[format('AZURE_CLIENT_ID_{0}', matrix.environment)] }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets[format('AZURE_SUBSCRIPTION_ID_{0}', matrix.environment)] }}
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
cloud-provider: ${{ matrix.cloud }}
environment-name: ${{ matrix.environment }}
aws-regions: ${{ vars.AWS_REGIONS }}
cloudflare-api-token: ${{ matrix.cloud == 'cloudflare' && secrets.CLOUDFLARE_API_TOKEN || '' }}
cloudflare-account-ids: ${{ vars.CLOUDFLARE_ACCOUNT_IDS }}permissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
include-policies: cost-optimization,governance # Only cost and governance rules
exclude-policies: leftsize-idle-vm # Skip a specific rulepermissions:
id-token: write # Required for OIDC
contents: read
jobs:
leftsize-scan:
runs-on: ubuntu-latest
steps:
- name: Run LeftSize Scan
id: leftsize
uses: leftsize/leftsize-action@v1
with:
installation-id: ${{ secrets.LEFTSIZE_INSTALLATION_ID }}
repository-token: ${{ secrets.LEFTSIZE_REPOSITORY_TOKEN }}
- name: Process Findings
run: |
echo "Found ${{ steps.leftsize.outputs.findings-count }} findings"
echo "Submitted: ${{ steps.leftsize.outputs.findings-submitted }}"
# Custom processing
echo '${{ steps.leftsize.outputs.findings-json }}' | jq '.[] | select(.severity == "high")'# Create app
az ad app create --display-name "LeftSize-GitHub-Action"
# Get app ID
APP_ID=$(az ad app list --display-name "LeftSize-GitHub-Action" --query "[0].appId" -o tsv)
# Create service principal
az ad sp create --id $APP_ID
# Get object ID
OBJECT_ID=$(az ad sp list --display-name "LeftSize-GitHub-Action" --query "[0].id" -o tsv)# Create credential configuration
cat > credential.json << EOF
{
"name": "github-actions",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:YOUR-ORG/YOUR-REPO:ref:refs/heads/main",
"audiences": ["api://AzureADTokenExchange"]
}
EOF
# Add federated credential
az ad app federated-credential create --id $APP_ID --parameters credential.json# Assign Reader role (minimum required)
az role assignment create \
--assignee $OBJECT_ID \
--role "Reader" \
--scope /subscriptions/YOUR-SUBSCRIPTION-ID
# Assign Monitoring Reader (for metrics)
az role assignment create \
--assignee $OBJECT_ID \
--role "Monitoring Reader" \
--scope /subscriptions/YOUR-SUBSCRIPTION-IDAdd these secrets to your repository:
AZURE_CLIENT_ID: App ID from step 1AZURE_TENANT_ID: Your Azure AD tenant IDAZURE_SUBSCRIPTION_ID: Your subscription IDLEFTSIZE_INSTALLATION_ID: From LeftSize onboardingLEFTSIZE_REPOSITORY_TOKEN: From LeftSize onboarding
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list 6938fd4d98bab03faadb97b34396831e3780aea1{
"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"
}
}
}
]
}aws iam attach-role-policy \
--role-name LeftSize-GitHub-Action \
--policy-arn arn:aws:iam::aws:policy/ReadOnlyAccessAWS_ROLE_ARN: ARN of the role created aboveLEFTSIZE_INSTALLATION_ID: From LeftSize onboardingLEFTSIZE_REPOSITORY_TOKEN: From LeftSize onboarding
Cloudflare has no OIDC or workload identity federation for API tokens, so the scan uses a read-only API token stored as a GitHub secret. The token stays on your runner; LeftSize never receives it.
Use an account-owned token (Manage Account > Account API tokens): it isn't tied to a person. Include all zones of the account. The LeftSize onboarding page and the Cloudflare setup guide have a link that opens the dashboard with these permissions filled in. All are Read:
| Scope | Permissions |
|---|---|
| Zone | Zone, Zone Settings, DNS, SSL and Certificates |
| Account | Account Settings, Account Analytics, Account API Tokens, Workers Scripts, Workers R2 Storage, Access: Apps and Policies, Access: Service Tokens, Access: Audit Logs, Access: Organizations, Identity Providers, and Groups, Cloudflare Tunnel, Load Balancing: Monitors and Pools |
Account-owned tokens can't read Page Rules or Registrar. The rules leftsize-cloudflare-page-rules-deprecated, leftsize-cloudflare-domain-expiring and leftsize-cloudflare-domain-transfer-unlocked need a user API token with Page Rules Read (zone) and Registrar Domains Read (account) added; the trade-off is that a user token is tied to a person.
Give the token a TTL and renew it before it expires: client IP filtering isn't practical with GitHub-hosted runners, whose addresses change.
CLOUDFLARE_API_TOKEN: the token from step 1LEFTSIZE_INSTALLATION_ID: From LeftSize onboardingLEFTSIZE_REPOSITORY_TOKEN: From LeftSize onboarding
Optional variable: CLOUDFLARE_ACCOUNT_IDS, the account IDs to scan (comma-separated).
The action first checks that the token can list zones (Zone Read). If it can't, it asks Cloudflare whether the token is active (an account-owned token only for the accounts in cloudflare-account-ids): an active token still runs the account-level rules and the zone rules are listed as not run; otherwise the step fails. Any other missing permission stops only the rules that need it: they are listed under Incomplete scan and in failed-policies. Some Cloudflare APIs return an empty list instead of an error without permission (Workers, Access applications, service tokens, tunnels); the log then shows a note like No <kind> found in account <id> (if there should be, check the API token's permissions).
Not scanned: Logpush jobs (listing them requires Logs Write, and LeftSize stays read-only), and Firewall Rules and the previous rate limiting rules (Cloudflare already converted them).
The action ships the curated LeftSize policies in policies/: cost optimization, deprecations and retirements, security and governance for AWS, Azure and Cloudflare. The rule catalog documents every rule: what it checks, why it matters and how to fix it.
ubuntu-latest). The action is a composite action that installs Cloud Custodian with Python 3.11 on the runner; Linux is the only runner type it's tested on.
jobs:
leftsize-scan:
runs-on: ubuntu-latest # RequiredLeftSize runs on your GitHub Actions runners, not our infrastructure:
- Free tier: 2000 minutes/month (GitHub Free)
- Typical scan: 3-5 minutes
- Result: ~400 scans/month on free tier
For larger organizations, use self-hosted runners for unlimited usage.
- ✅ No Cloud Credentials Stored - Uses OIDC (keyless authentication) for AWS and Azure; Cloudflare's read-only API token stays in your GitHub secrets and on your runner
- ✅ Read-Only Operations - All policies are 100% safe, no destructive actions
- ✅ Multi-Tenant Secure - Repository tokens prevent cross-tenant attacks
- ✅ Minimal Permissions - Reader and Monitoring Reader on Azure, ReadOnlyAccess on AWS, read-only permissions on Cloudflare
Azure:
# Test authentication locally
az login
az account show
# Verify service principal
az ad sp show --id $AZURE_CLIENT_IDAWS:
# Test authentication locally
aws sts get-caller-identity
# Verify role trust policy
aws iam get-role --role-name LeftSize-GitHub-ActionCloudflare: Cloudflare authentication failed: the API token can't list zones (it needs Zone Read) and isn't confirmed active means the token is wrong or expired, or lacks Zone Read and couldn't be verified. For an account-owned token without Zone Read, set cloudflare-account-ids so it can be verified.
# Check the token (an account-owned token)
curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/tokens/verify" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"This is normal! It means your infrastructure is well-optimized. The action will still submit a report with zero findings.
Check:
LEFTSIZE_INSTALLATION_IDis correctLEFTSIZE_REPOSITORY_TOKENmatches your repository- Backend URL is reachable (
https://api.leftsize.com)
Findings are saved as artifacts even if submission fails.
- 📚 Documentation
- 💬 GitHub Discussions
- 🐛 Report Issues
- 📧 Email: support@leftsize.com
MIT License - See LICENSE file for details.
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
Made with ❤️ by the LeftSize team