📋 In This Post
- Lab Overview
- Cloud Services and Concepts
- Architecture and Workflow
- Prerequisites
- Implementation
- Validation and Evidence
- Security and Cost
- Troubleshooting and Lessons
- Cleanup and Key Takeaways
Lab Overview
The problem. "Developers should self-serve" usually means a pipeline somebody wired up once, and that pipeline holds credentials: a service principal secret in repository secrets, a registry password in a login step, registry credentials in the application's own configuration. Each is a long-lived string that has to be stored, rotated and eventually explained to an auditor.
The objective. Build the path from commit to running container so that no credential exists at any of those three handoffs, measure how long the path takes, and — the part that actually matters — prove the alternative is closed rather than merely unused.
The outcome. Twelve Terraform resources, nine validation
checks passing, and 64 seconds from git push to
the new content being served. The registry's admin account does not exist, so
there is no password for a pipeline to hold.
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| Azure Container Registry (Basic) | Stores the image the pipeline builds | A private registry. Basic includes 10 GiB and supports Entra authentication; it bills a flat daily rate for existing |
| Azure Container Apps (Consumption) | Runs the image and gives it an HTTPS endpoint | Serverless containers billed per vCPU-second and per request, with a monthly free grant and no charge at zero replicas |
| Federated identity credential | Lets GitHub authenticate without a stored secret | A trust rule on an Entra app registration: "accept a token from GitHub, for this repository, on this branch". No password exists to leak |
| User-assigned managed identity | Lets the running app pull its own image | An Azure identity with no credential attached, granted only AcrPull |
| Repository variables | Carry the client, tenant and subscription IDs | Not secrets. A client ID grants nothing without a token Entra will mint only for this repo and branch |
One distinction worth making early. A secret is something you hold that proves who you are. A token is something issued to you, on the spot, because of what you already are. Everything in this week replaces the first with the second.
Architecture and Workflow
- A developer pushes a change under
app/. - GitHub mints an OIDC token naming this repository and branch, and
azure/loginexchanges it with Entra. az acr loginexchanges that same token for a registry refresh token — nodocker loginwith a password.- The image is built with the commit SHA baked into the page it serves, and pushed.
az containerapp updatepoints the app at the new tag.- The app pulls that image as its own managed identity and the new revision starts serving.
Three design decisions.
Two identities, not one. The application's identity holds
AcrPull and nothing else; the pipeline's holds
AcrPush and Contributor on one container app. Collapsing them
would mean anything that could read the running app's token could also publish
images to the registry.
Terraform does not own the image. The app is created pointing at a
bootstrap image, and ignore_changes on that field hands it to the
pipeline. Without it every terraform apply would revert the app and
the two systems would fight over one field forever. Platform owns the shell;
the pipeline owns what runs in it.
The CI role is scoped to the single app, not to the resource group. Its job is to change an image, not to create resources next to one.
Prerequisites
- An Azure subscription where you hold Owner, and a tenant where you can create an app registration.
- Resource providers:
Microsoft.App,Microsoft.ContainerRegistry,Microsoft.OperationalInsights,Microsoft.ManagedIdentity. - Terraform
>= 1.10,azurerm ~> 5.2,azuread ~> 3.0, GitHub CLI. - A GitHub repository you can set variables on. No secrets are needed, which is the point.
- Cross-week dependency, and a correction. Week 08's Log Analytics workspace was recorded as staying up; it is gone. This week creates its own, and would have had to anyway — see Troubleshooting.
Implementation
1. Enumerate what can bill, before deploying
2. Build the platform, with no admin account on the registry
resource "azurerm_container_registry" "acr" {
name = "acrwk15devscus001"
sku = "Basic"
admin_enabled = false # half the claim, not a hardening detail
}
resource "azurerm_container_app" "app" {
# ...
registry {
server = azurerm_container_registry.acr.login_server
identity = azurerm_user_assigned_identity.app.id # no username, no password
}
lifecycle {
ignore_changes = [template[0].container[0].image] # the pipeline owns this
}
}
logs_destination was stated alongside the workspace ID.3. Trust GitHub, without giving it anything to hold
resource "azuread_application_federated_identity_credential" "branch" {
application_id = azuread_application.ci.id
audiences = ["api://AzureADTokenExchange"]
issuer = "https://token.actions.githubusercontent.com"
subject = var.federated_subject # built from GitHub's own IDs
}
There is no azuread_application_password in that file and there
is not meant to be.
4. Push a commit and let the path run
Validation and Evidence
| Test | Expected | Actual | Status |
|---|---|---|---|
| Registry on Basic | Basic | Basic, $0.1666/day | Pass |
| Registry admin account disabled | false | false | Pass |
| App identity holds AcrPull | one assignment | AcrPull | Pass |
| App pulls by identity, no username | username empty | identity set, username: "" | Pass |
| CI app has no secrets | 0 passwords, 1 federated | secrets=0, federated=1 | Pass |
| Repository holds no Actions secrets | 0 | 0 | Pass |
| Revision serves a pipeline-built image | the pushed tag | orders:317e8ed | Pass |
| Page names its build commit | the pushed SHA | build: 317e8ed | Pass |
| Admin credentials cannot be retrieved | refused | refused | Pass |
What that measures, precisely. 64 seconds is wall-clock from
git push to the endpoint returning the new page, including the
runner starting, a container build, a registry push and a revision rollout. It
is one sample on a tiny image; a real application's build dominates it.
The control
A pipeline that succeeds while the admin account is still enabled has demonstrated that one of two available doors was used. The demo looks identical either way. Only the refusal distinguishes them.
Security and Cost
What is closed. No stored secret authenticates GitHub to
Azure, no registry password exists, and the application holds only
AcrPull — it can run an image but cannot publish one. The
federated credential names one repository and one branch, so a fork or another
branch cannot assume the identity.
What production adds. Image provenance: nothing here signs the image or records what went into it, so "the pipeline built it" is an assertion about a mutable tag. A real golden path attaches an SBOM and a signature at build and verifies them at deploy. Also a retention policy on the registry — untagged manifests accumulate and bill beyond the included 10 GiB, and that policy is a Premium feature.
Cost, and it inverts the previous week. Week 14's risk was per-hour compute bounded only by a clock. This week has exactly one standing charge:
| Component | Rate |
|---|---|
| Container Registry, Basic | $0.1666/day, flat |
| Container Apps, Consumption | $0.00 here — inside the monthly free grant, and zero at zero replicas |
| Log Analytics | capped at 0.5 GB/day in Terraform |
The registry bills because it exists, not because an image is pushed or pulled — and about $5 a month is small enough never to be noticed on an invoice, which makes a missed teardown worse here than somewhere expensive. Charges to 29 November: $0.0457. The final measured figure is read from the bill a day after teardown and this post is updated then.
The $72/month mistake available this week. Three meters sit at $0.10/hour. A Consumption-only environment pays none of them — but Microsoft's billing page states that private endpoints and planned maintenance attract the Dedicated plan management charge regardless of plan. So keeping this environment public is a costed decision, and private networking belongs to its own week.
Troubleshooting and Lessons
GitHub refused the workflow as possibly malicious.
- Problem. Every run, push and manual alike, completed in under a
second with
action_requiredand zero jobs. - Root cause. A step printed
${{ toJSON(secrets) }}through a shell command to show the context was empty. That is the shape used to exfiltrate secrets, and a scanner cannot distinguish a demonstration from the real thing. - Resolution. Removed. Absence is proved from outside, by asking GitHub for the repository's secret list.
- Lesson. It was also wrong on its own terms: had a secret existed, that expression would have expanded its value onto a command line. Demonstrating the absence of a credential must not use the technique for stealing one.
AADSTS700213, and a check that asked the wrong
question.
- Problem. Login failed: no matching federated identity record found for presented assertion subject.
- Root cause. GitHub sends an immutable subject carrying numeric
IDs —
repo:owner@63027619/repo@1342954118:ref:refs/heads/main— not the documentedrepo:owner/nameform. The deploy script had checked whether a custom subject claim was configured, found none, and concluded the documented form applied. - Resolution. The subject is now built from
gh api users/<owner> .idandgh api repos/<repo> .id, and the script refuses to guess if either lookup fails. - Lesson. The default is the immutable form, so the absence of a customisation proved nothing. A check that returns reassurance from the wrong question is worse than no check.
The provider refuses a workspace ID on its own.
log_analytics_workspace_id can only be set when
logs_destination is also set. That error also settled a
cross-week question: this destination authenticates with the workspace's shared
key, so week 08's workspace — built with local authentication disabled
— could never have been reused here.
The teardown reported Azure empty while an identity was still
live. terraform destroy hit
Directory_ConcurrencyViolation removing the federated credential
and exited 1. Every Azure resource count was zero; the Entra app registration
was not, because it lives in the tenant rather than the resource group. A
cleanup that trusted its own exit code, or counted only inside the group, would
have called it finished.
Cleanup and Key Takeaways
Takeaways.
- Prove the door is shut, not that a key works. The pipeline succeeding says nothing about credentials until the admin account is gone.
- Split the identities. Pull and push are different privileges; one identity for both hands a running workload the ability to publish.
- Decide who owns the image field. Terraform owning the platform and the pipeline owning the image is the whole mechanism behind "no platform engineer in the loop".
- Count outside the resource group. Entra objects outlive it, and a destroy's exit code is not evidence.
- A flat daily meter is the easy one to forget. $5 a month hides on an invoice in a way $300 a month does not.
Repository: week-15-golden-path
References
Comments