Skip to content

Commit 026a702

Browse files
Grant Arc machine managed identities Azure Relay Listener role
Each discovered Arc machine's system-assigned MI is granted the Azure Relay Listener role on its own HC, enabling the relay listener service to authenticate without a SAS key. Static machines (registered in the same apply) are excluded from the data source lookup and pick up the assignment on the next apply after Arc onboarding completes.
1 parent 435c721 commit 026a702

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

  • infrastructure/modules/arc-infra

infrastructure/modules/arc-infra/relay.tf

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

48-
# Listen-only SAS rule per HC — distributed to each gateway site via the deploy pipeline.
49-
# The cloud app uses a namespace-level Send SAS and does not need per-site keys.
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).
5050
resource "azurerm_relay_hybrid_connection_authorization_rule" "per_machine_listen" {
5151
for_each = local.arc_machines
5252

@@ -59,3 +59,23 @@ resource "azurerm_relay_hybrid_connection_authorization_rule" "per_machine_liste
5959
send = false
6060
manage = false
6161
}
62+
63+
# Look up each discovered Arc machine to obtain its system-assigned managed identity.
64+
# Static machines (registered in the same apply) are excluded — they are not yet
65+
# visible to the data source and will be picked up on the next apply after onboarding.
66+
data "azurerm_arc_machine" "machines" {
67+
for_each = local.arc_machines_discovered
68+
name = each.key
69+
resource_group_name = data.azurerm_resource_group.arc_enabled_servers[0].name
70+
}
71+
72+
# Grant each machine's MI the Azure Relay Listener role on its own HC so the relay
73+
# listener service can authenticate without a SAS key.
74+
module "relay_listener_role" {
75+
for_each = local.arc_machines_discovered
76+
source = "../dtos-devops-templates/infrastructure/modules/rbac-assignment"
77+
78+
scope = azurerm_relay_hybrid_connection.per_machine[each.key].id
79+
role_definition_name = "Azure Relay Listener"
80+
principal_id = data.azurerm_arc_machine.machines[each.key].identity[0].principal_id
81+
}

0 commit comments

Comments
 (0)