Workload identity and configuration
Workload identity and configuration
Workload identity lets an application authenticate as a scoped service principal without embedding a permanent credential.
Authentication establishes an identity; authorization limits operations and resource scope. Azure managed identities can be system-assigned (lifecycle coupled to a resource) or user-assigned (independent resource); AKS uses an appropriate workload identity integration. Azure Key Vault can supply needed secrets for dependencies that cannot use token-based access. AWS ECS task roles authorize application calls, while task execution roles support the ECS agent; Google Cloud Run uses a runtime service account distinct from the deployment identity. Never grant broad administrative roles to fix a denied request. Token audiences, tenant boundaries, expiry and actual service permissions matter. SDK credentials can use a documented credential chain locally, but production must constrain the intended identity and avoid unexpected developer credential fallback. Choose a provider credential implementation at the composition root behind an application-owned port; a fake is not proof of actual token validation. Configuration may combine JSON, environment variables and secret providers; in the common .NET configuration setup environment variables override earlier JSON values, and double underscores map nested keys. Validate required configuration at startup. Never write secrets, token bodies, or full connection strings to telemetry. Rotate keys where unavoidable and test access after rotation. All sample identities and data below are fabricated, and no credential is requested from a provider.
Baseline: .NET 10 / C# 14. All C# results below are reasoned, not executed. Synthetic calculations are not vendor quotes or production measurements.
Model exact resource authorization
The fake permission set is a local allowlist, not a cloud IAM engine.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;using System.Collections.Generic;var grants = new HashSet<(string Actor,string Action,string Resource)> { ("reader","read","catalog-a") };foreach (var request in new[] { ("reader","read","catalog-a"), ("reader","write","catalog-a"), ("reader","read","catalog-b"), ("deployer","read","catalog-a") }) Console.WriteLine(grants.Contains(request) ? "allow" : "deny");Expected result (not executed):
allowdenydenydenyThe scope includes both operation and resource. Actual IAM can have inheritance, explicit denies, conditions and propagation delays.
Resolve and validate nonsecret configuration
Use two in-memory providers to demonstrate precedence without reading host environment variables.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits. Requires the ASP.NET Core 10 shared framework.
using System;using System.Collections.Generic;using Microsoft.Extensions.Configuration;var settings = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary<string,string?> { ["Store:Region"] = "lab-a" }) .AddInMemoryCollection(new Dictionary<string,string?> { ["Store:Region"] = "lab-b" }).Build();string region = settings["Store:Region"] ?? throw new InvalidOperationException("missing region");if (region is not ("lab-a" or "lab-b")) throw new InvalidOperationException("invalid region");Console.WriteLine(region);Expected result (not executed):
lab-bLater providers override previous values for the same key. This shared-framework example deliberately does not inspect any real environment.
Use an injected storage boundary
A tiny fake returns one synthetic object only for the intended identity.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;IStore store = new LabStore();foreach (string actor in new[] { "reader", "other" }) { try { Console.WriteLine(store.Read(actor,"stock")); } catch (UnauthorizedAccessException) { Console.WriteLine("denied"); }}interface IStore { string Read(string actor,string key); }sealed class LabStore : IStore { public string Read(string actor,string key) => actor == "reader" && key == "stock" ? "units=3" : throw new UnauthorizedAccessException();}Expected result (not executed):
units=3deniedA real adapter gets authenticated identity from a trusted credential source, never a caller-supplied actor string. Test provider access separately; the fake tests application decisions only.
Apply the concept
Design a reader service and a deployment pipeline that cannot read each other's secrets. Include an allow/deny test matrix.
Use the manual practice and knowledge check. Do not deploy or publish these fixtures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Workload identity and configuration — knowledge check
Apply the lesson concepts to the following scenarios.
What does managed identity remove from application configuration?
Which ECS role should authorize application data access?
What wins between two providers for the same configuration key?
Does the local fake prove actual cloud IAM enforcement?
What is an appropriate log field after authentication failure?