Glimpse provides a few different mechanisms for security configuration.
The first, as you mentioned, is to leverage ASP.NET's built in security features. To do this, in your web.config
you can add a <location>
element, like this:
<location path="glimpse.axd">
<system.web>
<authorization>
<deny users="*"/>
<allow roles="Admin"/>
</authorization>
</system.web>
</location>
and now only users in the Admin role will be able to access Glimpse.axd
.
Coincidentally, the path does not have to be /Glimpse.axd
, this is just a default setting. You can move the HttpHandler's location to a url only known by you and your team by making a few changes to your web.config
:
<!-- configure system.webServer and/or system.web depending on your ISS configuration -->
<system.webServer>
<handlers>
<add name="Glimpse" path="unknownLocation.axd" ... />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="unknownLocation.axd" ... />
</httpHandlers>
</system.web>
<!-- then just configure Glimpse -->
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/unknownLocation.axd">
The second approach is to create an IRuntimePolicy
. Runtime policies can secure access to resources (which are served though Glimpse.axd
) as long as you return RuntimeEvent.ExecuteResource
from their ExecuteOn
property. Unfortunately for you, Glimpse is designed to ignore the IRuntimePolicy
's for requests to the default resource (which is Glimpse.axd
). The good news is, you can change the default resource. Here's how:
- Create or update a class so that it implements
IServiceLocator
.
Update your web.config
to point Glimpse to your service locator implementation.
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd" serviceLocatorType="YourNamespace.GlimpseLocator, YourAssembly">
Now Glimpse knows about your locator and will ask it for any type that it needs, including for the default resource.
- Implement an
IResource
. I'll show an example of how to create one that just redirects the user to the normal config page (that is no longer the default resource), but you could have it do anything you'd like.
- Now the calls directly to
/Glimpse.axd?n=glimpse_config
will respect all IRuntimePolicy
's you have in place, and calls to Glimpse.axd
redirect to there anyways.
Here's the code:
// Create the ServiceLocator that is referenced in web.config
public class GlimpseLocator : IServiceLocator
{
public T GetInstance<T>() where T : class
{
if (typeof(T) == typeof(IResource))
return new SecurityResource() as T;
return null;
}
public ICollection<T> GetAllInstances<T>() where T : class
{
return null;
}
}
//Implementation of new default resource that just redirects
public class SecurityResource : IResource
{
public string Name
{
get { return "Security"; }
}
public IEnumerable<ResourceParameterMetadata> Parameters
{
get { return Enumerable.Empty<ResourceParameterMetadata>(); }
}
public IResourceResult Execute(IResourceContext context)
{
return new RedirectResourceResult("/Glimpse.axd?n=glimpse_config");
}
}
// Your custom runtime policy
public class CustomPolicy : IRuntimePolicy
{
public RuntimeEvent ExecuteOn
{
get { return RuntimeEvent.ExecuteResource; }
}
public RuntimePolicy Execute(IRuntimePolicyContext policyContext)
{
//Perform any logic you like and return RuntimePolicy.On or RuntimePolicy.Off
return RuntimePolicy.Off;
}
}
Now, when users go to Glimpse.axd
they get redirected to Glimpse.axd?n=glimpse_config
which will either show the standard config page, or a *Runtime policy does not allow execution of resource named 'glimpse_config'.* message - depending on your IRuntimePolicy
.
So, like I said, the use case we optimized for is the first, to leverage ASP.NET's built in security mechanisms. Glimpse is not tied to that model though, you just have to jump through a few hoops to configure it ATM.
On a related note, we are going to be greatly improving the configuration story in Glimpse 2.0, which is currently in process.