Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Conversation

@ltwlf
Copy link
Contributor

@ltwlf ltwlf commented Sep 10, 2020

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

@coveralls
Copy link

coveralls commented Sep 10, 2020

Coverage Status

Coverage remained the same at 55.739% when pulling 6dc883c on ltwlf:authorization into 8ad58bd on microsoft:main.

@cwhitten
Copy link
Member

Thank you for the contribution @ltwlf - @carlosscastro will review soon.

Are you able to add any tests with this change?

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 13, 2020

I will check tests when the draft is confirmed as an useful feature for composer.

Copy link
Member

@carlosscastro carlosscastro left a 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.

Copy link
Member

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.

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 15, 2020

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.

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 17, 2020

@carlosscastro do you have feedback from the meeting? Would like to work on this at the weekend.
And do you have any hint for me where is the best place to integrate the feature on a higher level?

@carlosscastro
Copy link
Member

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!

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 22, 2020

@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

skill: {
  isSkill:false,
  allowedCallers:['*']
} 

is skill could then either be configured via settings.json or UI

Looking forward to your feedback.

Best wishes,
Christian

Copy link
Member

@carlosscastro carlosscastro left a 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.

Copy link
Member

@carlosscastro carlosscastro Sep 22, 2020

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 23, 2020

@carlosscastro I changed from PR draft and added some unit tests. Looking forward to your feedback,
After this is done, I'm glad to support the other runtimes. Can you please mention or assign me in this issues.

{
public class BotSkillSettings
{
// Is skill
Copy link
Member

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.

@ltwlf
Copy link
Contributor Author

ltwlf commented Sep 29, 2020

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...
@carlosscastro @cwhitten

@cwhitten
Copy link
Member

@ltwlf for some reason the unit tests are failing so I've re-run CI. We need that to pass before we can merge.

@cwhitten
Copy link
Member

Summary of all failing tests
FAIL packages/server/src/controllers/tests/project.test.ts (8.628 s)
● skill operation › should retrieve skill manifest

expect(jest.fn()).toHaveBeenCalledWith(...expected)

Expected: 200
Received: 404

Number of calls: 1

  339 |     } as Request;
  340 |     await ProjectController.getSkill(mockReq, mockRes);
> 341 |     expect(mockRes.status).toHaveBeenCalledWith(200);
      |                            ^
  342 |   }, 10000);
  343 | });
  344 | 

  at Object.toHaveBeenCalledWith (src/controllers/__tests__/project.test.ts:341:28)
      at runMicrotasks (<anonymous>)

Test Suites: 1 failed, 217 passed, 218 total
Tests: 1 failed, 3 skipped, 1 todo, 840 passed, 845 total
Snapshots: 5 passed, 5 total
Time: 410.851 s
Ran all test suites in 13 projects.
Force exiting Jest: Have you considered using --detectOpenHandles to detect async operations that kept running after all tests finished?
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

@cwhitten
Copy link
Member

@ltwlf The test failure is unrelated to this change. We'll merge this and address the failure in a follow-up PR

@cwhitten cwhitten merged commit 6dc0fa2 into microsoft:main Sep 29, 2020
@cwhitten cwhitten mentioned this pull request Nov 13, 2020
lei9444 pushed a commit to lei9444/BotFramework-Composer-1 that referenced this pull request Jun 15, 2021
* 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bot to bot authorization for skills is missing

4 participants