Skip to content
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

[MM-21688] Use dedicated bot account in Azure #32

Merged
merged 5 commits into from
Feb 11, 2020

Conversation

mickmister
Copy link
Contributor

@mickmister mickmister commented Feb 5, 2020

Summary

We are using the getSchedule Graph API endpoint to fetch user availabilities, and using application-level permissions to do so. The request requires us to supply a user ID, so we need a dedicated user in Azure to reference.

This PR allows the MM admin to connect the mscalendar bot to an account in Azure, using the /mscalendar connect_bot command.

Ticket Link

https://mattermost.atlassian.net/browse/MM-21688

Additional Info

Before running /mscalendar connect_bot, /mscalendar availability should fail, since we do not have a bot user to use for the user id.

Todo:

  • mscalendar/oauth2.go needs to have access to IsAuthorizedAdmin so we can ensure only admins can connect the bot account

    • IsAuthorizedAdmin is now bot.IsUserAdmin and PluginAPI.IsSysAdmin. Shouldn't we want to union these two, since a sys admin should be treated as a plugin admin?
  • fix command/connect_test.go and command/disconnect_test.go once ^ has been resolved

  • oauth2_connect_test.go and oauth2_complete_test.go have been deleted, but there are some tests I have written to assert things pertaining to connecting the bot account

  • Write README instructions for creating dedicated account in Azure

Fixes #24

@mickmister mickmister added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Feb 5, 2020
@jfrerich
Copy link
Contributor

jfrerich commented Feb 5, 2020

@mickmister, is this PR ready for review? I usually clone the repo to make checking some of the code easier to traverse and some of the methods don't exist.

server/command/connect.go Outdated Show resolved Hide resolved
server/mscalendar/availability.go Show resolved Hide resolved
server/remote/remote.go Outdated Show resolved Hide resolved
@mickmister
Copy link
Contributor Author

mickmister commented Feb 5, 2020

@jfrerich I should have marked the PR as draft since it is not properly building at the moment. IsAuthorizedAdmin in particular does not exist anymore after the project restructure, and needs to be exposed properly to some of the oauth related files. Is this the function you are referring to?

The connect.go, disconnect.go, and oauth* files have these issues. There are traces of GetRemoteUser as well, as @levb as pointed out.

@levb I need to discuss with you how to expose this admin-checking functionality to the oauth package, as only trusted admins should be able to connect/disconnect the bot from msgraph.

The oauth.App interface is more or less isolated from the rest of the packages at the moment (on purpose), but needs to have access to these admin-checking functions, as noted in a todo in the PR description. Or we need to restructure the flow to allow for checking before the oauth package receives the request.

@mickmister
Copy link
Contributor Author

@jfrerich I can comment out certain things that need to be restructured/added so it will properly compile, though the tests will still fail without the added functions.

* implement IsAuthorizedAdmin, and expose through MSCalendar interface
* ensure non-admins cannot connect the bot account
@mickmister mickmister requested a review from levb February 6, 2020 17:48
@mickmister
Copy link
Contributor Author

@jfrerich This PR is ready for review now

return a.api.GetUserStatusesByIds(mattermostUserIDs)
st, err := a.api.GetUserStatusesByIds(mattermostUserIDs)
if err != nil {
return nil, err
Copy link
Contributor Author

@mickmister mickmister Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levb If this function is implemented as just return a.api.GetUserStatusesByIds(mattermostUserIDs), a nil error will be treated as a non-nil value to the caller.

You and I talked once about handling model.AppError and error, specifically that an interface pointer to a (nil pointer to a concrete type) is not a nil interface pointer, but I don't understand why this needs to be here in this case, and not the other functions in this file.

@jfrerich
Copy link
Contributor

jfrerich commented Feb 6, 2020

Thanks @mickmister! I'll get on the review soon!

levb
levb previously approved these changes Feb 7, 2020
Copy link
Contributor

@levb levb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple nits/naming.

@@ -35,11 +35,25 @@ func (m *mscalendar) SyncStatusAll() (string, error) {
return "", err
}

mmIDs := userIndex.GetMattermostUserIDs()
index := userIndex.GetMattermostUserIDs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1/5 s/index/allIDs/

@@ -35,11 +35,25 @@ func (m *mscalendar) SyncStatusAll() (string, error) {
return "", err
}

mmIDs := userIndex.GetMattermostUserIDs()
index := userIndex.GetMattermostUserIDs()
mmIDs := []string{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1/5 s/mmIDs/filteredIDs/

Copy link
Contributor

@jfrerich jfrerich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, @mickmister! I have one question and a single suggestion on response wording to the user.

server/command/connect.go Outdated Show resolved Hide resolved
server/command/connect.go Outdated Show resolved Hide resolved
server/mscalendar/oauth2.go Show resolved Hide resolved
server/mscalendar/oauth2.go Show resolved Hide resolved
* reword user error strings
* rename vars
index := userIndex.GetMattermostUserIDs()
mmIDs := []string{}
for _, id := range index {
allIDs := userIndex.GetMattermostUserIDs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only if you do another push anyway... a nit of a nit, but maybe inline userIndex.GetMattermostUserIDs() and just use ids for the return? :)

Copy link
Contributor

@jfrerich jfrerich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes requests have been addressed and questions I had have been explained. Approving and thanks for the awesome work, @mickmister

@mickmister mickmister removed the 2: Dev Review Requires review by a core committer label Feb 10, 2020
@DHaussermann DHaussermann added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester labels Feb 10, 2020
Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke with @mickmister about this change. I will test post merge.

@mickmister mickmister merged commit 864a161 into master Feb 11, 2020
@mickmister mickmister deleted the bot-account-manual-merge branch February 11, 2020 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement user disconnect slash command
4 participants