Skip to content

Commit 825dcd0

Browse files
authored
Merge pull request #164 from NHSDigital/DTOSS_Remove_per-HC_SAS_listen_keys
Remove relay SAS keys
2 parents 2d09f36 + e9d76d8 commit 825dcd0

4 files changed

Lines changed: 3 additions & 35 deletions

File tree

docs/adr/ADR-005_Managed_Identity_For_Azure_Relay.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ The initial implementation used Shared Access Signature (SAS) tokens. These are
1616

1717
As the gateway runs inside the hospital network but is provisioned via Azure Arc, it can be assigned a managed identity through Arc-enabled infrastructure. Storing a long-lived shared secret in the environment is therefore unnecessary operational overhead and a potential security risk.
1818

19-
That said, setting up a working Relay connection locally is already complex. Mandating managed identity for all environments would add further friction for developers, who would need Azure CLI credentials with a Relay Listener role assignment before they could run the service.
2019

2120
## Decision
2221

23-
In **production** (`ENVIRONMENT=prod`), the gateway uses `ManagedIdentityCredential` exclusively. The SAS token path is unavailable regardless of what environment variables are set. The gateway's managed identity must be assigned the **Azure Relay Listener** role on the hybrid connection resource in Azure.
22+
All the deployed environments use `ManagedIdentityCredential` exclusively, from both the web application side and the gateway. The gateway's managed identity must be assigned the **Azure Relay Listener** role on the hybrid connection resource in Azure.
2423

25-
In **non-production** environments, the auth method is determined by whether `AZURE_RELAY_SHARED_ACCESS_KEY` is set:
24+
Developers need to connect to Azure relay but cannot use a managed identity. It is required to keep a relay with SAS keys enabled for their local testing. A SAS key may be provisioned and injected into `.env`.
2625

27-
- If set, a SAS token is generated and embedded in the WebSocket URL (`sb-hc-token`), preserving the simpler local development setup.
28-
- If absent, `DefaultAzureCredential` is used, which works with Azure CLI credentials (`az login`) for developers who have the Listener role assigned to their identity.
26+
If no SAS key is present, `DefaultAzureCredential` is used for developer scenarios that rely on `az login` and the appropriate Relay Listener role assignment.
2927

3028
The token is passed as an `Authorization: Bearer` HTTP header on the WebSocket upgrade request for managed identity paths. Azure Relay validates it against Azure AD.
3129

infrastructure/modules/arc-infra/outputs.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,3 @@ output "app_insights_connection_string" {
3333
sensitive = true
3434
value = var.enable_arc_servers ? module.app_insights[0].connection_string : null
3535
}
36-
37-
output "relay_listen_sas_keys" {
38-
description = "Per-machine relay listen SAS primary keys, keyed by Arc resource name. Used by the deploy pipeline to write .env files."
39-
sensitive = true
40-
value = var.enable_arc_servers ? {
41-
for k, rule in azurerm_relay_hybrid_connection_authorization_rule.per_machine_listen :
42-
k => rule.primary_key
43-
} : {}
44-
}

infrastructure/modules/arc-infra/relay.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ resource "azurerm_relay_hybrid_connection" "per_machine" {
4545
requires_client_authorization = true
4646
}
4747

48-
# Listen-only SAS rule per HC — retained for local development / break-glass access.
49-
# Production relay authentication uses Managed Identity (see relay_listener_role below).
50-
resource "azurerm_relay_hybrid_connection_authorization_rule" "per_machine_listen" {
51-
for_each = local.arc_machines
52-
53-
name = "listen"
54-
hybrid_connection_name = azurerm_relay_hybrid_connection.per_machine[each.key].name
55-
namespace_name = local.relay_namespace_name
56-
resource_group_name = local.relay_namespace_rg
57-
58-
listen = true
59-
send = false
60-
manage = false
61-
}
62-
6348
# Look up each discovered Arc machine to obtain its system-assigned managed identity.
6449
# Static machines (registered in the same apply) are excluded — they are not yet
6550
# visible to the data source and will be picked up on the next apply after onboarding.

infrastructure/terraform/outputs.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@ output "relay_namespace_hostname" {
88
description = "Relay namespace FQDN for AZURE_RELAY_NAMESPACE in the gateway .env"
99
value = module.arc_infra.relay_namespace_hostname
1010
}
11-
12-
output "relay_listen_sas_keys" {
13-
description = "Per-machine relay listen SAS primary keys, keyed by Arc resource name"
14-
sensitive = true
15-
value = module.arc_infra.relay_listen_sas_keys
16-
}

0 commit comments

Comments
 (0)