2021-04-19 22:30:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
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"
|
|
|
|
"goauthentik.io/internal/outpost/ldap"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const helpMessage = `authentik ldap
|
|
|
|
|
|
|
|
Required environment variables:
|
|
|
|
- AUTHENTIK_HOST: URL to connect to (format "http://authentik.company")
|
|
|
|
- AUTHENTIK_TOKEN: Token to authenticate with
|
|
|
|
- AUTHENTIK_INSECURE: Skip SSL Certificate verification`
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
2021-12-20 20:46:01 +00:00
|
|
|
log.SetFormatter(&log.JSONFormatter{
|
|
|
|
FieldMap: log.FieldMap{
|
|
|
|
log.FieldKeyMsg: "event",
|
|
|
|
log.FieldKeyTime: "timestamp",
|
|
|
|
},
|
2022-04-04 20:57:55 +00:00
|
|
|
DisableHTMLEscape: true,
|
2021-12-20 20:46:01 +00:00
|
|
|
})
|
2023-01-08 19:33:04 +00:00
|
|
|
debug.EnableDebugServer()
|
2023-01-08 13:19:08 +00:00
|
|
|
akURL := config.Get().AuthentikHost
|
|
|
|
if akURL == "" {
|
2021-04-19 22:30:27 +00:00
|
|
|
fmt.Println("env AUTHENTIK_HOST not set!")
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2023-01-08 13:19:08 +00:00
|
|
|
akToken := config.Get().AuthentikToken
|
|
|
|
if akToken == "" {
|
2021-04-19 22:30:27 +00:00
|
|
|
fmt.Println("env AUTHENTIK_TOKEN not set!")
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:29:01 +00:00
|
|
|
akURLActual, err := url.Parse(akURL)
|
2021-04-19 22:30:27 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:29:01 +00:00
|
|
|
ex := common.Init()
|
|
|
|
defer common.Defer()
|
2022-08-05 16:13:09 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-ex
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}()
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-06-16 15:29:01 +00:00
|
|
|
ac := ak.NewAPIController(*akURLActual, akToken)
|
2021-10-05 20:19:05 +00:00
|
|
|
if ac == nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-08-05 16:13:09 +00:00
|
|
|
defer ac.Shutdown()
|
2021-04-19 22:30:27 +00:00
|
|
|
|
|
|
|
ac.Server = ldap.NewServer(ac)
|
|
|
|
|
2021-04-26 10:24:46 +00:00
|
|
|
err = ac.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Panic("Failed to run server")
|
|
|
|
}
|
2021-04-19 22:30:27 +00:00
|
|
|
|
|
|
|
for {
|
2021-06-16 15:29:01 +00:00
|
|
|
<-ex
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
}
|