andrewmarkham / contentsecuritypolicy

Episerver addon to help manage the sites content security policy.
Apache License 2.0
9 stars 4 forks source link

Is there any way to make Jhoose Security support ReadOnly mode? #81

Closed ArjanX closed 10 months ago

ArjanX commented 1 year ago

Hi, is there any way to make Jhoose Security support ReadOnly mode? Or turn it off when that is on. I get the below error on startup. I could manually exclude it in my solution but it's a lot of exclusions throughout the codebase, there must be a better way.

Database writes are blocked since the application is set to ReadOnly mode. ReadOnly mode is set either by the 'databaseMode' attribute on the 'episerver.dataStore' section or by the 'episerver:DatabaseMode' setting under the 'appSettings' section. at EPiServer.Data.Providers.Internal.ReadOnlySqlDatabaseExecutor.ExecuteTransaction(Action action) at EPiServer.Data.Dynamic.StoreDefinition.<>cDisplayClass86_0.b0() at EPiServer.Data.Cache.Internal.LocalCache2.Add(TKey key, Boolean cacheNullValues, Boolean overwriteExistingValue, Func1 getAction, Action`2 setAction) at EPiServer.Data.Dynamic.StoreDefinition.CommitChanges(DataStoreProvider provider) at Jhoose.Security.Repository.StandardCspPolicyRepository.Remap[T]() at Jhoose.Security.Repository.StandardCspPolicyRepository.Bootstrap() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b272_0(Object obj) at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Microsoft.Extensions.Hosting.Internal.Host.d12.MoveNext() at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.d4.MoveNext() at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.d4.MoveNext() at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) at XXX.Web.Program.Main(String[] args) in C:.....\Program.cs:line 20

Turn on Readonly db mode: "EpiServer": { "Cms": { "DataAccess": { "DatabaseMode": "ReadOnly" } } }

andrewmarkham commented 1 year ago

Hi @ArjanX ,

Thanks for reporting this, I will take a look.

Did this happen in the general running of the feature, or when you tried to update a setting?

ArjanX commented 1 year ago

Thanks @andrewmarkham It fails on initialising already, so on the "services.AddJhooseSecurity" in Startup.cs. If it is there, it tries to update DDS on start and fails. The site never comes up.

I'm trying to have some things turn off in the site automatically when it is running in ReadOnly mode, so I'm testing with that config setting locally but this now fails the site completely.. I'm surprised no one reported this issue before?

matthewboniface commented 1 year ago

Hi @andrewmarkham, has there been any updates on this? Keen to know as we've got a client wanting to use ReadOnly mode but realise this is still an open issue.

andrewmarkham commented 1 year ago

Hi @matthewboniface

I am planning to put a fix in for this, I have not had time recently to work on this and several other issues. I am hoping to get some time soon as there are several other features I want to add.

matthewboniface commented 1 year ago

All good, thanks for the response!

damienkherbert commented 1 year ago

Hi @andrewmarkham you sound pretty busy, but I'm working with Matthew and our client is looking to implement read only mode next week. If you're unable to make time for this fix/change, we'll need to figure out our own alternative. I understand you've got a lot of commitments, so just hoping for an indication of whether we should start our alternate workaround or wait for an update, thanks!

andrewmarkham commented 1 year ago

Hi @damienkherbert

I would hope to get back to this in the next couple of weeks, but I can't commit to it. I would be more than happy to accept a PR if you wanted to make the changes... I imagine this is better for yourself as you don't have to find an alternate solution.

Let me know your thoughts.

andrewmarkham commented 10 months ago

Hi @damienkherbert / @ArjanX / @matthewboniface

Apologies for the delay in getting this resolved. I have just released version #86, which will fix the problem.

matthewboniface commented 10 months ago

Thanks @andrewmarkham, this is great 👍