debian-forge-composer/cmd/osbuild-composer/main.go
sanne 4a057bf3d5 auth: OpenID/OAUth2 middleware
2 configurations for the listeners are now possible:
- enableJWT=false with client ssl auth
- enableJWT=true with https

Actual verification of the tokens is handled by
https://github.com/openshift-online/ocm-sdk-go.

An authentication handler is run as the top level handler, before any
routing is done. Routes which do not require authentication should be
listed as exceptions.

Authentication can be restricted using an ACL file which allows
filtering based on JWT claims. For more information see the inline
comments in ocm-sdk/authentication.

As an added quirk the `-v` flag for the osbuild-composer executable was
changed to `-verbose` to avoid flag collision with glog which declares
the `-v` flag in the package `init()` function. The ocm-sdk depends on
glog and pulls it in.
2021-09-04 02:48:52 +02:00

112 lines
2.8 KiB
Go

package main
import (
"flag"
"log"
"os"
"github.com/coreos/go-systemd/activation"
)
const (
configFile = "/etc/osbuild-composer/osbuild-composer.toml"
ServerKeyFile = "/etc/osbuild-composer/composer-key.pem"
ServerCertFile = "/etc/osbuild-composer/composer-crt.pem"
)
var repositoryConfigs = []string{
"/etc/osbuild-composer",
"/usr/share/osbuild-composer",
}
func main() {
var verbose bool
flag.BoolVar(&verbose, "verbose", false, "Print access log")
flag.Parse()
var logger *log.Logger
if verbose {
logger = log.New(os.Stdout, "", 0)
}
config, err := LoadConfig(configFile)
if err != nil {
if os.IsNotExist(err) {
config = &ComposerConfigFile{}
} else {
log.Fatalf("Error loading configuration: %v", err)
}
}
log.Println("Loaded configuration:")
err = DumpConfig(config, log.Writer())
if err != nil {
log.Fatalf("Error printing configuration: %v", err)
}
stateDir, ok := os.LookupEnv("STATE_DIRECTORY")
if !ok {
log.Fatal("STATE_DIRECTORY is not set. Is the service file missing StateDirectory=?")
}
cacheDir, ok := os.LookupEnv("CACHE_DIRECTORY")
if !ok {
log.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
}
composer, err := NewComposer(config, stateDir, cacheDir, logger)
if err != nil {
log.Fatalf("%v", err)
}
listeners, err := activation.ListenersWithNames()
if err != nil {
log.Fatalf("Could not get listening sockets: " + err.Error())
}
if l, exists := listeners["osbuild-composer.socket"]; exists {
if len(l) != 1 {
log.Fatal("The osbuild-composer.socket unit is misconfigured. It should contain only one socket.")
}
err = composer.InitWeldr(repositoryConfigs, l[0], config.weldrDistrosImageTypeDenyList())
if err != nil {
log.Fatalf("Error initializing weldr API: %v", err)
}
}
if l, exists := listeners["osbuild-local-worker.socket"]; exists {
if len(l) != 1 {
log.Fatal("The osbuild-local-worker.socket unit is misconfigured. It should contain only one socket.")
}
composer.InitLocalWorker(l[0])
}
if l, exists := listeners["osbuild-composer-api.socket"]; exists {
if len(l) != 1 {
log.Fatal("The osbuild-composer-api.socket unit is misconfigured. It should contain only one socket.")
}
err = composer.InitAPI(ServerCertFile, ServerKeyFile, config.ComposerAPI.EnableJWT, l[0])
if err != nil {
log.Fatalf("Error initializing koji API: %v", err)
}
}
if l, exists := listeners["osbuild-remote-worker.socket"]; exists {
if len(l) != 1 {
log.Fatal("The osbuild-remote-worker.socket unit is misconfigured. It should contain only one socket.")
}
err = composer.InitRemoteWorkers(ServerCertFile, ServerKeyFile, config.Worker.EnableJWT, l[0])
if err != nil {
log.Fatalf("Error initializing worker API: %v", err)
}
}
err = composer.Start()
if err != nil {
log.Fatalf("%v", err)
}
}