Home› Blog› Week 14 — A Database With No Password, and a Failo…
Azure Weekly Lab Azure Terraform

Week 14 — A Database With No Password, and a Failover Measured From the Client

The administrator account is not protected by a strong password. It does not exist. And the failover that proves the standby is real took 32 seconds, inside an operation that ran for six minutes.

Verified against current vendor documentation on 22 November 2026. Pricing, limits and API behaviour were checked against the official docs on that date. Cloud services change fast — if you are reading this much later, treat the specifics as a starting point and re-check the linked sources.
PostgreSQL Flexible Server Microsoft Entra ID Private Link Managed Identity Terraform
Azure Platform Engineering Lab · Week 14 of 52

📋 In This Post

Lab Overview

The problem. Every managed database asks you to invent an administrator password at creation time. From that moment it is something someone has to store, rotate, share with a pipeline, and eventually leak. The usual answers — a key vault, a rotation policy, a secret scanner — all manage the password. None of them remove it.

The objective. Deploy a PostgreSQL flexible server that has no administrator account at all, reachable only from inside a virtual network, and prove both claims: an application logs in with a token it mints for its own identity, and the same server refuses a password. Then force a failover and measure what the application actually loses.

The outcome. Twenty Terraform resources, ten validation checks passing, and two forced failovers measured at 27.57 s and 32.16 s of client downtime. The portal's own Reset password button is greyed out, because there is nothing to reset.

Cloud Services and Concepts

ServicePurpose hereWhat it is
Azure Database for PostgreSQL flexible server The database, with password authentication switched off Managed PostgreSQL where you choose the compute tier, the availability model and the networking mode
Microsoft Entra authentication The only way to log in The server accepts an Entra access token in place of a password. Three modes exist: PostgreSQL only, Entra only, or both
User-assigned managed identity The database's only administrator, and the client's identity An Azure identity with no credential attached. Azure mints tokens for it on request; there is no secret to store
Private endpoint Gives the server a private IP inside the subnet A network interface in your subnet that maps to one instance of a platform service, not the whole service
Private DNS zone Resolves the public hostname to the private address privatelink.postgres.database.azure.com, so the connection string never changes
NAT gateway Outbound internet for a VM with no public IP The explicit egress method Microsoft recommends. New virtual networks are moving to private subnets by default, so egress is something you build rather than inherit

Two terms worth separating. Authentication is who you are; the token answers that. Network reachability is whether you can open a socket at all; the private endpoint answers that. This lab closes both doors, and they are independent — a server with Entra-only auth is still exposed to the internet unless public access is disabled.

Architecture and Workflow

Architecture diagram. A virtual network holds two subnets. In the application subnet, an Ubuntu virtual machine with no public IP address carries a user-assigned managed identity, and reaches the internet only outbound through a NAT gateway with a single public IP. In the database subnet, a private endpoint holds the address 10.60.1.4. A private DNS zone named privatelink.postgres.database.azure.com resolves the server's public hostname to that private address, so the client connects using the documented FQDN. The PostgreSQL flexible server sits outside the virtual network as a platform service, with public network access disabled, password authentication disabled, and no local administrator account at all; its only administrator is the managed identity. A standby replica in the same availability zone receives synchronous commits and is what a forced failover promotes. Microsoft Entra ID issues the access token that the virtual machine fetches from the instance metadata service and sends as its password.
The database is a platform service outside the network. The private endpoint is what brings it inside, and the private DNS zone is what keeps the connection string honest.
  1. Terraform creates the server with administrator_login and administrator_password omitted, and password_auth_enabled = false.
  2. A user-assigned managed identity is set as the server's Entra administrator — the only administrator it has.
  3. A private endpoint in snet-db takes the address 10.60.1.4; public network access on the server is disabled.
  4. The private DNS zone rewrites the server's documented hostname to that address, so the client connects to the FQDN and never learns an IP.
  5. The client VM asks the instance metadata service for a token for its own identity and passes it to psql as the password.
  6. A forced failover promotes the standby; a writer on the VM logs every attempt, and the gap between the last success and the next one is the downtime.

Three design decisions.

