worker: Prefix https always
Also, with oauth, add a root CA if present.
This commit is contained in:
parent
0f44250237
commit
cb5acbac74
2 changed files with 39 additions and 32 deletions
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -49,14 +48,18 @@ func createTLSConfig(config *connectionConfig) (*tls.Config, error) {
|
||||||
return nil, errors.New("failed to append root certificate")
|
return nil, errors.New("failed to append root certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := tls.LoadX509KeyPair(config.ClientCertFile, config.ClientKeyFile)
|
var certs []tls.Certificate
|
||||||
if err != nil {
|
if config.ClientKeyFile != "" && config.ClientCertFile != "" {
|
||||||
return nil, err
|
cert, err := tls.LoadX509KeyPair(config.ClientCertFile, config.ClientKeyFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
certs = append(certs, cert)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tls.Config{
|
return &tls.Config{
|
||||||
RootCAs: roots,
|
RootCAs: roots,
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: certs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,33 +159,37 @@ func main() {
|
||||||
var client *worker.Client
|
var client *worker.Client
|
||||||
if unix {
|
if unix {
|
||||||
client = worker.NewClientUnix(address, config.BasePath)
|
client = worker.NewClientUnix(address, config.BasePath)
|
||||||
} else {
|
} else if config.Authentication != nil && config.Authentication.OfflineTokenPath != "" {
|
||||||
var token *string
|
var conf *tls.Config
|
||||||
var oAuthURL *string
|
conConf := &connectionConfig{
|
||||||
if config.Authentication != nil && config.Authentication.OfflineTokenPath != "" {
|
CACertFile: "/etc/osbuild-composer/ca-crt.pem",
|
||||||
t, err := ioutil.ReadFile(config.Authentication.OfflineTokenPath)
|
}
|
||||||
|
if _, err = os.Stat(conConf.CACertFile); err == nil {
|
||||||
|
conf, err = createTLSConfig(conConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Could not read offline token: %v", err)
|
logrus.Fatalf("Error creating TLS config: %v", err)
|
||||||
}
|
|
||||||
t2 := strings.TrimSpace(string(t))
|
|
||||||
token = &t2
|
|
||||||
|
|
||||||
if config.Authentication.OAuthURL == "" {
|
|
||||||
logrus.Fatal("OAuth URL should be specified together with the offline token")
|
|
||||||
}
|
|
||||||
oAuthURL = &config.Authentication.OAuthURL
|
|
||||||
|
|
||||||
if strings.HasPrefix(address, "http") {
|
|
||||||
out, err := exec.Command("systemd-escape", "-u", address).Output()
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatalf("Could not escape remote worker address: %v", err)
|
|
||||||
}
|
|
||||||
address = strings.TrimSpace(string(out))
|
|
||||||
} else {
|
|
||||||
address = fmt.Sprintf("https://%s", address)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var token *string
|
||||||
|
var oAuthURL *string
|
||||||
|
t, err := ioutil.ReadFile(config.Authentication.OfflineTokenPath)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatalf("Could not read offline token: %v", err)
|
||||||
|
}
|
||||||
|
t2 := strings.TrimSpace(string(t))
|
||||||
|
token = &t2
|
||||||
|
|
||||||
|
if config.Authentication.OAuthURL == "" {
|
||||||
|
logrus.Fatal("OAuth URL should be specified together with the offline token")
|
||||||
|
}
|
||||||
|
oAuthURL = &config.Authentication.OAuthURL
|
||||||
|
|
||||||
|
client, err = worker.NewClient(fmt.Sprintf("https://%s", address), conf, token, oAuthURL, config.BasePath)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatalf("Error creating worker client: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
var conf *tls.Config
|
var conf *tls.Config
|
||||||
conConf := &connectionConfig{
|
conConf := &connectionConfig{
|
||||||
CACertFile: "/etc/osbuild-composer/ca-crt.pem",
|
CACertFile: "/etc/osbuild-composer/ca-crt.pem",
|
||||||
|
|
@ -196,7 +203,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err = worker.NewClient(address, conf, token, oAuthURL, config.BasePath)
|
client, err = worker.NewClient(fmt.Sprintf("https://%s", address), conf, nil, nil, config.BasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Error creating worker client: %v", err)
|
logrus.Fatalf("Error creating worker client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1179,7 +1179,7 @@ pg_database = "osbuildcomposer"
|
||||||
pg_user = "postgres"
|
pg_user = "postgres"
|
||||||
pg_password = "foobar"
|
pg_password = "foobar"
|
||||||
pg_ssl_mode = "disable"
|
pg_ssl_mode = "disable"
|
||||||
enable_tls = false
|
enable_tls = true
|
||||||
enable_mtls = false
|
enable_mtls = false
|
||||||
enable_jwt = true
|
enable_jwt = true
|
||||||
jwt_keys_url = "https://localhost:8080/certs"
|
jwt_keys_url = "https://localhost:8080/certs"
|
||||||
|
|
@ -1224,7 +1224,7 @@ TOKEN="$(curl localhost:8081/token | jq -r .access_token)"
|
||||||
--header "Authorization: Bearer badtoken" \
|
--header "Authorization: Bearer badtoken" \
|
||||||
http://localhost:443/api/composer/v1/version)" = "401" ]
|
http://localhost:443/api/composer/v1/version)" = "401" ]
|
||||||
|
|
||||||
sudo systemctl start osbuild-remote-worker@http:--localhost:8700.service
|
sudo systemctl start osbuild-remote-worker@localhost:8700.service
|
||||||
sudo systemctl is-active --quiet osbuild-remote-worker@http:--localhost:8700.service
|
sudo systemctl is-active --quiet osbuild-remote-worker@localhost:8700.service
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue