How can I limit access to glimpse.axd when deploying to production?
I am using a custom RuntimePolicy to ensure that glimpse is not enabled in production however I want to ensure that users do not get to the axd as well.
If we were using authorization from asp.net then I understand that i could protect via location path in web.config but this option is not available to me.
Ideas?
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.configyou can add a<location>element, like this: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 yourweb.config:The second approach is to create an
IRuntimePolicy. Runtime policies can secure access to resources (which are served thoughGlimpse.axd) as long as you returnRuntimeEvent.ExecuteResourcefrom theirExecuteOnproperty. Unfortunately for you, Glimpse is designed to ignore theIRuntimePolicy's for requests to the default resource (which isGlimpse.axd). The good news is, you can change the default resource. Here's how:IServiceLocator.Update your
web.configto 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.
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./Glimpse.axd?n=glimpse_configwill respect allIRuntimePolicy's you have in place, and calls toGlimpse.axdredirect to there anyways.Here's the code:
Now, when users go to
Glimpse.axdthey get redirected toGlimpse.axd?n=glimpse_configwhich will either show the standard config page, or a *Runtime policy does not allow execution of resource named 'glimpse_config'.* message - depending on yourIRuntimePolicy.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.