Private endpoint, not virtual network injection. Flexible Server offers two networking modes and they are mutually exclusive at creation. Injection puts the server in a delegated subnet it can never leave — you cannot move it, and it cannot later use Private Link. Microsoft now names Private Link the recommended alternative, and its feature matrix lists high availability and Entra authentication as working as designed.

User-assigned, not system-assigned identity. The identity has to be the database's administrator, which means it must exist and be grantable before the server does. A system-assigned identity does not exist until its resource does, which would invert the dependency.

No SSH, and no public IP on the client. The VM is driven through the Azure control plane with az vm run-command. A public IP on the client would weaken the thing being demonstrated, so the only public address in the week belongs to the NAT gateway and accepts nothing inbound.

Prerequisites

  • An Azure subscription where you hold Owner, and a tenant where you can create a managed identity.
  • Resource providers registered: Microsoft.DBforPostgreSQL, Microsoft.Network, Microsoft.Compute, Microsoft.ManagedIdentity.
  • Terraform >= 1.10, azurerm ~> 5.2, Azure CLI 2.86 or later.
  • A region with availability zones if you want zone-redundant HA — and see Troubleshooting, because having zones is not sufficient.
  • Budget awareness. This is the first week in this lab since week 11 with real per-hour compute. Nothing here is free.

Implementation

1. Enumerate what can bill, before deploying

Why. High availability doubles compute, and a per-hour meter has no equivalent of a daily cap. The gate lists every flat meter the week's services can charge on and refuses to pass until each is acknowledged in a committed file with a reason.

Terminal output of price_check.py for week 14 listing flat recurring meters including a DNS private resolver endpoint at 180 dollars a month and a fixed private endpoint at 14 dollars an hour, all acknowledged, plus two pattern acknowledgements covering Virtual Machines and Storage with their ceilings shown
Two of these meters were invisible to the gate until this week — see Troubleshooting.

2. Create the server with no administrator

Why. Both fields are optional on the provider. Omitting them is what makes the claim structural rather than a matter of discipline.

resource "azurerm_postgresql_flexible_server" "db" {
  name     = "psql-wk14-dev-scus-001"
  version  = "17"
  sku_name = "GP_Standard_D2ds_v5"

  # No administrator_login. No administrator_password.
  public_network_access_enabled = false

  authentication {
    active_directory_auth_enabled = true
    password_auth_enabled         = false
    tenant_id                     = var.tenant_id
  }

  high_availability {
    mode = var.ha_mode
  }
}

Validation. az postgres flexible-server show --query authConfig returns passwordAuth: Disabled, and administratorLogin is empty.

Azure portal blade for the PostgreSQL flexible server showing Administrator login as three dashes, the Reset password command greyed out, high availability enabled, availability zone 1, and configuration General Purpose D2ds v5 with 2 vCores
Administrator login: --- and Reset password greyed out. There is no account to reset.

3. Make the identity the administrator, and bring the server inside the network

resource "azurerm_postgresql_flexible_server_active_directory_administrator" "app" {
  server_name    = azurerm_postgresql_flexible_server.db.name
  object_id      = azurerm_user_assigned_identity.app.principal_id
  principal_name = azurerm_user_assigned_identity.app.name
  principal_type = "ServicePrincipal"
}

resource "azurerm_private_endpoint" "db" {
  subnet_id = azurerm_subnet.db.id

  private_service_connection {
    private_connection_resource_id = azurerm_postgresql_flexible_server.db.id
    subresource_names              = ["postgresqlServer"]
    is_manual_connection           = false
  }

  private_dns_zone_group {
    name                 = "pdzg-psql"
    private_dns_zone_ids = [azurerm_private_dns_zone.psql.id]
  }
}
Azure portal blade for the private endpoint showing connection status Approved, request response Auto-Approved, target sub-resource postgresqlServer, and the virtual network and subnet vnet-wk14-dev-scus-001 slash snet-db
Target sub-resource postgresqlServer, auto-approved, in the database subnet.

4. Log in with a token, and watch a password fail

Why. A successful login on its own proves only that something can get in. The control is the same server, same user, a password instead of a token.

