Scripted Actions Azure Runbook Enable Private Endpoints

This scripted action adds private endpoints and service endpoints so that the Nerdio Manager app service can reach its SQL database, key vault, and automation accounts over a private network, with no traffic routed over the public internet. It then restricts public access to the database, the key vault, and the other components that it covers.

You can run the script again at any time to bring newly enabled components onto the same private network. The script never re-enables public access on anything that a previous run restricted.

Components that the script covers

The script covers the following components, if they are deployed in your environment:

  • Nerdio Manager: the key vault, SQL server, Nerdio Manager automation account, scripted actions automation account, app service, DPS storage account, and scripted actions storage account.

  • Cost Calculator: the key vault, storage account, and web app.

  • Intune Insights: the key vault, SQL server, and web app.

  • Real Time Insights: the key vault, SQL server, web app, and storage account.

If you enable a component after you run the script, run the script again to bring it onto the same private network. The script doesn't handle Azure Monitor, Log Analytics, or Application Insights. See What the script doesn't make private.

Before you run the script

Important

With the default CssaStorageAccount value (Restricted), or with Private, the script restricts public access to the scripted actions storage account. If your Azure runbooks run in download mode, Azure Automation can no longer download the script for any scripted action after that, and every later scripted action silently does nothing. This includes a later run of this script. Switch the Azure Runbook Execution Mode to Inline Script before you run the script. See Scripted actions for Azure runbooks for details.

  • Link the virtual networks whose hosts need access to the scripted actions storage account, or to the Real Time Insights app service, to Nerdio Manager. The Restricted settings allow access only from the subnets of linked networks. See Azure Environment: linked networks and resource groups.

  • Make sure that the following PowerShell modules are available in the scripted actions automation account: Az.Accounts, Az.Resources, Az.KeyVault, Az.Sql, Az.Storage, Az.Websites, Az.Network, Az.PrivateDns, and Az.Automation. If a module is missing, the script stops before it changes anything and names the module.

What the script does

When you run the script, it does the following:

  • Creates the private endpoint VNet and its subnets, or uses the ones that already exist. The script looks for the VNet in the Nerdio Manager resource group first, and then in the rest of the subscription.

  • Creates private DNS zones and links them to the VNet, or uses your existing zones (see ExistingDNSZonesRG and SkipDNS). The script searches the subscription for existing private endpoints.

  • Creates the private endpoints, connects the app services to the app service subnet, and peers the VNets that you specify.

  • Runs a connectivity probe from inside the VNet-integrated app service worker to the key vault (port 443), the SQL server (port 1433), and the DPS storage account (blob, port 443). If any target fails, the script stops with an error and nothing is made private on that run.

  • Disables public network access on the components that it covers, subject to the parameters below. If any private endpoint or DNS zone group fails to be created, the script makes nothing private and lists the components that failed.

  • Sets the minimum TLS version to 1.2 on the storage accounts and SQL servers, and disallows anonymous public blob access on the storage accounts.

  • Warns about network security groups and route tables that are attached to the private endpoint subnet or the app service subnet. The script only reports them. It doesn't change them.

  • Restarts the Nerdio Manager app service.

If the same script ran in the previous 10 minutes, the script replays the output of that earlier run instead of running again.

To customize the names of the resources that the script creates, such as private endpoint names, clone the script and edit the variables at the top of the script.

Runtime parameters

The following parameters can be specified at runtime:

Parameter

Default

Description

PrivateLinkVnetName

nmw-private-vnet

VNet for private endpoints. If the VNet does not exist, it is created. If you specify an existing VNet, the VNet or its resource group must be linked to Nerdio Manager in System > Settings > Azure.

VnetAddressRange

10.250.250.0/23

Address range for the private endpoint VNet. Ignored if the VNet already exists.

PrivateEndpointSubnetName

nmw-privateendpoints-subnet

Name of the private endpoint subnet. If the subnet does not exist, it is created.

PrivateEndpointSubnetRange

10.250.250.0/24

Address range for the private endpoint subnet. Ignored if the subnet already exists.

AppServiceSubnetName

nmw-app-subnet

Name of the app service subnet. If the subnet does not exist, it is created.

AppServiceSubnetRange

10.250.251.0/26

Address range for the app service subnet. Ignored if the subnet already exists. To resize an existing subnet, see Resize the app service subnet.

ExistingDNSZonesRG

None

If you have private DNS zones already configured for use with the new private endpoints, specify their resource group here. The script finds and uses the existing DNS zones. See Private DNS zones for the zone names.

Note

This resource group must be linked to Nerdio Manager in System > Settings > Azure, or Nerdio Manager must be granted the Private DNS Zone Contributor role on the zones.

ExistingDNSZonesSubId

None

The subscription ID of ExistingDNSZonesRG, if the resource group is in a different subscription than Nerdio Manager. Use this parameter only together with ExistingDNSZonesRG.

CssaStorageAccount

Restricted

Controls network access to the scripted actions storage account. Valid values are:

  • Restricted: Creates a private endpoint, and restricts the public endpoint of the storage account to the subnets of linked networks that have the Microsoft.Storage service endpoint enabled. Use Microsoft.Storage.Global for a subnet in a different region than the storage account.

  • Public: Leaves the storage account unchanged.

  • Private: Creates a private endpoint and fully disables public network access, with no allow-list.

The script doesn't enable service endpoints on subnets that it didn't create. It reports the subnets that don't have one, and skips them. If no linked network has a subnet with the service endpoint, Restricted changes nothing, because restricting the storage account with an empty allow-list would have the same effect as Private.

A more restrictive setting is never relaxed on a later run. To allow public access again, change it in the Azure portal.

