* prepare client auth with inbuilt server Signed-off-by: Jens Langhammer <jens@goauthentik.io> * introduce better IPC auth Signed-off-by: Jens Langhammer <jens@goauthentik.io> * init Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start stage Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only allow trusted proxies to set MTLS headers Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more stage progress Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dont fail if ipc_key doesn't exist Signed-off-by: Jens Langhammer <jens@goauthentik.io> * actually install app Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add some tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update API Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix unquote Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix int serial number not jsonable Signed-off-by: Jens Langhammer <jens@goauthentik.io> * init ui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add UI Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix git pull in makefile Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix parse helper Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add test for outpost Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more tests and improvements Signed-off-by: Jens Langhammer <jens@goauthentik.io> * improve labels Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add support for multiple CAs on brand Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add support for multiple CAs to MTLS stage Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dont log ipcuser secret views Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix go mod Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			119 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			119 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"net/http"
 | 
						|
	"net/url"
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/getsentry/sentry-go"
 | 
						|
	log "github.com/sirupsen/logrus"
 | 
						|
	"github.com/spf13/cobra"
 | 
						|
 | 
						|
	"goauthentik.io/internal/common"
 | 
						|
	"goauthentik.io/internal/config"
 | 
						|
	"goauthentik.io/internal/constants"
 | 
						|
	"goauthentik.io/internal/debug"
 | 
						|
	"goauthentik.io/internal/outpost/ak"
 | 
						|
	"goauthentik.io/internal/outpost/proxyv2"
 | 
						|
	sentryutils "goauthentik.io/internal/utils/sentry"
 | 
						|
	webutils "goauthentik.io/internal/utils/web"
 | 
						|
	"goauthentik.io/internal/web"
 | 
						|
)
 | 
						|
 | 
						|
var rootCmd = &cobra.Command{
 | 
						|
	Use:     "authentik",
 | 
						|
	Short:   "Start authentik instance",
 | 
						|
	Version: constants.FullVersion(),
 | 
						|
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
 | 
						|
		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) {
 | 
						|
		debug.EnableDebugServer()
 | 
						|
		l := log.WithField("logger", "authentik.root")
 | 
						|
 | 
						|
		if config.Get().ErrorReporting.Enabled {
 | 
						|
			err := sentry.Init(sentry.ClientOptions{
 | 
						|
				Dsn:              config.Get().ErrorReporting.SentryDSN,
 | 
						|
				AttachStacktrace: true,
 | 
						|
				EnableTracing:    true,
 | 
						|
				TracesSampler:    sentryutils.SamplerFunc(config.Get().ErrorReporting.SampleRate),
 | 
						|
				Release:          fmt.Sprintf("authentik@%s", constants.VERSION),
 | 
						|
				Environment:      config.Get().ErrorReporting.Environment,
 | 
						|
				HTTPTransport:    webutils.NewUserAgentTransport(constants.UserAgent(), http.DefaultTransport),
 | 
						|
				IgnoreErrors: []string{
 | 
						|
					http.ErrAbortHandler.Error(),
 | 
						|
				},
 | 
						|
			})
 | 
						|
			if err != nil {
 | 
						|
				l.WithError(err).Warning("failed to init sentry")
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		ex := common.Init()
 | 
						|
		defer common.Defer()
 | 
						|
 | 
						|
		u, err := url.Parse(fmt.Sprintf("http://%s%s", config.Get().Listen.HTTP, config.Get().Web.Path))
 | 
						|
		if err != nil {
 | 
						|
			panic(err)
 | 
						|
		}
 | 
						|
 | 
						|
		ws := web.NewWebServer()
 | 
						|
		ws.Core().AddHealthyCallback(func() {
 | 
						|
			if config.Get().Outposts.DisableEmbeddedOutpost {
 | 
						|
				return
 | 
						|
			}
 | 
						|
			go attemptProxyStart(ws, u)
 | 
						|
		})
 | 
						|
		ws.Start()
 | 
						|
		<-ex
 | 
						|
		l.Info("shutting down webserver")
 | 
						|
		go ws.Shutdown()
 | 
						|
	},
 | 
						|
}
 | 
						|
 | 
						|
func attemptProxyStart(ws *web.WebServer, u *url.URL) {
 | 
						|
	maxTries := 100
 | 
						|
	attempt := 0
 | 
						|
	l := log.WithField("logger", "authentik.server")
 | 
						|
	for {
 | 
						|
		l.Debug("attempting to init outpost")
 | 
						|
		ac := ak.NewAPIController(*u, config.Get().SecretKey)
 | 
						|
		if ac == nil {
 | 
						|
			attempt += 1
 | 
						|
			time.Sleep(1 * time.Second)
 | 
						|
			if attempt > maxTries {
 | 
						|
				break
 | 
						|
			}
 | 
						|
			continue
 | 
						|
		}
 | 
						|
		ac.AddRefreshHandler(func() {
 | 
						|
			ws.BrandTLS.Check()
 | 
						|
		})
 | 
						|
 | 
						|
		srv := proxyv2.NewProxyServer(ac)
 | 
						|
		ws.ProxyServer = srv
 | 
						|
		ac.Server = srv
 | 
						|
		l.Debug("attempting to start outpost")
 | 
						|
		err := ac.StartBackgroundTasks()
 | 
						|
		if err != nil {
 | 
						|
			l.WithError(err).Warning("outpost failed to start")
 | 
						|
			attempt += 1
 | 
						|
			time.Sleep(15 * time.Second)
 | 
						|
			if attempt > maxTries {
 | 
						|
				break
 | 
						|
			}
 | 
						|
			continue
 | 
						|
		} else {
 | 
						|
			select {}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |