CostLensAzure Accounts

Azure Accounts

Connect an Azure subscription to CostLens in one click — sign in with Microsoft and CostLens discovers your subscriptions and grants itself read access automatically.

Updated September 20269 min read

CostLens reads your Azure cost data and resource configuration through a dedicated App Registration (service principal), granted read-only Azure RBAC roles. The guided Add Account wizard connects with a Microsoft sign-in — no app registration, role assignment, or IDs to find and paste.

Multi-cloud from one workspace

Azure subscriptions sit alongside your AWS and GCP accounts in the same CostLens organization. Spend, recommendations, and fixes are filterable per cloud and rolled up across all of them.

How it works

StepWhat happens
1. Choose access levelRead-Only (monitoring, reporting, recommendations) or Read/Write (adds Auto-Fix for idle-VM stop/start).
2. Review exactly what's grantedCostLens shows the precise Azure roles it's about to request before anything happens.
3. AuthorizeOpens Microsoft sign-in in the same tab.
4. CostLens discovers and connects automaticallyAfter you sign in and consent, CostLens lists every subscription your account can see, grants itself Cost Management Reader + Reader on each, and connects them — no subscription ID to type.
5. First sync startsBilling sync via the Cost Management Query API, optimization checks, and AI explanations run automatically.

Connect a new Azure subscription

Step 1 — Add Account → Azure → choose access level

From the Accounts page, click Add Account, choose Azure, then choose Read-Only or Read/Write:

Access levelGrantsEnables
Read-OnlyCost Management Reader (billing) + Reader (resource inventory, Azure Monitor metrics, VMSS enumeration)Billing visibility, inventory, anomaly detection, recommendations & savings estimates
Read/WriteEverything in Read-Only, plus a least-privilege custom role limited to idle-VM start/deallocate and a few other reversible actions — never Contributor or OwnerEverything in Read-Only, plus Apply Fix and Auto-Fix

The trust model is a multi-tenant Microsoft Entra application granted Azure RBAC at the scope you consent to, using a federated credential where supported — no long-lived client secret is required for this flow.

Step 2 — Authorize (Microsoft sign-in)

Click Authorize. This redirects your browser to Microsoft's own sign-in page (the standard OAuth consent screen) — sign in as a user with Owner (or equivalent role-assignment rights) on the subscriptions you want to connect, and accept.

Sign in with the right account

CostLens can only see and grant itself access to subscriptions the signed-in user can already manage. If you don't see an expected subscription later, you likely signed in as the wrong user or lack Owner rights on it.

Step 3 — CostLens discovers and connects automatically

Microsoft redirects you back into CostLens. From here everything is automatic:

  1. CostLens lists every subscription visible to your signed-in identity.
  2. It assigns itself Cost Management Reader and Reader on each one.
  3. As soon as at least one subscription's roles are confirmed, that subscription connects and its first sync starts.

Azure RBAC can take up to about a minute to propagate — the wizard keeps checking automatically during that window, so you don't need to do anything but wait.

Multiple subscriptions found

If your account has access to more than one subscription, CostLens connects the first one automatically and lists the rest as separate accounts you can add the same way, or via Connect an organization below.

Connect a whole tenant (management group)

To grant CostLens access to every subscription under a management group in one step instead of one at a time, use the Connect an organization flow from the Accounts page (the same multi-account discovery used for AWS Organizations): pick an already-connected Azure account, optionally run the generated management-group grant script once, then Discover & connect — CostLens enumerates and connects every subscription it can now see.

Reconnecting a removed subscription

If a subscription was previously connected and later removed, reconnecting it (Authorize again, sign in the same way) reuses the existing role assignments rather than creating duplicates — Azure role assignments are naturally idempotent, so there's nothing to clean up first, unlike AWS's CloudFormation stacks.

If you connect a subscription that turns out to already be active in your CostLens organization, you'll see "This account already exists — it's already connected. Nothing was added again" on the success screen.