Terminal card showing a token fetched from the instance metadata service for the user-assigned managed identity and passed to psql as PGPASSWORD, returning connected-as equals the identity name, followed by two refusals: the access token has invalid format when a password is sent for the identity, and password authentication failed for user pgadmin
The two refusals say different things. The first is the sharper one.

Sending a password as the managed identity returns FATAL: The access token has invalid format — the server does not evaluate the string as a password at all, it tries to parse it as a token. Sending one as pgadmin returns password authentication failed, because that role was never created.

Validation and Evidence

TestExpectedActualStatus
High availability enableda standby existsSameZone / HealthyPass
Password authentication disabledDisabledDisabledPass
Entra authentication enabledEnabledEnabledPass
No local administratoremptynonePass
Public network access disabledDisabledDisabledPass
Private endpoint approvedApprovedApprovedPass
Hostname resolves privatelya 10.60.1.x address10.60.1.4Pass
Identity connects with a tokena row returnsconnected-as=id-app-wk14-dev-scus-001Pass
Password login refusedrejectedFATAL: The access token has invalid formatPass
Write lands in the databaserows increase2 rowsPass

What the DNS row proves. The client connects to psql-wk14-dev-scus-001.postgres.database.azure.com — the documented public hostname — and inside the network that resolves to a private address. Nothing in the connection string knows the private endpoint exists, which is what makes this pattern safe to retrofit.

The failover

A forced failover is the documented way to test one — it stops the primary rather than draining it, which is what an unplanned outage looks like:

az postgres flexible-server restart -g $RG -n $SERVER --failover Forced
Terminal card showing a forced failover requested at 19:16:12 UTC with the CLI call returning at 19:22:19, 616 write attempts of which 544 succeeded and 72 failed, and a measured client downtime of 32.16 seconds, with the server healthy afterwards
32.16 seconds of application downtime inside a six-minute operation.

A writer on the VM inserts a row every 250 ms and logs each outcome with its own clock. Read the two timestamps together: the CLI call did not return for six minutes, because it waits for the whole workflow — promote the standby, update DNS, build a new standby. The application was writing again after 32 seconds and never saw the rest.

Microsoft's guidance says exactly this: measure the downtime from the application or client perspective, not from the operation. Quoting the operation here would have overstated the outage elevenfold. Two failovers were performed: 27.57 s and 32.16 s. Both on an idle database — a busy server replays more write-ahead log before the standby can be promoted.

Security and Cost

What is closed. No password exists on the server. No public endpoint exists. No inbound port is open on the client, which has no public IP. The only credential anywhere is a token with a bounded lifetime that the platform mints on request.

What a production deployment adds. Here the managed identity is the administrator, which suited a lab with one client. A real application gets its own principal and a PostgreSQL role granted only what it needs, with the administrator held by a group that humans join through PIM.

Cost. The tier decision is the whole story. Burstable B1ms is $0.0204/hour and is unusable here for a reason unrelated to money — and this was tested rather than quoted:

az postgres flexible-server create --tier Burstable --sku-name Standard_B1ms   --high-availability SameZone

ERROR: High availability is not supported for the Burstable tier.

Wanting a standby forces General Purpose, and the standby then doubles it: a twentyfold increase driven by one feature. The test was worth running because the documentation only rules out the zone-redundant case on Burstable and is silent on same-zone, while the capability API cheerfully lists both modes against every Burstable SKU — the same API that said zone-redundant was available in a region which then refused it.

ComponentRate
PostgreSQL, 2 vCores General Purpose, with HA$0.4104/hour
Client VM and its disk$0.0995/hour
NAT gateway and its public IP$0.0500/hour
Private endpoint, private DNS zone, storage$0.0209/hour
Predicted for a three-hour window$1.74

The prediction was written into the repository before deploying, so the invoice can contradict it. The resources existed from 18:21Z to 19:36Z — one hour fifteen against a three-hour budget, which at the rates above is about $0.73. The measured figure is read from the bill a day after teardown and this post is updated then; a rate card is not a cost, and that applies to the estimate in this paragraph too.

