-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Future AuthZ improvements list #4670
Comments
My additional thoughts on this. We're looking at making the concept of an endpoint available at a low level from the dispatcher. Endpoints will have arbitrary metadata in an ordered list. This is the equivalent to what MVC does today by passing the action descriptor. We'll probably also have a concept of active metadata which are metadata items that have been hydrated with the request context. These might be useful/necessary building blocks for these things. Additionally in the case of MVC, the current |
Interesting, well if we have a new endpoint concept with a clean slate for metadata, we should probably just expose all of the basic building blocks
Some examples:
Would behave the same as today (using some default policy which relies on context.User, and still only does RequireAuthenticatedUser by default
Would use the Bearer scheme and only require that it exists.
Would use the merged Bearer Cookie schemes and require an admin claim. |
Which challenge would you issue? |
All of them, its not any different than today |
Challenging both Bearer and Cookie is nonsensical. |
Not disagreeing, but today if you have a policy that has Bearer and Cookies, that's what it does today as well |
Unless we want to eliminate being able to specify multiple schemes entirely... that's an option that would simplify things... |
It does? What happens as a result? Don't they stomp on each other? |
Yeah they do, last one wins, multiple auth schemes in policies has always been a bit weird |
Some are compatible like Bearer, Basic, and Windows. |
@HaoK please log new issues for any 2.1.0 proposals. |
@HaoK Is it going to be a part of 2.1 release? |
I want to have ability to return custom json if specific policy failed. for example |
No the error authZ improvements didn't make it into 2.1, I'll try to get them in 2.2 |
I assume that is why the title changed to 2.2 😜⁉ |
Yup, I've got some cycles this week so I'll try to prototype something |
So rough idea of some initial AuthZ improvements I've got at the top of my head for 2.2
|
I think we should close this issue and revisit this in 2.2 planning so we can scope it down. |
Close or leave it open for planning? |
Have you considered adding some way how we can access the list of policies which is run and which is failed. Also I thought it could be a helpful to have overload of method |
Is this what currently prevents something such as the ability to show a specific page when a specific policy fails. For example, when a policy fails, redirect to a page that shows how to get that particular policy? (i.e. paying for a new membership level). |
This is currently also serving as tracking several other asks we haven't done yet for AuthZ:
We moved this into backlog in triage last week so I think its safe to just leave this parked there for now |
Is there any progress on custom failure message? Or any official workaround? |
I too wonder about how to get a custom json body when ForbidResult is called. Is there any way to get at the AuthorizationResult(s) later in the pipeline? As far as I can tell it gets swallowed as part of the PolicyEvaluator (line 84 where it calls authorizationService). The following works inside the controller action but it completely bypasses the filters and I really don't want to go this route. //ControllerAction
public async Task<IActionResult> GetSomeThing() {
var a = await this._authorizationService.AuthorizeAsync(User, "MyPolicy");
if (!a.Succeeded)
{
return this.StatusCode(403, a.Failure.FailedRequirements);
}
} Just putting this out there as part of the conversation, I came across the following issue and being able to map the AuthorizationResult (and FailedRequirements) to a ProblemDetail would be amazing. |
Ping! Any progress on these issues in this ticket? I am looking for a solution to obtain the reason an AuthorizationPolicy failed, as in, what Claim or scope was missing or whatever the reason might be for the HTTP 403 when access is denied. I would like to provide a JSON body in the 403 reply with said information. |
@bugnuker As far as I can tell, there's still no support for specific "reasons" why an authorization is marked as Forbidden. However, if your system is relatively simple (e.g. mine is mostly just role based), then you could write a
Then I wrapped/adapted the
|
We are also building a Asp.Net Web application with api controllers with Attribute based authorization and need a way to returm some additional information about the reason why a request was forbidden by the authorization handler The possibility to add a custom header or json body would do a lot for us. |
Also interested in returning a reason as part failing a policy. For anyone else, there is a very dodgy workaround you can use here |
Returning an auth failure reason now seems to be supported thanks to #21117 ? |
@HaoK @blowdart is there any design progress on allowing the construction of AuthorizationAttributes that make use of resources? Instead of having to fall back on imperative resource-based authorization. |
No there is not. We can't have model binding before authz, because people do weird things in model binding which can have side effects, which in turn cause security issues. It's a non-starter. |
Regarding this specifically - it's possible to access routing's info in AuthZ with the current layering. So you could figure out the Not sure if this helps 😆 |
I've seen that permission based authorizations have finally been taken into account, that's great! May I suggest hierarchial roles (with parent/child) out of the box? |
@rynowak could you point me towards the doc for doing that when you have a minute sometime? Maybe I'm misunderstanding your suggestion. Thanks so much!! |
@blowdart , I know you're busy as heck, but do you know what Ryan was referring to here? I can't figure out what he's referring to, or find documentation about it. Thanks so much
|
@ericsampson No idea, and he's moved on from .net. @pranavkm any idea? |
There's some discussion about it here: dotnet/AspNetCore.Docs#12564 tl,dr:
if (context.Resource is Endpoint endpoint)
{
var controllerActionDescriptor = endpoint.Metadata
.GetMetadata<ControllerActionDescriptor>();
if (controllerActionDescriptor != null)
{
// ...
}
}
@HaoK to verify if (2) is still the right way to go about this. |
Right, with the change that passed the Endpoint as the resource, it should be easier to inspect things from the endpoint without needing to rely on the HttpContext. I'm not sure what (2) is referring to exactly? |
I think (2) is required if you were looking for the |
is any of this documented in the official docs? |
Ah yes, due to layering with the core authz layer being lower than Http, the handlers just have get IHttpContextAccessor from DI |
If possible, how can the example from @pranavkm (which shows controllerActionDescriptor), also be used for razor pages, including getting the razor page handler name? Also is there any way to determine the HttpMethod (if it was a GET or POST) via endpoint metadata as opposed using IHttpContextAccessor?
|
AuthorizationFailure.FailedRequirements is empty even AuthorizeAsync result failed? was trying to add customization message based on failed requirements... |
@HaoK Can we add support for populating the failed requirements in case the explicit Fail() was called? We are internally using it since version 2.0.3 but since we are now migrating to .Net Core, thought of asking here if there is anything that is stopping us in terms of design or core principle of Authz? Let me know if you want me to raise a PR first and discuss there? |
This issue will track all the various Authorization improvements we are looking at for 2.1.
Some initial thoughts:
From @davidfowl
We've had a bunch of feedback about our authz system with respect to flowing context from the authorize attribute to the authorization handler:
Today the Authorize attribute supports has enough metadata to describe the policy but it doesn't let you specify the resource (via IAuthorizeData). I think if we solve that, it might solve a bulk of the issues since people will be able to write custom attributes that flow the relevant context to the authorization handler.
Today that's only possible when doing imperative authz. I was thinking something like:
If the attribute implemented this, we would flow that as the resource to the handler. This way you implement permissions of whatever you please via resources.
From @rynowak
Look into providing overriding semantics in MVC, maybe a marker interface:
IAuthorizeMetadata
. Any attributes that implement that interface on the endpoint could be flowed. Then it’s up to developers to build whatever they want. (Also look into flowing single objects vs many objects + requirements VS resources)We will also look into making it possible to specify requirements via Attributes similar to imperative AuthZ so you don't have to preconstruct policies for attributes.
Misc other improvements:
The text was updated successfully, but these errors were encountered: