CI/CD on Azure · Appendix to part 4

Restricting access to Container Apps with Entra ID (Easy Auth)

Putting Entra ID authentication in front of the staging container, so that only accounts from the right tenant can reach it.

  • Azure
  • Entra ID
  • Easy Auth

Why this appendix

Article 4 deploys the Container App with an external ingress, publicly reachable as soon as it is created, and therefore technically reachable by anyone who knows (or scans) its generated URL, even if it is not indexed anywhere. Rather than relying on the obscurity of that URL, this appendix explicitly restricts who can reach it, with Entra ID authentication in front of the container.

The principle (Easy Auth)

Container Apps ships with a built-in authentication mechanism, commonly called Easy Auth: a sidecar managed by Azure that sits in front of the app’s container, handles the OAuth flow with Entra ID, validates the tokens, and only forwards requests to Nginx once the user is authenticated. The container itself needs to know strictly nothing about this mechanism: no code to write, no auth library to integrate into the site.

For a sysadmin, the closest analogy is a reverse proxy with pre-authentication (something like oauth2-proxy in front of an internal service), except that here, Azure hosts and fully manages that proxy.

Step 1: Creating the app registration in Entra ID

This application identity is what lets Entra ID recognize our Container App as a legitimate OAuth client. First get the app’s URL (needed for the callback URL):

powershell
$app = Get-AzContainerApp -Name "ca-westbalidrivers-staging" -ResourceGroupName $rg
$fqdn = $app.Configuration.IngressFqdn

$redirectUri = "https://$fqdn/.auth/login/aad/callback"
powershell
$adApp = New-AzADApplication `
  -DisplayName "westbalidrivers-staging-auth" `
  -Web @{ RedirectUri = @($redirectUri) }

# Generate a client secret for this app registration
$clientSecret = New-AzADAppCredential -ObjectId $adApp.Id

The Az.Resources module (which handles Entra ID app registrations) has, like Az.App, changed signature several times over recent versions. If -Web returns a parameter error, Get-Help New-AzADApplication -Full gives the exact structure expected by the installed version.

Step 2: Storing the secret and configuring authentication

The client secret must be registered as a secret of the Container App, then referenced by name in the auth configuration, never in clear text in the configuration itself:

powershell
$secretObject = New-AzContainerAppSecretObject `
  -Name "entra-client-secret" `
  -Value $clientSecret.SecretText

Update-AzContainerApp `
  -Name "ca-westbalidrivers-staging" `
  -ResourceGroupName $rg `
  -Secret $secretObject

$identityProvider = New-AzContainerAppIdentityProviderObject `
  -RegistrationAppId $adApp.AppId `
  -RegistrationAppSecretSettingName "entra-client-secret"

New-AzContainerAppAuthConfig `
  -Name "current" `
  -ContainerAppName "ca-westbalidrivers-staging" `
  -ResourceGroupName $rg `
  -PlatformEnabled `
  -GlobalValidationUnauthenticatedClientAction "RedirectToLoginPage" `
  -IdentityProvider $identityProvider

-GlobalValidationUnauthenticatedClientAction "RedirectToLoginPage" is the parameter that does all the work: any unauthenticated request is redirected to the Entra ID sign-in screen before it reaches the Nginx container. A bot or a scanner that stumbles on the URL runs into this sign-in page, never into the site itself.

Step 3: Restricting to accounts from the right tenant

By default, the Entra ID app registration may accept accounts from any Microsoft tenant. For a useful restriction, we need to check that the configuration really limits access to a specific tenant: the issuer parameter of the configuration must be scoped to the exact tenant we want to refer to (https://login.microsoftonline.com/<TENANT_ID>/v2.0), not to the generic multi-tenant endpoint.

Step 4: Verification

bash
curl -IL https://$fqdn

Without being authenticated, this request must now return a redirect to the Entra ID sign-in page rather than a direct 200 OK: that is the proof that Easy Auth works. Once signed in through a browser with an account from the right tenant, the site should display normally.

A useful side effect!

Along the way, this restriction settles a legitimate question about how scale-to-zero behaves with bots: a bot or a scanner that has neither the right IP nor the right credentials never wakes the container up, whatever its scanning behavior. The redirect to Entra ID happens before the request even reaches the app. As a result, we can guarantee “guaranteed” cost control for our Azure Container App, with no untimely or unwanted scale-ups.

Checklist

  • The Entra ID app registration exists, with the right RedirectUri and a generated secret
  • New-AzContainerAppAuthConfig is in place, with RedirectToLoginPage as the default action
  • The issuer parameter is scoped to the tenant, not to the multi-tenant endpoint
  • An anonymous request is indeed redirected to the Entra ID sign-in page
  • The Container App responds normally once authenticated with an account from the right tenant
© 2026 Louis Lecat