fluxcd / notification-controller

The GitOps Toolkit event forwarder and notification dispatcher
https://fluxcd.io
Apache License 2.0
150 stars 131 forks source link

Add support for custom headers with Grafana provider #821

Open sentros opened 4 months ago

sentros commented 4 months ago

We have Grafana set up behind google IAP and then a custom rule for the /api/annotations/ endpoint that allows us to circumvent IAP with a custom header for flux notifications. According to the flux documentation the NATS provider supports custom HTTP headers but that doesn't seem to be the case for Grafana.

I would like the grafana provider to work like this:

---
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
  name: grafana
  namespace: flux-system
spec:
  type: grafana
  address: https://${grafana_fqdn}/api/annotations
  secretRef:
    name: grafana-secret
---
apiVersion: v1
kind: Secret
metadata:
  name: grafana-secret
  namespace: flux-system
stringData:
  headers: |
    Authorization: "${grafana_annotations_token}"
    CustomHeader: "${custom_secret}"

or alternatively like this:

---
apiVersion: v1
kind: Secret
metadata:
  name: grafana-secret
  namespace: flux-system
stringData:
  headers: |
    CustomHeader: "${custom_secret}"
  token: "${grafana_annotations_token}"

I tried looking through the code but I'm not well versed in go. To my eye it seems like headers are only added when there's a non empty username+password or token here. So I'm guessing some additions would need to be made for custom header support.

fsequeira1 commented 4 months ago

I will take this one