diff --git a/cmd/ldap/server.go b/cmd/ldap/server.go index 6668a1c59..4b6ac0cb1 100644 --- a/cmd/ldap/server.go +++ b/cmd/ldap/server.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" "goauthentik.io/internal/common" + "goauthentik.io/internal/debug" "goauthentik.io/internal/outpost/ak" "goauthentik.io/internal/outpost/ldap" ) @@ -27,6 +28,7 @@ func main() { log.FieldKeyTime: "timestamp", }, }) + go debug.EnableDebugServer() akURL, found := os.LookupEnv("AUTHENTIK_HOST") if !found { fmt.Println("env AUTHENTIK_HOST not set!") diff --git a/cmd/proxy/server.go b/cmd/proxy/server.go index cd085342b..fbcdd89c0 100644 --- a/cmd/proxy/server.go +++ b/cmd/proxy/server.go @@ -9,6 +9,7 @@ import ( log "github.com/sirupsen/logrus" "goauthentik.io/internal/common" + "goauthentik.io/internal/debug" "goauthentik.io/internal/outpost/ak" "goauthentik.io/internal/outpost/proxyv2" ) @@ -32,6 +33,7 @@ func main() { log.FieldKeyTime: "timestamp", }, }) + go debug.EnableDebugServer() akURL, found := os.LookupEnv("AUTHENTIK_HOST") if !found { fmt.Println("env AUTHENTIK_HOST not set!") diff --git a/cmd/server/main.go b/cmd/server/main.go index ecb3b1d2f..1971b8717 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -11,6 +11,7 @@ import ( "goauthentik.io/internal/common" "goauthentik.io/internal/config" "goauthentik.io/internal/constants" + "goauthentik.io/internal/debug" "goauthentik.io/internal/gounicorn" "goauthentik.io/internal/outpost/ak" "goauthentik.io/internal/outpost/proxyv2" @@ -28,6 +29,7 @@ func main() { log.FieldKeyTime: "timestamp", }, }) + go debug.EnableDebugServer() l := log.WithField("logger", "authentik.root") config.DefaultConfig() err := config.LoadConfig("./authentik/lib/default.yml") diff --git a/internal/debug/debug.go b/internal/debug/debug.go new file mode 100644 index 000000000..e8cb2ad61 --- /dev/null +++ b/internal/debug/debug.go @@ -0,0 +1,24 @@ +package debug + +import ( + "net/http" + "net/http/pprof" + "os" + "strings" + + log "github.com/sirupsen/logrus" +) + +func EnableDebugServer() { + l := log.WithField("logger", "authentik.go_debugger") + if deb := os.Getenv("AUTHENTIK_DEBUG"); strings.ToLower(deb) != "true" { + l.Info("not enabling debug server, set `AUTHENTIK_DEBUG` to `true` to enable it.") + } + h := http.NewServeMux() + h.HandleFunc("/debug/pprof/", pprof.Index) + h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + h.HandleFunc("/debug/pprof/profile", pprof.Profile) + h.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + h.HandleFunc("/debug/pprof/trace", pprof.Trace) + l.Println(http.ListenAndServe("0.0.0.0:9900", nil)) +}