Skip to main content
Version: Next

Appendix C: Authentication & Session Setup

Reference Azure

DOCUMENT CATEGORY: Reference SCOPE: Authentication setup PURPOSE: Azure authentication options MASTER REFERENCE: Microsoft Learn - Azure Auth

Status: Active


This appendix consolidates the authentication options used throughout the runbook so you can quickly establish a valid Azure session in your preferred shell.

Before You Begin

Ensure you have the appropriate Azure permissions for the stage you're executing. Most Azure Foundation stages require Contributor or Owner role at the subscription level.


Execution Options

Use this method when running PowerShell scripts on Windows or in PowerShell Core with the Az module.

Connect-AzureSession.ps1
# Variables - Update these to match your environment
$TenantId = "your-tenant-id-here" # Azure AD Tenant ID
$SubscriptionId = "your-subscription-id" # Target Azure Subscription ID

# Connect to Azure (interactive login)
Connect-AzAccount -TenantId $TenantId

# Set the subscription context
Set-AzContext -SubscriptionId $SubscriptionId

# Verify connection
Write-Host "Connected to Azure:" -ForegroundColor Green
Get-AzContext | Select-Object Name, Account, Environment, Subscription, Tenant

Device Code Authentication (Headless/Remote Sessions)

Use device code authentication when running from a remote session without browser access:

Connect with Device Code
Connect-AzAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -DeviceCode

Variable Reference

All variables used in these authentication scripts should match the values documented in:

VariableSourceExample
TenantIdinfrastructure.yamlazure.tenant_id12345678-1234-1234-1234-123456789012
SubscriptionIdinfrastructure.yamlazure.subscription_id00000000-1111-2222-3333-444444444444
SpnAppIdAzure Key Vault(Retrieved from Key Vault)
SpnSecretAzure Key Vault(Retrieved from Key Vault)

Security Best Practices

Never Hard-Code Credentials

Never hard-code credentials in scripts or commit secrets to source control.

PracticeDescription
Use Key VaultStore service principal secrets in Azure Key Vault
Managed IdentitiesPrefer managed identities for Azure-hosted automation
Least PrivilegeGrant only the permissions required for each task
Rotate SecretsRotate service principal secrets regularly (90 days recommended)
Audit AccessEnable audit logging on Key Vault and review access logs

Troubleshooting

Common Issues

IssueCauseSolution
AADSTS50076MFA required by Conditional AccessComplete the MFA prompt; use device code flow for headless sessions; or configure MFA exclusion for SPN
AADSTS700016Application not foundVerify SPN App ID is correct
AADSTS7000215Invalid client secretSecret expired or incorrect — regenerate in Entra ID
The subscription could not be foundWrong subscription ID or no accessVerify subscription ID and RBAC assignments
Browser doesn't openHeadless/remote session (SSH, jump box)Use -UseDeviceAuthentication (Az), -UseDeviceCode (CLI PS), or --use-device-code (Bash)
az: command not foundAzure CLI not installed or not in PATHInstall from Microsoft Learn
Az.Accounts module not foundModule not installedRun Install-Module Az.Accounts -Scope CurrentUser

Verify Current Session

Check Azure PowerShell Session
# Show current context
Get-AzContext

# List all available contexts
Get-AzContext -ListAvailable

# Clear and re-authenticate
Disconnect-AzAccount
Connect-AzAccount -TenantId $TenantId
Check Azure CLI Session
# Show current account
az account show

# List all subscriptions
az account list --output table

# Clear and re-authenticate
az logout
az login --tenant "$TENANT_ID"

Execution Context: Permission Transitions

The Azure Local deployment process has a permission transition point at Stage 05 Step 2. Before this point, you must use elevated administrator credentials. After this point, the deployment SPN or deployment user can be used.

Permission Timeline

Part 02: Management Infrastructure ──┐
Part 03: Azure Foundation │
├─ Phase 03: Landing Zones │ ⚡ ELEVATED ADMIN REQUIRED
├─ Phase 04: Resource Providers │
└─ Phase 05: RBAC │
├─ Task 1: Create Roles │
└─ Task 2: Assign Roles ──────┴─ 🔄 PERMISSION TRANSITION POINT
└─ Step 3+: Verify ───────── ✅ DEPLOYMENT SPN/USER NOW VALID
Part 04: On-Prem Prerequisites ──────── ✅ Can use Deployment SPN
Part 05: Cluster Deployment ─────────── ✅ Can use Deployment SPN

Execution Context by Stage

Stage RangeExecutorReason
00-04 (through Stage 05 Step 1)Elevated AdminSPN doesn't have RBAC assignments yet
Stage 05 Step 2Elevated AdminThis step ASSIGNS RBAC to SPN/deployment user
Stage 05 Step 3+ onwardsDeployment SPN or Deployment UserRBAC now assigned

Who Is the Elevated Admin?

IdentityRequired RolesScope
Azure Local Cloud EngineerOwner or User Access AdministratorSubscription or Tenant Root
Customer Admin (if self-deploy)Owner or User Access AdministratorSubscription

Who Is the Deployment SPN/User?

IdentityAssigned InRoles Granted
Azure Local Cloud-cicd Service PrincipalStage 05 Step 2Contributor, User Access Administrator
Deployment User AccountStage 05 Step 2Contributor, User Access Administrator
Transition Confirmation

After completing Stage 05 Step 2, verify the SPN can authenticate and access resources before proceeding. See Phase 05: RBAC Permissions for verification steps.


Quick Reference

MethodCommandBest For
Interactive (Az)Connect-AzAccountDevelopment, manual execution
Interactive (CLI)az loginDevelopment, cross-platform
Device CodeConnect-AzAccount -DeviceCodeRemote/headless sessions
Service PrincipalConnect-AzAccount -ServicePrincipalAutomation, CI/CD
Managed IdentityConnect-AzAccount -IdentityAzure-hosted resources