Skip to content

Commit db03c74

Browse files
Allow authentication with bearer token on alerts and alertmanager commands (#245)
* Enable auth token support on alerts and alertmanager commands * Add authToken config command to README * Update README.md Co-authored-by: Oleg Zaytsev <[email protected]> Co-authored-by: Oleg Zaytsev <[email protected]>
1 parent fc11f14 commit db03c74

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ Config commands interact with the Cortex api and read/create/update/delete user
3636

3737
#### Configuration
3838

39-
| Env Variables | Flag | Description |
40-
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------- |
41-
| CORTEX_ADDRESS | `address` | Address of the API of the desired Cortex cluster. |
42-
| CORTEX_API_USER | `user` | In cases where the Cortex API is set behind a basic auth gateway, a user can be set as a basic auth user. If empty and CORTEX_API_KEY is set, CORTEX_TENANT_ID will be used instead. |
43-
| CORTEX_API_KEY | `key` | In cases where the Cortex API is set behind a basic auth gateway, a key can be set as a basic auth password. |
44-
| CORTEX_TENANT_ID | `id` | The tenant ID of the Cortex instance to interact with. |
39+
| Env Variables | Flag | Description |
40+
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------- |
41+
| CORTEX_ADDRESS | `address` | Address of the API of the desired Cortex cluster. |
42+
| CORTEX_API_USER | `user` | In cases where the Cortex API is set behind a basic auth gateway, a user can be set as a basic auth user. If empty and CORTEX_API_KEY is set, CORTEX_TENANT_ID will be used instead. |
43+
| CORTEX_API_KEY | `key` | In cases where the Cortex API is set behind a basic auth gateway, a key can be set as a basic auth password. |
44+
| CORTEX_AUTH_TOKEN | `authToken`| In cases where the Cortex API is set behind gateway authenticating by bearer token, a token can be set as a bearer token header. |
45+
| CORTEX_TENANT_ID | `id` | The tenant ID of the Cortex instance to interact with. |
4546

4647
#### Alertmanager
4748

pkg/commands/alerts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (a *AlertmanagerCommand) Register(app *kingpin.Application) {
6565
alertCmd := app.Command("alertmanager", "View & edit alertmanager configs stored in cortex.").PreAction(a.setup)
6666
alertCmd.Flag("address", "Address of the cortex cluster, alternatively set CORTEX_ADDRESS.").Envar("CORTEX_ADDRESS").Required().StringVar(&a.ClientConfig.Address)
6767
alertCmd.Flag("id", "Cortex tenant id, alternatively set CORTEX_TENANT_ID.").Envar("CORTEX_TENANT_ID").Required().StringVar(&a.ClientConfig.ID)
68+
alertCmd.Flag("authToken", "Authentication token for bearer token or JWT auth, alternatively set CORTEX_AUTH_TOKEN.").Default("").Envar("CORTEX_AUTH_TOKEN").StringVar(&a.ClientConfig.AuthToken)
6869
alertCmd.Flag("user", "API user to use when contacting cortex, alternatively set CORTEX_API_USER. If empty, CORTEX_TENANT_ID will be used instead.").Default("").Envar("CORTEX_API_USER").StringVar(&a.ClientConfig.User)
6970
alertCmd.Flag("key", "API key to use when contacting cortex, alternatively set CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&a.ClientConfig.Key)
7071
alertCmd.Flag("tls-ca-path", "TLS CA certificate to verify cortex API as part of mTLS, alternatively set CORTEX_TLS_CA_PATH.").Default("").Envar("CORTEX_TLS_CA_PATH").StringVar(&a.ClientConfig.TLS.CAPath)
@@ -143,6 +144,7 @@ func (a *AlertCommand) Register(app *kingpin.Application) {
143144
alertCmd := app.Command("alerts", "View active alerts in alertmanager.").PreAction(a.setup)
144145
alertCmd.Flag("address", "Address of the cortex cluster, alternatively set CORTEX_ADDRESS.").Envar("CORTEX_ADDRESS").Required().StringVar(&a.ClientConfig.Address)
145146
alertCmd.Flag("id", "Cortex tenant id, alternatively set CORTEX_TENANT_ID.").Envar("CORTEX_TENANT_ID").Required().StringVar(&a.ClientConfig.ID)
147+
alertCmd.Flag("authToken", "Authentication token for bearer token or JWT auth, alternatively set CORTEX_AUTH_TOKEN.").Default("").Envar("CORTEX_AUTH_TOKEN").StringVar(&a.ClientConfig.AuthToken)
146148
alertCmd.Flag("user", "API user to use when contacting cortex, alternatively set CORTEX_API_USER. If empty, CORTEX_TENANT_ID will be used instead.").Default("").Envar("CORTEX_API_USER").StringVar(&a.ClientConfig.User)
147149
alertCmd.Flag("key", "API key to use when contacting cortex, alternatively set CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&a.ClientConfig.Key)
148150

0 commit comments

Comments
 (0)