Alternative: connect with your own App Registration

If your organization requires using its own app registration rather than CostLens's, or Authorize isn't available in your environment, use the manual path instead.

Step 1 — Azure CLI setup script

The wizard's manual-entry step generates this script with your Subscription ID pre-filled and offers a one-click copy/download. Run it in Azure Cloud Shell or any terminal with the az CLI signed in as a user who can create app registrations and assign roles.

bash
#!/usr/bin/env bash
# CostLens — Azure connection setup (Cost Management Reader, least privilege)
set -euo pipefail
 
SUBSCRIPTION_ID="<SUBSCRIPTION_ID>"
APP_NAME="costlens-cost-reader"
 
az account set --subscription "$SUBSCRIPTION_ID"
 
# 1. Create an app registration + service principal
APP_ID=$(az ad app create --display-name "$APP_NAME" --query appId -o tsv)
az ad sp create --id "$APP_ID" >/dev/null
 
# 2. Create a client secret (valid 12 months) — copy the printed value
CLIENT_SECRET=$(az ad app credential reset --id "$APP_ID" --years 1 --query password -o tsv)
 
# 3. Grant Cost Management Reader (read-only cost data) at the subscription scope
az role assignment create \
  --assignee "$APP_ID" \
  --role "Cost Management Reader" \
  --scope "/subscriptions/$SUBSCRIPTION_ID"
 
# 4. Grant Reader (resource inventory, Monitor metrics) at the same scope
az role assignment create \
  --assignee "$APP_ID" \
  --role "Reader" \
  --scope "/subscriptions/$SUBSCRIPTION_ID"
 
TENANT_ID=$(az account show --query tenantId -o tsv)
 
echo ""
echo "Enter these into CostLens's manual connect step:"
echo "  Tenant ID:       $TENANT_ID"
echo "  Client ID:       $APP_ID"
echo "  Client secret:   $CLIENT_SECRET"
echo "  Subscription ID: $SUBSCRIPTION_ID"

Broader scope

To cover many subscriptions at once, assign both roles at a management group scope instead of a single subscription: --scope "/providers/Microsoft.Management/managementGroups/<MG_ID>".

Step 2 — Enter the details in CostLens

On the wizard's manual-entry step, enter the Directory (tenant) ID, Subscription ID, and — since you're using your own app registration rather than CostLens's — the Application (client) ID and client secret the script printed. Click Connect account.

Recommendations & Advisor

Azure recommendations come from two places, both read-only:

  • Azure Advisor cost recommendations (right-sizing, shutdown, reservations) — the authoritative source, surfaced by the Azure Advisor (Cost) check. When Advisor's own "right-size or shut down" recommendation targets a VM, CostLens can apply it directly using the same fix flow as its own VM checks.
  • CostLens resource checks over the Azure Resource Manager + Monitor APIs — idle VMs, unattached disks, orphaned snapshots, idle public IPs and load balancers.

Both Reader (resource/metric reads) and Cost Management Reader (billing) are granted automatically by Authorize; the manual path needs both assigned explicitly (Step 1 above).

Kubernetes (AKS) cost & optimization

The Cost Management Reader + Reader roles above already give CostLens what it needs for AKS. Reader covers Azure Monitor metric reads and VM Scale Set enumeration, so no separate Monitoring Reader role is required.

Node-pool optimization — no cluster change needed

CostLens follows each AKS node pool to its backing VM Scale Set (in the MC_… node resource group) and reads its CPU from Azure Monitor. Idle / right-sizing / Spot node-pool recommendations appear on the Recommendations page automatically. See Kubernetes Optimization.

Per-cluster node cost — automatic

AKS node compute lives in the cluster's node resource group (MC_<resource-group>_<cluster>_<region>). CostLens attributes that resource group's spend to the cluster using the Cost Management Reader role — nothing to enable.

Per-namespace & per-workload cost — enable the AKS cost analysis add-on

