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

PAS-452 | Self-hosting and mailing bugs #707

Merged
merged 5 commits into from
Aug 29, 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
14 changes: 14 additions & 0 deletions run_self-hosting-image-ssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
docker stop passwordless
docker rm passwordless
docker build . -f self-host/Dockerfile -t bitwarden/passwordless

docker run \
--name passwordless \
-p 5701:5701 \
-e BWP_PORT=5701 \
-e BWP_DOMAIN=yourdomain.local \
-e BWP_ENABLE_SSL=true \
-e BWP_ENABLE_SSL_CA=true \
-e BWP_SSL_CA_CERT=ssl.crt \
-v /your/path/passwordless-self-hosting:/etc/bitwarden_passwordless \
bitwarden/passwordless
5 changes: 3 additions & 2 deletions run_self-hosting-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ docker build . -f self-host/Dockerfile -t bitwarden/passwordless
docker run \
--name passwordless \
-p 5701:5701 \
-e BWP_ENABLE_SSL=true \
-e BWP_PORT=5701 \
-e BWP_DOMAIN=yourdomain.com \
-e BWP_ENABLE_SSL=false \
-v /your/path/passwordless-self-hosting:/etc/bitwarden_passwordless \
bitwarden/passwordless
66 changes: 7 additions & 59 deletions self-host/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,6 @@ else
export ConnectionStrings__sqlite__admin=${ConnectionStrings__sqlite__admin:-$SQLITE_CONNECTION_STRING_ADMIN}
fi

#################
# E-mail / SMTP #
#################
if [ -z "$BWP_SMTP_FROM" ] || [ "$BWP_SMTP_HOST" == "null" ]; then
export Mail__File__Path="$mounted_dir"
echo "[Configuration] SMTP E-mail configuration not set. Writing to a local file instead in '/etc/bitwarden_passwordless/mail.md' or your mounted volume. See 'https://docs.passwordless.dev/guide/self-hosting/configuration.html'.";
else
if [ -n "$BWP_SMTP_FROM" ] && [ "$BWP_SMTP_FROM" != "null" ]; then
export Mail__Smtp__From=$BWP_SMTP_FROM
fi

if [ -n "$BWP_SMTP_USERNAME" ] && [ "$BWP_SMTP_USERNAME" != "null" ]; then
export Mail__Smtp__Username=$BWP_SMTP_USERNAME
fi

if [ -n "$BWP_SMTP_PASSWORD" ] && [ "$BWP_SMTP_PASSWORD" != "null" ]; then
export Mail__Smtp__Password=$BWP_SMTP_PASSWORD
fi

if [ -n "$BWP_SMTP_HOST" ] && [ "$BWP_SMTP_HOST" != "null" ]; then
export Mail__Smtp__Host=$BWP_SMTP_HOST
fi

if [ -n "$BWP_SMTP_PORT" ] && [ "$BWP_SMTP_PORT" != "null" ]; then
export Mail__Smtp__Port=$BWP_SMTP_PORT
fi

if [ -n "$BWP_SMTP_STARTTLS" ] && [ "$BWP_SMTP_STARTTLS" != "null" ]; then
export Mail__Smtp__StartTls=$BWP_SMTP_STARTTLS
fi

if [ -n "$BWP_SMTP_SSL" ] && [ "$BWP_SMTP_SSL" != "null" ]; then
export Mail__Smtp__Ssl=$BWP_SMTP_SSL
fi

if [ -n "$BWP_SMTP_SSLOVERRIDE" ] && [ "$BWP_SMTP_SSLOVERRIDE" != "null" ]; then
export Mail__Smtp__SslOverride=$BWP_SMTP_SSLOVERRIDE
fi

if [ -n "$BWP_SMTP_TRUSTSERVER" ] && [ "$BWP_SMTP_TRUSTSERVER" != "null" ]; then
export Mail__Smtp__TrustServer=$BWP_SMTP_TRUSTSERVER
fi
fi

#########################
# Url #
#########################
Expand All @@ -92,22 +48,14 @@ if [ "$BWP_DOMAIN" != "localhost" ] && [ "$BWP_ENABLE_SSL" != "false" ]; then
echo "[Configuration] WARNING: WebAuthn requires SSL when not running on 'localhost'. This could result in unexpected behavior.";
fi

if [ "$BWP_ENABLE_SSL" = "true" ]; then
echo "[Configuration] SSL: Enabled";
scheme="https"
else
echo "[Configuration] SSL: Disabled";
scheme="http"
fi
if [ "$BWP_PORT" == "null" ]; then
echo "WARNING: 'BWP_PORT' not set, defaulting to 5701.";
exit 1;
export Passwordless__ApiUrl="https://${BWP_DOMAIN}/api/"
export PasswordlessManagement__ApiUrl="https://${BWP_DOMAIN}/api/"
else
export Passwordless__ApiUrl="https://${BWP_DOMAIN}:${BWP_PORT}/api/"
export PasswordlessManagement__ApiUrl="https://${BWP_DOMAIN}:${BWP_PORT}/api/"
fi

