-
Notifications
You must be signed in to change notification settings - Fork 345
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
Trouble with Dapr auth when api versioning and default policy is in place. #1406
Comments
@WTW-Jacob-Evans Let me try to address these concerns one at a time starting with authentication and authorization. If you aren't passing options that contain the API token to the extensions, there's not a huge point in using them, especially if they're conflicting with your application. If you do want to use the token and it's conflicting, I'd suggest putting your API token instead in the With 1.15 (releasing in December), this behavior will change ever so slightly in that it'll first read the value for the same key from your And with regards to API Versioning, let me research this and get back to you. I'm not aware that there's anything in the existing implementation that's using anything from a versioning perspective, so there's nothing that can be overridden, but if it's proving to be a problem for you, it's something I'd like to look at addressing. I'll give it a look and follow up with any questions in the coming days. |
Thanks for the reply @WhitWaldo. In reference to the authorization; I have the required env vars in place as specified in the documentation; my problem is that even with these, Dapr is still not able to pick up on the authN / AuthZ dapr policy, even after configuring it with the extensions:
Once Similarly, on the topic routes themselves; without explicitly decorating the controller with Once the attribute is in place, Dapr can publish to the topic route correctly. It would seem to me that the Dapr auth policy does not seem to actually get applied directly to the Dapr routes that the SDK establishes, and there is an assumption that this is the only authorization policy in place. If the Dapr auth policy is the only one present then it will of course be applied, but alongside any others it will be overridden (unless of course the Dapr auth policy was applied first and is the default). This goes back to my original suggestion that the auth policy should be applied directly to routes that Dapr is publishing to (although this would prove difficult for topic routes, given these are completely user defined and simply discovered by the Dapr/subscribe route on sidecar startup). Perhaps this is a case for extending the documentation. Apologies again if I have missed some key piece of config, but this should fully explain the issue I have had. On the API versioning issue, I have found a few more open issues that discuss this problem: I think supporting versioning could be incredibly useful, and help integrate Dapr within APIs that have API versioning set up; as you can see in the original post, without specifying it the application will reject the request. This can be hardcoded as |
Wasn't sure what to post this under, so created a general discussion.
Dapr conflicting with in place authorization policy
When calling in Startup
and then calling:
I would expect the Dapr endpoints to have the authorization "Dapr" policy applied to them (perhaps if the APP_API_TOKEN is in place, as this would indicate that I am trying to use daprs sidecar auth).
This causes conflict when I have a default Bearer AuthN and AuthZ policy applied to my endpoints; the policy I want to apply for my other controllers, like so:
this is called just before the Dapr AuthZ and AuthN in Startup:
What I observed is the Dapr user is authenticated (although I have observed it not being authenticated), but then falling into the default authPolicy (as I have set it with
options.DefaultPolicy
);obviously I cant remove this default policy, as it would mean altering the entire applications permissions for our pubsub component.
I can add:
endpointBuilder.MapSubscribeHandler() .RequireAuthorization("Dapr");
which will cause the
dapr/subscribe
endpoint to use the policy and authenticate and authorize properly. This will still cause thedapr/config
endpoint to fail authorization.I also decorate my controllers that are dapr topic endpoints with
[Authorize("Dapr")]
Additionally, the default "Dapr" auth policy could be exposed by the .NET SDK so that it can be used by the main application.
API Versioning
Another issue is that when dapr tries to execute the mapped endpoint discovered off
/dapr/subscribe
, it wont include API versioning, which causes the app to log this error:I assume it is trying to auth against the fallback policy.
I have two work arounds for this currently; either removing the
[ApiController]
attribute and making it a[Controller]
, or adding[ApiVersionNeutral]
. It would be helpful if there was a way to specify in the dapr sidecar config to dispatch requests with api versioning (ideally in different formats: URL segment, query param, headers etc), however I understand you have a policy of not adapting the runtime to benefit certain implementations, which that may fall under.This issue seems relevant #977
I did a pretty in-depth look at the docs and SDK source to find answers to my question (hence the default Dapr policy suggestion), but apologies if I've missed something.
The text was updated successfully, but these errors were encountered: