2021-01-16 20:41:39 +00:00
|
|
|
package ak
|
|
|
|
|
|
|
|
import (
|
2021-12-23 18:01:32 +00:00
|
|
|
"fmt"
|
2021-01-16 20:41:39 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
httptransport "github.com/go-openapi/runtime/client"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-03-03 09:40:07 +00:00
|
|
|
"goauthentik.io/api/v3"
|
2023-01-08 19:33:04 +00:00
|
|
|
"goauthentik.io/internal/config"
|
2021-06-16 10:35:17 +00:00
|
|
|
"goauthentik.io/internal/constants"
|
2022-06-10 20:19:48 +00:00
|
|
|
sentryutils "goauthentik.io/internal/utils/sentry"
|
2022-06-20 09:54:10 +00:00
|
|
|
webutils "goauthentik.io/internal/utils/web"
|
2021-01-16 20:41:39 +00:00
|
|
|
)
|
|
|
|
|
2023-12-18 21:07:59 +00:00
|
|
|
var (
|
|
|
|
initialSetup = false
|
|
|
|
tlsTransport *http.RoundTripper = nil
|
|
|
|
)
|
2022-05-21 11:18:06 +00:00
|
|
|
|
2022-05-26 13:15:30 +00:00
|
|
|
func doGlobalSetup(outpost api.Outpost, globalConfig *api.Config) {
|
2021-12-20 20:23:19 +00:00
|
|
|
l := log.WithField("logger", "authentik.outpost")
|
2021-12-20 20:46:01 +00:00
|
|
|
m := outpost.Managed.Get()
|
2022-04-03 11:23:55 +00:00
|
|
|
level, ok := outpost.Config[ConfigLogLevel]
|
|
|
|
if !ok {
|
|
|
|
level = "info"
|
|
|
|
}
|
2021-12-20 20:46:01 +00:00
|
|
|
if m == nil || *m == "" {
|
2022-04-03 11:23:55 +00:00
|
|
|
switch level.(string) {
|
2021-12-20 20:23:19 +00:00
|
|
|
case "trace":
|
|
|
|
log.SetLevel(log.TraceLevel)
|
|
|
|
case "debug":
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
case "info":
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
case "warning":
|
|
|
|
log.SetLevel(log.WarnLevel)
|
|
|
|
case "error":
|
|
|
|
log.SetLevel(log.ErrorLevel)
|
|
|
|
default:
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-20 21:43:58 +00:00
|
|
|
l.Debug("Managed outpost, not setting global log level")
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 13:42:19 +00:00
|
|
|
if globalConfig.ErrorReporting.Enabled {
|
2022-05-21 11:18:06 +00:00
|
|
|
if !initialSetup {
|
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).Debug("Error reporting enabled")
|
|
|
|
}
|
2021-09-14 15:40:31 +00:00
|
|
|
err := sentry.Init(sentry.ClientOptions{
|
2022-11-15 15:05:29 +00:00
|
|
|
Dsn: globalConfig.ErrorReporting.SentryDsn,
|
2022-06-10 20:19:48 +00:00
|
|
|
Environment: globalConfig.ErrorReporting.Environment,
|
2022-12-09 11:20:41 +00:00
|
|
|
EnableTracing: true,
|
2022-06-10 20:19:48 +00:00
|
|
|
TracesSampler: sentryutils.SamplerFunc(float64(globalConfig.ErrorReporting.TracesSampleRate)),
|
|
|
|
Release: fmt.Sprintf("authentik@%s", constants.VERSION),
|
2022-06-20 09:54:10 +00:00
|
|
|
HTTPTransport: webutils.NewUserAgentTransport(constants.OutpostUserAgent(), http.DefaultTransport),
|
2021-12-20 18:42:45 +00:00
|
|
|
IgnoreErrors: []string{
|
|
|
|
http.ErrAbortHandler.Error(),
|
|
|
|
},
|
2021-09-14 15:40:31 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).WithError(err).Warning("Failed to initialise sentry")
|
2021-09-14 15:40:31 +00:00
|
|
|
}
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
2022-05-21 11:18:06 +00:00
|
|
|
|
|
|
|
if !initialSetup {
|
|
|
|
l.WithField("hash", constants.BUILD("tagged")).WithField("version", constants.VERSION).Info("Starting authentik outpost")
|
|
|
|
initialSetup = true
|
|
|
|
}
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 22:01:16 +00:00
|
|
|
// GetTLSTransport Get a TLS transport instance, that skips verification if configured via environment variables.
|
|
|
|
func GetTLSTransport() http.RoundTripper {
|
2022-11-25 17:24:01 +00:00
|
|
|
if tlsTransport != nil {
|
|
|
|
return *tlsTransport
|
|
|
|
}
|
|
|
|
tmp, err := httptransport.TLSTransport(httptransport.TLSClientOptions{
|
2023-01-08 19:33:04 +00:00
|
|
|
InsecureSkipVerify: config.Get().AuthentikInsecure,
|
2021-01-16 20:41:39 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-11-25 17:24:01 +00:00
|
|
|
tlsTransport = &tmp
|
|
|
|
return *tlsTransport
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|