1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Feature/self hosted development (#1921)

* Add self-host option to migration runner

* Add Self-host launch options

* Add self-hosted settings override

Let's a single secrets/env config file control both
cloud and self-hosted settings by allowing
overrides to cloud settings with self-hosted

* Allow dev-signed licenses on dev self-hosted

* Allow setting bitwarden cloud api url

Useful for testing api integration between installations and cloud

* Remove testing echoes

* Remove run config property groups

* Use `getopts` for options

* Pass in full environment
This commit is contained in:
Matt Gibson
2022-03-21 18:13:00 -04:00
committed by GitHub
parent dea1427ba2
commit 4814cef245
23 changed files with 564 additions and 28 deletions

View File

@ -22,6 +22,15 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:62911/"
},
"Admin-SelfHost": {
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"developSelfHosted": "true"
},
"applicationUrl": "http://localhost:62912/"
}
}
}

View File

@ -38,7 +38,7 @@ namespace Bit.Admin
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
services.Configure<AdminSettings>(Configuration.GetSection("AdminSettings"));
// Data Protection

View File

@ -22,6 +22,15 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Api-SelfHost": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:4000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"developSelfHosted": "true"
}
}
}
}
}

View File

@ -43,7 +43,7 @@ namespace Bit.Api
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
if (!globalSettings.SelfHosted)
{
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));

View File

@ -18,13 +18,15 @@ namespace Bit.Billing
{
public class Startup
{
public Startup(IConfiguration configuration)
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
Environment = env;
}
public IConfiguration Configuration { get; }
public IWebHostEnvironment Environment { get; set; }
public void ConfigureServices(IServiceCollection services)
{
@ -32,7 +34,7 @@ namespace Bit.Billing
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
services.Configure<BillingSettings>(Configuration.GetSection("BillingSettings"));
// Stripe Billing

View File

@ -15,6 +15,7 @@
<ItemGroup>
<EmbeddedResource Include="licensing.cer" />
<EmbeddedResource Include="licensing_dev.cer" />
<EmbeddedResource Include="MailTemplates\Handlebars\**\*.hbs" />
</ItemGroup>

View File

@ -45,12 +45,12 @@ namespace Bit.Core.Services
_logger = logger;
_globalSettings = globalSettings;
var certThumbprint = environment.IsDevelopment() && !_globalSettings.SelfHosted ?
var certThumbprint = environment.IsDevelopment() ?
"207E64A231E8AA32AAF68A61037C075EBEBD553F" :
"B34876439FCDA2846505B2EFBBA6C4A951313EBE";
if (_globalSettings.SelfHosted)
{
_certificate = CoreHelpers.GetEmbeddedCertificateAsync("licensing.cer", null)
_certificate = CoreHelpers.GetEmbeddedCertificateAsync(environment.IsDevelopment() ? "licensing_dev.cer" : "licensing.cer", null)
.GetAwaiter().GetResult();
}
else if (CoreHelpers.SettingHasValue(_globalSettings.Storage?.ConnectionString) &&

View File

@ -424,6 +424,7 @@ namespace Bit.Core.Settings
public class InstallationSettings
{
private string _identityUri;
private string _apiUri;
public Guid Id { get; set; }
public string Key { get; set; }
@ -432,6 +433,10 @@ namespace Bit.Core.Settings
get => string.IsNullOrWhiteSpace(_identityUri) ? "https://identity.bitwarden.com" : _identityUri;
set => _identityUri = value;
}
public string ApiUri
{
get => string.IsNullOrWhiteSpace(_apiUri) ? "https://api.biwarden.com" : _apiUri;
}
}
public class AmazonSettings

BIN
src/Core/licensing_dev.cer Normal file

Binary file not shown.

View File

@ -22,6 +22,15 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:46273/"
},
"Events-SelfHost": {
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"developSelfHosted": "true"
},
"applicationUrl": "http://localhost:46274/"
}
}
}

View File

@ -31,7 +31,7 @@ namespace Bit.Events
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
// Repositories
services.AddSqlServerRepositories(globalSettings);

View File

@ -30,7 +30,7 @@ namespace Bit.EventsProcessor
services.AddOptions();
// Settings
services.AddGlobalSettingsServices(Configuration);
services.AddGlobalSettingsServices(Configuration, Environment);
// Hosted Services
services.AddHostedService<AzureQueueHostedService>();

View File

@ -16,13 +16,15 @@ namespace Bit.Icons
{
public class Startup
{
public Startup(IConfiguration configuration)
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
Environment = env;
}
public IConfiguration Configuration { get; }
public IWebHostEnvironment Environment { get; }
public void ConfigureServices(IServiceCollection services)
{
@ -30,7 +32,7 @@ namespace Bit.Icons
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
var iconsSettings = new IconsSettings();
ConfigurationBinder.Bind(Configuration.GetSection("IconsSettings"), iconsSettings);
services.AddSingleton(s => iconsSettings);

View File

@ -15,6 +15,15 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Identity-SelfHost": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:33657",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"developSelfHosted": "true"
}
},
"Identity": {
"commandName": "Project",
"launchBrowser": false,
@ -24,4 +33,4 @@
}
}
}
}
}

View File

@ -38,7 +38,7 @@ namespace Bit.Identity
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
if (!globalSettings.SelfHosted)
{
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));

View File

@ -32,7 +32,7 @@ namespace Bit.Notifications
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
// Identity
services.AddIdentityAuthenticationServices(globalSettings, Environment, config =>

View File

@ -462,10 +462,17 @@ namespace Bit.SharedWeb.Utilities
}
public static GlobalSettings AddGlobalSettingsServices(this IServiceCollection services,
IConfiguration configuration)
IConfiguration configuration, IWebHostEnvironment environment)
{
var globalSettings = new GlobalSettings();
ConfigurationBinder.Bind(configuration.GetSection("GlobalSettings"), globalSettings);
if (environment.IsDevelopment() && configuration.GetValue<bool>("developSelfHosted"))
{
// Override settings with selfHostedOverride settings
ConfigurationBinder.Bind(configuration.GetSection("Dev:SelfHostOverride:GlobalSettings"), globalSettings);
}
services.AddSingleton(s => globalSettings);
services.AddSingleton<IGlobalSettings, GlobalSettings>(s => globalSettings);
return globalSettings;