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
|
|
|
"math/rand"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2021-01-16 20:45:24 +00:00
|
|
|
"goauthentik.io/outpost/pkg/ak"
|
|
|
|
"goauthentik.io/outpost/pkg/proxy"
|
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
|
|
|
|
- AUTHENTIK_INSECURE: Skip SSL Certificate verification`
|
2020-09-18 23:29:49 +00:00
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
func main() {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
2020-12-05 21:08:42 +00:00
|
|
|
pbURL, found := os.LookupEnv("AUTHENTIK_HOST")
|
2020-09-02 22:04:12 +00:00
|
|
|
if !found {
|
2020-12-05 21:08:42 +00:00
|
|
|
fmt.Println("env AUTHENTIK_HOST not set!")
|
2020-09-18 23:29:49 +00:00
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 22:04:12 +00:00
|
|
|
}
|
2020-12-05 21:08:42 +00:00
|
|
|
pbToken, found := os.LookupEnv("AUTHENTIK_TOKEN")
|
2020-09-02 22:04:12 +00:00
|
|
|
if !found {
|
2020-12-05 21:08:42 +00:00
|
|
|
fmt.Println("env AUTHENTIK_TOKEN not set!")
|
2020-09-18 23:29:49 +00:00
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 22:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pbURLActual, err := url.Parse(pbURL)
|
|
|
|
if err != nil {
|
2020-09-18 23:29:49 +00:00
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
2020-09-02 22:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
ac := ak.NewAPIController(*pbURLActual, pbToken)
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(interrupt, os.Interrupt)
|
|
|
|
|
2021-01-16 20:41:39 +00:00
|
|
|
ac.Server = proxy.NewServer(ac)
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
ac.Start()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-interrupt:
|
|
|
|
ac.Shutdown()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|