Skip to content

Commit ead7f51

Browse files
DTOSS-13125: extract assign-arc-app-roles into a dedicated make target
Separates `assign_arc_app_roles.sh` from `resource-group-init` into its own `assign-arc-app-roles` make target, as the two operations have different lifecycles — bootstrap runs once per environment, while app role assignment must be re-run each time a new Arc machine is onboarded. Updates onboard-hospital-vm.md to reorder steps so Grant API access (Step 3) comes before Trigger Terraform (Step 4), matching the end-to-end deployment diagram. Also corrects the prerequisites checklist to reflect that the SPN secret is generated fresh with a 1-day expiry rather than retrieved from Key Vault.
1 parent be616a7 commit ead7f51

4 files changed

Lines changed: 22 additions & 20 deletions

File tree

docs/deployment/deployment-pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ The ADO managed identity holds:
422422

423423
The managed identity does **not** hold `Key Vault Secrets Officer` — it cannot write secrets. Cloud API tokens must be provisioned separately by the team managing the cloud application.
424424

425-
The managed identity also does **not** hold `AppRoleAssignment.ReadWrite.All`. Microsoft Graph requires this explicit application permission to create app role assignments — being an owner of the enterprise app service principal is insufficient in application auth context. Granting this tenant-wide permission is not permitted under the organisation's Entra policy. Arc machine managed identity app role assignments are therefore granted manually by running `make <env> resource-group-init` under a user account with ownership of `spn-manbrs-web-api-<env>` — see [`scripts/bash/assign_arc_app_roles.sh`](../../scripts/bash/assign_arc_app_roles.sh) and the [Onboard Hospital VM runbook](./runbooks/onboard-hospital-vm.md#step-4--grant-api-access).
425+
The managed identity also does **not** hold `AppRoleAssignment.ReadWrite.All`. Microsoft Graph requires this explicit application permission to create app role assignments — being an owner of the enterprise app service principal is insufficient in application auth context. Granting this tenant-wide permission is not permitted under the organisation's Entra policy. Arc machine managed identity app role assignments are therefore granted manually by running `make <env> assign-arc-app-roles` under a user account with ownership of `spn-manbrs-web-api-<env>` — see [`scripts/bash/assign_arc_app_roles.sh`](../../scripts/bash/assign_arc_app_roles.sh) and the [Onboard Hospital VM runbook](./runbooks/onboard-hospital-vm.md#step-3--grant-api-access).
426426

427427
### Separation of environments
428428

docs/deployment/infrastructure/create-environment.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ az provider show --namespace Microsoft.GuestConfiguration --query registrationSt
5454

