-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add support for Bearer Token authentication to Provider alertmanager
#1021
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for this contribution, @d4rkfella! Left a few comments.
We also need to update the docs to mention this feature. Please update this file:
notification-controller/docs/spec/v1beta3/providers.md
Lines 922 to 947 in fa7d9f2
To configure a Provider for Prometheus Alertmanager, create a Secret with [the | |
`address`](#address-example) set to the Prometheus Alertmanager [HTTP API | |
URL](https://prometheus.io/docs/alerting/latest/https/#http-traffic) | |
including Basic Auth credentials, and a `alertmanager` Provider with a [Secret | |
reference](#secret-reference). | |
```yaml | |
--- | |
apiVersion: notification.toolkit.fluxcd.io/v1beta3 | |
kind: Provider | |
metadata: | |
name: alertmanager | |
namespace: default | |
spec: | |
type: alertmanager | |
secretRef: | |
name: alertmanager-address | |
--- | |
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: alertmanager-address | |
namespace: default | |
stringData: | |
address: https://username:password@<alertmanager-url>/api/v2/alerts/" | |
``` |
Please mention that the authentication for this provider can now be done through two options: basic auth (the one already documented), and bearer token. You can duplicate the example of basic auth and adapt it for the token. In this case, instead of setting the address
field in the secret, this field would be set directly in the Provider
object, .spec.address
, and the secret would contain the token
field instead.
27cf38a
to
cf64337
Compare
Ok i made the changes you suggested, took me a while to figure out how to fix the Signed off by message hah . |
alertmanager
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.
Thanks for working through my comments 🙏
There's a final batch, after those I think we won't need any more changes 😁
Before we merge this, I'll ask you to please kindly test this change in your environment and post here evidence that it works, e.g. logs, screenshots, etc.
Here are the steps to test this:
- If you haven't done this already, please generate a GitHub Personal Access Token (Classic) with the
write:packages
permission in order to push images to the GitHub Container Registry (GHCR). Login locally in Docker using this token:docker login -u d4rkfella ghcr.io --password-stdin
and paste the token in the prompt. - Edit the project
Makefile
in the root directory changing the image like this:
IMG ?= fluxcd/notification-controller:latest
Becomes:
IMG ?= ghcr.io/d4rkfella/fluxcd/notification-controller:am-bearer
- Build an image using the following command:
make docker-build docker-push
- After this you should see a package in your GitHub profile. Click on it and make it public, so your cluster can download the image without a secret.
- Update notification-controller in your test environment to use the image:
ghcr.io/d4rkfella/fluxcd/notification-controller:am-bearer
- Configure the feature and test.
Thanks in advance!
Ok, i build the image locally and tested it by intentionally making a mistake in my kustomization resources and the event was successfully dispatched to alertmanager. I'm not sure why it includes
Request is authenticated to oauth2-proxy successfully and send to the upstream alertmanager service.
|
Does the fuzz_test need additional changes to test with token and with an empty string like how its setup for other providers that use token based authentication ?
Sorry if asking stupid questions, trying to get a grasp of things :P |
Sorry to bug you with this @d4rkfella, the fuzz tests are flaky at the moment, don't worry about that. The CI has passed 😀 Now the last thing before I merge this PR, I'll need you to please squash all the commits into one, with the message:
(This will require a force push.) |
6e6791e
to
c3a8185
Compare
Oh man, i screwed that up |
No need to panic, I'm writing specific instructions for you to recover your work. |
I'm sorry for wasting more of your time. |
You work is in the commit
|
Signed-off-by: Georgi Panov <[email protected]> Signed-off-by: Darkfella91 <[email protected]> Update alertmanager_test.go Signed-off-by: Georgi Panov <[email protected]> Signed-off-by: Darkfella91 <[email protected]> Update alertmanager_fuzz_test.go Signed-off-by: Georgi Panov <[email protected]> Signed-off-by: Darkfella91 <[email protected]> Update factory.go Signed-off-by: Georgi Panov <[email protected]> Signed-off-by: Darkfella91 <[email protected]> Update factory.go Signed-off-by: Darkfella91 <[email protected]> Fix a mistake with the last commit to update the docs Signed-off-by: Darkfella91 <[email protected]> Fix another formatting issue Signed-off-by: Darkfella91 <[email protected]> Screwed up my previous commit so implementing the suggested changes again and fixed formatting for the structs Signed-off-by: Darkfella91 <[email protected]> Tried to use better wording, to outline that authentication is optional Signed-off-by: Darkfella91 <[email protected]> Another small change to the explanation for bearer token authentication Signed-off-by: Darkfella91 <[email protected]> Fix incorrect article usage and the configured address example as suggested Signed-off-by: Darkfella91 <[email protected]>
Thanks for your patience. That should be it :) |
I'm not a programmer, but after examining the other providers, i think this should be correct. Please let me know :)
Closes: #1020