Restrict access to Sitecore admin pages by customising the CheckSecurity method
Based on an old StackExchange query and a recent conversation, I decided to build Role-based security for Sitecore Admin pages. So, here is the blog article and associated Github code. Now, someone can use this as solution or as framework to build their own custom solution.
1. It is common knowledge that you can disable a config file by adding the .disabled suffix and even .aspx pages can be disabled by suffixing with .disabled as per this link.
2. You can completely disable or enable a few admin pages by adding the .disabled or .enabled file in the admin folder as covered in this blog. The .enabled and .disabled file is applicable only for pages inheriting from NonSecurePage like SqlShell.aspx or PowerShell.aspx.
3. Then, there are a few admin pages accessible to non-administrators too like the following, in other words, they don't pop-up the Sitecore login page if you have the developer role assigned to your user profile:
- cache.aspx
- DBCleanup.aspx
- RawSearch.aspx
- Stats.aspx
- EventQueueStats.aspx
- logs.aspx
- PublishQueueStats.aspx
Inbuilt or Default Access:
If you are one of those purists who thinks admin pages must not be accessible to anyone other than admins then, here are a few ways to handle the situation:
I've just used one of the pages as example but the approach is same for all the above pages and in the Github code I have customised all such pages for Sitecore 10.3:
In each of these pages, there is a call to CheckSecurity as follows:
This method is part of AdminPage class and does the job of checking if the logged-in user is of role developer or the user is administrator and if they are one of the two, doesn't pop the login page:
Option-1:
Just administrator user access:
The original class, for example, CacheAdmin for cache.aspx will inherit from the new AdminPage as follows:
Add the new namespace/class to the .aspx page:
Rectify the original calls as need-be:
CheckSecurity()
Deploy the page and library to your website instance.
So, only administrators can access the above page.
With this approach, you can stick-in your own set of roles/rules to the CheckSecurity method and restrict access as needed.
Page |
Class |
RawSearch.aspx |
|
Disadvantages:
- Users apart from administrator cannot access
- Not fine-grained or no Role Based Access Control (RBAC)
Option-2:
Admin Page Access with a Custom role:
This approach would be to create a role just for this purpose and then override the CheckSecurity method as follows. For this example, I created a role named AdminPageAccess. through Role Manager:
Page |
Custom Role |
Jobs.aspx |
JobsPageAccess |
Logs.aspx |
LogsPageAccess |
DbCleanup.aspx |
DbClieanupPageAccess |
Stats.aspx |
StatsPageAccess |
EventQueueStats.aspx |
EventQueueStatsPageAccess |
PublishQueueStats.aspx |
PublishQueueStatsPageAccess |
Cache.aspx |
CachePageAccess |
RawSearch.aspx |
RawSearchPageAccess |
Comments
Post a Comment