Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a default TLS version for Azure SQL to 1.2 #5043

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal static IResourceBuilder<SqlServerServerResource> PublishAsAzureSqlDatab
sqlServer.AssignProperty(x => x.Administrators.Sid, construct.PrincipalIdParameter);
sqlServer.AssignProperty(x => x.Administrators.Login, construct.PrincipalNameParameter);
sqlServer.AssignProperty(x => x.Administrators.TenantId, "subscription().tenantId");
sqlServer.AssignProperty(x => x.MinimalTlsVersion, "'1.2'");

sqlServer.Properties.Tags["aspire-resource-name"] = construct.Resource.Name;

Expand Down
32 changes: 24 additions & 8 deletions tests/Aspire.Hosting.Azure.Tests/AzureBicepResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,21 @@ param principalType string
Assert.Equal(expectedBicep, manifest.BicepText);
}

[Fact]
public async Task AsAzureSqlDatabaseViaRunMode()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task AsAzureSqlDatabaseViaRunMode(bool overrideDefaultTlsVersion)
{
using var builder = TestDistributedApplicationBuilder.Create();

var sql = builder.AddSqlServer("sql").AsAzureSqlDatabase((azureSqlBuilder, _, _, _) =>
var sql = builder.AddSqlServer("sql").AsAzureSqlDatabase((azureSqlBuilder, _, sql, _) =>
{
azureSqlBuilder.Resource.Outputs["sqlServerFqdn"] = "myserver";

if (overrideDefaultTlsVersion)
{
sql.AssignProperty(s => s.MinimalTlsVersion, "'1.3'");
}
});
sql.AddDatabase("db", "dbName");

Expand All @@ -1151,7 +1158,7 @@ public async Task AsAzureSqlDatabaseViaRunMode()
""";
Assert.Equal(expectedManifest, manifest.ManifestNode.ToString());

var expectedBicep = """
var expectedBicep = $$"""
targetScope = 'resourceGroup'

@description('')
Expand All @@ -1175,6 +1182,7 @@ param principalType string
}
properties: {
version: '12.0'
minimalTlsVersion: '{{(overrideDefaultTlsVersion ? "1.3" : "1.2")}}'
publicNetworkAccess: 'Enabled'
administrators: {
administratorType: 'ActiveDirectory'
Expand Down Expand Up @@ -1220,14 +1228,21 @@ param principalType string
Assert.Equal(expectedBicep, manifest.BicepText);
}

[Fact]
public async Task AsAzureSqlDatabaseViaPublishMode()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task AsAzureSqlDatabaseViaPublishMode(bool overrideDefaultTlsVersion)
{
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);

var sql = builder.AddSqlServer("sql").AsAzureSqlDatabase((azureSqlBuilder, _, _, _) =>
var sql = builder.AddSqlServer("sql").AsAzureSqlDatabase((azureSqlBuilder, _, sql, _) =>
{
azureSqlBuilder.Resource.Outputs["sqlServerFqdn"] = "myserver";

if (overrideDefaultTlsVersion)
{
sql.AssignProperty(s => s.MinimalTlsVersion, "'1.3'");
}
});
sql.AddDatabase("db", "dbName");

Expand All @@ -1249,7 +1264,7 @@ public async Task AsAzureSqlDatabaseViaPublishMode()
""";
Assert.Equal(expectedManifest, manifest.ManifestNode.ToString());

var expectedBicep = """
var expectedBicep = $$"""
targetScope = 'resourceGroup'

@description('')
Expand All @@ -1270,6 +1285,7 @@ param principalName string
}
properties: {
version: '12.0'
minimalTlsVersion: '{{(overrideDefaultTlsVersion ? "1.3" : "1.2")}}'
publicNetworkAccess: 'Enabled'
administrators: {
administratorType: 'ActiveDirectory'
Expand Down