Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add IP_LOGGING_ENABLED flag (#571)

Leendert de Borst38ac1f731a85
diff --git a/install.sh b/install.sh
index d7481d4ba..8682b448e 100755
--- a/install.sh
+++ b/install.sh
@@ -45,6 +45,7 @@ show_usage() {
printf " configure-ssl Configure SSL certificates (Let's Encrypt or self-signed)\n"
printf " configure-email Configure email domains for receiving emails\n"
printf " configure-registration Configure new account registration (enable or disable)\n"
+ printf " configure-ip-logging Configure IP address logging (enable or disable)\n"
printf " start Start AliasVault containers using remote images\n"
printf " stop Stop AliasVault containers using remote images\n"
printf " restart Restart AliasVault containers using remote images\n"
@@ -133,6 +134,10 @@ parse_args() {
COMMAND="configure-registration"
shift
;;
+ configure-ip-logging|ip-logging)
+ COMMAND="configure-ip-logging"
+ shift
+ ;;
start|s)
COMMAND="start"
shift
@@ -254,6 +259,9 @@ main() {
"configure-hostname")
handle_hostname_configuration
;;
+ "configure-ip-logging")
+ handle_ip_logging_configuration
+ ;;
"start")
handle_start
;;
@@ -519,6 +527,15 @@ set_public_registration() {
fi
}
+set_ip_logging() {
+ printf "${CYAN}> Checking IP_LOGGING_ENABLED...${NC}\n"
+ if ! grep -q "^IP_LOGGING_ENABLED=" "$ENV_FILE" || [ -z "$(grep "^IP_LOGGING_ENABLED=" "$ENV_FILE" | cut -d '=' -f2)" ]; then
+ update_env_var "IP_LOGGING_ENABLED" "true"
+ else
+ printf " ${GREEN}> IP_LOGGING_ENABLED already exists.${NC}\n"
+ fi
+}
+
# Function to generate admin password
generate_admin_password() {
printf "${CYAN}> Generating admin password...${NC}\n"
@@ -829,6 +846,7 @@ handle_build() {
set_smtp_tls_enabled || { printf "${RED}> Failed to set SMTP TLS${NC}\n"; exit 1; }
set_default_ports || { printf "${RED}> Failed to set default ports${NC}\n"; exit 1; }
set_public_registration || { printf "${RED}> Failed to set public registration${NC}\n"; exit 1; }
+ set_ip_logging || { printf "${RED}> Failed to set IP logging${NC}\n"; exit 1; }
# Only generate admin password if not already set
if ! grep -q "^ADMIN_PASSWORD_HASH=" "$ENV_FILE" || [ -z "$(grep "^ADMIN_PASSWORD_HASH=" "$ENV_FILE" | cut -d '=' -f2)" ]; then
@@ -2034,4 +2052,55 @@ handle_hostname_configuration() {
fi
}
+# Function to handle IP logging configuration
+handle_ip_logging_configuration() {
+ # Get current IP logging setting
+ CURRENT_SETTING=$(grep "^IP_LOGGING_ENABLED=" "$ENV_FILE" | cut -d '=' -f2)
+
+ printf "${YELLOW}+++ Configure IP Address Logging +++${NC}\n"
+ printf "\n"
+ printf "Current setting: ${CYAN}${CURRENT_SETTING}${NC}\n"
+ printf "\n"
+ printf "1) Enable IP address logging\n"
+ printf "2) Disable IP address logging\n"
+ printf "\n"
+ printf "Choose an option (1-2): "
+ read -r choice
+
+ case $choice in
+ 1)
+ update_env_var "IP_LOGGING_ENABLED" "true"
+ printf "${GREEN}> IP address logging enabled.${NC}\n"
+
+ printf "\n${YELLOW}Warning: Docker containers need to be restarted to apply these changes.${NC}\n"
+ read -p "Restart now? (y/n): " restart_confirm
+
+ if [ "$restart_confirm" != "y" ] && [ "$restart_confirm" != "Y" ]; then
+ printf "${YELLOW}Please restart manually to apply the changes.${NC}\n"
+ exit 0
+ fi
+
+ handle_restart
+ ;;
+ 2)
+ update_env_var "IP_LOGGING_ENABLED" "false"
+ printf "${GREEN}> IP address logging disabled.${NC}\n"
+
+ printf "\n${YELLOW}Warning: Docker containers need to be restarted to apply these changes.${NC}\n"
+ read -p "Restart now? (y/n): " restart_confirm
+
+ if [ "$restart_confirm" != "y" ] && [ "$restart_confirm" != "Y" ]; then
+ printf "${YELLOW}Please restart manually to apply the changes.${NC}\n"
+ exit 0
+ fi
+
+ handle_restart
+ ;;
+ *)
+ printf "${RED}Invalid option selected.${NC}\n"
+ return 1
+ ;;
+ esac
+}
+
main "$@"
diff --git a/src/AliasVault.Admin/Config.cs b/src/AliasVault.Admin/Config.cs
index f1c5904cd..f82364e7f 100644
--- a/src/AliasVault.Admin/Config.cs
+++ b/src/AliasVault.Admin/Config.cs
@@ -7,10 +7,12 @@
namespace AliasVault.Admin;
+using AliasVault.Shared.Models.Configuration;
+
/// <summary>
/// Configuration class for the Admin project with values loaded from environment variables.
/// </summary>
-public class Config
+public class Config : SharedConfig
{
/// <summary>
/// Gets or sets the admin password hash which is generated by install.sh and will be set
diff --git a/src/AliasVault.Admin/Program.cs b/src/AliasVault.Admin/Program.cs
index e1c5c4cfc..f055df968 100644
--- a/src/AliasVault.Admin/Program.cs
+++ b/src/AliasVault.Admin/Program.cs
@@ -29,13 +29,16 @@ builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.Environment
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../logs");
// Create global config object, get values from environment variables.
-Config config = new Config();
+var config = new Config();
var adminPasswordHash = Environment.GetEnvironmentVariable("ADMIN_PASSWORD_HASH") ?? throw new KeyNotFoundException("ADMIN_PASSWORD_HASH environment variable is not set.");
config.AdminPasswordHash = adminPasswordHash;
var lastPasswordChanged = Environment.GetEnvironmentVariable("ADMIN_PASSWORD_GENERATED") ?? throw new KeyNotFoundException("ADMIN_PASSWORD_GENERATED environment variable is not set.");
config.LastPasswordChanged = DateTime.Parse(lastPasswordChanged, CultureInfo.InvariantCulture);
+var ipLoggingEnabled = Environment.GetEnvironmentVariable("IP_LOGGING_ENABLED") ?? "false";
+config.IpLoggingEnabled = bool.Parse(ipLoggingEnabled);
+
builder.Services.AddSingleton(config);
builder.Services.AddAliasVaultDataProtection("AliasVault.Admin");
diff --git a/src/AliasVault.Admin/Properties/launchSettings.json b/src/AliasVault.Admin/Properties/launchSettings.json
index c29f7137e..594c69013 100644
--- a/src/AliasVault.Admin/Properties/launchSettings.json
+++ b/src/AliasVault.Admin/Properties/launchSettings.json
@@ -18,7 +18,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"ADMIN_PASSWORD_HASH": "AQAAAAIAAYagAAAAEKWfKfa2gh9Z72vjAlnNP1xlME7FsunRznzyrfqFte40FToufRwa3kX8wwDwnEXZag==",
"ADMIN_PASSWORD_GENERATED": "2030-01-01T00:00:00Z",
- "DATA_PROTECTION_CERT_PASS": "Development"
+ "DATA_PROTECTION_CERT_PASS": "Development",
+ "IP_LOGGING_ENABLED": "true"
}
},
"https": {
@@ -27,7 +28,11 @@
"launchBrowser": true,
"applicationUrl": "https://localhost:7025;http://localhost:5216",
"environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "ADMIN_PASSWORD_HASH": "AQAAAAIAAYagAAAAEKWfKfa2gh9Z72vjAlnNP1xlME7FsunRznzyrfqFte40FToufRwa3kX8wwDwnEXZag==",
+ "ADMIN_PASSWORD_GENERATED": "2030-01-01T00:00:00Z",
+ "DATA_PROTECTION_CERT_PASS": "Development",
+ "IP_LOGGING_ENABLED": "true"
}
},
"IIS Express": {
diff --git a/src/AliasVault.Api/Config.cs b/src/AliasVault.Api/Config.cs
index 8055c551e..2b23079ca 100644
--- a/src/AliasVault.Api/Config.cs
+++ b/src/AliasVault.Api/Config.cs
@@ -7,10 +7,12 @@
namespace AliasVault.Api;
+using AliasVault.Shared.Models.Configuration;
+
/// <summary>
/// Configuration class for the Client project with values loaded from appsettings.json.
/// </summary>
-public class Config
+public class Config : SharedConfig
{
/// <summary>
/// Gets or sets a value indicating whether public registration is enabled.
diff --git a/src/AliasVault.Api/Program.cs b/src/AliasVault.Api/Program.cs
index 21e935294..078acb0f4 100644
--- a/src/AliasVault.Api/Program.cs
+++ b/src/AliasVault.Api/Program.cs
@@ -34,6 +34,9 @@ config.PublicRegistrationEnabled = bool.Parse(publicRegistrationEnabled);
var privateEmailDomains = Environment.GetEnvironmentVariable("PRIVATE_EMAIL_DOMAINS")?.Split(",").Select(d => d.Trim());
config.PrivateEmailDomains = privateEmailDomains?.ToList() ?? new List<string>();
+var ipLoggingEnabled = Environment.GetEnvironmentVariable("IP_LOGGING_ENABLED") ?? "false";
+config.IpLoggingEnabled = bool.Parse(ipLoggingEnabled);
+
builder.Services.AddSingleton(config);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../logs");
diff --git a/src/AliasVault.Api/Properties/launchSettings.json b/src/AliasVault.Api/Properties/launchSettings.json
index 17b943c09..689bbec26 100644
--- a/src/AliasVault.Api/Properties/launchSettings.json
+++ b/src/AliasVault.Api/Properties/launchSettings.json
@@ -9,7 +9,8 @@
"JWT_KEY": "12345678901234567890123456789012",
"DATA_PROTECTION_CERT_PASS": "Development",
"PUBLIC_REGISTRATION_ENABLED": "true",
- "PRIVATE_EMAIL_DOMAINS": "example.tld,example2.tld"
+ "PRIVATE_EMAIL_DOMAINS": "example.tld,example2.tld",
+ "IP_LOGGING_ENABLED": "true"
},
"dotnetRunMessages": true,
"applicationUrl": "http://0.0.0.0:5092"
@@ -23,7 +24,8 @@
"JWT_KEY": "12345678901234567890123456789012",
"DATA_PROTECTION_CERT_PASS": "Development",
"PUBLIC_REGISTRATION_ENABLED": "true",
- "PRIVATE_EMAIL_DOMAINS": "example.tld,example2.tld"
+ "PRIVATE_EMAIL_DOMAINS": "example.tld,example2.tld",
+ "IP_LOGGING_ENABLED": "true"
},
"dotnetRunMessages": true,
"applicationUrl": "https://0.0.0.0:7223"
diff --git a/src/Shared/AliasVault.Shared/Models/Configuration/SharedConfig.cs b/src/Shared/AliasVault.Shared/Models/Configuration/SharedConfig.cs
new file mode 100644
index 000000000..af7e17946
--- /dev/null
+++ b/src/Shared/AliasVault.Shared/Models/Configuration/SharedConfig.cs
@@ -0,0 +1,21 @@
+//-----------------------------------------------------------------------
+// <copyright file="SharedConfig.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.Configuration;
+
+/// <summary>
+/// Shared configuration model for the AliasVault project that is used by both the API and Admin projects
+/// and is used for other shared projects to access common configuration values.
+/// </summary>
+public class SharedConfig
+{
+ /// <summary>
+ /// Gets or sets a value indicating whether IP logging is enabled, used by the Auth logging service
+ /// to determine if the IP address for a request should be logged.
+ /// </summary>
+ public bool IpLoggingEnabled { get; set; }
+}
diff --git a/src/Utilities/AliasVault.Auth/AuthLoggingService.cs b/src/Utilities/AliasVault.Auth/AuthLoggingService.cs
index 870591726..ae15f86b8 100644
--- a/src/Utilities/AliasVault.Auth/AuthLoggingService.cs
+++ b/src/Utilities/AliasVault.Auth/AuthLoggingService.cs
@@ -8,6 +8,7 @@
namespace AliasVault.Auth;
using AliasServerDb;
+using AliasVault.Shared.Models.Configuration;
using AliasVault.Shared.Models.Enums;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
@@ -32,6 +33,9 @@ public class AuthLoggingService(IServiceProvider serviceProvider, IHttpContextAc
var httpContext = httpContextAccessor.HttpContext;
var clientHeader = httpContext?.Request.Headers["X-AliasVault-Client"].FirstOrDefault();
+ var config = httpContext?.RequestServices.GetService<SharedConfig>();
+ var ipAddress = config?.IpLoggingEnabled == true ? IpAddressUtility.GetIpFromContext(httpContext) : "xxx.xxx.xxx.xxx";
+
var authAttempt = new AuthLog
{
Timestamp = DateTime.UtcNow,
@@ -39,7 +43,7 @@ public class AuthLoggingService(IServiceProvider serviceProvider, IHttpContextAc
EventType = eventType,
IsSuccess = true,
FailureReason = null,
- IpAddress = IpAddressUtility.GetIpFromContext(httpContext),
+ IpAddress = ipAddress,
UserAgent = httpContext?.Request.Headers.UserAgent,
Client = clientHeader,
RequestPath = httpContext?.Request.Path,
@@ -68,6 +72,9 @@ public class AuthLoggingService(IServiceProvider serviceProvider, IHttpContextAc
var httpContext = httpContextAccessor.HttpContext;
var clientHeader = httpContext?.Request.Headers["X-AliasVault-Client"].FirstOrDefault();
+ var config = httpContext?.RequestServices.GetService<SharedConfig>();
+ var ipAddress = config?.IpLoggingEnabled == true ? IpAddressUtility.GetIpFromContext(httpContext) : "xxx.xxx.xxx.xxx";
+
var authAttempt = new AuthLog
{
Timestamp = DateTime.UtcNow,
@@ -75,7 +82,7 @@ public class AuthLoggingService(IServiceProvider serviceProvider, IHttpContextAc
EventType = eventType,
IsSuccess = false,
FailureReason = failureReason,
- IpAddress = IpAddressUtility.GetIpFromContext(httpContext),
+ IpAddress = ipAddress,
UserAgent = httpContext?.Request.Headers.UserAgent,
Client = clientHeader,
RequestPath = httpContext?.Request.Path,