Skip to content

Commit 2bcc81c

Browse files
committed
Make Sql Server use Dev cert
Inject the dev cert to the sql server container, and configure sql to use it.
1 parent 749dd16 commit 2bcc81c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static IResourceBuilder<SqlServerServerResource> AddSqlServer(this IDistr
4848
var healthCheckKey = $"{name}_check";
4949
builder.Services.AddHealthChecks().AddSqlServer(sp => connectionString ?? throw new InvalidOperationException("Connection string is unavailable"), name: healthCheckKey);
5050

51+
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
5152
return builder.AddResource(sqlServer)
5253
.WithEndpoint(port: port, targetPort: 1433, name: SqlServerServerResource.PrimaryEndpointName)
5354
.WithImage(SqlServerContainerImageTags.Image, SqlServerContainerImageTags.Tag)
@@ -86,7 +87,23 @@ public static IResourceBuilder<SqlServerServerResource> AddSqlServer(this IDistr
8687
{
8788
await CreateDatabaseAsync(sqlConnection, sqlDatabase, @event.Services, ct).ConfigureAwait(false);
8889
}
90+
})
91+
.WithServerAuthenticationCertificateConfiguration(async ctx =>
92+
{
93+
builder.CreateResourceBuilder((SqlServerServerResource)ctx.Resource)
94+
.WithContainerFiles("/var/opt/mssql/", [
95+
new ContainerFile {
96+
Name = "mssql.conf",
97+
Contents = $"""
98+
[network]
99+
tlscert = {await ctx.CertificatePath.GetValueAsync(ctx.CancellationToken).ConfigureAwait(false)}
100+
tlskey = {await ctx.KeyPath.GetValueAsync(ctx.CancellationToken).ConfigureAwait(false)}
101+
#forceencryption = 1
102+
"""
103+
}
104+
]);
89105
});
106+
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
90107
}
91108

92109
/// <summary>

0 commit comments

Comments
 (0)