[transport] make tls client and server commandline parameters for consistency with docker + guess tls-server-name from target address in client if not specified explicitly;

docker-18.09
Tino Rusch 2017-12-21 06:18:54 +01:00
parent 03f717bd32
commit 98a836592e
No known key found for this signature in database
GPG Key ID: E931E57509A81CEA
2 changed files with 21 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"net/url"
"os" "os"
"github.com/moby/buildkit/client" "github.com/moby/buildkit/client"
@ -32,22 +33,22 @@ func main() {
Value: defaultAddress, Value: defaultAddress,
}, },
cli.StringFlag{ cli.StringFlag{
Name: "server-name", Name: "tlsservername",
Usage: "buildkitd server name for certificate validation", Usage: "buildkitd server name for certificate validation",
Value: "", Value: "",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "ca-cert", Name: "tlscacert",
Usage: "CA certificate for validation", Usage: "CA certificate for validation",
Value: "", Value: "",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "cert", Name: "tlscert",
Usage: "client certificate", Usage: "client certificate",
Value: "", Value: "",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "key", Name: "tlskey",
Usage: "client key", Usage: "client key",
Value: "", Value: "",
}, },
@ -82,12 +83,20 @@ func main() {
} }
func resolveClient(c *cli.Context) (*client.Client, error) { func resolveClient(c *cli.Context) (*client.Client, error) {
serverName := c.GlobalString("server-name") serverName := c.GlobalString("tlsservername")
caCert := c.GlobalString("ca-cert") if serverName == "" {
cert := c.GlobalString("cert") // guess servername as hostname of target address
key := c.GlobalString("key") uri, err := url.Parse(c.GlobalString("addr"))
if err != nil {
return nil, err
}
serverName = uri.Hostname()
}
caCert := c.GlobalString("tlscacert")
cert := c.GlobalString("tlscert")
key := c.GlobalString("tlskey")
opts := []client.ClientOpt{client.WithBlock()} opts := []client.ClientOpt{client.WithBlock()}
if serverName != "" { if caCert != "" || cert != "" || key != "" {
opts = append(opts, client.WithCredentials(serverName, caCert, cert, key)) opts = append(opts, client.WithCredentials(serverName, caCert, cert, key))
} }
return client.New(c.GlobalString("addr"), opts...) return client.New(c.GlobalString("addr"), opts...)

View File

@ -84,15 +84,15 @@ func main() {
Value: "", Value: "",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "cert", Name: "tlscert",
Usage: "certificate file to use", Usage: "certificate file to use",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "key", Name: "tlskey",
Usage: "key file to use", Usage: "key file to use",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "ca-cert", Name: "tlscacert",
Usage: "ca certificate to verify clients", Usage: "ca certificate to verify clients",
}, },
} }