providers/proxy: only send misconfiguration event once

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-06-16 10:32:32 +02:00
parent 9610f96c11
commit 79bec6f6b2
1 changed files with 7 additions and 0 deletions

View File

@ -13,6 +13,8 @@ import (
"goauthentik.io/internal/constants" "goauthentik.io/internal/constants"
) )
var hasReportedMisconfiguration = false
func (a *Application) addHeaders(headers http.Header, c *Claims) { func (a *Application) addHeaders(headers http.Header, c *Claims) {
// https://goauthentik.io/docs/providers/proxy/proxy // https://goauthentik.io/docs/providers/proxy/proxy
@ -103,6 +105,9 @@ func (a *Application) getNginxForwardUrl(r *http.Request) (*url.URL, error) {
func (a *Application) ReportMisconfiguration(r *http.Request, msg string, fields map[string]interface{}) { func (a *Application) ReportMisconfiguration(r *http.Request, msg string, fields map[string]interface{}) {
fields["message"] = msg fields["message"] = msg
a.log.WithFields(fields).Error("Reporting configuration error") a.log.WithFields(fields).Error("Reporting configuration error")
if hasReportedMisconfiguration {
return
}
req := api.EventRequest{ req := api.EventRequest{
Action: api.EVENTACTIONS_CONFIGURATION_ERROR, Action: api.EVENTACTIONS_CONFIGURATION_ERROR,
App: "authentik.providers.proxy", // must match python apps.py name App: "authentik.providers.proxy", // must match python apps.py name
@ -112,6 +117,8 @@ func (a *Application) ReportMisconfiguration(r *http.Request, msg string, fields
_, _, err := a.ak.Client.EventsApi.EventsEventsCreate(context.Background()).EventRequest(req).Execute() _, _, err := a.ak.Client.EventsApi.EventsEventsCreate(context.Background()).EventRequest(req).Execute()
if err != nil { if err != nil {
a.log.WithError(err).Warning("failed to report configuration error") a.log.WithError(err).Warning("failed to report configuration error")
} else {
hasReportedMisconfiguration = true
} }
} }