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

Add authentication (username and password) to Aspire.Hosting.Seq containers #6878

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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.Seq/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#nullable enable

static Aspire.Hosting.SeqBuilderExtensions.WithAuthentication(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SeqResource!>! builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource!>! username, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource!>! password) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SeqResource!>!
34 changes: 30 additions & 4 deletions src/Aspire.Hosting.Seq/SeqBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace Aspire.Hosting;
public static class SeqBuilderExtensions
{
// The path within the container in which Seq stores its data
const string SeqContainerDataDirectory = "/data";
private const string SeqContainerDataDirectory = "/data";

private const string AcceptEulaEnvVarName = "ACCEPT_EULA";
private const string UserEnvVarName = "SEQ_FIRSTRUN_ADMINUSERNAME";
private const string PasswordEnvVarName = "SEQ_FIRSTRUN_ADMINPASSWORD";

/// <summary>
/// Adds a Seq server resource to the application model. A container is used for local development.
Expand All @@ -35,15 +39,37 @@ public static IResourceBuilder<SeqResource> AddSeq(
.WithHttpEndpoint(port: port, targetPort: 80, name: SeqResource.PrimaryEndpointName)
.WithImage(SeqContainerImageTags.Image, SeqContainerImageTags.Tag)
.WithImageRegistry(SeqContainerImageTags.Registry)
.WithEnvironment("ACCEPT_EULA", "Y");
.WithEnvironment(AcceptEulaEnvVarName, "Y");

return resourceBuilder;
}

/// <summary>
/// Enable authentication, providing a username and password for the default admin user.
/// </summary>
/// <remarks>If container storage is persisted, the username and password will also be
/// persisted and must be managed through the Seq web interface. This method will not enable
/// authentication if the container has already been persisted without authentication enabled.</remarks>
/// <param name="builder">The Seq resource builder.</param>
/// <param name="username">A parameter containing a username for the default Seq admin user.</param>
/// <param name="password">A parameter a password for the default admin user.</param>
/// <exception cref="ArgumentException">The supplied username or password is blank.</exception>
public static IResourceBuilder<SeqResource> WithAuthentication(
this IResourceBuilder<SeqResource> builder,
IResourceBuilder<ParameterResource> username,
IResourceBuilder<ParameterResource> password)
{
ArgumentException.ThrowIfNullOrWhiteSpace(username.Resource.Value, nameof(username));
ArgumentException.ThrowIfNullOrWhiteSpace(password.Resource.Value, nameof(username));
return builder
.WithEnvironment(UserEnvVarName, username)
.WithEnvironment(PasswordEnvVarName, password);
}

/// <summary>
/// Adds a named volume for the data folder to a Seq container resource.
/// </summary>
/// <param name="builder">The resource builder.</param>
/// <param name="builder">The Seq resource builder.</param>
/// <param name="name">The name of the volume. Defaults to an auto-generated name based on the application and resource names.</param>
/// <param name="isReadOnly">A flag that indicates if this is a read-only volume.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
Expand All @@ -53,7 +79,7 @@ public static IResourceBuilder<SeqResource> WithDataVolume(this IResourceBuilder
/// <summary>
/// Adds a bind mount for the data folder to a Seq container resource.
/// </summary>
/// <param name="builder">The resource builder.</param>
/// <param name="builder">The Seq resource builder.</param>
/// <param name="source">The source directory on the host to mount into the container.</param>
/// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
Expand Down
Loading