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

View File

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