Skip to content

Commit be85bed

Browse files
committed
adding changes for checking for SAS keys, this should only apply in review environment
1 parent c1b298c commit be85bed

5 files changed

Lines changed: 29 additions & 20 deletions

File tree

docs/adr/ADR-005_Managed_Identity_For_Azure_Relay.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ That said, setting up a working Relay connection locally is already complex. Man
2222

2323
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.
2424

25-
In **non-production** environments, the auth method is determined by whether `AZURE_RELAY_SHARED_ACCESS_KEY` is set:
25+
In **non-production** environments, SAS-based authentication is only enabled in the review environment
2626

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.
27+
- In the review environment, a SAS key may be provisioned and injected into `.env` so local testing against the gateway test VM continues to work.
28+
- In dev, preprod, and prod the relay listener uses managed identity / Azure AD authentication and no SAS key is provisioned or injected into `.env`.
29+
- If no SAS key is present, `DefaultAzureCredential` is used for developer scenarios that rely on `az login` and the appropriate Relay Listener role assignment.
2930

3031
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.
3132

docs/relay-listener/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Relay listener uses websocket communication to Manage Breast Screening service via Azure Relay.
44
The listener processes worklist actions sent from Manage/Django and creates worklist items in the Modality Worklist server.
55

6+
Note: SAS-based relay authentication is review-only. For dev, preprod, and prod, the listener should use managed identity and no `AZURE_RELAY_SHARED_ACCESS_KEY` should be injected into `.env`.
67

78
## Architecture
89

infrastructure/modules/arc-infra/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ output "app_insights_connection_string" {
3535
}
3636

3737
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."
38+
description = "Per-machine relay listen SAS primary keys, keyed by Arc resource name. Populated only for the review environment."
3939
sensitive = true
40-
value = var.enable_arc_servers ? {
40+
value = var.enable_arc_servers && var.env_config == "review" ? {
4141
for k, rule in azurerm_relay_hybrid_connection_authorization_rule.per_machine_listen :
4242
k => rule.primary_key
4343
} : {}

infrastructure/modules/arc-infra/relay.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "azurerm_relay_hybrid_connection" "per_machine" {
4848
# Listen-only SAS rule per HC — retained for local development / break-glass access.
4949
# Production relay authentication uses Managed Identity (see relay_listener_role below).
5050
resource "azurerm_relay_hybrid_connection_authorization_rule" "per_machine_listen" {
51-
for_each = local.arc_machines
51+
for_each = var.env_config == "review" ? local.arc_machines : {}
5252

5353
name = "listen"
5454
hybrid_connection_name = azurerm_relay_hybrid_connection.per_machine[each.key].name

scripts/bash/deploy_arc_ring.sh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,31 @@ while IFS= read -r MACHINE_JSON; do
7373
LOCATION=$(echo "$MACHINE_JSON" | jq -r '.location')
7474
echo "Preparing deploy for $MACHINE ($LOCATION)..."
7575

76+
RELAY_AUTH_BLOCK=""
77+
if [[ "${ENV_CONFIG}" == "review" && -n "${AZURE_RELAY_SHARED_ACCESS_KEY:-}" ]]; then
78+
RELAY_AUTH_BLOCK="AZURE_RELAY_KEY_NAME=listen
79+
AZURE_RELAY_SHARED_ACCESS_KEY=${AZURE_RELAY_SHARED_ACCESS_KEY}
80+
"
81+
fi
82+
7683
# Build .env, then base64-encode to pass newlines as a run command parameter.
7784
# NOTE: Arc Run Command drops protectedParameters for inline source.script,
7885
# so EnvContentB64 travels as a regular parameter (base64-encoded, not plain text).
7986
ENV_CONTENT="AZURE_RELAY_NAMESPACE=${RELAY_NAMESPACE_HOSTNAME}
80-
AZURE_RELAY_HYBRID_CONNECTION=hc-${MACHINE}
81-
CLOUD_API_ENDPOINT=${CLOUD_API_ENDPOINT}
82-
CLOUD_API_RESOURCE=${CLOUD_API_RESOURCE}
83-
APPLICATIONINSIGHTS_CONNECTION_STRING=${APPLICATIONINSIGHTS_CONNECTION_STRING}
84-
ENVIRONMENT=${ENVIRONMENT}
85-
MWL_AET=RUBIE_MWL_${API_ENVIRONMENT}
86-
MWL_PORT=104
87-
MWL_DB_PATH=${BASE_PATH}/data/worklist.db
88-
PACS_AET=RUBIE_PACS_${API_ENVIRONMENT}
89-
PACS_PORT=11112
90-
PACS_STORAGE_PATH=${BASE_PATH}/data/storage
91-
PACS_DB_PATH=${BASE_PATH}/data/pacs.db
92-
LOG_LEVEL=INFO
93-
SAMPLE_IMAGES_PATH=${BASE_PATH}/current/sample_images"
87+
AZURE_RELAY_HYBRID_CONNECTION=hc-${MACHINE}
88+
CLOUD_API_ENDPOINT=${CLOUD_API_ENDPOINT}
89+
CLOUD_API_RESOURCE=${CLOUD_API_RESOURCE}
90+
APPLICATIONINSIGHTS_CONNECTION_STRING=${APPLICATIONINSIGHTS_CONNECTION_STRING}
91+
ENVIRONMENT=${ENVIRONMENT}
92+
MWL_AET=RUBIE_MWL_${API_ENVIRONMENT}
93+
MWL_PORT=104
94+
MWL_DB_PATH=${BASE_PATH}/data/worklist.db
95+
PACS_AET=RUBIE_PACS_${API_ENVIRONMENT}
96+
PACS_PORT=11112
97+
PACS_STORAGE_PATH=${BASE_PATH}/data/storage
98+
PACS_DB_PATH=${BASE_PATH}/data/pacs.db
99+
LOG_LEVEL=INFO
100+
${RELAY_AUTH_BLOCK}SAMPLE_IMAGES_PATH=${BASE_PATH}/current/sample_images"
94101

95102
# Cross-platform base64 encoding (works on macOS and Linux)
96103
ENV_CONTENT_B64=$(printf '%s' "$ENV_CONTENT" | base64 | tr -d '\n')

0 commit comments

Comments
 (0)