outposts: remove duplicate startup/setup code, add pyroscope, make sentry not reconfigure every time (#14724)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
		| @ -2,17 +2,13 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/url" |  | ||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
| 	log "github.com/sirupsen/logrus" |  | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
|  |  | ||||||
| 	"goauthentik.io/internal/common" | 	"goauthentik.io/internal/common" | ||||||
| 	"goauthentik.io/internal/config" |  | ||||||
| 	"goauthentik.io/internal/constants" | 	"goauthentik.io/internal/constants" | ||||||
| 	"goauthentik.io/internal/debug" | 	"goauthentik.io/internal/outpost/ak/entrypoint" | ||||||
| 	"goauthentik.io/internal/outpost/ak" |  | ||||||
| 	"goauthentik.io/internal/outpost/ak/healthcheck" | 	"goauthentik.io/internal/outpost/ak/healthcheck" | ||||||
| 	"goauthentik.io/internal/outpost/ldap" | 	"goauthentik.io/internal/outpost/ldap" | ||||||
| ) | ) | ||||||
| @ -27,63 +23,13 @@ Required environment variables: | |||||||
| var rootCmd = &cobra.Command{ | var rootCmd = &cobra.Command{ | ||||||
| 	Long:             helpMessage, | 	Long:             helpMessage, | ||||||
| 	Version:          constants.FullVersion(), | 	Version:          constants.FullVersion(), | ||||||
| 	PersistentPreRun: func(cmd *cobra.Command, args []string) { | 	PersistentPreRun: common.PreRun, | ||||||
| 		log.SetLevel(log.DebugLevel) | 	RunE: func(cmd *cobra.Command, args []string) error { | ||||||
| 		log.SetFormatter(&log.JSONFormatter{ | 		err := entrypoint.OutpostMain("authentik.outpost.ldap", ldap.NewServer) | ||||||
| 			FieldMap: log.FieldMap{ |  | ||||||
| 				log.FieldKeyMsg:  "event", |  | ||||||
| 				log.FieldKeyTime: "timestamp", |  | ||||||
| 			}, |  | ||||||
| 			DisableHTMLEscape: true, |  | ||||||
| 		}) |  | ||||||
| 	}, |  | ||||||
| 	Run: func(cmd *cobra.Command, args []string) { |  | ||||||
| 		debug.EnableDebugServer() |  | ||||||
| 		akURL := config.Get().AuthentikHost |  | ||||||
| 		if akURL == "" { |  | ||||||
| 			fmt.Println("env AUTHENTIK_HOST not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		akToken := config.Get().AuthentikToken |  | ||||||
| 		if akToken == "" { |  | ||||||
| 			fmt.Println("env AUTHENTIK_TOKEN not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		akURLActual, err := url.Parse(akURL) |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			fmt.Println(err) |  | ||||||
| 			fmt.Println(helpMessage) | 			fmt.Println(helpMessage) | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		ex := common.Init() |  | ||||||
| 		defer common.Defer() |  | ||||||
| 		go func() { |  | ||||||
| 			for { |  | ||||||
| 				<-ex |  | ||||||
| 				os.Exit(0) |  | ||||||
| 			} |  | ||||||
| 		}() |  | ||||||
|  |  | ||||||
| 		ac := ak.NewAPIController(*akURLActual, akToken) |  | ||||||
| 		if ac == nil { |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		defer ac.Shutdown() |  | ||||||
|  |  | ||||||
| 		ac.Server = ldap.NewServer(ac) |  | ||||||
|  |  | ||||||
| 		err = ac.Start() |  | ||||||
| 		if err != nil { |  | ||||||
| 			log.WithError(err).Panic("Failed to run server") |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		for { |  | ||||||
| 			<-ex |  | ||||||
| 		} | 		} | ||||||
|  | 		return err | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -2,17 +2,13 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/url" |  | ||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
| 	log "github.com/sirupsen/logrus" |  | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
|  |  | ||||||
| 	"goauthentik.io/internal/common" | 	"goauthentik.io/internal/common" | ||||||
| 	"goauthentik.io/internal/config" |  | ||||||
| 	"goauthentik.io/internal/constants" | 	"goauthentik.io/internal/constants" | ||||||
| 	"goauthentik.io/internal/debug" | 	"goauthentik.io/internal/outpost/ak/entrypoint" | ||||||
| 	"goauthentik.io/internal/outpost/ak" |  | ||||||
| 	"goauthentik.io/internal/outpost/ak/healthcheck" | 	"goauthentik.io/internal/outpost/ak/healthcheck" | ||||||
| 	"goauthentik.io/internal/outpost/proxyv2" | 	"goauthentik.io/internal/outpost/proxyv2" | ||||||
| ) | ) | ||||||
| @ -30,63 +26,13 @@ Optionally, you can set these: | |||||||
| var rootCmd = &cobra.Command{ | var rootCmd = &cobra.Command{ | ||||||
| 	Long:             helpMessage, | 	Long:             helpMessage, | ||||||
| 	Version:          constants.FullVersion(), | 	Version:          constants.FullVersion(), | ||||||
| 	PersistentPreRun: func(cmd *cobra.Command, args []string) { | 	PersistentPreRun: common.PreRun, | ||||||
| 		log.SetLevel(log.DebugLevel) | 	RunE: func(cmd *cobra.Command, args []string) error { | ||||||
| 		log.SetFormatter(&log.JSONFormatter{ | 		err := entrypoint.OutpostMain("authentik.outpost.proxy", proxyv2.NewProxyServer) | ||||||
| 			FieldMap: log.FieldMap{ |  | ||||||
| 				log.FieldKeyMsg:  "event", |  | ||||||
| 				log.FieldKeyTime: "timestamp", |  | ||||||
| 			}, |  | ||||||
| 			DisableHTMLEscape: true, |  | ||||||
| 		}) |  | ||||||
| 	}, |  | ||||||
| 	Run: func(cmd *cobra.Command, args []string) { |  | ||||||
| 		debug.EnableDebugServer() |  | ||||||
| 		akURL := config.Get().AuthentikHost |  | ||||||
| 		if akURL == "" { |  | ||||||
| 			fmt.Println("env AUTHENTIK_HOST not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		akToken := config.Get().AuthentikToken |  | ||||||
| 		if akToken == "" { |  | ||||||
| 			fmt.Println("env AUTHENTIK_TOKEN not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		akURLActual, err := url.Parse(akURL) |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			fmt.Println(err) |  | ||||||
| 			fmt.Println(helpMessage) | 			fmt.Println(helpMessage) | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		ex := common.Init() |  | ||||||
| 		defer common.Defer() |  | ||||||
| 		go func() { |  | ||||||
| 			for { |  | ||||||
| 				<-ex |  | ||||||
| 				os.Exit(0) |  | ||||||
| 			} |  | ||||||
| 		}() |  | ||||||
|  |  | ||||||
| 		ac := ak.NewAPIController(*akURLActual, akToken) |  | ||||||
| 		if ac == nil { |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		defer ac.Shutdown() |  | ||||||
|  |  | ||||||
| 		ac.Server = proxyv2.NewProxyServer(ac) |  | ||||||
|  |  | ||||||
| 		err = ac.Start() |  | ||||||
| 		if err != nil { |  | ||||||
| 			log.WithError(err).Panic("Failed to run server") |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		for { |  | ||||||
| 			<-ex |  | ||||||
| 		} | 		} | ||||||
|  | 		return err | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -2,16 +2,13 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/url" |  | ||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
| 	log "github.com/sirupsen/logrus" |  | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
|  |  | ||||||
| 	"goauthentik.io/internal/common" | 	"goauthentik.io/internal/common" | ||||||
| 	"goauthentik.io/internal/constants" | 	"goauthentik.io/internal/constants" | ||||||
| 	"goauthentik.io/internal/debug" | 	"goauthentik.io/internal/outpost/ak/entrypoint" | ||||||
| 	"goauthentik.io/internal/outpost/ak" |  | ||||||
| 	"goauthentik.io/internal/outpost/ak/healthcheck" | 	"goauthentik.io/internal/outpost/ak/healthcheck" | ||||||
| 	"goauthentik.io/internal/outpost/rac" | 	"goauthentik.io/internal/outpost/rac" | ||||||
| ) | ) | ||||||
| @ -26,63 +23,13 @@ Required environment variables: | |||||||
| var rootCmd = &cobra.Command{ | var rootCmd = &cobra.Command{ | ||||||
| 	Long:             helpMessage, | 	Long:             helpMessage, | ||||||
| 	Version:          constants.FullVersion(), | 	Version:          constants.FullVersion(), | ||||||
| 	PersistentPreRun: func(cmd *cobra.Command, args []string) { | 	PersistentPreRun: common.PreRun, | ||||||
| 		log.SetLevel(log.DebugLevel) | 	RunE: func(cmd *cobra.Command, args []string) error { | ||||||
| 		log.SetFormatter(&log.JSONFormatter{ | 		err := entrypoint.OutpostMain("authentik.outpost.rac", rac.NewServer) | ||||||
| 			FieldMap: log.FieldMap{ |  | ||||||
| 				log.FieldKeyMsg:  "event", |  | ||||||
| 				log.FieldKeyTime: "timestamp", |  | ||||||
| 			}, |  | ||||||
| 			DisableHTMLEscape: true, |  | ||||||
| 		}) |  | ||||||
| 	}, |  | ||||||
| 	Run: func(cmd *cobra.Command, args []string) { |  | ||||||
| 		debug.EnableDebugServer() |  | ||||||
| 		akURL, found := os.LookupEnv("AUTHENTIK_HOST") |  | ||||||
| 		if !found { |  | ||||||
| 			fmt.Println("env AUTHENTIK_HOST not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		akToken, found := os.LookupEnv("AUTHENTIK_TOKEN") |  | ||||||
| 		if !found { |  | ||||||
| 			fmt.Println("env AUTHENTIK_TOKEN not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		akURLActual, err := url.Parse(akURL) |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			fmt.Println(err) |  | ||||||
| 			fmt.Println(helpMessage) | 			fmt.Println(helpMessage) | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		ex := common.Init() |  | ||||||
| 		defer common.Defer() |  | ||||||
| 		go func() { |  | ||||||
| 			for { |  | ||||||
| 				<-ex |  | ||||||
| 				os.Exit(0) |  | ||||||
| 			} |  | ||||||
| 		}() |  | ||||||
|  |  | ||||||
| 		ac := ak.NewAPIController(*akURLActual, akToken) |  | ||||||
| 		if ac == nil { |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		defer ac.Shutdown() |  | ||||||
|  |  | ||||||
| 		ac.Server = rac.NewServer(ac) |  | ||||||
|  |  | ||||||
| 		err = ac.Start() |  | ||||||
| 		if err != nil { |  | ||||||
| 			log.WithError(err).Panic("Failed to run server") |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		for { |  | ||||||
| 			<-ex |  | ||||||
| 		} | 		} | ||||||
|  | 		return err | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -2,16 +2,13 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/url" |  | ||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
| 	log "github.com/sirupsen/logrus" |  | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
|  |  | ||||||
| 	"goauthentik.io/internal/common" | 	"goauthentik.io/internal/common" | ||||||
| 	"goauthentik.io/internal/constants" | 	"goauthentik.io/internal/constants" | ||||||
| 	"goauthentik.io/internal/debug" | 	"goauthentik.io/internal/outpost/ak/entrypoint" | ||||||
| 	"goauthentik.io/internal/outpost/ak" |  | ||||||
| 	"goauthentik.io/internal/outpost/ak/healthcheck" | 	"goauthentik.io/internal/outpost/ak/healthcheck" | ||||||
| 	"goauthentik.io/internal/outpost/radius" | 	"goauthentik.io/internal/outpost/radius" | ||||||
| ) | ) | ||||||
| @ -26,63 +23,13 @@ Required environment variables: | |||||||
| var rootCmd = &cobra.Command{ | var rootCmd = &cobra.Command{ | ||||||
| 	Long:             helpMessage, | 	Long:             helpMessage, | ||||||
| 	Version:          constants.FullVersion(), | 	Version:          constants.FullVersion(), | ||||||
| 	PersistentPreRun: func(cmd *cobra.Command, args []string) { | 	PersistentPreRun: common.PreRun, | ||||||
| 		log.SetLevel(log.DebugLevel) | 	RunE: func(cmd *cobra.Command, args []string) error { | ||||||
| 		log.SetFormatter(&log.JSONFormatter{ | 		err := entrypoint.OutpostMain("authentik.outpost.radius", radius.NewServer) | ||||||
| 			FieldMap: log.FieldMap{ |  | ||||||
| 				log.FieldKeyMsg:  "event", |  | ||||||
| 				log.FieldKeyTime: "timestamp", |  | ||||||
| 			}, |  | ||||||
| 			DisableHTMLEscape: true, |  | ||||||
| 		}) |  | ||||||
| 	}, |  | ||||||
| 	Run: func(cmd *cobra.Command, args []string) { |  | ||||||
| 		debug.EnableDebugServer() |  | ||||||
| 		akURL, found := os.LookupEnv("AUTHENTIK_HOST") |  | ||||||
| 		if !found { |  | ||||||
| 			fmt.Println("env AUTHENTIK_HOST not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		akToken, found := os.LookupEnv("AUTHENTIK_TOKEN") |  | ||||||
| 		if !found { |  | ||||||
| 			fmt.Println("env AUTHENTIK_TOKEN not set!") |  | ||||||
| 			fmt.Println(helpMessage) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		akURLActual, err := url.Parse(akURL) |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			fmt.Println(err) |  | ||||||
| 			fmt.Println(helpMessage) | 			fmt.Println(helpMessage) | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		ex := common.Init() |  | ||||||
| 		defer common.Defer() |  | ||||||
| 		go func() { |  | ||||||
| 			for { |  | ||||||
| 				<-ex |  | ||||||
| 				os.Exit(0) |  | ||||||
| 			} |  | ||||||
| 		}() |  | ||||||
|  |  | ||||||
| 		ac := ak.NewAPIController(*akURLActual, akToken) |  | ||||||
| 		if ac == nil { |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 		defer ac.Shutdown() |  | ||||||
|  |  | ||||||
| 		ac.Server = radius.NewServer(ac) |  | ||||||
|  |  | ||||||
| 		err = ac.Start() |  | ||||||
| 		if err != nil { |  | ||||||
| 			log.WithError(err).Panic("Failed to run server") |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		for { |  | ||||||
| 			<-ex |  | ||||||
| 		} | 		} | ||||||
|  | 		return err | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -25,18 +25,9 @@ var rootCmd = &cobra.Command{ | |||||||
| 	Use:              "authentik", | 	Use:              "authentik", | ||||||
| 	Short:            "Start authentik instance", | 	Short:            "Start authentik instance", | ||||||
| 	Version:          constants.FullVersion(), | 	Version:          constants.FullVersion(), | ||||||
| 	PersistentPreRun: func(cmd *cobra.Command, args []string) { | 	PersistentPreRun: common.PreRun, | ||||||
| 		log.SetLevel(log.DebugLevel) |  | ||||||
| 		log.SetFormatter(&log.JSONFormatter{ |  | ||||||
| 			FieldMap: log.FieldMap{ |  | ||||||
| 				log.FieldKeyMsg:  "event", |  | ||||||
| 				log.FieldKeyTime: "timestamp", |  | ||||||
| 			}, |  | ||||||
| 			DisableHTMLEscape: true, |  | ||||||
| 		}) |  | ||||||
| 	}, |  | ||||||
| 	Run: func(cmd *cobra.Command, args []string) { | 	Run: func(cmd *cobra.Command, args []string) { | ||||||
| 		debug.EnableDebugServer() | 		debug.EnableDebugServer("authentik.core") | ||||||
| 		l := log.WithField("logger", "authentik.root") | 		l := log.WithField("logger", "authentik.root") | ||||||
|  |  | ||||||
| 		if config.Get().ErrorReporting.Enabled { | 		if config.Get().ErrorReporting.Enabled { | ||||||
| @ -99,7 +90,7 @@ func attemptProxyStart(ws *web.WebServer, u *url.URL) { | |||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
| 		srv := proxyv2.NewProxyServer(ac) | 		srv := proxyv2.NewProxyServer(ac) | ||||||
| 		ws.ProxyServer = srv | 		ws.ProxyServer = srv.(*proxyv2.ProxyServer) | ||||||
| 		ac.Server = srv | 		ac.Server = srv | ||||||
| 		l.Debug("attempting to start outpost") | 		l.Debug("attempting to start outpost") | ||||||
| 		err := ac.StartBackgroundTasks() | 		err := ac.StartBackgroundTasks() | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								go.mod
									
									
									
									
									
								
							| @ -16,6 +16,7 @@ require ( | |||||||
| 	github.com/gorilla/securecookie v1.1.2 | 	github.com/gorilla/securecookie v1.1.2 | ||||||
| 	github.com/gorilla/sessions v1.4.0 | 	github.com/gorilla/sessions v1.4.0 | ||||||
| 	github.com/gorilla/websocket v1.5.3 | 	github.com/gorilla/websocket v1.5.3 | ||||||
|  | 	github.com/grafana/pyroscope-go v1.2.2 | ||||||
| 	github.com/jellydator/ttlcache/v3 v3.3.0 | 	github.com/jellydator/ttlcache/v3 v3.3.0 | ||||||
| 	github.com/mitchellh/mapstructure v1.5.0 | 	github.com/mitchellh/mapstructure v1.5.0 | ||||||
| 	github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484 | 	github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484 | ||||||
| @ -58,8 +59,10 @@ require ( | |||||||
| 	github.com/go-openapi/strfmt v0.23.0 // indirect | 	github.com/go-openapi/strfmt v0.23.0 // indirect | ||||||
| 	github.com/go-openapi/swag v0.23.0 // indirect | 	github.com/go-openapi/swag v0.23.0 // indirect | ||||||
| 	github.com/go-openapi/validate v0.24.0 // indirect | 	github.com/go-openapi/validate v0.24.0 // indirect | ||||||
|  | 	github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect | ||||||
| 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||||||
| 	github.com/josharian/intern v1.0.0 // indirect | 	github.com/josharian/intern v1.0.0 // indirect | ||||||
|  | 	github.com/klauspost/compress v1.18.0 // indirect | ||||||
| 	github.com/mailru/easyjson v0.7.7 // indirect | 	github.com/mailru/easyjson v0.7.7 // indirect | ||||||
| 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||||||
| 	github.com/oklog/ulid v1.3.1 // indirect | 	github.com/oklog/ulid v1.3.1 // indirect | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								go.sum
									
									
									
									
									
								
							| @ -178,6 +178,10 @@ github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2e | |||||||
| github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||||||
| github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= | github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= | ||||||
| github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||||||
|  | github.com/grafana/pyroscope-go v1.2.2 h1:uvKCyZMD724RkaCEMrSTC38Yn7AnFe8S2wiAIYdDPCE= | ||||||
|  | github.com/grafana/pyroscope-go v1.2.2/go.mod h1:zzT9QXQAp2Iz2ZdS216UiV8y9uXJYQiGE1q8v1FyhqU= | ||||||
|  | github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg= | ||||||
|  | github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU= | ||||||
| github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= | github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= | ||||||
| github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= | github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= | ||||||
| github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | ||||||
| @ -262,6 +266,8 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= | |||||||
| github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||||
| github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||||
|  | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= | ||||||
|  | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= | ||||||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||||||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||||
| github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								internal/common/prerun.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								internal/common/prerun.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | package common | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	log "github.com/sirupsen/logrus" | ||||||
|  | 	"github.com/spf13/cobra" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func PreRun(cmd *cobra.Command, args []string) { | ||||||
|  | 	log.SetLevel(log.DebugLevel) | ||||||
|  | 	log.SetFormatter(&log.JSONFormatter{ | ||||||
|  | 		FieldMap: log.FieldMap{ | ||||||
|  | 			log.FieldKeyMsg:  "event", | ||||||
|  | 			log.FieldKeyTime: "timestamp", | ||||||
|  | 		}, | ||||||
|  | 		DisableHTMLEscape: true, | ||||||
|  | 	}) | ||||||
|  | } | ||||||
| @ -5,19 +5,24 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/pprof" | 	"net/http/pprof" | ||||||
|  | 	"os" | ||||||
|  | 	"runtime" | ||||||
|  |  | ||||||
| 	"github.com/gorilla/mux" | 	"github.com/gorilla/mux" | ||||||
|  | 	"github.com/grafana/pyroscope-go" | ||||||
| 	log "github.com/sirupsen/logrus" | 	log "github.com/sirupsen/logrus" | ||||||
| 	"goauthentik.io/internal/config" | 	"goauthentik.io/internal/config" | ||||||
| 	"goauthentik.io/internal/utils/web" | 	"goauthentik.io/internal/utils/web" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func EnableDebugServer() { | var l = log.WithField("logger", "authentik.debugger.go") | ||||||
| 	l := log.WithField("logger", "authentik.go_debugger") |  | ||||||
|  | func EnableDebugServer(appName string) { | ||||||
| 	if !config.Get().Debug { | 	if !config.Get().Debug { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	h := mux.NewRouter() | 	h := mux.NewRouter() | ||||||
|  | 	enablePyroscope(appName) | ||||||
| 	h.HandleFunc("/debug/pprof/", pprof.Index) | 	h.HandleFunc("/debug/pprof/", pprof.Index) | ||||||
| 	h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | 	h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | ||||||
| 	h.HandleFunc("/debug/pprof/profile", pprof.Profile) | 	h.HandleFunc("/debug/pprof/profile", pprof.Profile) | ||||||
| @ -54,3 +59,38 @@ func EnableDebugServer() { | |||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func enablePyroscope(appName string) { | ||||||
|  | 	p, pok := os.LookupEnv("AUTHENTIK_PYROSCOPE_HOST") | ||||||
|  | 	if !pok { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	l.Debug("Enabling pyroscope") | ||||||
|  | 	runtime.SetMutexProfileFraction(5) | ||||||
|  | 	runtime.SetBlockProfileRate(5) | ||||||
|  | 	hostname, err := os.Hostname() | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	_, err = pyroscope.Start(pyroscope.Config{ | ||||||
|  | 		ApplicationName: appName, | ||||||
|  | 		ServerAddress:   p, | ||||||
|  | 		Logger:          pyroscope.StandardLogger, | ||||||
|  | 		Tags:            map[string]string{"hostname": hostname}, | ||||||
|  | 		ProfileTypes: []pyroscope.ProfileType{ | ||||||
|  | 			pyroscope.ProfileCPU, | ||||||
|  | 			pyroscope.ProfileAllocObjects, | ||||||
|  | 			pyroscope.ProfileAllocSpace, | ||||||
|  | 			pyroscope.ProfileInuseObjects, | ||||||
|  | 			pyroscope.ProfileInuseSpace, | ||||||
|  | 			pyroscope.ProfileGoroutines, | ||||||
|  | 			pyroscope.ProfileMutexCount, | ||||||
|  | 			pyroscope.ProfileMutexDuration, | ||||||
|  | 			pyroscope.ProfileBlockCount, | ||||||
|  | 			pyroscope.ProfileBlockDuration, | ||||||
|  | 		}, | ||||||
|  | 	}) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
| @ -135,6 +135,10 @@ func NewAPIController(akURL url.URL, token string) *APIController { | |||||||
| 	return ac | 	return ac | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (a *APIController) Log() *log.Entry { | ||||||
|  | 	return a.logger | ||||||
|  | } | ||||||
|  |  | ||||||
| // Start Starts all handlers, non-blocking | // Start Starts all handlers, non-blocking | ||||||
| func (a *APIController) Start() error { | func (a *APIController) Start() error { | ||||||
| 	err := a.Server.Refresh() | 	err := a.Server.Refresh() | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								internal/outpost/ak/entrypoint/entrypoint.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								internal/outpost/ak/entrypoint/entrypoint.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | package entrypoint | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"errors" | ||||||
|  | 	"net/url" | ||||||
|  | 	"os" | ||||||
|  |  | ||||||
|  | 	"goauthentik.io/internal/common" | ||||||
|  | 	"goauthentik.io/internal/config" | ||||||
|  | 	"goauthentik.io/internal/debug" | ||||||
|  | 	"goauthentik.io/internal/outpost/ak" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func OutpostMain(appName string, server func(ac *ak.APIController) ak.Outpost) error { | ||||||
|  | 	debug.EnableDebugServer(appName) | ||||||
|  | 	akURL := config.Get().AuthentikHost | ||||||
|  | 	if akURL == "" { | ||||||
|  | 		return errors.New("environment variable `AUTHENTIK_HOST` not set") | ||||||
|  | 	} | ||||||
|  | 	akToken := config.Get().AuthentikToken | ||||||
|  | 	if akToken == "" { | ||||||
|  | 		return errors.New("environment variable `AUTHENTIK_TOKEN` not set") | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	akURLActual, err := url.Parse(akURL) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	ex := common.Init() | ||||||
|  | 	defer common.Defer() | ||||||
|  |  | ||||||
|  | 	ac := ak.NewAPIController(*akURLActual, akToken) | ||||||
|  | 	if ac == nil { | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | 	defer ac.Shutdown() | ||||||
|  |  | ||||||
|  | 	ac.Server = server(ac) | ||||||
|  |  | ||||||
|  | 	err = ac.Start() | ||||||
|  | 	if err != nil { | ||||||
|  | 		ac.Log().WithError(err).Panic("Failed to run server") | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for { | ||||||
|  | 		<-ex | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -48,7 +48,6 @@ func doGlobalSetup(outpost api.Outpost, globalConfig *api.Config) { | |||||||
| 	if globalConfig.ErrorReporting.Enabled { | 	if globalConfig.ErrorReporting.Enabled { | ||||||
| 		if !initialSetup { | 		if !initialSetup { | ||||||
| 			l.WithField("env", globalConfig.ErrorReporting.Environment).Debug("Error reporting enabled") | 			l.WithField("env", globalConfig.ErrorReporting.Environment).Debug("Error reporting enabled") | ||||||
| 		} |  | ||||||
| 			err := sentry.Init(sentry.ClientOptions{ | 			err := sentry.Init(sentry.ClientOptions{ | ||||||
| 				Dsn:           globalConfig.ErrorReporting.SentryDsn, | 				Dsn:           globalConfig.ErrorReporting.SentryDsn, | ||||||
| 				Environment:   globalConfig.ErrorReporting.Environment, | 				Environment:   globalConfig.ErrorReporting.Environment, | ||||||
| @ -64,6 +63,7 @@ func doGlobalSetup(outpost api.Outpost, globalConfig *api.Config) { | |||||||
| 				l.WithField("env", globalConfig.ErrorReporting.Environment).WithError(err).Warning("Failed to initialise sentry") | 				l.WithField("env", globalConfig.ErrorReporting.Environment).WithError(err).Warning("Failed to initialise sentry") | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if !initialSetup { | 	if !initialSetup { | ||||||
| 		l.WithField("hash", constants.BUILD("tagged")).WithField("version", constants.VERSION).Info("Starting authentik outpost") | 		l.WithField("hash", constants.BUILD("tagged")).WithField("version", constants.VERSION).Info("Starting authentik outpost") | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ type LDAPServer struct { | |||||||
| 	providers   []*ProviderInstance | 	providers   []*ProviderInstance | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewServer(ac *ak.APIController) *LDAPServer { | func NewServer(ac *ak.APIController) ak.Outpost { | ||||||
| 	ls := &LDAPServer{ | 	ls := &LDAPServer{ | ||||||
| 		log:       log.WithField("logger", "authentik.outpost.ldap"), | 		log:       log.WithField("logger", "authentik.outpost.ldap"), | ||||||
| 		ac:        ac, | 		ac:        ac, | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ type ProxyServer struct { | |||||||
| 	akAPI       *ak.APIController | 	akAPI       *ak.APIController | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewProxyServer(ac *ak.APIController) *ProxyServer { | func NewProxyServer(ac *ak.APIController) ak.Outpost { | ||||||
| 	l := log.WithField("logger", "authentik.outpost.proxyv2") | 	l := log.WithField("logger", "authentik.outpost.proxyv2") | ||||||
| 	defaultCert, err := crypto.GenerateSelfSignedCert() | 	defaultCert, err := crypto.GenerateSelfSignedCert() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ type RACServer struct { | |||||||
| 	conns map[string]connection.Connection | 	conns map[string]connection.Connection | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewServer(ac *ak.APIController) *RACServer { | func NewServer(ac *ak.APIController) ak.Outpost { | ||||||
| 	rs := &RACServer{ | 	rs := &RACServer{ | ||||||
| 		log:   log.WithField("logger", "authentik.outpost.rac"), | 		log:   log.WithField("logger", "authentik.outpost.rac"), | ||||||
| 		ac:    ac, | 		ac:    ac, | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ type RadiusServer struct { | |||||||
| 	providers []*ProviderInstance | 	providers []*ProviderInstance | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewServer(ac *ak.APIController) *RadiusServer { | func NewServer(ac *ak.APIController) ak.Outpost { | ||||||
| 	rs := &RadiusServer{ | 	rs := &RadiusServer{ | ||||||
| 		log:       log.WithField("logger", "authentik.outpost.radius"), | 		log:       log.WithField("logger", "authentik.outpost.radius"), | ||||||
| 		ac:        ac, | 		ac:        ac, | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ package web | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  |  | ||||||
| 	"github.com/getsentry/sentry-go" | 	"github.com/getsentry/sentry-go" | ||||||
| @ -20,7 +19,7 @@ func NewTracingTransport(ctx context.Context, inner http.RoundTripper) *tracingT | |||||||
| func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { | func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { | ||||||
| 	span := sentry.StartSpan(tt.ctx, "authentik.go.http_request") | 	span := sentry.StartSpan(tt.ctx, "authentik.go.http_request") | ||||||
| 	r.Header.Set("sentry-trace", span.ToSentryTrace()) | 	r.Header.Set("sentry-trace", span.ToSentryTrace()) | ||||||
| 	span.Description = fmt.Sprintf("%s %s", r.Method, r.URL.String()) | 	span.Description = r.Method + " " + r.URL.String() | ||||||
| 	span.SetTag("url", r.URL.String()) | 	span.SetTag("url", r.URL.String()) | ||||||
| 	span.SetTag("method", r.Method) | 	span.SetTag("method", r.Method) | ||||||
| 	defer span.Finish() | 	defer span.Finish() | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens L.
					Jens L.