Azure Application Gateway guidelines
These rules apply to every change to the ION Application Gateway. MUST and MUST NOT are mandatory. SHOULD and SHOULD NOT are the expected default, and any deviation is recorded in the PR. MAY is optional. Where the current configuration differs from a rule, the gap and its remediation are listed in implementation.
Topology and routing
- Every public hostname on the gateway MUST be
agw-<app>-webapp.<domain>for a frontend, oragw-api.<domain>for the API. A hostname MUST have one A record indns.tfthat points to the gateway public IP. - Every listener MUST be HTTPS only. The gateway MUST NOT have an HTTP listener or a plain-HTTP backend.
- Backends MUST be addressed by FQDN, over HTTPS on 443, with the backend FQDN as the host override.
- A listener MUST route to APIM or to a SPA or storage backend. It MUST NOT route to a BFF, Function App, or domain service directly. The legacy docs-site listener is the one exception, and it is removed under gap 24, because the docs site is now on GitHub Pages.
- SPA hostnames MUST use path-based routing, so API prefixes go to APIM and the rest goes to the SPA host (ADR-0027).
- Routing-rule priorities MUST be unique. A rule for a specific hostname MUST have a lower number than a rule for a less specific listener, and the host-less catch-all MUST have the highest number.
- Unused objects MUST be removed: the unused private frontend IP, listeners with no consumer, and the legacy Yammer listener, pool, and rule once the service is retired.
- New listeners MUST be added in a per-app
data-<app>-fe.tffile, not inline inapplication_gateway.tf.
Capacity and zones
- The gateway MUST run in zones 1, 2, and 3 in every environment, in line with ADR-0017.
mgtgmaandmgtprdMUST have a minimum capacity of 2 or more.- The maximum capacity MUST be sized from the capacity model and reviewed when a frontend is added.
- Minimum and maximum capacity MUST be Terraform variables. They MUST NOT be hardcoded in the module.
- An alert MUST fire when capacity units exceed 80% of the maximum.
Health probes
- Every backend settings entry MUST have its own probe.
- Probe interval SHOULD be 10 to 15 seconds. Probe timeout SHOULD be 5 to 10 seconds and MUST be shorter than the interval. Unhealthy threshold SHOULD be 2 or 3.
- Probes MUST target a real, shallow, anonymous health path, and MUST NOT
call optional dependencies:
- APIM:
/status-0123456789abcdef; - Azure SignalR:
/api/health; - SPA hosts:
/.
- APIM:
- Expected status codes SHOULD be the narrowest set the endpoint returns. A wider set needs a comment that says why.
- A probe host MUST match the HTTP settings host.
Connection draining and affinity
- Connection draining SHOULD be enabled on every backend pool with more than one instance. The timeout SHOULD cover the longest normal request.
- Cookie-based affinity MUST be disabled on every backend settings entry, including the SignalR leg. Azure SignalR handles its own connection routing.
- Backend request timeout SHOULD be the shortest value that covers the longest normal request. The default of 30 seconds is acceptable for APIM and SPA hosts.
TLS and certificates
- TLS MUST be used on every hop, with no exceptions.
- The SSL policy MUST be a predefined policy of
AppGwSslPolicy20220101Sor later, or a custom policy with a minimum of TLS 1.2. - The listener certificate MUST come from Key Vault and MUST be referenced by a versionless secret ID. It MUST NOT be a PFX in source, a pipeline variable, or a Terraform variable.
- The gateway MUST use a dedicated user-assigned managed identity with
Key Vault Secrets Userscoped to the certificate secrets. It MUST NOT use a shared platform identity. - Certificate near-expiry (30 days or less) MUST raise an alert.
- Trusted-root certificate configuration MUST NOT be present unless a backend presents a private-CA certificate. ION backends present publicly trusted certificates.
- Module inputs that pin a certificate version MUST NOT be used.
Network
- The NSG MUST allow
GatewayManageron 65200 to 65535,AzureLoadBalancer,AzureFrontDoor.Backendon 443, andInterneton 443 for the sanctioned exceptions only. - The NSG MUST NOT allow
Interneton port 80. No HTTP listener exists. - An
AzureSignalRinbound rule MUST be removed unless something uses SignalR upstream calls. - Backends that support it MUST restrict access to the gateway subnet through service endpoints or access restrictions. App Service hosts that also serve as Front Door priority-2 origins follow the Front Door origin lockdown rules.
- ZPA MUST NOT be used for the runtime path from the gateway to a backend. It is for engineers only.
Rewrites and CORS
- Every Front Door rewrite, header rule, and CORS rule that affects an
/api/*path or security header MUST have a documented gateway mirror, and the PR checklist MUST check parity. A route that exists only in Front Door breaks the outage bypass. - Security headers MUST be added by the gateway only when
X-Azure-FDIDdoes not match ION’s Front Door. The profile ID MUST be read from a Terraform data source, and MUST NOT be written in documentation. - The gateway MUST set CORS only for hostnames that browsers reach directly, with
an explicit allow-list of exact
https://origins. It MUST NOT use*. Access-Control-Allow-CredentialsMUST be set only together with an exact matched origin.Access-Control-Allow-HeadersMUST list only the headers that browsers send to that hostname. The# TODO: FIXrule MUST be resolved.- Rewrite rules MUST NOT add credentials, API keys, or shared secrets to requests. Rules that set trusted forwarding headers MUST overwrite client-supplied values.
- CSP variants SHOULD be consolidated into a small shared set.
X-Xss-ProtectionSHOULD be removed. - Long term, Front Door and gateway rewrites SHOULD be generated from one route map.
Exceptions
Only these paths may reach the gateway without Front Door, as in ADR-0015 and security:
- SignalR WebSocket to
agw-alya-sigrandagw-alya-shell-sigr. ION SHOULD re-evaluate routing it through Front Door, which now supports WebSockets. - Front Door outage bypass, a human change approved by the incident commander.
A new exception MUST be added through an ADR-0015 amendment before it is deployed. Application Gateway MUST NOT be described as Front Door-only until the target-state WAF custom rule exists (security).
Observability
- Access and performance logs MUST go to the Switzerland North Log Analytics workspace. Azure Policy applies the diagnostic setting, and a stack MUST NOT work around it with a separate setting.
- Query strings MUST NOT carry secrets or personal data, except the protocol-mandated SignalR connection token, which MUST be short-lived.
- These alerts MUST exist in every environment, routed to the CPE action group:
- Resource Health;
- unhealthy host count;
- backend
5xx; - failed requests;
- capacity units (80% of maximum);
- backend connect time;
- certificate near-expiry.
Change management
- Changes MUST go through a PR with plan output and be deployed through Runway by CPE. Emergency portal changes MUST be reconciled into IaC immediately.
- Changes MUST be promoted through
mgtapa,mgtbta, andmgtgmabeforemgtprd, and thehub-test-suiteMUST pass in each environment before the next. - A PR that changes a shared object (the
gateway-rewrite-ruleset,gateway-pool, certificate, probe, or rule priority) MUST call it out, because it affects every hostname. - A new listener MUST add its routes to
hub-test-suite/agw_routes.yamlin the same PR. - IDs (subscription, tenant, Front Door profile ID) and public IP addresses MUST NOT be hard-coded in documentation.
- The gateway module SHOULD be consumed from a pinned, versioned source. It is a local relative path today.