5555
- Confirm the web API enterprise application exists:
5656
- Name: `spn-manbrs-web-api-[environment]`
57-
- If it does not exist, raise a ServiceNow request for the platform team to create it — the `resource-group-init` Bicep deployment and the `assign_arc_app_roles.sh` script both depend on it
57+
- If it does not exist, raise a ServiceNow request for the platform team to create it — the `resource-group-init` Bicep deployment and the `assign-arc-app-roles` make target both depend on it
5858
- [Form for ServiceNow](https://nhsdigitallive.service-now.com/nhs_digital?id=sc_cat_item&sys_id=28f3ab4f1bf3ca1078ac4337b04bcb78&sysparm_category=114fced51bdae1502eee65b9bd4bcbdc)
5959

6060
## Code
@@ -239,10 +239,10 @@ Terraform automatically discovers Arc machines registered in the Arc-enabled ser
239239
make [environment] terraform-apply
240240
```
241241

242-
After Terraform provisions the Hybrid Connection, re-run `resource-group-init` to assign the `Gateway.Access` app role to the new machine's managed identity:
242+
After Terraform provisions the Hybrid Connection, run `assign-arc-app-roles` to assign the `Gateway.Access` app role to the new machine's managed identity:
243243

244244
```bash
245-
make [environment] resource-group-init
245+
make [environment] assign-arc-app-roles
246246
```
247247

248-
> **Why is this a separate step?** The pipeline managed identity cannot create app role assignments — `AppRoleAssignment.ReadWrite.All` is required in application auth context regardless of SP ownership, and this permission is not permitted under the organisation's Entra policy. Running `resource-group-init` under a user account with ownership of `spn-manbrs-web-api-[environment]` is sufficient. Without this step the gateway will fail to authenticate against the cloud web API. See [Onboard Hospital VM — Step 4](../runbooks/onboard-hospital-vm.md#step-4--grant-api-access).
248+
> **Why is this a separate step?** The pipeline managed identity cannot create app role assignments — `AppRoleAssignment.ReadWrite.All` is required in application auth context regardless of SP ownership, and this permission is not permitted under the organisation's Entra policy. Running `assign-arc-app-roles` under a user account with ownership of `spn-manbrs-web-api-[environment]` is sufficient. Without this step the gateway will fail to authenticate against the cloud web API. See [Onboard Hospital VM — Step 3](../runbooks/onboard-hospital-vm.md#step-3--grant-api-access).

docs/deployment/runbooks/onboard-hospital-vm.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- [ ] Trust ODS code confirmed via the [ODS portal](https://odsportal.nhsbsa.nhs.uk/)
1616
- [ ] NHS region confirmed (`nw` | `neyh` | `mids` | `eoe` | `lon` | `se` | `sw`)
1717
- [ ] Deployment ring agreed with the programme team
18-
- [ ] `arc-onboarding-spn-client-id` and `arc-onboarding-spn-client-secret` retrieved from Key Vault
18+
- [ ] `arc-onboarding-spn-client-id` retrieved from Entra ID; new `arc-onboarding-spn-client-secret` generated with 1-day expiry and shared with the hospital trust IT team before the onboarding call
1919

2020
---
2121

@@ -91,32 +91,32 @@ Logs are written to `C:\ArcSetup\ArcSetup.log`.
9191

9292
**Verify**: In the Azure portal, navigate to `rg-mbsgw-<env>-uks-arc-enabled-servers` → Azure Arc machines → `gw-hull-university-teaching-hospitals-nhs-trust-rwa-01`. Status should be **Connected**.
9393

94-
## Step 3 — Trigger Terraform to provision the Hybrid Connection
95-
96-
Run the ADO pipeline **Deploy Arc Infrastructure - \<env\>** manually. Terraform discovers the new Arc machine and creates:
97-
98-
- `hc-gw-hull-university-teaching-hospitals-nhs-trust-rwa-01` in the relay namespace (`relay-manbrs-<env>`)
99-
- `listen` auth rule on that Hybrid Connection
100-
101-
**Verify**: In the Azure portal, navigate to `relay-manbrs-<env>` → Hybrid Connections → `hc-gw-hull-university-teaching-hospitals-nhs-trust-rwa-01` is present.
102-
103-
## Step 4 — Grant API access
94+
## Step 3 — Grant API access
10495

10596
> [!IMPORTANT]
10697
> Without this step the gateway services will start but fail to authenticate against the cloud web API. The Arc machine's managed identity must be assigned the `Gateway.Access` app role on `spn-manbrs-web-api-<env>` before the first deployment.
10798
10899
Run from a developer machine with Owner access to the enterprise application:
109100

110101
```bash
111-
make <env> resource-group-init
102+
make <env> assign-arc-app-roles
112103
```
113104

114105
This calls [`scripts/bash/assign_arc_app_roles.sh`](../../../scripts/bash/assign_arc_app_roles.sh) which discovers all Arc machines in `rg-mbsgw-<env>-uks-arc-enabled-servers` and assigns the `Gateway.Access` role to each machine's managed identity.
115106

116-
> **Why is this manual?** The pipeline managed identity (`mi-mbsgw-<env>-adotoaz-uks`) cannot create app role assignments via the pipeline — Microsoft Graph requires `AppRoleAssignment.ReadWrite.All` in application auth context regardless of SP ownership, and this permission cannot be granted under the organisation's Entra policy. Running `resource-group-init` under a user account with ownership of the enterprise app SP is sufficient. See [Deployment Pipeline — Section 12](../deployment-pipeline.md#12-pipeline-identities-and-permissions) for details.
107+
> **Why is this manual?** The pipeline managed identity (`mi-mbsgw-<env>-adotoaz-uks`) cannot create app role assignments via the pipeline — Microsoft Graph requires `AppRoleAssignment.ReadWrite.All` in application auth context regardless of SP ownership, and this permission cannot be granted under the organisation's Entra policy. Running `assign-arc-app-roles` under a user account with ownership of the enterprise app SP is sufficient. See [Deployment Pipeline — Section 12](../deployment-pipeline.md#12-pipeline-identities-and-permissions) for details.
117108
118109
**Verify**: In the Azure portal navigate to **Enterprise Applications → spn-manbrs-web-api-\<env\> → Users and groups**. The Arc machine (`gw-hull-university-teaching-hospitals-nhs-trust-rwa-01`) should appear with the `Gateway.Access` role.
119110

111+
## Step 4 — Trigger Terraform to provision the Hybrid Connection
112+
113+
Run the ADO pipeline **Deploy Arc Infrastructure - \<env\>** manually. Terraform discovers the new Arc machine and creates:
114+
115+
- `hc-gw-hull-university-teaching-hospitals-nhs-trust-rwa-01` in the relay namespace (`relay-manbrs-<env>`)
116+
- `listen` auth rule on that Hybrid Connection
117+
118+
**Verify**: In the Azure portal, navigate to `relay-manbrs-<env>` → Hybrid Connections → `hc-gw-hull-university-teaching-hospitals-nhs-trust-rwa-01` is present.
119+
120120
## Step 5 — Deploy the gateway application
121121

122122
Run the ADO pipeline **Deploy Gateway - \<env\>** with:
@@ -172,7 +172,7 @@ Check Log Analytics Workspace for an initial heartbeat within 5 minutes of servi
172172
Check `C:\ArcSetup\ArcSetup.log` on the VM. Common causes:
173173

174174
- **Firewall blocking outbound** — confirm the VM can reach `*.arc.azure.com` on port 443
175-
- **SPN credentials wrong**verify client ID and secret from Key Vault are current
175+
- **SPN credentials wrong**confirm the one-time secret shared before the call has not expired (1-day validity); generate a new one and retry if needed
176176
- **VM already registered** — if the machine was previously connected under a different name, disconnect first: `azcmagent disconnect`
177177

178178
### Script execution blocked

scripts/terraform/terraform.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ ci: # Skip manual approvals when running in CI - make ci <env> <action>
2121
set-azure-account: # Set the Azure account for the environment - make <env> set-azure-account
2222
[ "${SKIP_AZURE_LOGIN}" != "true" ] && az account set -s ${AZURE_SUBSCRIPTION} || true
2323

24-
resource-group-init: set-azure-account get-subscription-ids # Initialise resources required by terraform and assign Gateway.Access role to Arc machine managed identities - make <env> resource-group-init
24+
resource-group-init: set-azure-account get-subscription-ids # Initialise resources required by terraform - make <env> resource-group-init
2525
$(eval STORAGE_ACCOUNT_NAME=sa${APP_SHORT_NAME}${ENV_CONFIG}tfstate)
2626
scripts/bash/resource_group_init.sh "${REGION}" "${HUB_SUBSCRIPTION_ID}" "${ENABLE_SOFT_DELETE}" "${ENV_CONFIG}" "${STORAGE_ACCOUNT_RG}" "${STORAGE_ACCOUNT_NAME}" "${APP_SHORT_NAME}" "${ARM_SUBSCRIPTION_ID}"
27+
28+
assign-arc-app-roles: set-azure-account get-subscription-ids # Assign Gateway.Access app role to Arc machine managed identities - make <env> assign-arc-app-roles
2729
scripts/bash/assign_arc_app_roles.sh "${ENV_CONFIG}" "${ARM_SUBSCRIPTION_ID}"
2830

2931
get-subscription-ids: # Retrieve the hub subscription ID based on the subscription name in ${HUB_SUBSCRIPTION} - make <env> get-subscription-ids

0 commit comments

Comments
 (0)