File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed
Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,10 @@ Main features:
1919
2020### Configuration
2121
22- Whether running manually or via the Docker image, the configuration is set
22+ Whether running manually or via the Docker image, the configuration is set
2323via environment variables. When running manually, copy ` .env.default `
24- into ` .env ` , set the values and they will be loaded automatically.
25- When using the Docker image, set the environment variables when running
24+ into ` .env ` , set the values and they will be loaded automatically.
25+ When using the Docker image, set the environment variables when running
2626the container.
2727
2828### Docker
@@ -37,11 +37,20 @@ You will need to configure a webhook receiver in Alertmanager. It should looks s
3737receivers :
3838- name : ' myreceiver'
3939 webhook_configs :
40- - url : ' https://my-matrix-alertmanager.tld/alerts?secret=veryverysecretkeyhere'
40+ - url : ' https://my-matrix-alertmanager.tld/alerts'
41+ http_config :
42+ authorization :
43+ type : Bearer
44+ credentials : ' veryverysecretkeyhere'
4145` ` `
4246
4347The secret key obviously should match the one in the alertmanager configuration.
4448
49+ The configuration above will pass the secret as an Authorization
50+ header bearer token, alternatively you can pass it as a query
51+ parameter ` secret`, but if you do it that way then it is not redacted
52+ from the Alertmanager web UI so this is not really recommended.
53+
4554# ## Prometheus rules
4655
4756Add some styling to your prometheus rules
Original file line number Diff line number Diff line change 11const client = require ( './client' )
22const utils = require ( './utils' )
33
4+ const crypto = require ( 'crypto' )
5+
6+ const passwordsEqual = ( a , b ) => {
7+ return a && b && a . length === b . length && crypto . timingSafeEqual ( Buffer . from ( a ) , Buffer . from ( b ) )
8+ }
9+
410const routes = {
511 getRoot : ( req , res ) => {
612 res . send ( 'Hey 👋' )
713 } ,
814 postAlerts : async ( req , res ) => {
9- const secret = req . query . secret
10- if ( secret !== process . env . APP_ALERTMANAGER_SECRET ) {
15+ let authorized = false
16+ let expectedSecret = process . env . APP_ALERTMANAGER_SECRET
17+
18+ if ( ! expectedSecret ) {
19+ console . error ( "APP_ALERTMANAGER_SECRET is not configured, unable to authenticate requests" )
20+ res . status ( 500 ) . end ( )
21+ return
22+ }
23+
24+ if ( passwordsEqual ( req . query . secret , expectedSecret ) ) {
25+ authorized = true
26+ }
27+
28+ if ( passwordsEqual ( req . get ( 'authorization' ) , `Bearer ${ expectedSecret } ` ) ) {
29+ authorized = true
30+ }
31+
32+ if ( ! authorized ) {
1133 res . status ( 403 ) . end ( )
1234 return
1335 }
36+
1437 const alerts = utils . parseAlerts ( req . body )
1538
1639 if ( ! alerts ) {
You can’t perform that action at this time.
0 commit comments