Note

With Private, any client without network access to the private endpoint, including AVD session hosts, loses access to the storage account, and the scripted actions that need it fail on those hosts. Use PeerVnetIds to peer the session hosts' VNet to the private endpoint VNet, and make sure that DNS resolves the storage account's FQDN to the private endpoint. Alternatively, use Restricted.

PeerVnetIds

None

Optional. Valid values are All or a comma-separated list of Azure resource IDs of VNets to peer to the private endpoint VNet. If you specify All, all linked VNets in the same subscription are peered. The VNets or their resource groups must be linked to Nerdio Manager in System > Settings > Azure, and the VNets must be in the same subscription as Nerdio Manager. Peer VNets in other subscriptions manually.

If MakeAppServicePrivate is true, or RtiAppService is not Public, the script also links the app service private DNS zone to the peered VNets.

MakeAppServicePrivate

false

Limits access to the Nerdio Manager app service and the Intune Insights web app. If you set it to true, only hosts on the VNet that this script creates, or on peered VNets, can access them. The Intune Insights web app is displayed inside Nerdio Manager, so both must be reachable by the same clients.

Warning

You might no longer be able to access Nerdio Manager after you enable this option. Setting the parameter back to false doesn't re-enable public access. To allow public access again, change it in the Azure portal.

RtiAppService

Public

Controls network access to the Real Time Insights app service. Valid values are:

  • Public: Leaves the app service unchanged.

  • Restricted: Restricts the public endpoint to the subnets of linked networks that have the Microsoft.Web service endpoint enabled.

  • Private: Fully disables public network access.

Warning

Restricted and Private can silently cut off devices that have no network access to the private VNet, including Windows 365 Cloud PCs and roaming Intune-managed devices. You can't restore their access by peering or by firewall rules. The only symptom is missing Real Time Insights history.

SkipDNS

false

Skips all DNS zone creation, lookup, and linking, including the zone groups that write the A records for the private endpoints. Use it only if you manage DNS yourself. The script stops with an error if you set both SkipDNS and ExistingDNSZonesRG.

Warning

The script can still disable public access on the key vault and SQL server in the same run. Until your DNS records resolve to the private endpoints, Nerdio Manager can't reach them.

App service access

The following table shows how the script controls public access to each app service.

App service

Controlled by

Behavior

Nerdio Manager app service

MakeAppServicePrivate

If set to true, the script disables public network access. Otherwise, it leaves public access unchanged.

Intune Insights web app

MakeAppServicePrivate

Follows the Nerdio Manager app service, because it is displayed inside Nerdio Manager.

Cost Calculator web app

Not configurable

Always made private, regardless of MakeAppServicePrivate. Only the Nerdio Manager app service communicates with it, and that traffic uses the private network.

Real Time Insights app service

RtiAppService

Public leaves it unchanged, Restricted limits the public endpoint to linked networks, and Private disables public access.

What the script doesn't make private

  • Azure Resource Manager control plane traffic (management.azure.com, or management.usgovcloudapi.net in US Government clouds).

  • Azure Monitor, Log Analytics workspaces, and Application Insights. The script doesn't change them.

  • The queue and file sub-resources of storage accounts. The script creates a blob private endpoint for each storage account that it covers, and a table private endpoint for the Real Time Insights storage account, because nothing in Nerdio Manager uses the others.

Private DNS zones

The script creates the following private DNS zones, or finds them in ExistingDNSZonesRG:

Service

Azure commercial

Azure US Government

Key vault

privatelink.vaultcore.azure.net

privatelink.vaultcore.usgovcloudapi.net

SQL server

privatelink.database.windows.net

privatelink.database.usgovcloudapi.net

Automation

privatelink.azure-automation.net

privatelink.azure-automation.us

Blob storage

privatelink.blob.core.windows.net

privatelink.blob.core.usgovcloudapi.net

Table storage

privatelink.table.core.windows.net

privatelink.table.core.usgovcloudapi.net

App service

privatelink.azurewebsites.net

privatelink.azurewebsites.us

Recover from a lockout

The script only ever disables public network access. It never re-enables it. To allow public access to a resource again, change its networking settings in the Azure portal.

  • If you set SkipDNS to true and the DNS records for the private endpoints don't resolve to the private IP addresses, Nerdio Manager can't reach its key vault and SQL server, and the app fails to load with a 500.30 error. Create the DNS records, or allow public access to the key vault and SQL server in the Azure portal until they resolve.

  • If you can't reach Nerdio Manager after you set MakeAppServicePrivate to true, connect from a host on the private VNet or a peered VNet, or allow public access to the app service in the Azure portal.

  • If scripted actions stop running after the scripted actions storage account was restricted, switch the Azure Runbook Execution Mode to Inline Script. See Scripted actions for Azure runbooks.

Resize the app service subnet

The script doesn't change the address range of an app service subnet that already exists. Azure requires a subnet of /28 or larger for App Service regional VNet integration, and a /26 is recommended for the up to four apps that integrate into the subnet: the Nerdio Manager app service, Intune Insights, Cost Calculator, and Real Time Insights. Previous versions of the script created a /28 subnet. The default is now a /26.

The script stops with an error if the existing subnet is smaller than a /28, and warns if it is a /27 or a /28. You can't widen the range of a subnet while apps are integrated with it.

To widen an existing app service subnet:
  1. In the Azure portal, remove the VNet integration from each app that uses the subnet.

  2. Change the address range of the subnet to a /26 or larger.

  3. Run the script again. It integrates the apps with the subnet again.

Was this article helpful?

0 out of 0 found this helpful
Have more questions? Submit a request

Comments (0 comments)

Please sign in to leave a comment.