Azure Setup: OIDC and Read-Only Roles
This guide sets up OIDC authentication between GitHub Actions and Azure. No client secrets are stored in your repository: GitHub Actions requests a short-lived token for each scan.
Prerequisites
- An Azure subscription with resources to scan
- Permission to create App Registrations in Microsoft Entra ID and to assign roles on the subscription
- A GitHub repository with LeftSize installed
Step 1: Create an App Registration
- Go to the Azure Portal > Microsoft Entra ID > App registrations
- Click New registration
- Set the name to
leftsize-scanner(or any name you prefer) - Leave Supported account types as the default (single tenant)
- Click Register
- Note the Application (client) ID and Directory (tenant) ID
Step 2: Add federated credentials
- In the App Registration, go to Certificates & secrets > Federated credentials
- Click Add credential
- Select GitHub Actions deploying Azure resources
- Configure:
- Organization: your GitHub organization or username
- Repository: the repository where the LeftSize workflow runs
- Entity type: Branch
- Branch: your default branch, usually
main - Name:
leftsize-scan
- Click Add
Scheduled runs use the default branch. To start manual runs from other branches, add a federated credential for each branch.
Step 3: Assign roles
Assign these read-only roles to the App Registration on each subscription you want to scan:
- Go to Subscriptions > select your subscription > Access control (IAM)
- Click Add role assignment
- Assign:
| Role | Purpose |
|---|---|
| Reader | Read resource configuration (types, sizes, settings) |
| Monitoring Reader | Read metrics (CPU, connections, throughput) |
Billing currency
The action also detects the subscription’s billing currency, from its price sheet or Cost Management (read-only queries that Reader allows on most subscription types). If that fails it records USD. Savings amounts in issues are always in US dollars either way; see Cost estimation.
Optional: Key Vault certificates
The expiring Key Vault certificates rule reads certificate metadata from inside each Key Vault, which Reader doesn’t cover. To use it, give the App Registration the Key Vault Certificate User role on the vaults (or a List certificate permission in vaults that use access policies). Without it, that rule finds nothing and the rest of the scan runs normally.
LeftSize never changes your infrastructure.
Step 4: Add secrets to GitHub
In your repository, go to Settings > Secrets and variables > Actions and add:
| Secret | Value |
|---|---|
AZURE_CLIENT_ID_MAIN |
Application (client) ID from Step 1 |
AZURE_SUBSCRIPTION_ID_MAIN |
Subscription to scan |
AZURE_TENANT_ID |
Directory (tenant) ID from Step 1 |
LEFTSIZE_INSTALLATION_ID |
Provided during LeftSize onboarding |
LEFTSIZE_REPOSITORY_TOKEN |
Provided during LeftSize onboarding |
Scanning multiple subscriptions
Each workflow job scans the subscription it signs in to. To scan several subscriptions, add them to the matrix in the workflow:
strategy:
fail-fast: false
matrix:
environment: [MAIN, PROD, DEV]
For each environment, create matching secrets:
AZURE_CLIENT_ID_PROD,AZURE_SUBSCRIPTION_ID_PRODAZURE_CLIENT_ID_DEV,AZURE_SUBSCRIPTION_ID_DEV
You can use one App Registration for all of them: assign its roles on every subscription and store the same client ID in each AZURE_CLIENT_ID_<ENV> secret. Or use a separate App Registration per environment. The generated workflow uses a single AZURE_TENANT_ID, so all subscriptions must be in the same tenant.
Findings are grouped per subscription and resource group, so issues from different subscriptions never mix.
Other ways to authenticate
OIDC is the recommended setup: nothing secret is stored, and every run gets a token that expires within the hour. The LeftSize action itself doesn’t care how you sign in. It uses whatever credentials the earlier login step in the job sets up, so these also work:
- A service principal with a client secret: use
azure/loginwithcreds: ${{ secrets.AZURE_CREDENTIALS }}(the JSON with client ID, secret, tenant and subscription) instead of the federated credential. - A self-hosted runner with a managed identity, or any other setup where
az loginhas already run on the runner.
The roles are the same: Reader and Monitoring Reader on the subscriptions you scan. With a client secret you have a long-lived credential in GitHub that you need to protect and rotate before it expires, 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 Azure Login (OIDC) step succeeds and the job summary lists the scan results
If authentication fails, check that:
- The federated credential matches your repository name and branch exactly
- The App Registration has Reader and Monitoring Reader on the subscription
- The secret names match the matrix entry (for example
AZURE_CLIENT_ID_MAINforenvironment: MAIN)
What LeftSize reads
- Resource configuration through Azure Resource Manager
- Metrics through Azure Monitor
- Never creates, changes or deletes resources
- Never reads the data inside your resources (no blob contents, no database contents)
Was this article helpful?