diff --git a/authorization/authz_test.go b/authorization/authz_test.go index 369150b..75c549b 100644 --- a/authorization/authz_test.go +++ b/authorization/authz_test.go @@ -13,7 +13,7 @@ import ( "testing" "github.com/docker/docker/pkg/plugins" - "github.com/docker/docker/pkg/tlsconfig" + "github.com/docker/go-connections/tlsconfig" "github.com/gorilla/mux" ) diff --git a/discovery/kv/kv.go b/discovery/kv/kv.go index 186bf57..8b7b4ed 100644 --- a/discovery/kv/kv.go +++ b/discovery/kv/kv.go @@ -8,7 +8,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/docker/docker/pkg/discovery" - "github.com/docker/docker/pkg/tlsconfig" + "github.com/docker/go-connections/tlsconfig" "github.com/docker/libkv" "github.com/docker/libkv/store" "github.com/docker/libkv/store/consul" diff --git a/plugins/client.go b/plugins/client.go index e9e31a8..d871012 100644 --- a/plugins/client.go +++ b/plugins/client.go @@ -11,8 +11,8 @@ import ( "time" "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/sockets" - "github.com/docker/docker/pkg/tlsconfig" + "github.com/docker/go-connections/sockets" + "github.com/docker/go-connections/tlsconfig" ) const ( diff --git a/plugins/client_test.go b/plugins/client_test.go index 3def6e2..d9e14e2 100644 --- a/plugins/client_test.go +++ b/plugins/client_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/docker/docker/pkg/tlsconfig" + "github.com/docker/go-connections/tlsconfig" ) var ( diff --git a/plugins/plugins.go b/plugins/plugins.go index 5ad4d89..6317e4f 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -28,7 +28,7 @@ import ( "time" "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/tlsconfig" + "github.com/docker/go-connections/tlsconfig" ) var ( diff --git a/sockets/README.md b/sockets/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/sockets/tcp_socket.go b/sockets/tcp_socket.go deleted file mode 100644 index 6665a3b..0000000 --- a/sockets/tcp_socket.go +++ /dev/null @@ -1,44 +0,0 @@ -// Package sockets provides helper functions to create and configure Unix or TCP -// sockets. -package sockets - -import ( - "crypto/tls" - "net" - "net/http" - "time" -) - -// NewTCPSocket creates a TCP socket listener with the specified address and -// and the specified tls configuration. If TLSConfig is set, will encapsulate the -// TCP listener inside a TLS one. -func NewTCPSocket(addr string, tlsConfig *tls.Config) (net.Listener, error) { - l, err := net.Listen("tcp", addr) - if err != nil { - return nil, err - } - if tlsConfig != nil { - tlsConfig.NextProtos = []string{"http/1.1"} - l = tls.NewListener(l, tlsConfig) - } - return l, nil -} - -// ConfigureTCPTransport configures the specified Transport according to the -// specified proto and addr. -// If the proto is unix (using a unix socket to communicate) the compression -// is disabled. -func ConfigureTCPTransport(tr *http.Transport, proto, addr string) { - // Why 32? See https://github.com/docker/docker/pull/8035. - timeout := 32 * time.Second - if proto == "unix" { - // No need for compression in local communications. - tr.DisableCompression = true - tr.Dial = func(_, _ string) (net.Conn, error) { - return net.DialTimeout(proto, addr, timeout) - } - } else { - tr.Proxy = http.ProxyFromEnvironment - tr.Dial = (&net.Dialer{Timeout: timeout}).Dial - } -} diff --git a/sockets/unix_socket.go b/sockets/unix_socket.go deleted file mode 100644 index c10aced..0000000 --- a/sockets/unix_socket.go +++ /dev/null @@ -1,80 +0,0 @@ -// +build linux freebsd - -package sockets - -import ( - "fmt" - "net" - "os" - "strconv" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/opencontainers/runc/libcontainer/user" -) - -// NewUnixSocket creates a unix socket with the specified path and group. -func NewUnixSocket(path, group string) (net.Listener, error) { - if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) { - return nil, err - } - mask := syscall.Umask(0777) - defer syscall.Umask(mask) - l, err := net.Listen("unix", path) - if err != nil { - return nil, err - } - if err := setSocketGroup(path, group); err != nil { - l.Close() - return nil, err - } - if err := os.Chmod(path, 0660); err != nil { - l.Close() - return nil, err - } - return l, nil -} - -func setSocketGroup(path, group string) error { - if group == "" { - return nil - } - if err := changeGroup(path, group); err != nil { - if group != "docker" { - return err - } - logrus.Debugf("Warning: could not change group %s to docker: %v", path, err) - } - return nil -} - -func changeGroup(path string, nameOrGid string) error { - gid, err := lookupGidByName(nameOrGid) - if err != nil { - return err - } - logrus.Debugf("%s group found. gid: %d", nameOrGid, gid) - return os.Chown(path, 0, gid) -} - -func lookupGidByName(nameOrGid string) (int, error) { - groupFile, err := user.GetGroupPath() - if err != nil { - return -1, err - } - groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool { - return g.Name == nameOrGid || strconv.Itoa(g.Gid) == nameOrGid - }) - if err != nil { - return -1, err - } - if groups != nil && len(groups) > 0 { - return groups[0].Gid, nil - } - gid, err := strconv.Atoi(nameOrGid) - if err == nil { - logrus.Warnf("Could not find GID %d", gid) - return gid, nil - } - return -1, fmt.Errorf("Group %s not found", nameOrGid) -}