-
Notifications
You must be signed in to change notification settings - Fork 164
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
feat: Matrix integration #106
Open
edwargix
wants to merge
2
commits into
argoproj:master
Choose a base branch
from
edwargix:matrix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Matrix | ||
|
||
**NOTE:** native end-to-end encryption (e2ee) for Matrix notifications is not yet supported because CGO, which is needed to link to [libolm](https://gitlab.matrix.org/matrix-org/olm), is not supported by Argo. Those who want end-to-end encryption support for their Argo notifications bot can setup [pantalaimon](https://github.com/matrix-org/pantalaimon). | ||
|
||
To be able to send notifications via Matrix, do the following steps: | ||
|
||
1. [Register a Matrix account](#register-a-matrix-account) | ||
2. [Generate an access token and device ID for the account](#generate-an-access-token-and-device-id-for-the-account) | ||
3. [Upload a profile picture (optional)](#upload-a-profile-picture-optional) | ||
4. [Configure notifiers and subscription recipients](#configure-notifiers-and-subscription-recipients) | ||
|
||
## Register a Matrix account | ||
|
||
Registering a Matrix account can be done via a standard Matrix client like [Element](https://element.io) or many others listed at <https://matrix.org/clients>. | ||
|
||
If your homeserver is a Synapse instance and you have access to the `registration_shared_secret`, which is only available to people with shell access to Synapse, you can register a new user with the [`/_synapse/admin/v1/register` endpoint](https://matrix-org.github.io/synapse/latest/admin_api/register_api.html). | ||
|
||
## Generate an access token and device ID for the account | ||
|
||
Before beginning, ensure you have `curl`, `jq`, and standard unix shell utilities installed. | ||
|
||
Set the environment variables `USERID` and `PASSWORD` to your argo user's ID and password, respectively: | ||
|
||
```sh | ||
# your argo user's ID. Of the form "@localpart:domain.tld" | ||
export USERID="@argocd:example.org" | ||
# set this to the password for your argo user. If you need to use a different | ||
# authentication method, the commands in this guide won't work | ||
export PASSWORD="ch@ngeMe!" | ||
``` | ||
|
||
Then, run the following commands: | ||
|
||
```sh | ||
export SERVER_NAME=$(printf "$USERID" | cut -d: -f2-) | ||
export HOMESERVER_URL=$(curl -LSs https://${SERVER_NAME}/.well-known/matrix/client | jq -r '."m.homeserver"."base_url"') | ||
|
||
RESP=`curl -d "{\"type\": \"m.login.password\", \"identifier\": {\"type\": \"m.id.user\", \"user\": \"$USERID\"}, \"password\": \"$PASSWORD\"}" \ | ||
-X POST $HOMESERVER_URL/_matrix/client/v3/login` | ||
|
||
export ACCESS_TOKEN=`printf "$RESP" | jq -r .access_token` | ||
export DEVICEID=`printf "$RESP" | jq -r .device_id` | ||
|
||
echo "Access Token: $ACCESS_TOKEN" | ||
echo "Device ID: $DEVICEID" | ||
``` | ||
|
||
You can now use the Access Token and Device ID printed in the last command as the respective parameters in the next section. | ||
|
||
## Upload a profile picture (optional) | ||
|
||
It is recommended, though not required, to give your argo user a profile picture, which you'll see next to all argocd Matrix notifications. | ||
|
||
**NOTE**: this uses some of the environment variables set in the last section. | ||
|
||
```sh | ||
curl -LSs https://argocd-operator.readthedocs.io/en/stable/assets/logo.png > profile.png | ||
|
||
RESP=`curl --data-binary @profile.png \ | ||
-H 'Content-Type: image/png' \ | ||
-H "Authorization: Bearer $ACCESS_TOKEN" \ | ||
"$HOMESERVER_URL/_matrix/media/v3/upload?filename=profile.png"` | ||
|
||
PROFILE_URI=`printf "$RESP" | jq -r .content_uri` | ||
|
||
curl -X PUT -d "{\"avatar_url\": \"$PROFILE_URI\"}" \ | ||
-H "Authorization: Bearer $ACCESS_TOKEN" $HOMESERVER_URL/_matrix/client/v3/profile/$USERID/avatar_url | ||
``` | ||
|
||
## Configure notifiers and subscription recipients | ||
|
||
The Matrix notification service requires specifying the following settings: | ||
|
||
* `accessToken` - the access token retrieved after logging in. This was displayed at the end of the [Generate an access token and device ID for the account](#generate-an-access-token-and-device-id-for-the-account) section | ||
* `deviceID` - the device ID. Retrieved alongside the access token at the end of the [Generate an access token and device ID for the account](#generate-an-access-token-and-device-id-for-the-account) section | ||
* `homeserverURL` - optional, the homeserver base URL. If unspecified, the base URL will be retrieved using the [well-known URI](https://spec.matrix.org/v1.3/client-server-api/#well-known-uri), if possible | ||
* `userID` - the user ID. Of the form `@localpart:server.tld` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you please comment why you need change this ?
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.
This PR supports sending Matrix messages to Matrix rooms and room aliases.
A Matrix room is identified with the syntax
!opaque_id:domain.tld
[0] and a room alias with#room_alias:domain.tld
[1].So the code change here in
pkg/api/config.go
is to make it so that thedomain.tld
part isn't lost. Here's an example config; notice that the recipients have two:
s in them:Without this PR's change to
pkg/api/config.go
, we'd lose theexample.org
from the recipients and our Destinations for the Send function would be#my-room-alias
and!my-room-id
(which we can't send notifications to).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.
What I'm hoping is that once this project upgrades to golang 1.18, we can revert this PR's 2nd commit to simplify the code a bit.