Volume 5 · Chapter 9 — Advanced .NET Cloud Native Architecture
Security Architecture
9.1 Introduction
Security in cloud-native systems is architectural, not a bolt-on. It rests on a few principles applied consistently: never trust the network (zero trust), grant the least privilege necessary, keep no secrets in code, encrypt everywhere, and verify identity for every request - human or workload. This chapter frames how those principles translate into concrete Azure and .NET mechanisms.
9.2 Zero Trust and Defense in Depth
Zero trust means every request is authenticated and authorized regardless of where it originates - being inside the network grants nothing. Defense in depth layers controls (network, identity, application, data) so that breaching one doesn’t compromise the system. In practice: private endpoints and network segmentation, plus per-service authentication, plus authorization at the application, plus encrypted data - each an independent barrier.
sequenceDiagram autonumber participant Client participant Entra as Entra ID participant API participant KV as Key Vault Client->>Entra: authenticate Entra-->>Client: access token (JWT) Client->>API: request + Bearer token API->>API: validate token, check scopes/roles API->>KV: fetch secret via managed identity KV-->>API: secret (no credential stored in app) API-->>Client: authorized response
9.3 Identity: Managed Identity and Workload Identity
The single most impactful practice is eliminating stored credentials. Managed identities give an Azure resource (an App Service, an AKS pod via workload identity) an Entra ID identity that Azure rotates automatically, so the app authenticates to Key Vault, SQL, or Service Bus with no connection-string secret in code or config. Human access uses Entra ID with MFA and conditional access; service-to-service uses tokens with scopes.
// No secrets in code: DefaultAzureCredential uses the resource's managed identity in Azure.
var credential = new DefaultAzureCredential();
var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), credential);
KeyVaultSecret secret = await client.GetSecretAsync("Db-ConnectionString");
// Azure rotates the identity's credentials automatically - nothing to leak in source control.
9.4 Secrets, Encryption, and Data Protection
Secrets live in Azure Key Vault (or Kubernetes secrets backed by it), never in code or plain config, accessed via managed identity and rotated regularly. Data is encrypted in transit (TLS everywhere) and at rest (Azure storage/SQL encryption, with customer-managed keys where required). Sensitive fields may be additionally encrypted or tokenized at the application layer, and access to keys is itself audited.
9.5 Authorization and Least Privilege
Authorization enforces least privilege: identities - users and workloads - get only the permissions they need. In .NET this is policy-based authorization on APIs (scopes, roles, claims); in Azure it’s RBAC scoped as narrowly as possible on resources. The principle is that a compromised component or credential should be able to do as little as possible, containing blast radius.
Why is eliminating stored secrets with managed identities so important, and how does it work?
Eliminating stored secrets is important because stored credentials - connection strings, API keys, passwords in code, config files, or environment variables - are the single most common and damaging source of breaches: they leak into source control, logs, backups, and screenshots; they’re rarely rotated; they’re shared and hard to revoke; and one leaked long-lived secret can grant an attacker persistent access to a database or service. Every stored secret is a liability that must be protected, rotated, and audited, and in practice teams do all three poorly. Managed identity removes the secret from the equation entirely, which is why it’s the highest- impact security practice available on Azure. It works by giving an Azure resource - an App Service, Function, VM, or (via workload identity) an AKS pod - its own identity in Entra ID that Azure manages. Instead of the app holding a credential to authenticate to Key Vault, SQL, Storage, or Service Bus, the app requests a token for its managed identity from the platform, and Azure issues a short-lived token proving “I am this resource”; the target service is configured to trust that identity via RBAC. In .NET,DefaultAzureCredentialtransparently obtains this token when running in Azure, so the same code that uses managed identity in production can use a developer’s own credentials locally, with no secret anywhere. The credentials backing the identity are rotated automatically by Azure and never exposed to the application or to developers, so there is nothing to leak, nothing to rotate manually, and nothing to accidentally commit. The security benefits compound: there are no long-lived secrets in code, config, or pipelines to steal; access is authorization on an identity, so it’s revoked instantly by removing a role rather than rotating a secret everywhere it’s copied; every access is tied to a specific identity and auditable; and least privilege is enforced by scoping that identity’s RBAC narrowly (this pod can read this one Key Vault secret, nothing else), so a compromise has minimal blast radius. For secrets that genuinely must exist - a third-party API key, a certificate - they live in Key Vault and are fetched at runtime via the managed identity, so even those aren’t in code and are centrally rotated and audited. So the practice is: give workloads platform-managed identities, grant them least-privilege RBAC on the resources they need, fetch any unavoidable secrets from Key Vault via that identity, and keep zero credentials in source or config. That eliminates the largest, most preventable category of breaches - leaked stored secrets - and it’s the answer I’d expect a senior engineer to reach for immediately when asked how to secure service-to-service and service-to-data access on Azure.
Design a zero-trust, defense-in-depth security architecture for a regulated enterprise workload on Azure.
I’d build layered, independent controls around a zero-trust core - every request authenticated and authorized regardless of origin, least privilege everywhere, no stored secrets, encryption in transit and at rest - so that breaching any single layer doesn’t compromise the system, and I’d make the secure path the default. Identity is the foundation: all human access is through Entra ID with MFA and conditional access (device compliance, location, risk), and just-in-time privileged access rather than standing admin rights; all workload access uses managed/workload identities with no stored credentials, and service-to-service calls carry Entra tokens with narrowly-scoped scopes that APIs validate on every request - being inside the network grants nothing. Network is a layer, not the trust boundary: private endpoints keep data services (SQL, Storage, Key Vault, Service Bus) off the public internet, VNets are segmented so compromise of one tier can’t freely reach others, ingress passes through a WAF/Front Door and an API gateway that terminate TLS and enforce authentication and rate limiting, and egress is restricted. Application layer enforces authorization with least privilege - policy-based checks on scopes, roles, and claims, and RBAC scoped as narrowly as possible on every Azure resource - so a compromised component can do very little. Data is protected independently: encrypted in transit (TLS everywhere) and at rest (with customer-managed keys in Key Vault where the regulator requires key control), sensitive fields additionally encrypted or tokenized at the application layer, and all secrets and keys held in Key Vault, accessed via managed identity, rotated regularly, with key access itself audited. Around all of this I add detection and governance because defense in depth assumes prevention can fail: centralized logging and monitoring (Defender for Cloud, Sentinel) for threat detection, comprehensive audit trails of who/what accessed what, Azure Policy enforcing non-negotiable guardrails (no public storage, mandatory encryption, required private endpoints, allowed regions for data residency) so misconfigurations are blocked or remediated automatically, and secure CI/CD with IaC scanning, image scanning, and least-privilege pipeline identities so vulnerabilities and insecure config are caught before deployment. I design for blast- radius containment: narrow identities, network segmentation, and per-tenant/per-service isolation so an incident is bounded, plus break-glass procedures that are audited. And I ensure the secure way is the easy way - golden IaC modules and platform defaults so teams inherit private endpoints, managed identity, and encryption without having to assemble them correctly themselves. The result is genuine defense in depth: identity, network, application, and data are each an independent barrier, every request is verified (zero trust), least privilege limits what any compromise achieves, no secrets exist to steal, everything is encrypted and audited, and policy plus monitoring provide enforcement and detection - which is the architecture a regulated enterprise needs and what I’d expect a security architect to lay out end to end.
9.6 Healthcare Enterprise Scenario
A healthcare platform runs zero trust: clinicians authenticate through Entra ID with MFA and conditional access, and every API validates a scoped token on each request. All services use managed identities - no connection strings anywhere - to reach SQL, Storage, and Key Vault over private endpoints. Patient data is encrypted at rest with customer-managed keys and sensitive fields are tokenized at the application layer. Azure Policy blocks public data services and enforces data residency, Sentinel monitors for threats, and every access to patient data is audited, so a breach of any one layer is contained by the others.
Chapter Revision Notes
- Zero trust: authenticate and authorize every request; the network grants no implicit trust.
- Managed/workload identities eliminate stored secrets - the highest-impact security practice on Azure.
- Secrets in Key Vault, fetched via managed identity, rotated and audited - never in code or config.
- Encrypt in transit and at rest; customer-managed keys where regulation requires key control.
- Defense in depth: independent identity, network, application, and data layers contain any single breach.