-
Notifications
You must be signed in to change notification settings - Fork 494
Auth: Support required endorsements #2019
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
Changes from all commits
c94e292
dda6adc
5ddeb2c
491aa73
0f66b75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.Bot.Connector.Authentication | ||
{ | ||
/// <summary> | ||
/// General configuration settings for authentication. | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that this is explicitly a class and not an interface, | ||
/// since interfaces don't support default values, after the initial release any change would break backwards compatibility. | ||
/// </remarks> | ||
public class AuthenticationConfiguration | ||
{ | ||
public string[] RequiredEndorsements { get; set; } = new string[] { }; | ||
} | ||
carlosscastro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,23 +12,28 @@ namespace Microsoft.Bot.Connector.Authentication | |
public static class EndorsementsValidator | ||
{ | ||
/// <summary> | ||
/// Verify that a channel matches the endorsements found on the JWT token. | ||
/// Verify that the specified endorsement exists on the JWT token. Call this method multiple times to validate multiple endorsements. | ||
/// For example, if an <see cref="Schema.Activity"/> comes from WebChat, that activity's | ||
/// <see cref="Schema.Activity.ChannelId"/> property is set to "webchat" and the signing party | ||
/// of the JWT token must have a corresponding endorsement of “Webchat”. | ||
/// </summary> | ||
/// <param name="channelId">The ID of the channel to validate, typically extracted from the activity's | ||
/// <see cref="Schema.Activity.ChannelId"/> property, that to which the Activity is affinitized.</param> | ||
/// <remarks> | ||
/// JWT token signing keys contain endorsements matching the IDs of the channels they are approved to sign for. | ||
/// They also contain keywords representing compliance certifications. This code ensures that a channel ID or compliance | ||
/// certification is present on the signing key used for the request's token. | ||
/// </remarks> | ||
/// <param name="expectedEndorsement">The expected endorsement. Generally the ID of the channel to validate, typically extracted from the activity's | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The right way to think about this is:
|
||
/// <see cref="Schema.Activity.ChannelId"/> property, that to which the Activity is affinitized. Alternatively, it could represent a compliance certification that is required.</param> | ||
/// <param name="endorsements">The JWT token’s signing party is permitted to send activities only for | ||
/// specific channels. That list, the set of channels the service can sign for, is called the the endorsement list. | ||
/// The activity’s <see cref="Schema.Activity.ChannelId"/> MUST be found in the endorsement list, or the incoming | ||
/// activity is not considered valid.</param> | ||
/// <returns>True if the channel ID is found in the endorsements list; otherwise, false.</returns> | ||
public static bool Validate(string channelId, HashSet<string> endorsements) | ||
public static bool Validate(string expectedEndorsement, HashSet<string> endorsements) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the logic above, I expect that new endorsements are added to the channel ID endorsement. We could have a mode where all endorsements are removed, but this is advanced and I'm not sure we have a use case for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I see how the channel ID endorsement verification is enforced at the layer above. Seems OK to me. Maybe just comment that multiple endorsements are enforced by calling this method multiple times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading more through the comment on this method, it should be rewritten to something more like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, EndorsementsValidator.Validate is only a collection existence check which was somewhat underwhelming to find out. |
||
{ | ||
// If the Activity came in and doesn't have a channel ID then it's making no | ||
// assertions as to who endorses it. This means it should pass. | ||
if (string.IsNullOrEmpty(channelId)) | ||
if (string.IsNullOrEmpty(expectedEndorsement)) | ||
{ | ||
return true; | ||
} | ||
|
@@ -48,7 +53,7 @@ public static bool Validate(string channelId, HashSet<string> endorsements) | |
// JWTTokenExtractor | ||
|
||
// Does the set of endorsements match the channelId that was passed in? | ||
var endorsementPresent = endorsements.Contains(channelId); | ||
var endorsementPresent = endorsements.Contains(expectedEndorsement); | ||
return endorsementPresent; | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.