Azure Identity Federation Token Generation and Resource Retrieval
This document outlines the process of generating an access token using the Azure CLI to authenticate as a service principal, using the token to retrieve virtual machines in a specified Azure subscription, and configuring the Cloud Builder role for organization-wide scanning in Azure, GCP, and AWS. The process was completed on July 1, 2025, at 10:53 PM IST.Purpose
To enable secure access to Azure resources using service principal authentication and to configure the Cloud Builder role to collect audit logs, cost data, and resource information across Azure, GCP, and AWS at the subscription, management group, or resource group level.Scope
This document covers:- Generating an access token in Azure using a service principal to access virtual machines.
- Creating and assigning the Cloud Builder role in Azure, GCP, and AWS for Steampipe scanning, with options to scope permissions to subscription, management group, or resource group levels.
- Applicable to users managing cloud resources in a single Azure subscription or across a management group.
Assumptions
- The user has administrative access to the Azure subscription, Google Cloud project, and AWS account.
- The
az,gcloud, andawsCLIs are installed and authenticated with sufficient permissions. - The user has basic knowledge of service principals and cloud resource management.
- A service principal with appropriate permissions is available for authentication.
Best Practices for Identity Federation
- Use Short-Lived Tokens: Generate tokens with a short expiration time to minimize security risks.
- Least Privilege: Assign only the necessary permissions to the service principal to reduce the attack surface.
- Secure Service Principal Access: Restrict access to service principal credentials.
- Audit and Monitor: Regularly audit role assignments and monitor token usage to detect unauthorized access.
- Scope Permissions Appropriately: Assign the Cloud Builder role at the management group level for broad scanning, or at the subscription/resource group level for granular control.
- Use Managed Authentication: Prefer
az accountcommands for token generation to simplify the process and reduce manual key management.
Prerequisites
- Azure CLI installed and authenticated with a user or service principal with sufficient permissions (e.g.,
Contributor,Reader). gcloudCLI installed and authenticated for GCP operations.awsCLI installed and authenticated for AWS operations.- Azure Subscription:
your-azure-subscription-id. - Google Cloud Project:
your-project-name(Project Number:your-project-number). - AWS Account:
your-aws-account-id. - Service Principal:
your-service-principal@your-tenant.onmicrosoft.com.
Step-by-Step Guide to Access Token Creation
The following steps outline the process to generate an access token via service principal authentication, use it to access Azure resources, and configure the Cloud Builder role.Step 1: Create a Service Principal
Create a new service principal (your-service-principal) for authentication.
1.1 Create the Service Principal
Outcome:
- Service principal created with
Readerrole, e.g.: - Save the
appId,password, andtenantfor use asYOUR_CLIENT_ID,YOUR_CLIENT_SECRET, andYOUR_TENANT_ID.
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 Azure, GCP, and AWS, with options to scope permissions to subscription, management group, or resource group levels.2.1 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.
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 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 Azure and GCP, assigned to the Steampipe service via role assumption.
Step 3: Generate an Access Token
Useaz login to authenticate as the service principal and generate an access token.
3.1 Authenticate with Azure CLI
3.2 Generate the Access Token
Outcome:
- Generated an access token, e.g.:
- Extract the
accessTokenfor use asYOUR_ACCESS_TOKEN.
Summary
- Service Principal:
your-service-principal@your-tenant.onmicrosoft.com - Cloud Builder Role:
CloudBuilder - Access Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6... - Resource Retrieved: Virtual machines in
your-azure-subscription-id. - Cloud Builder Role: Created and assigned in Azure, GCP, and AWS for Steampipe scanning, with permissions scoped to management group, subscription/project, or resource group levels as needed.