Azure Application Gateway implementation
This page explains how the gateway is laid out in code, how to add a listener and backend, how to run the regression suite, and where the current configuration differs from the guidelines, with the remediation for each gap.
Repository layout
| Path | Contents |
|---|---|
rome-ion/infrastructure/hub/application-gateway/application_gateway.tf | Module call: listener, pool, settings, probe, rewrite, path-map, and rule lists. Global CORS rules. Routing-rule priorities |
rome-ion/infrastructure/hub/application-gateway/data-<app>-fe.tf | One file per frontend: locals for its listener, pool, probe, settings, rewrite sets, and path map |
rome-ion/infrastructure/hub/application-gateway/data.tf | Backend endpoint locals and the CSP header variants |
rome-ion/infrastructure/hub/application-gateway/dns.tf | One agw-* A record per hostname |
rome-ion/infrastructure/hub/application-gateway/alert.tf | Resource Health alert |
rome-ion/infrastructure/hub/application-gateway/variables.tf and environments/mgmt-*.tfvars | Domain, certificate secret ID, and Static Web Apps endpoints per environment |
rome-ion/infrastructure/hub/application-gateway/scripts/get_cert_renewal_status.py | Manual certificate-order check. Not scheduled |
tf-modules/azure/application-gateway/ | Module: public IP, gateway resource, identity, SSL policy, zones, autoscale, dynamic blocks for the lists above |
rome-ion/infrastructure/hub/networking/nsgs.tf and subnets.tf | Gateway subnet, service endpoints, and NSG rules |
rome-ion/infrastructure/hub/hub-test-suite/ | Post-deployment regression suite for the gateway and Front Door |
Current configuration
Each row compares a guideline with the current Terraform. Rows marked Verify depend on Azure state or configuration that IaC does not show.
| # | Guideline | Current configuration | Remediation | Owner |
|---|---|---|---|---|
| 1 | Probe interval 10 to 15 s, timeout 5 to 10 s, threshold 2 to 3 | 30 s, 30 s, 3 on every probe | Tighten the probes | CPE |
| 2 | Zones in every environment. Min and max capacity as variables | Zones, min 2, and max 10 hardcoded in the module | Add min_capacity and max_capacity variables. Keep zones fixed. Alpha and beta MAY set a lower minimum | CPE |
| 3 | Metric alerts for unhealthy hosts, backend 5xx, failed requests, capacity, connect time | No metric alerts | Add the metric alerts | CPE with SRE |
| 4 | Resource Health alert in every environment | health_alert_for_resources_enabled is true only for mgtprd | Enable in every environment | CPE |
| 5 | Certificate near-expiry alert | No alert. get_cert_renewal_status.py is manual and checks App Service Certificate orders | Add a Key Vault near-expiry alert for the wildcard certificate | CPE |
| 6 | Connection draining on multi-instance pools | Not configured. The module does not expose it | Add connection_draining to the module settings block, then enable per pool (guideline) | CPE |
| 7 | No cookie affinity, including SignalR | Alya-sigr-BackendHttpSettings has affinity enabled (SigrApplicationGatewayAffinity). The shell SignalR settings are disabled | Set cookie_based_affinity = "Disabled" and confirm in mgtapa that SignalR clients still connect | CPE with Alya team |
| 8 | No Internet port 80 rule | NSG allows Internet on 80. No HTTP listener exists | Remove the rule. Same item as Front Door gap 14 | CPE |
| 9 | No unused AzureSignalR inbound rule | NSG has an AzureSignalR inbound rule | Verify whether SignalR upstream calls exist. Remove the rule if not | CPE with Alya team |
| 10 | No unused private frontend IP | A static private IP (.4 of the subnet) is allocated and no listener binds it | Remove it in IaC unless a consumer is found. Check the plan does not recreate the gateway | CPE |
| 11 | Dedicated gateway identity with Key Vault Secrets User scoped to the certificate | The platform-wide identity id-ion-<env>-chn-01 is used | Create a dedicated user-assigned identity, grant the scoped role, and switch the module input | CPE |
| 12 | No pinned certificate version or trusted-root inputs | The module still takes a version-pinned certificate secret ID and a trusted-root list. No listener or backend uses them. Their last consumer was removed with the service it served | Remove both inputs and their data sources from the stack and the module | CPE |
| 13 | Legacy listeners removed | Yammer listener, pool, settings, probe, rule (priority 81), and A record remain | Remove them with the Yammer retirement ticket | CPE |
| 14 | Specific rule before catch-all | gateway-rule (host-less) has priority 100, and default-api-gateway-rule (agw-api) has 110 | Verify the effective order. Give agw-api the lower number | CPE |
| 15 | Unique rewrite rule sequences | The AllowOrigin, AllowRoadieOrigin, and AllowAlyaPortalOrigin rules share sequence 100 | Verify the effective result. Give each rule a unique sequence | CPE |
| 16 | CORS credentials only with a matched origin. Accurate allowed headers | AllowCredentials is a fixed true. AllowHeaders is marked # TODO: FIX | Condition the credentials header on the matched origin. Trim and fix the headers list | CPE with frontend teams |
| 17 | Rewrite parity with Front Door | No parity check. Rewrites are hand-maintained in two places | Add the parity item to the PR template. Long term, generate both from one map | CPE |
| 18 | Rewrite rules apply every condition and header | Module dynamic blocks read only the first condition and first header configuration ([0]) | Fix the module so each rule applies all of its entries. Check existing rules before and after | CPE |
| 19 | Regression suite covers every listener | No coverage for portal shell, portal core, lobotomy, docs site, or the SignalR hostnames. Tests accept 401 and 403. No prd run | Extend the suite | CPE |
| 20 | Pinned module source | Local relative path. The JFrog v4.0.0 source is commented out | Publish the current module and pin the stack to it | CPE |
| 21 | Front Door-only enforcement per listener | Not enforced. NSG allows Internet on 443 and the service tag covers every Front Door profile | Target-state WAF custom rule (security) | CPE |
| 22 | WAF on exception listeners | No WAF | Target state, phase 1 and 2 (security) | CPE with security |
| 23 | No bearer tokens in access logs | Flagged risk. The SignalR access_token query parameter is recorded in the access logs of the SignalR hostnames | Keep the token short-lived and user-scoped, restrict read access to the workspace, and do not copy raw access logs into tickets. Evaluate a log transformation that strips the query string for these hostnames | CPE with Alya team |
| 24 | Docs-site listener matches the hosting | The docs site is hosted on GitHub Pages, deployed by Terraform. Terraform still routes agw-docsite-webapp to the legacy func-doc-<env>-we-01 App Service | Remove the legacy agw-docsite-webapp listener, pool, rule, and A record. Align the Front Door docs route with GitHub Pages | CPE |
| 25 | Rewrite parity with Front Door for the Shell SignalR negotiate path | The Alya bypass rewrite set (data-alya-shell-fe.tf) has alya-sigr-v1-rewrite but no v2/signalr rule, so negotiate fails during a Front Door outage bypass | Add a rule that rewrites v2/signalr to /assgr-ext/v2/signalr. Same item as RT-03 | CPE |
Add a listener and backend
These steps add a frontend agw-<app>-webapp that serves a SPA and rewrites its API
prefix to APIM. The Front Door side is in
add a frontend to Front Door.
Create the per-app file
Owner: Service team
Create data-<app>-fe.tf with one locals block. Start from an existing file such as
data-service-management-fe.tf. Use the target probe values from the
guidelines.
locals {
imfe_webapp_endpoint = "web-imfe-${local.spoke_environment}-chn-01.azurewebsites.net"
imfe_webapp_http_listener = {
name = "imfe-webapp-http-listener"
host_names = ["agw-imfe-webapp.${var.rome_domain}"]
ssl_certificate_name = var.default_ssl_certificate
protocol = "Https"
}
imfe_webapp_backend_pool = {
name = "imfe-webapp-backendpool"
fqdns = [local.imfe_webapp_endpoint]
}
imfe_webapp_health_probe = {
name = "imfe-webapp-health-probe"
host = local.imfe_webapp_endpoint
interval = 15
timeout = 5
unhealthy_threshold = 3
path = "/"
protocol = "Https"
expected_status_code = ["200-399"]
}
imfe_webapp_backend_http_settings = {
name = "imfe-webapp-backend-httpsettings"
cookie_based_affinity = "Disabled"
host_name = local.imfe_webapp_endpoint
port = 443
protocol = "Https"
request_timeout = 30
probe_name = local.imfe_webapp_health_probe.name
}
}Add the header rewrite set
Owner: Service team
Add a basic rewrite set that adds the security headers only when X-Azure-FDID
does not match the ION profile, with negate = true. Read the profile ID from
data.azurerm_cdn_frontdoor_profile.rome.resource_guid. If the app is a Module
Federation remote, add a CORS rule for the Alya shell origin at the end of the
set (sequence 900), so it applies after other rewrites.
Add the path map and the API rewrite
Owner: Service team
Add the URL path map. Order matters: the most specific path rule comes first. The default pool and settings point at the APIM pool.
imfe_url_path_map = {
name = "imfe-url-path-map"
default_backend_address_pool_name = "gateway-pool"
default_backend_http_settings_name = "gateway-settings"
path_rules = [
{
name = "imfe-mfe-api-path-rule"
paths = ["/api/*"]
backend_address_pool_name = "gateway-pool"
backend_http_settings_name = "gateway-settings"
rewrite_rule_set_name = local.gateway_imfe_mfe_api_rewrite_ruleset.name
},
{
name = "imfe-mfe-webapp-path-rule"
paths = ["/*"]
backend_address_pool_name = local.imfe_webapp_backend_pool.name
backend_http_settings_name = local.imfe_webapp_backend_http_settings.name
rewrite_rule_set_name = local.imfe_webapp_rewrite_rule_set.name
}
]
}The API rewrite set maps each public /api/... prefix to the APIM API path. It must be
the same mapping as the Front Door route. For attachments or other blob paths,
add a separate path rule on the blob pool, with a rewrite that strips the prefix.
Register the objects
Owner: Service team
In application_gateway.tf, add each local to its list:
| Local | List |
|---|---|
| Listener | http_listeners |
| Backend pool | backend_address_pool_fqdns |
| Backend settings | backend_http_settings_trusted_cas |
| Probe | probes |
| Header rewrite set | basic_rewrite_rule_sets |
| API rewrite sets | path_rewrite_rule_sets |
| Path map | url_path_maps |
Then add the routing rule to request_routing_rules_rewrite_path_maps:
{
priority = 97 # unique, lower than the host-less catch-all
name = "imfe-webapp-routing-rule"
rule_type = "PathBasedRouting"
http_listener_name = local.imfe_webapp_http_listener.name
url_path_map_name = local.imfe_url_path_map.name
},Add the DNS record
Owner: Service team
In dns.tf, add the A record that points to the gateway public IP:
resource "azurerm_dns_a_record" "agw-imfe-webapp" {
name = "agw-imfe-webapp"
zone_name = var.rome_domain
resource_group_name = "rg-rome-${var.environment_short}-chn-01"
ttl = 300
records = [data.azurerm_public_ip.agw.ip_address]
}Restrict the backend
Owner: Service team
Restrict the SPA host to the gateway subnet (agwsbn), ION’s Front Door for the
priority-2 path, engineers through ZPA, and deployment runners. See
lock down a priority-2 origin.
Add the regression test route
Owner: Service team
Add the listener to hub-test-suite/agw_routes.yaml for each environment: one entry for
/ and one for each API prefix. The same PR MUST add it.
Register identity and CORS
Owner: Service team
Add https://agw-<app>-webapp.<domain> as an Entra redirect URI and as an APIM CORS
origin. This makes the portal bypass-capable for a Front Door outage.
Open a PR and promote
Owner: Service team and CPE
Open the PR with the plan output and the Front Door parity item checked. CPE deploys
through Runway in mgtapa, then mgtbta, then mgtgma, then mgtprd. Run the
regression suite after each deployment.
Tighten the probes
Change the values in each *_health_probe local and in the inline probes in
application_gateway.tf:
interval = 15 # 10 to 15
timeout = 5 # 5 to 10, always below the interval
unhealthy_threshold = 3 # 2 or 3
Keep each probe path as it is. APIM already uses /status-0123456789abcdef,
SignalR uses /api/health, and the SPAs use /. Roll the change out in mgtapa
first, watch UnhealthyHostCount for a day, and then promote. A timeout that is
too low can mark a slow but healthy host unhealthy, so check the backend response
time in Log Analytics before the change.
Add the metric alerts
Add the alerts to alert.tf, routed to the existing CPE action group
(data.azurerm_monitor_action_group.cpe_ag). var.agw_max_capacity is the variable
added by gap 2. Two examples:
resource "azurerm_monitor_metric_alert" "agw_unhealthy_hosts" {
name = "alert-agw-${var.environment_short}-unhealthy-hosts"
resource_group_name = "rg-rome-${var.environment_short}-chn-01"
scopes = [module.rome-agw.application_gateway_id]
severity = 2
frequency = "PT1M"
window_size = "PT5M"
criteria {
metric_namespace = "Microsoft.Network/applicationGateways"
metric_name = "UnhealthyHostCount"
aggregation = "Average"
operator = "GreaterThan"
threshold = 0
}
action {
action_group_id = data.azurerm_monitor_action_group.cpe_ag.id
}
}
resource "azurerm_monitor_metric_alert" "agw_capacity_units" {
name = "alert-agw-${var.environment_short}-capacity-units"
resource_group_name = "rg-rome-${var.environment_short}-chn-01"
scopes = [module.rome-agw.application_gateway_id]
severity = 2
frequency = "PT5M"
window_size = "PT15M"
criteria {
metric_namespace = "Microsoft.Network/applicationGateways"
metric_name = "CapacityUnits"
aggregation = "Average"
operator = "GreaterThan"
threshold = var.agw_max_capacity * 0.8
}
action {
action_group_id = data.azurerm_monitor_action_group.cpe_ag.id
}
}
Add the same pattern for FailedRequests, BackendConnectTime, and
BackendResponseStatus (dimension HttpStatusGroup equal to 5xx). Use
Resource Health for platform incidents by setting
health_alert_for_resources_enabled to true in every environment. The certificate
near-expiry alert is on the Key Vault that holds the certificate, not on the gateway.
Run the regression suite
The suite is the post-deployment gate for each environment. It needs Python 3.14 or
later and uv.
cd rome-ion/infrastructure/hub/hub-test-suite
uv run python main.py --infra agw --env apa # then bta, then gma
- Environment keys in
agw_routes.yamlareapa,bta, andgma. - Tokens come from environment variables named
ION_INFRA_<NAME>_TOKEN, for exampleION_INFRA_ALYA_TOKEN. - The suite writes an HTML report with status, latency, and TLS certificate expiry for each route.
- API routes accept
401and403, so they prove routing and rewrites, not authorization.
Extend the regression suite
Close gap 19 by adding these checks:
- Add listeners for portal shell, portal core, and lobotomy. Do not add the docs site: its listener is legacy and is removed under gap 24.
- Add a WebSocket reachability check for
agw-alya-sigrandagw-alya-shell-sigr. - Add a header check: with no
X-Azure-FDID, the response carries the security headers. With the ION profile ID, it does not. - Add a CORS check that a disallowed origin gets no
Access-Control-Allow-Origin. - Add a
prdsection that runs read-only checks after a production deployment.
Diagnose a gateway failure
- Use the Log Analytics access log for the gateway and filter by host and status.
- For a failed deployment, compare the plan output with the last known good state, and revert the PR rather than editing in the portal.
- If Front Door is the source of the failure, use the bypass runbook.