1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-21 21:15:10 -05:00

manage data protection keys with azure and enc

This commit is contained in:
Kyle Spearrin 2017-03-23 22:02:55 -04:00
parent 47477f6ca5
commit ca9aa40873
4 changed files with 23 additions and 0 deletions

View File

@ -22,6 +22,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />

View File

@ -31,6 +31,8 @@ using Serilog;
using Serilog.Events; using Serilog.Events;
using Bit.Api.IdentityServer; using Bit.Api.IdentityServer;
using Bit.Core.Enums; using Bit.Core.Enums;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.WindowsAzure.Storage;
namespace Bit.Api namespace Bit.Api
{ {
@ -71,6 +73,16 @@ namespace Bit.Api
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions")); services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies")); services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
// Data Protection
if(Environment.IsProduction())
{
var dataProtectionCert = CoreHelpers.GetCertificate(globalSettings.DataProtection.CertificateThumbprint);
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
services.AddDataProtection()
.PersistKeysToAzureBlobStorage(storageAccount, "aspnet-dataprotection/keys.xml")
.ProtectKeysWithCertificate(dataProtectionCert);
}
// Repositories // Repositories
services.AddSingleton<IUserRepository, SqlServerRepos.UserRepository>(); services.AddSingleton<IUserRepository, SqlServerRepos.UserRepository>();
services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>(); services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>();
@ -81,6 +93,7 @@ namespace Bit.Api
services.AddSingleton<ISubvaultRepository, SqlServerRepos.SubvaultRepository>(); services.AddSingleton<ISubvaultRepository, SqlServerRepos.SubvaultRepository>();
services.AddSingleton<ISubvaultUserRepository, SqlServerRepos.SubvaultUserRepository>(); services.AddSingleton<ISubvaultUserRepository, SqlServerRepos.SubvaultUserRepository>();
services.AddSingleton<IFolderRepository, SqlServerRepos.FolderRepository>(); services.AddSingleton<IFolderRepository, SqlServerRepos.FolderRepository>();
services.AddSingleton<ISubvaultCipherRepository, SqlServerRepos.SubvaultCipherRepository>();
// Context // Context
services.AddScoped<CurrentContext>(); services.AddScoped<CurrentContext>();

View File

@ -24,6 +24,9 @@
"identityServer": { "identityServer": {
"certificateThumbprint": "SECRET" "certificateThumbprint": "SECRET"
}, },
"dataProtection": {
"certificateThumbprint": "SECRET"
},
"storage": { "storage": {
"connectionString": "SECRET" "connectionString": "SECRET"
}, },

View File

@ -11,6 +11,7 @@
public virtual PushSettings Push { get; set; } = new PushSettings(); public virtual PushSettings Push { get; set; } = new PushSettings();
public virtual StorageSettings Storage { get; set; } = new StorageSettings(); public virtual StorageSettings Storage { get; set; } = new StorageSettings();
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings(); public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings();
public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings(); public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings();
public class SqlServerSettings public class SqlServerSettings
@ -49,6 +50,11 @@
public string CertificateThumbprint { get; set; } public string CertificateThumbprint { get; set; }
} }
public class DataProtectionSettings
{
public string CertificateThumbprint { get; set; }
}
public class DocumentDbSettings public class DocumentDbSettings
{ {
public string Uri { get; set; } public string Uri { get; set; }