JonPSmith / AuthPermissions.AspNetCore

This library provides extra authorization and multi-tenant features to an ASP.NET Core application.
https://www.thereformedprogrammer.net/finally-a-library-that-improves-role-authorization-in-asp-net-core/
MIT License
782 stars 159 forks source link

What's the need of sharding File store cache #115

Closed gopskrish closed 2 weeks ago

gopskrish commented 1 month ago

I have my code deployed in the azure app, but if the server cache is cleared then the ShardingCache file is deleted and since this file is deleted the login breaks.

Is it necessary to cache the sharding and store it as file cache, it's a cache file right, if this file is deleted then the login breaks because, it can't find the db details if the file is not present. Shouldn't if fetch the details from the db if there's no file when the service is restated?

//This is used for a) hold the sharding entries and b) to set a tenant as "Down", builder.Services.AddDistributedFileStoreCache(options => { options.WhichVersion = FileStoreCacheVersions.Class; options.FirstPartOfCacheFileName = "Example6CacheFileStore"; }, builder.Environment);

JonPSmith commented 1 month ago

Hi @gopskrish,

The ShardingCache file contains data that isn't held in a database, so loosing the ShardingCache file means that the tenants won't work. I have made the ShardingCache code pretty robust, but I do assume that the ShardingCache file is there. Deleting the ShardingCache file is NOT handled by the current code.

Yes, it could add code to hold the sharing information in a database as a backup, but since building this library I have dementia (see this article) but its not trivial and I would take a long time to create a solution - see this section as to why it would take a long time.

JonPSmith commented 1 month ago

Hi @gopskrish,

I have been looking to this and here is what I plan to do. Can you check that this should fix your problem.

Summary of the problem

  1. The sharding information (class ShardingEntry) is stored in the FileStore cache.
  2. Currently the FileStore cache is the only place where the ShardingEntry data is held.
  3. Therefore, deleting the FileStore cache means tenants don’t work.
  4. There are two reasons where the FileStore cache are deleted: a. When you want to delete/reset a multi-tenant app, e.g. during development. This requires BOTH the databases and the FileStore cache are deleted. b. The FileStore cache is deleted, e.g. due to a server cache clear.
  5. The solution to 4b is: a. In normal use sharding information changes are also written to a database. b. On startup, if the FileStore cache is empty it fill the FileStore cache from the saved sharding information database.

    Summary of the solution

gopskrish commented 1 month ago

@JonPSmith I hope for your speedy recovery, Yes the suggested solution should be able to solve my problem thanks

JonPSmith commented 2 weeks ago

Hi @gopskrish,

I have released AuthP version 8.1.0 which provides a backup version of the sharding entries in case that the FileStore Cache file is deleted. See the Securing the sharding data page in the AuthP Wiki.