From a3a914adfec63dfe2d1c35a0ed69c54977992b15 Mon Sep 17 00:00:00 2001 From: ta264 Date: Tue, 9 Nov 2021 21:35:20 +0000 Subject: [PATCH] Fixed: Forms login persists across restarts in docker Closes #1307 (cherry picked from commit a219b4a1b869863b2ef47d4bdf33d308cb261ba3) --- src/NzbDrone.Common/Extensions/PathExtensions.cs | 5 +++++ src/NzbDrone.Host/Bootstrap.cs | 4 ++++ src/NzbDrone.Host/Startup.cs | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 9d749a86e..7c71c4615 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -259,6 +259,11 @@ namespace NzbDrone.Common.Extensions return appFolderInfo.AppDataFolder; } + public static string GetDataProtectionPath(this IAppFolderInfo appFolderInfo) + { + return Path.Combine(GetAppDataPath(appFolderInfo), "asp"); + } + public static string GetLogFolder(this IAppFolderInfo appFolderInfo) { return Path.Combine(GetAppDataPath(appFolderInfo), "logs"); diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index 0d8a24806..3e2e3e0b1 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -7,8 +7,10 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using DryIoc; using DryIoc.Microsoft.DependencyInjection; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting.WindowsServices; using NLog; @@ -135,6 +137,7 @@ namespace NzbDrone.Host }) .ConfigureWebHost(builder => { + builder.UseConfiguration(config); builder.UseUrls(urls.ToArray()); builder.UseKestrel(options => { @@ -190,6 +193,7 @@ namespace NzbDrone.Host var appFolder = new AppFolderInfo(context); return new ConfigurationBuilder() .AddXmlFile(appFolder.GetConfigPath(), optional: true, reloadOnChange: false) + .AddInMemoryCollection(new List> { new ("dataProtectionFolder", appFolder.GetDataProtectionPath()) }) .Build(); } diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index 96c82959b..0b04eb837 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; -using DryIoc; +using System.IO; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; @@ -46,6 +47,7 @@ namespace NzbDrone.Host b.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); b.AddFilter("Microsoft.AspNetCore", Microsoft.Extensions.Logging.LogLevel.Warning); b.AddFilter("Readarr.Http.Authentication", LogLevel.Information); + b.AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", LogLevel.Error); b.AddNLog(); }); @@ -95,6 +97,9 @@ namespace NzbDrone.Host options.PayloadSerializerOptions = STJson.GetSerializerSettings(); }); + services.AddDataProtection() + .PersistKeysToFileSystem(new DirectoryInfo(Configuration["dataProtectionFolder"])); + services.AddSingleton(); services.AddAuthorization(options => {