Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Validate Azure configurations, ARM/Bicep templates, and resource settings before deployment
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/aspire-functions-secrets.md
1# Aspire + Azure Functions: Secret Storage Validation23> โ ๏ธ **Pre-provisioning check** โ Run this BEFORE `azd provision`.45## When This Applies67This check is required when **all** of these are true:89| Condition | How to detect |10|-----------|--------------|11| .NET Aspire project | `*.AppHost.csproj` exists or `Aspire.Hosting` package reference |12| Azure Functions component | `AddAzureFunctionsProject` call in `AppHost.cs` or `Program.cs` |13| Identity-based storage | `WithHostStorage` call (Aspire default) |1415## Detection1617Search for `AddAzureFunctionsProject` in the AppHost source file(s):1819```bash20grep -rn "AddAzureFunctionsProject" . --include="*.cs"21```2223**PowerShell:**24```powershell25Get-ChildItem -Recurse -Filter "*.cs" | Select-String "AddAzureFunctionsProject" -List26```2728If found, check whether `AzureWebJobsSecretStorageType` is already configured in those same file(s):2930```bash31# Check only the AppHost file(s) that contain AddAzureFunctionsProject32find . -name "*.cs" -path "*AppHost*" -print0 | xargs -0 grep -l "AddAzureFunctionsProject" 2>/dev/null | xargs grep -l "AzureWebJobsSecretStorageType"33```3435**PowerShell:**36```powershell37Get-ChildItem -Recurse -Filter "*.cs" |38Where-Object { $_.FullName -match "AppHost" } |39Select-String "AddAzureFunctionsProject" -List |40ForEach-Object { Select-String "AzureWebJobsSecretStorageType" -Path $_.Path }41```4243**If `AddAzureFunctionsProject` is present but `AzureWebJobsSecretStorageType` is NOT configured in the same file โ fix is required.**4445## Fix4647Add `.WithEnvironment("AzureWebJobsSecretStorageType", "Files")` to the Azure Functions project builder chain in the AppHost source file that contains the `AddAzureFunctionsProject` call (often `Program.cs` in the `*.AppHost` project).4849### Before5051```csharp52var functions = builder.AddAzureFunctionsProject<Projects.MyFunctions>("functions")53.WithHostStorage(storage)54.WithReference(queues);55```5657### After5859```csharp60var functions = builder.AddAzureFunctionsProject<Projects.MyFunctions>("functions")61.WithHostStorage(storage)62.WithEnvironment("AzureWebJobsSecretStorageType", "Files")63.WithReference(queues);64```6566> ๐ก **Tip:** Place `.WithEnvironment(...)` immediately after `.WithHostStorage(...)` for clarity.6768## Why This Is Required6970Azure Functions needs storage for managing host secrets/keys (function keys, host keys, master key). By default, it stores them as blobs in the `AzureWebJobsStorage` account.7172When Aspire configures identity-based storage access (via `WithHostStorage`), it sets URI-based environment variables like `AzureWebJobsStorage__blobServiceUri` instead of a connection string. The Functions runtime's secret manager does **not** support these identity-based URIs โ it requires either a connection string or SAS token.7374Setting `AzureWebJobsSecretStorageType=Files` switches the Functions host to file-system-based key storage, bypassing the blob storage dependency for secrets.7576## Error Without This Setting7778```79System.InvalidOperationException: Secret initialization from Blob storage failed80due to missing both an Azure Storage connection string and a SAS connection URI.81For Blob Storage, please provide at least one of these.82```8384## When This Check Does NOT Apply8586| Scenario | Why |87|----------|-----|88| Aspire project without Azure Functions | No Functions secret manager involved |89| Standalone Azure Functions (not Aspire) | Uses connection string by default |90| Functions with explicit connection string | `AzureWebJobsStorage` is a full connection string, not identity-based |91| `AzureWebJobsSecretStorageType` already set | Configuration is already present |92