2021-01-16 20:41:39 +00:00
|
|
|
package main
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-18 23:29:49 +00:00
|
|
|
"fmt"
|
2020-09-02 22:04:12 +00:00
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2023-04-21 10:32:48 +00:00
|
|
|
"github.com/spf13/cobra"
|
2021-01-16 20:41:39 +00:00
|
|
|
|
2021-06-16 15:29:01 +00:00
|
|
|
"goauthentik.io/internal/common"
|
2023-01-08 13:19:08 +00:00
|
|
|
"goauthentik.io/internal/config"
|
2022-01-25 16:04:28 +00:00
|
|
|
"goauthentik.io/internal/debug"
|
2021-06-16 10:02:02 +00:00
|
|
|
"goauthentik.io/internal/outpost/ak"
|
2023-04-21 10:32:48 +00:00
|
|
|
"goauthentik.io/internal/outpost/ak/healthcheck"
|
2021-09-08 18:04:56 +00:00
|
|
|
"goauthentik.io/internal/outpost/proxyv2"
|
2020-09-02 22:04:12 +00:00
|
|
|
)
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
const helpMessage = `authentik proxy
|
2020-09-18 23:29:49 +00:00
|
|
|
|
|
|
|
Required environment variables:
|
2021-01-16 20:41:39 +00:00
|
|
|
- AUTHENTIK_HOST: URL to connect to (format "http://authentik.company")
|
|
|
|
- AUTHENTIK_TOKEN: Token to authenticate with
|
2021-09-08 18:04:56 +00:00
|
|
|
- AUTHENTIK_INSECURE: Skip SSL Certificate verification
|
|
|
|
|
|
|
|
Optionally, you can set these:
|
2022-08-03 19:33:27 +00:00
|
|
|
- AUTHENTIK_HOST_BROWSER: URL to use in the browser, when it differs from AUTHENTIK_HOST`
|
2020-09-18 23:29:49 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Long: helpMessage,
|
|
|
|
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()
|
|
|
|
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)
|
|
|
|
}
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
akURLActual, err := url.Parse(akURL)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
ex := common.Init()
|
|
|
|
defer common.Defer()
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-ex
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
ac := ak.NewAPIController(*akURLActual, akToken)
|
|
|
|
if ac == nil {
|
|
|
|
os.Exit(1)
|
2022-08-05 16:13:09 +00:00
|
|
|
}
|
2023-04-21 10:32:48 +00:00
|
|
|
defer ac.Shutdown()
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
ac.Server = proxyv2.NewProxyServer(ac)
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
err = ac.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Panic("Failed to run server")
|
|
|
|
}
|
2021-01-16 20:41:39 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
for {
|
|
|
|
<-ex
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2023-04-21 10:32:48 +00:00
|
|
|
func main() {
|
|
|
|
rootCmd.AddCommand(healthcheck.Command)
|
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
2020-09-02 22:04:12 +00:00
|
|
|
}
|
|
|
|
}
|