There is no cap for a per-hour meter. Week 13 could bound ingestion with a daily quota; compute has no equivalent. Left running for a day this week would cost $13.94. The only control is the clock, so deploy, validate, fail over and destroy happened in one sitting.

Troubleshooting and Lessons

The guardrail denied this week's own server.

  • Problem. A deny policy assigned two scopes above the subscription refused a deliberately small 2-vCore server with RequestDisallowedByPolicy.
  • Root cause. The allowlist held GP_Standard_D2ds_v5, the composite form Terraform and the CLI accept. ARM stores sku.name = Standard_D2ds_v5 with the tier in a separate field, so the list matched nothing and the policy denied every PostgreSQL server.
  • Resolution. Rewrite the allowlist in ARM sku.name values.
  • Lesson. The policy had been tested the day before — with a 64-vCore server, which it refused. That is exactly what a correct policy does. A deny needs a pair: something it refuses and something it must let through.

Zone-redundant HA was refused in a region with three zones.

  • Problem. Creation failed with MultiAzHaIsOfferRestricted.
  • Root cause. list-skus reports supportedHaMode: [SameZone, ZoneRedundant] per SKU, while the same response's region-level capability reads zoneRedundantHaSupported: Disabled. The region-level flag wins.
  • Lesson. When two fields of one API response disagree, the narrower scope is the one that decides. The HA mode was a validated variable for exactly this reason; same-zone costs the same and still carries a real failover.

I cited a retirement date that does not exist, and the publish-day check caught it.

  • Problem. The NAT gateway went into the design on the belief that default outbound access was "retired for new deployments on 30 September 2025", and that a VM with no public IP therefore had no egress at all.
  • Root cause. Microsoft's page says something narrower: default outbound access is an implicit platform behaviour to avoid relying on, the portal already creates private subnets, and for the API version released after 31 March 2026 subnets in new virtual networks set defaultOutboundAccess = false. Existing networks are unchanged.
  • Resolution. The gateway stays — it is the recommended explicit method and costs $0.045/hour — but the justification is now the real one. Whether the client would have reached the internet without it was never tested, and the resource group is gone, so that stays untested rather than asserted.
  • Lesson. Re-verifying every vendor claim on publish day is not a formality. This one had already been written into the Terraform comments, the repository README and the cost file before the check found it.

The cost gate had two blind spots, and this week found both.

  • Its filter asked for one region. A private endpoint is priced under armRegionName: Global, as is every NAT gateway meter — so the gate had never seen two of the resources being deployed.
  • It only treated 1/Hour and 1/Month as recurring. A private DNS zone bills $0.50 per zone per month against a bare unit of 1; so does a DNS Private Resolver endpoint, at $180 a month.
  • Lesson. A gate that reports clean is making a claim about its own coverage. Both holes are closed, and an ambiguous unit is now treated as recurring — the direction that costs an explanation rather than a surprise.

Cleanup and Key Takeaways

Terminal card showing the week 14 teardown: the resource group deleted, terraform destroy run, and Azure queried afterwards for counts of PostgreSQL servers, virtual machines, managed disks, private endpoints, NAT gateways, public IP addresses and private DNS zones, all zero
The counts are asked of Azure after the destroy, not inferred from its exit code.

The resource group is deleted whole — it catches anything Terraform never managed — and then Azure is asked how many of each resource type remain. A failed teardown here costs about $13 a day, which is the difference between a cleanup script and a cleanup script somebody has watched work.

Takeaways.

  1. The strongest control over a credential is not having one. administrator_login is optional; omitting it removes a class of risk that no rotation policy can.
  2. Prove a security control with a pair. A login that succeeds proves something works. Only the refusal proves the other path is closed — and that applies to deny policies as much as to logins.
  3. Measure availability where the user stands. The same failover was 32 seconds to the application and six minutes to the API.
  4. High availability is a tier decision, not a checkbox. Burstable supports none, so wanting a standby multiplied the compute bill twentyfold.
  5. A clean gate is a claim about coverage. This one passed while blind to meters priced globally and to anything billed on an ambiguous unit.

Repository: week-14-postgres-no-passwords

References

Comments

How was your experience?
Your feedback helps improve this site.
PoorExcellent