Skip to content

Commit 8858303

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 beb9cfe commit 8858303

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,31 @@ public static IResourceBuilder<SqlServerServerResource> AddSqlServer(this IDistr
8787
{
8888
await CreateDatabaseAsync(sqlConnection, sqlDatabase, @event.Services, ct).ConfigureAwait(false);
8989
}
90-
});
90+
})
91+
.WithContainerFiles("/var/opt/mssql/", async (ctx, ct) => {
92+
#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.
93+
var certContext = ctx.ServerAuthenticationCertificateContext;
94+
95+
if (certContext == null)
96+
{
97+
return [];
98+
}
99+
100+
var certPath = await certContext.CertificatePath.GetValueAsync(ct).ConfigureAwait(false);
101+
var keyPath = await certContext.KeyPath.GetValueAsync(ct).ConfigureAwait(false);
102+
103+
return [ new ContainerFile
104+
{
105+
Name = "mssql.conf",
106+
Contents = $"""
107+
[network]
108+
tlscert = {certPath}
109+
tlskey = {keyPath}
110+
#forceencryption = 1
111+
"""
112+
}];
113+
#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.
114+
});
91115
}
92116

93117
/// <summary>

0 commit comments

Comments
 (0)