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

chore: Add Mattermost webhook handler #10237

Merged
merged 11 commits into from
Nov 4, 2024
Merged

Conversation

Dschoordsch
Copy link
Contributor

@Dschoordsch Dschoordsch commented Sep 17, 2024

Description

Fixes #10219
We verify that messages from mattermost are signed correctly but then totally trust the mattermost instance that they verify the email.

Demo

[If possible, please include a screenshot or gif/video, it'll make it easier for reviewers to understand the scope of the changes and how the change is supposed to work. If you're introducing something new or changing the existing patterns, please share a Loom and explain what decisions you've made and under what circumstances]

Testing scenarios

[Please list all the testing scenarios a reviewer has to check before approving the PR]

  • Scenario A

    • Step 1
    • Step 2...
  • Scenario B

    • Step 1
    • Step 2....

Final checklist

  • I checked the code review guidelines
  • I have added Metrics Representative as reviewer(s) if my PR invovles metrics/data/analytics related changes
  • I have performed a self-review of my code, the same way I'd do it for any other team member
  • I have tested all cases I listed in the testing scenarios and I haven't found any issues or regressions
  • Whenever I took a non-obvious choice I added a comment explaining why I did it this way
  • I added the label Skip Maintainer Review Indicating the PR only requires reviewer review and can be merged right after it's approved if the PR introduces only minor changes, does not contain any architectural changes or does not introduce any new patterns and I think one review is sufficient'
  • PR title is human readable and could be used in changelog

@Dschoordsch Dschoordsch marked this pull request as ready for review October 14, 2024 13:11
@dbumblis-parabol
Copy link
Contributor

@Dschoordsch Do you need something from me for this PR?

@Dschoordsch
Copy link
Contributor Author

@dbumblis-parabol I don't think so. I think you were automatically added because I've added a new environment variable. We will not use this in our SaaS though.

@Dschoordsch Dschoordsch removed the request for review from mattkrick October 17, 2024 12:54
res
})

const {query, variables, email} = body ?? {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this particular setup we blindly trust the mattermost instance to send valid emails and assume emails on our end are also verified. This can only work with private instances at the moment, so it's the admins responsibility to setup the infrastructure accordingly.

Also we're using no the public graphql interface with a user token
generated from the submitted email from mattermost. So we still trust
mattermost, but don't want to have the rights escalated so the rest of
the permission checks still work.
The queries need to be compiled to work in production.
import sendToSentry from '../../utils/sendToSentry'

const MATTERMOST_SECRET = process.env.MATTERMOST_SECRET
const PORT = __PRODUCTION__ ? process.env.PORT : process.env.SOCKET_PORT
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, same conditional as in

const PORT = Number(__PRODUCTION__ ? process.env.PORT : process.env.SOCKET_PORT)

}
> = {
meetingTemplates: {
query: `
Copy link
Member

Choose a reason for hiding this comment

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

+1 it'd be nice to validate these strings so if the schema changes we're alerted https://www.loom.com/share/effc307dce5b42e5992e36c7e7c9aee6?sid=bf22c73b-cac7-48ba-a110-d79bb0a3cdc3

we could add this eslint plugin to do the work for us: https://the-guild.dev/graphql/eslint/docs

note:

i had to update my graphql.config.js file to the following:

module.exports = {
  schema: './packages/server/graphql/public/schema.graphql',
  documents: './packages/server/**/*'
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would be nice. I couldn't get the linting rule running in a reasonable amount of time, so I will add it in a separate PR.

@@ -55,7 +55,7 @@ const rewriteIndexHTML = () => {
github: process.env.GITHUB_CLIENT_ID,
google: process.env.GOOGLE_OAUTH_CLIENT_ID,
googleAnalytics: process.env.GA_TRACKING_ID,
mattermostDisabled: process.env.MATTERMOST_DISABLED === 'true',
mattermostDisabled: !!process.env.MATTERMOST_SECRET || process.env.MATTERMOST_DISABLED === 'true',
Copy link
Member

Choose a reason for hiding this comment

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

+1 i'm probably not thinking about this correctly.
if mattermost is disabled, how do they turn it on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This env is used to hide the row in the team integrations UI. With these variables set, the plugin will be available on the whole instance. Notification settings will be configured in Mattermost.
This version will not use the sharedSecret integration provider I've added in another PR. That would be a cleaner solution for the future, but I'll go a simpler route for now.

@Dschoordsch Dschoordsch merged commit f50e32f into master Nov 4, 2024
6 checks passed
@Dschoordsch Dschoordsch deleted the feat/10219/mattermostPlugin branch November 4, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mattermost Plugin: Create plugin with configuration
3 participants