-
Notifications
You must be signed in to change notification settings - Fork 374
feat: Feature authorization middleware #4086
Conversation
|
Thank you for the contribution @ltwlf - @carlosscastro will review soon. Are you able to add any tests with this change? |
|
I will check tests when the draft is confirmed as an useful feature for composer. |
carlosscastro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! This is great and perfect timing. The change is very close to being in a mergeable state. Just 2 things that need to be addressed: 1) I added a comment about naming and the granularity of this feature. Please take a look. and 2) Tomorrow, we're having a discussion on how allowed claims lists will be configured in the UI. From that meeting, there might be some extra requirements around this. If that is the case, I'll update the Pr and we can discuss.
runtime/dotnet/azurewebapp/Authorization/AllowedCallersClaimsValidator.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: Features should be higher level feature ideally. A more high level, user facing feature I'm thinking here would be is Is this a Skill? or Is this a Skill Host?. In that context, we could have 2 settings: IsSkill and IsSkillHost, and when IsSkill is true, then one of the consequences is that we enable this authorization claims validator.
I encourage you to provide feedback on this suggestion, would love to hear your thoughts on it.
|
Will check the feedback tomorrow in detail. The idea with the higher level feature make sense. As far as I know claims validation makes only sense for skills and not for consumers. As soon as you activate that the bot can be consumed as a skill the claim validation should be activated and the skill manifest should become part of the composer project (not sure how this is handled) currently. Let’s see what the others say. |
|
@carlosscastro do you have feedback from the meeting? Would like to work on this at the weekend. |
|
Hello @ltwlf! After the meeting, the direction we discussed looks good. Some more details below:
Let me know if any of that doesn't make sense, happy to discuss. I'll be around over the weekend so just tag me if you have questions! |
b3345b7 to
75fc42e
Compare
|
@carlosscastro here is my new draft for skill authorization. I've created an own class for skill settings, because there may will be more skill specific settings. I create default settings like this is skill could then either be configured via settings.json or UI Looking forward to your feedback. Best wishes, |
carlosscastro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Last details on my comments: 1) copyright header missing, 2) possible null ref exception in startup.cs and 3) potential improvement in registration (which may not have a happy solution, just a suggestion). Once we have these, we should be ready to go.
Separately, FYI we will create items to port this to the (in progress) js runtime and azure functions. But that can be done by other contributors, or by you in a separate PR -- your call. Definitely let's focus on this in this PR, since it's almost ready to go. Thanks again for iterating on this.
runtime/dotnet/azurewebapp/Authorization/AllowedCallersClaimsValidator.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we want to move away from doing GetService in startup.cs. If we could optionally do a services.AddSingleton<AuthenticationConfiguration> and have DI wire it into the adapter's constructor , and also do services.AddSingleton<ICredentialProvider>(new ConfigurationCredentialProvider...), then we could avoid the getService. Not 100% sure that would work because of the numerous overloads of BotFrameworkHttpAdapter constructor. If that doesn't work, then as-is is good. We are currently refactoring the adapter and will soon refactor this startup.cs, so we should clean this up soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a way to inject the Authorization. That's why I used GetService.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings could be null, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If yes, we cannot throw NullRef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsSkill returns false when null:
public bool IsSkill(BotSettings settings)
{
return settings?.Skill?.IsSkill == true;
}So it should be fine
035c523 to
3553038
Compare
|
@carlosscastro I changed from PR draft and added some unit tests. Looking forward to your feedback, |
| { | ||
| public class BotSkillSettings | ||
| { | ||
| // Is skill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, optional: Ideally we strive for either xml docs (/// format) or no docs.
Add copyright header to test file.
|
Hi, can I do anything to finalize this PR? When this PR is merged, I would like to the same for Azure Funcs and then for JS... |
|
@ltwlf for some reason the unit tests are failing so I've re-run CI. We need that to pass before we can merge. |
|
Summary of all failing tests Test Suites: 1 failed, 217 passed, 218 total |
|
@ltwlf The test failure is unrelated to this change. We'll merge this and address the failure in a follow-up PR |
* Skill authorization draft 2.0 * Skill authorization: little improvements; tests; copyright * Update runtime/dotnet/tests/AllowedCallersClaimsValidationTests.cs Add copyright header to test file. Co-authored-by: Carlos Castro <[email protected]> Co-authored-by: Chris Whitten <[email protected]>
Description
This PR adds a claim validation middleware for secure bot to bot communication. Users should whitelist which consumers can call a composer skill bot. By default the feature is activated (secure by config) and adds AllowedCallers=["*"] to the appsettings.json. The middleware implementation is included in the runtime as C# file so that devs can customize the validation.
This implementation should be compatible with older bot versions. Middleware will not be activated when the feature flag in the setting is missing.
Task Item
closes #4084