2021-01-16 20:41:39 +00:00
|
|
|
package main
|
2020-09-02 23:04:12 +01:00
|
|
|
|
|
|
|
import (
|
2020-09-19 00:29:49 +01:00
|
|
|
"fmt"
|
2020-09-02 23:04:12 +01:00
|
|
|
"net/url"
|
|
|
|
"os"
|
2021-09-09 09:23:46 +01:00
|
|
|
"strconv"
|
2020-09-02 23:04:12 +01:00
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
"goauthentik.io/internal/common"
|
2022-01-25 16:04:28 +00:00
|
|
|
"goauthentik.io/internal/debug"
|
2021-06-16 11:02:02 +01:00
|
|
|
"goauthentik.io/internal/outpost/ak"
|
2021-09-08 19:04:56 +01:00
|
|
|
"goauthentik.io/internal/outpost/proxyv2"
|
2020-09-02 23:04:12 +01:00
|
|
|
)
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
const helpMessage = `authentik proxy
|
2020-09-19 00:29:49 +01: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 19:04:56 +01:00
|
|
|
- AUTHENTIK_INSECURE: Skip SSL Certificate verification
|
|
|
|
|
|
|
|
Optionally, you can set these:
|
2021-09-09 09:23:46 +01:00
|
|
|
- AUTHENTIK_HOST_BROWSER: URL to use in the browser, when it differs from AUTHENTIK_HOST
|
|
|
|
- AUTHENTIK_PORT_OFFSET: Offset to add to the listening ports, i.e. value of 100 makes proxy listen on 9100`
|
2020-09-19 00:29:49 +01:00
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
func main() {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
2021-12-20 20:23:19 +00:00
|
|
|
log.SetFormatter(&log.JSONFormatter{
|
|
|
|
FieldMap: log.FieldMap{
|
|
|
|
log.FieldKeyMsg: "event",
|
|
|
|
log.FieldKeyTime: "timestamp",
|
|
|
|
},
|
|
|
|
})
|
2022-01-25 16:04:28 +00:00
|
|
|
go debug.EnableDebugServer()
|
2021-06-16 16:29:01 +01:00
|
|
|
akURL, found := os.LookupEnv("AUTHENTIK_HOST")
|
2020-09-02 23:04:12 +01:00
|
|
|
if !found {
|
2020-12-05 21:08:42 +00:00
|
|
|
fmt.Println("env AUTHENTIK_HOST not set!")
|
2020-09-19 00:29:49 +01:00
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 23:04:12 +01:00
|
|
|
}
|
2021-06-16 16:29:01 +01:00
|
|
|
akToken, found := os.LookupEnv("AUTHENTIK_TOKEN")
|
2020-09-02 23:04:12 +01:00
|
|
|
if !found {
|
2020-12-05 21:08:42 +00:00
|
|
|
fmt.Println("env AUTHENTIK_TOKEN not set!")
|
2020-09-19 00:29:49 +01:00
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 23:04:12 +01:00
|
|
|
}
|
2021-09-09 09:23:46 +01:00
|
|
|
portOffset := 0
|
|
|
|
portOffsetS := os.Getenv("AUTHENTIK_PORT_OFFSET")
|
|
|
|
if portOffsetS != "" {
|
|
|
|
v, err := strconv.Atoi(portOffsetS)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
portOffset = v
|
|
|
|
}
|
2020-09-02 23:04:12 +01:00
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
akURLActual, err := url.Parse(akURL)
|
2020-09-02 23:04:12 +01:00
|
|
|
if err != nil {
|
2020-09-19 00:29:49 +01:00
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 23:04:12 +01:00
|
|
|
}
|
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
ex := common.Init()
|
|
|
|
defer common.Defer()
|
2020-09-02 23:04:12 +01:00
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
ac := ak.NewAPIController(*akURLActual, akToken)
|
2021-10-05 21:19:05 +01:00
|
|
|
if ac == nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-09-02 23:04:12 +01:00
|
|
|
|
2021-09-09 09:23:46 +01:00
|
|
|
ac.Server = proxyv2.NewProxyServer(ac, portOffset)
|
2021-01-16 20:41:39 +00:00
|
|
|
|
2021-04-19 19:43:13 +01:00
|
|
|
err = ac.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Panic("Failed to run server")
|
|
|
|
}
|
2020-09-02 23:04:12 +01:00
|
|
|
|
|
|
|
for {
|
2021-06-16 16:29:01 +01:00
|
|
|
<-ex
|
2021-04-19 19:43:13 +01:00
|
|
|
ac.Shutdown()
|
|
|
|
os.Exit(0)
|
2020-09-02 23:04:12 +01:00
|
|
|
}
|
|
|
|
}
|