On each cluster, enable the AKS cost analysis add-on (Azure Portal → cluster → Cost analysis, or the aks-preview CLI). Azure Cost Management then allocates the cluster's spend by Kubernetes namespace and controller, which appears in the Kubernetes panel on the Billing page within ~24 hours. See Kubernetes Costs.

No agent, no cluster access

CostLens reads AKS cost and utilisation entirely from Cost Management, Azure Resource Graph, and Azure Monitor — there is nothing to install in the cluster and no Kubernetes API access is required.

Applying fixes (optional)

Choosing Read/Write during onboarding already grants what Auto-Fix needs. Scanning itself is always read-only regardless of access level. Today's Azure remediations:

ActionReversible?
Stop an idle VM (deallocate)Yes — Auto-Fix can apply this automatically; a 24-hour manual rollback window follows
Delete an unattached disk / orphaned snapshot / idle public IP / idle load balancerNo — always requires manual approval with typed confirmation, on any cloud

If you connected with Read-Only and want Auto-Fix later, reconnect with Read/Write — Authorize again and choose Read/Write; CostLens adds the missing role assignments to the existing service principal rather than creating a new one.

Enabling automatic Auto-Fix with your own app registration (least privilege)

If you used the manual/own-app-registration path, grant only VM power control via a custom role rather than broad Contributor:

bash
az role definition create --role-definition '{
  "Name": "CostLens Auto-Fix (VM power)",
  "Description": "Least-privilege VM start/deallocate for CostLens Auto-Fix",
  "Actions": [
    "Microsoft.Compute/virtualMachines/read",
    "Microsoft.Compute/virtualMachines/start/action",
    "Microsoft.Compute/virtualMachines/deallocate/action"
  ],
  "AssignableScopes": ["/subscriptions/<SUBSCRIPTION_ID>"]
}'
az role assignment create --assignee "<CLIENT_ID>" \
  --role "CostLens Auto-Fix (VM power)" --scope "/subscriptions/<SUBSCRIPTION_ID>"

First sync phases

PhaseWhat happens
Fetching billing dataPulls monthly + daily cost (normalised to USD via the CostUSD metric) from the Cost Management Query API
Running optimisation checksIngests Azure Advisor + runs the CostLens resource checks
Generating AI explanationsAevi writes plain-English explanations and savings estimates

Managing connected accounts

ActionWho can do itDescription
Sync NowOperators, AdminsTriggers an immediate billing sync
Test ConnectionOperators, AdminsRe-validates the credentials without changing anything
Edit CredentialsAdmins onlyUpdate the account name, tenant/client/subscription IDs, or rotate the client secret
Remove AccountAdmins onlyDisconnects and permanently deletes all associated data — cannot be undone

Common errors and fixes

ErrorFix
Microsoft sign-in didn't complete / "consent was not granted"Authorize again — you may have closed the Microsoft window or clicked Cancel. Make sure you sign in as a user with Owner rights on the subscription.
Couldn't read your Azure subscriptions after sign-inSign in again as a subscription Owner so CostLens can assign itself the read roles, then wait — RBAC can take up to a minute to propagate before the automatic retry succeeds.
AUTH_FAILED (manual path)The client secret is wrong or expired. Re-run az ad app credential reset and update the secret via Edit Credentials.
INSUFFICIENT_PERMISSIONSThe service principal is missing a role. Confirm Cost Management Reader (and Reader for resource checks) is assigned at the correct scope — Authorize assigns both automatically; the manual path needs both assigned explicitly.
EXPORT_NOT_CONFIGUREDCost Management data isn't available yet for a new subscription — allow up to 24–48 hours after first usage.
No recommendations appearAzure Advisor needs a few days of usage to generate cost recommendations; resource checks require the Reader role.
No per-namespace AKS costEnable the AKS cost analysis add-on on the cluster; allow ~24h for allocated data to appear.
CostLens
Previous
AWS Accounts
CostLens
Next
GCP Accounts