Skip to main content

What the state holds

The Terraform state and the plan files are stored and read outside the module: by your backend, your pipeline and anyone who can read either. A password in them is a password exposed. This page says how the engine signs in to the database, what the module keeps out of the state, and what the state still holds. Keep the state encrypted and private in every case.

How the engine signs in to the database​

By default the PostgreSQL server has Microsoft Entra authentication on and password authentication off. The module's managed identity, id- followed by name, is made an Entra administrator of the server, and the database URL signs in as it with no password: postgres://id-pw-example@psql-pw-example.postgres.database.azure.com:5432/pathways. No password exists, so there is none for the state to hold.

The engine and the migrate job sign in with a Microsoft Entra ID token as the identity, which needs Pathways 0.0.9 or later. The module gives the app and the job AZURE_CLIENT_ID, the identity's client id, and PATHWAYS_DATABASE_AUTH, entra by default or password when a password is on. Your pathways.yaml reads it:

storage:
postgres:
url: { env: PATHWAYS_DATABASE_URL }
tls: {}
auth: { env: PATHWAYS_DATABASE_AUTH, default: password }

When you need a password, keep it in a Key Vault you run, read it with an ephemeral block in your own configuration, and pass its value with a version number:

ephemeral "azurerm_key_vault_secret" "postgres_password" {
name = "pathways-postgres-password"
key_vault_id = "<your Key Vault's resource id>"
}

module "pathways" {
# ...
postgres = {
delegated_subnet_id = "<subnet id>"
private_dns_zone_id = "<private DNS zone id>"
administrator_password_version = 1
}
postgres_administrator_password = ephemeral.azurerm_key_vault_secret.postgres_password.value
}

Password authentication is then on beside Entra ID, the server's password administrator is pathways_admin, and the engine signs in with the password. The value is ephemeral: it reaches the server and the database-url secret only through write-only arguments, which Terraform sends to Azure and never records. Terraform writes it only when administrator_password_version changes, so raise the number after you change the secret. The machine that plans and applies needs to read that secret.

What the module keeps out of the plan and the state​

  • The database password. By default there is none. With a password, the state holds its version number and nothing else.
  • A database URL that holds a password. With a password, the database-url secret is written through its write-only value.
  • The alarms' health token, generated by an ephemeral resource and written through a write-only value.
  • The master keys in encryption_key_secrets: you create those secrets, and the module holds only their names.
  • With existing_postgres, the URL of your server: you put it in the vault, and the module never reads it.

What the state still holds​

  • The database URL with no password, as the value of the database-url secret: the server's host name, the identity's name and the database's name. It is not a credential.
  • The name, id and address of every resource: the server's host name, the Key Vault's URI, the identity's client and principal ids, your tenant id, and the subnet and DNS zone ids you pass.
  • The Log Analytics workspace's shared keys, which the azurerm provider reads for every workspace. They let the holder send data to the workspace through its older ingestion APIs.
  • With alarms on, the Application Insights connection string and instrumentation key, attributes of that resource. They let the holder send telemetry and read nothing.
  • With storage on, the storage account's access keys, where Azure returns them. The module turns the account's shared keys off, so Azure refuses a request signed with one.

What we have not solved​

  • An older engine cannot sign in. Pathways 0.0.8 or earlier, or a pathways.yaml with no auth key, sends no token, and the server takes nothing else by default. Upgrade the engine and set auth as shown above, or turn a password on.
  • The engine's identity is an Entra administrator of the server. That is the role the password administrator holds: the migrate job creates and alters the engine's tables. The module cannot create a narrower database role: that takes a connection to the server, which has private access only.
  • Changing an existing server. Our tests plan against mocked providers, so we have not seen whether Azure turns password authentication off, or on, in place on a running server, or whether it takes a password administrator on a server made without one. Read the plan before you apply, and do not apply a plan that replaces the server.
  • A restore in another region. A restored server keeps its Entra administrators and its password administrator. The module in the second region has an identity of its own, which is not an administrator of the restored server: add it as one, or sign in with the password.
  • The state is still sensitive. It maps your network, names every resource and holds the keys above. Keep it in a private, encrypted backend that few people can read.