export Passwordless__ApiUrl="$scheme://${BWP_DOMAIN:-localhost}:${BWP_PORT:-5701}/api"
export PasswordlessManagement__ApiUrl="$scheme://${BWP_DOMAIN:-localhost}:${BWP_PORT:-5701}/api"
echo "[Configuration] API public: $PasswordlessManagement__ApiUrl";

##############################################
# Generate ApiKey, ApiSecret & ManagementKey #
##############################################
Expand Down Expand Up @@ -175,8 +123,8 @@ if [ "$BWP_ENABLE_SSL" = "true" ] && [ ! -f /etc/bitwarden_passwordless/${BWP_SS
-out /etc/bitwarden_passwordless/${BWP_SSL_CERT:-ssl.crt} \
-reqexts SAN \
-extensions SAN \
-config <(cat /usr/lib/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:${BWP_DOMAIN:-localhost}\nbasicConstraints=CA:true")) \
-subj "/C=US/ST=California/L=Santa Barbara/O=Bitwarden Inc./OU=Bitwarden Passwordless/CN=${BWP_DOMAIN:-localhost}"
-config <(cat /usr/lib/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:${BWP_DOMAIN}\nbasicConstraints=CA:true")) \
-subj "/C=US/ST=California/L=Santa Barbara/O=Bitwarden Inc./OU=Bitwarden Passwordless/CN=${BWP_DOMAIN}"
fi

# Launch a loop to rotate nginx logs on a daily basis
Expand Down
12 changes: 3 additions & 9 deletions src/AdminConsole/Components/Pages/Initialize.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@inject TimeProvider TimeProvider
@inject UserManager<ConsoleAdmin> UserManager
@inject ILogger<Initialize> Logger
@inject IPasswordlessManagementClient PasswordlessManagementClient

<h3>🚀 Let's set up the Admin Console</h3>
<Alert Style="@ContextualStyles.Warning" class="mt-5">Admin Console is configured to use the API at <strong>@ManagementOptions.Value.ApiUrl</strong></Alert>
Expand Down Expand Up @@ -104,19 +105,12 @@
// Create app in the API
try
{
using var http = new HttpClient();
http.BaseAddress = new Uri(ManagementOptions.Value.ApiUrl);
http.DefaultRequestHeaders.Add("ManagementKey", ManagementOptions.Value.ManagementKey);

using var response = await http.PostAsJsonAsync("/admin/apps/adminconsole/create", new CreateAppDto
const string appName = "adminconsole";
appCreationResult = await PasswordlessManagementClient.CreateApplicationAsync(appName, new CreateAppDto
{
AdminEmail = Form.AdminEmail,
MagicLinkEmailMonthlyQuota = 2000
});

response.EnsureSuccessStatusCode();

appCreationResult = (await response.Content.ReadFromJsonAsync<CreateAppResultDto>())!;
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PasswordlessManagementClient(HttpClient http) : IPasswordlessManage
public async Task<CreateAppResultDto> CreateApplicationAsync(string appId, CreateAppDto options)
{
using var response = await http.PostAsJsonAsync(
$"/admin/apps/{Uri.EscapeDataString(appId)}/create",
$"admin/apps/{Uri.EscapeDataString(appId)}/create",
options
);

Expand Down
5 changes: 5 additions & 0 deletions src/Common/Services/Mail/AggregateMailProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ public AggregateMailProvider(

public async Task SendAsync(MailMessage message)
{

if (message.From == null)
{
message.From = _options.Value.From;
}
if (message.FromDisplayName == null)
{
message.FromDisplayName = _options.Value.FromName;
}
foreach (var providerConfiguration in _options.Value.Providers)
{
try
Expand Down
5 changes: 4 additions & 1 deletion src/Common/Services/Mail/Aws/AwsMailProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public async Task SendAsync(MailMessage message)
{
var request = new SendEmailRequest
{
FromEmailAddress = message.From
FromEmailAddress = message.FromDisplayName != null
? $"{message.FromDisplayName} <{message.From}>"
: message.From

};

if (message.To.Any())
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Services/Mail/MailConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class MailConfiguration
/// </summary>
public string? From { get; set; }

/// <summary>
/// The default name to use as the sender.
/// </summary>
public string? FromName { get; set; }

/// <summary>
/// The ordered list of mail providers to use.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Services/Mail/MailMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MailMessage()

public string? From { get; set; }

public string FromDisplayName { get; init; }
public string? FromDisplayName { get; set; }

public string Subject { get; init; }

Expand Down
Loading