Skip to content

SQL Server deployment scripts fail when private endpoints are used (PublicNetworkAccess=Disabled) #14421

@mitchdenny

Description

@mitchdenny

Description

When AddPrivateEndpoint is used with an AzureSqlServerResource, the PublicNetworkAccess is set to Disabled. However, the AddRoleAssignments method in AzureSqlServerResource.cs uses an AzurePowerShellScript deployment script that connects to the SQL Server over the public FQDN to create database users:

$connectionString = "Server=tcp:${sqlServerFqdn},1433;Initial Catalog=${sqlDatabaseName};Authentication=Active Directory Default;"
Invoke-Sqlcmd -ConnectionString $connectionString -Query $sqlCmd

The Azure deployment script container runs outside the VNet, so when public network access is disabled, the TCP connection is blocked and the deployment fails with DeploymentFailed on the role assignment step.

Reproduction

var vnet = builder.AddAzureVirtualNetwork("vnet");
var acaSubnet = vnet.AddSubnet("aca-subnet", "10.0.0.0/23");
var peSubnet = vnet.AddSubnet("pe-subnet", "10.0.2.0/24");

builder.AddAzureContainerAppEnvironment("env")
    .WithDelegatedSubnet(acaSubnet);

var sql = builder.AddAzureSqlServer("sql");
var db = sql.AddDatabase("db");
peSubnet.AddPrivateEndpoint(sql);

builder.AddProject<Projects.Web>("web")
    .WithReference(db);

Deploy with aspire deploy — the deployment fails at the provision-webfrontend-roles-sql step.

Root Cause

AzureSqlServerResource.AddRoleAssignments() (line 194-287) creates an AzurePowerShellScript that needs TCP access to the SQL Server. When private endpoints disable public access, the script container (which runs outside the VNet) cannot connect.

Suggested Fix

When private endpoints are present, the AzurePowerShellScript should be configured to run inside the VNet using the SubnetResourceIds property. Azure deployment scripts support VNet integration: https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-script-vnet

Environment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions