mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	update cadvisor, docker, and runc godeps
This commit is contained in:
		
							
								
								
									
										177
									
								
								vendor/github.com/docker/go-connections/nat/nat.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										177
									
								
								vendor/github.com/docker/go-connections/nat/nat.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -85,14 +85,10 @@ func (p Port) Port() string {
 | 
			
		||||
// Int returns the port number of a Port as an int
 | 
			
		||||
func (p Port) Int() int {
 | 
			
		||||
	portStr := p.Port()
 | 
			
		||||
	if len(portStr) == 0 {
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// We don't need to check for an error because we're going to
 | 
			
		||||
	// assume that any error would have been found, and reported, in NewPort()
 | 
			
		||||
	port, _ := strconv.ParseUint(portStr, 10, 16)
 | 
			
		||||
	return int(port)
 | 
			
		||||
	port, _ := ParsePort(portStr)
 | 
			
		||||
	return port
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Range returns the start/end port numbers of a Port range as ints
 | 
			
		||||
@@ -132,92 +128,115 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding,
 | 
			
		||||
		exposedPorts = make(map[Port]struct{}, len(ports))
 | 
			
		||||
		bindings     = make(map[Port][]PortBinding)
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	for _, rawPort := range ports {
 | 
			
		||||
		proto := "tcp"
 | 
			
		||||
 | 
			
		||||
		if i := strings.LastIndex(rawPort, "/"); i != -1 {
 | 
			
		||||
			proto = rawPort[i+1:]
 | 
			
		||||
			rawPort = rawPort[:i]
 | 
			
		||||
		}
 | 
			
		||||
		if !strings.Contains(rawPort, ":") {
 | 
			
		||||
			rawPort = fmt.Sprintf("::%s", rawPort)
 | 
			
		||||
		} else if len(strings.Split(rawPort, ":")) == 2 {
 | 
			
		||||
			rawPort = fmt.Sprintf(":%s", rawPort)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		parts, err := PartParser(portSpecTemplate, rawPort)
 | 
			
		||||
		portMappings, err := ParsePortSpec(rawPort)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var (
 | 
			
		||||
			containerPort = parts["containerPort"]
 | 
			
		||||
			rawIP         = parts["ip"]
 | 
			
		||||
			hostPort      = parts["hostPort"]
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		if rawIP != "" && net.ParseIP(rawIP) == nil {
 | 
			
		||||
			return nil, nil, fmt.Errorf("Invalid ip address: %s", rawIP)
 | 
			
		||||
		}
 | 
			
		||||
		if containerPort == "" {
 | 
			
		||||
			return nil, nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		startPort, endPort, err := ParsePortRange(containerPort)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, nil, fmt.Errorf("Invalid containerPort: %s", containerPort)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var startHostPort, endHostPort uint64 = 0, 0
 | 
			
		||||
		if len(hostPort) > 0 {
 | 
			
		||||
			startHostPort, endHostPort, err = ParsePortRange(hostPort)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, nil, fmt.Errorf("Invalid hostPort: %s", hostPort)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if hostPort != "" && (endPort-startPort) != (endHostPort-startHostPort) {
 | 
			
		||||
			// Allow host port range iff containerPort is not a range.
 | 
			
		||||
			// In this case, use the host port range as the dynamic
 | 
			
		||||
			// host port range to allocate into.
 | 
			
		||||
			if endPort != startPort {
 | 
			
		||||
				return nil, nil, fmt.Errorf("Invalid ranges specified for container and host Ports: %s and %s", containerPort, hostPort)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if !validateProto(strings.ToLower(proto)) {
 | 
			
		||||
			return nil, nil, fmt.Errorf("Invalid proto: %s", proto)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for i := uint64(0); i <= (endPort - startPort); i++ {
 | 
			
		||||
			containerPort = strconv.FormatUint(startPort+i, 10)
 | 
			
		||||
			if len(hostPort) > 0 {
 | 
			
		||||
				hostPort = strconv.FormatUint(startHostPort+i, 10)
 | 
			
		||||
			}
 | 
			
		||||
			// Set hostPort to a range only if there is a single container port
 | 
			
		||||
			// and a dynamic host port.
 | 
			
		||||
			if startPort == endPort && startHostPort != endHostPort {
 | 
			
		||||
				hostPort = fmt.Sprintf("%s-%s", hostPort, strconv.FormatUint(endHostPort, 10))
 | 
			
		||||
			}
 | 
			
		||||
			port, err := NewPort(strings.ToLower(proto), containerPort)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, nil, err
 | 
			
		||||
			}
 | 
			
		||||
		for _, portMapping := range portMappings {
 | 
			
		||||
			port := portMapping.Port
 | 
			
		||||
			if _, exists := exposedPorts[port]; !exists {
 | 
			
		||||
				exposedPorts[port] = struct{}{}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			binding := PortBinding{
 | 
			
		||||
				HostIP:   rawIP,
 | 
			
		||||
				HostPort: hostPort,
 | 
			
		||||
			}
 | 
			
		||||
			bslice, exists := bindings[port]
 | 
			
		||||
			if !exists {
 | 
			
		||||
				bslice = []PortBinding{}
 | 
			
		||||
			}
 | 
			
		||||
			bindings[port] = append(bslice, binding)
 | 
			
		||||
			bindings[port] = append(bslice, portMapping.Binding)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return exposedPorts, bindings, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PortMapping is a data object mapping a Port to a PortBinding
 | 
			
		||||
type PortMapping struct {
 | 
			
		||||
	Port    Port
 | 
			
		||||
	Binding PortBinding
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func splitParts(rawport string) (string, string, string) {
 | 
			
		||||
	parts := strings.Split(rawport, ":")
 | 
			
		||||
	n := len(parts)
 | 
			
		||||
	containerport := parts[n-1]
 | 
			
		||||
 | 
			
		||||
	switch n {
 | 
			
		||||
	case 1:
 | 
			
		||||
		return "", "", containerport
 | 
			
		||||
	case 2:
 | 
			
		||||
		return "", parts[0], containerport
 | 
			
		||||
	case 3:
 | 
			
		||||
		return parts[0], parts[1], containerport
 | 
			
		||||
	default:
 | 
			
		||||
		return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ParsePortSpec parses a port specification string into a slice of PortMappings
 | 
			
		||||
func ParsePortSpec(rawPort string) ([]PortMapping, error) {
 | 
			
		||||
	var proto string
 | 
			
		||||
	rawIP, hostPort, containerPort := splitParts(rawPort)
 | 
			
		||||
	proto, containerPort = SplitProtoPort(containerPort)
 | 
			
		||||
 | 
			
		||||
	// Strip [] from IPV6 addresses
 | 
			
		||||
	ip, _, err := net.SplitHostPort(rawIP + ":")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Invalid ip address %v: %s", rawIP, err)
 | 
			
		||||
	}
 | 
			
		||||
	if ip != "" && net.ParseIP(ip) == nil {
 | 
			
		||||
		return nil, fmt.Errorf("Invalid ip address: %s", ip)
 | 
			
		||||
	}
 | 
			
		||||
	if containerPort == "" {
 | 
			
		||||
		return nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	startPort, endPort, err := ParsePortRange(containerPort)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Invalid containerPort: %s", containerPort)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var startHostPort, endHostPort uint64 = 0, 0
 | 
			
		||||
	if len(hostPort) > 0 {
 | 
			
		||||
		startHostPort, endHostPort, err = ParsePortRange(hostPort)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("Invalid hostPort: %s", hostPort)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if hostPort != "" && (endPort-startPort) != (endHostPort-startHostPort) {
 | 
			
		||||
		// Allow host port range iff containerPort is not a range.
 | 
			
		||||
		// In this case, use the host port range as the dynamic
 | 
			
		||||
		// host port range to allocate into.
 | 
			
		||||
		if endPort != startPort {
 | 
			
		||||
			return nil, fmt.Errorf("Invalid ranges specified for container and host Ports: %s and %s", containerPort, hostPort)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !validateProto(strings.ToLower(proto)) {
 | 
			
		||||
		return nil, fmt.Errorf("Invalid proto: %s", proto)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ports := []PortMapping{}
 | 
			
		||||
	for i := uint64(0); i <= (endPort - startPort); i++ {
 | 
			
		||||
		containerPort = strconv.FormatUint(startPort+i, 10)
 | 
			
		||||
		if len(hostPort) > 0 {
 | 
			
		||||
			hostPort = strconv.FormatUint(startHostPort+i, 10)
 | 
			
		||||
		}
 | 
			
		||||
		// Set hostPort to a range only if there is a single container port
 | 
			
		||||
		// and a dynamic host port.
 | 
			
		||||
		if startPort == endPort && startHostPort != endHostPort {
 | 
			
		||||
			hostPort = fmt.Sprintf("%s-%s", hostPort, strconv.FormatUint(endHostPort, 10))
 | 
			
		||||
		}
 | 
			
		||||
		port, err := NewPort(strings.ToLower(proto), containerPort)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		binding := PortBinding{
 | 
			
		||||
			HostIP:   ip,
 | 
			
		||||
			HostPort: hostPort,
 | 
			
		||||
		}
 | 
			
		||||
		ports = append(ports, PortMapping{Port: port, Binding: binding})
 | 
			
		||||
	}
 | 
			
		||||
	return ports, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/docker/go-connections/nat/parse.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/docker/go-connections/nat/parse.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -8,6 +8,7 @@ import (
 | 
			
		||||
 | 
			
		||||
// PartParser parses and validates the specified string (data) using the specified template
 | 
			
		||||
// e.g. ip:public:private -> 192.168.0.1:80:8000
 | 
			
		||||
// DEPRECATED: do not use, this function may be removed in a future version
 | 
			
		||||
func PartParser(template, data string) (map[string]string, error) {
 | 
			
		||||
	// ip:public:private
 | 
			
		||||
	var (
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								vendor/github.com/docker/go-connections/sockets/BUILD
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								vendor/github.com/docker/go-connections/sockets/BUILD
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -8,10 +8,8 @@ go_library(
 | 
			
		||||
        "sockets.go",
 | 
			
		||||
        "sockets_unix.go",
 | 
			
		||||
        "tcp_socket.go",
 | 
			
		||||
        "unix_socket.go",
 | 
			
		||||
    ] + select({
 | 
			
		||||
        "@io_bazel_rules_go//go/platform:linux_amd64": [
 | 
			
		||||
            "unix_socket.go",
 | 
			
		||||
        ],
 | 
			
		||||
        "@io_bazel_rules_go//go/platform:windows_amd64": [
 | 
			
		||||
            "sockets_windows.go",
 | 
			
		||||
        ],
 | 
			
		||||
@@ -21,10 +19,6 @@ go_library(
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//vendor/golang.org/x/net/proxy:go_default_library",
 | 
			
		||||
    ] + select({
 | 
			
		||||
        "@io_bazel_rules_go//go/platform:linux_amd64": [
 | 
			
		||||
            "//vendor/github.com/Sirupsen/logrus:go_default_library",
 | 
			
		||||
            "//vendor/github.com/opencontainers/runc/libcontainer/user:go_default_library",
 | 
			
		||||
        ],
 | 
			
		||||
        "@io_bazel_rules_go//go/platform:windows_amd64": [
 | 
			
		||||
            "//vendor/github.com/Microsoft/go-winio:go_default_library",
 | 
			
		||||
        ],
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								vendor/github.com/docker/go-connections/sockets/inmem_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								vendor/github.com/docker/go-connections/sockets/inmem_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -79,11 +79,3 @@ func (a dummyAddr) Network() string {
 | 
			
		||||
func (a dummyAddr) String() string {
 | 
			
		||||
	return string(a)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// timeoutError is used when there is a timeout with a connection
 | 
			
		||||
// this implements the net.Error interface
 | 
			
		||||
type timeoutError struct{}
 | 
			
		||||
 | 
			
		||||
func (e *timeoutError) Error() string   { return "i/o timeout" }
 | 
			
		||||
func (e *timeoutError) Timeout() bool   { return true }
 | 
			
		||||
func (e *timeoutError) Temporary() bool { return true }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								vendor/github.com/docker/go-connections/sockets/sockets.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								vendor/github.com/docker/go-connections/sockets/sockets.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -2,6 +2,7 @@
 | 
			
		||||
package sockets
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -10,6 +11,9 @@ import (
 | 
			
		||||
// Why 32? See https://github.com/docker/docker/pull/8035.
 | 
			
		||||
const defaultTimeout = 32 * time.Second
 | 
			
		||||
 | 
			
		||||
// ErrProtocolNotAvailable is returned when a given transport protocol is not provided by the operating system.
 | 
			
		||||
var ErrProtocolNotAvailable = errors.New("protocol not available")
 | 
			
		||||
 | 
			
		||||
// ConfigureTransport configures the specified Transport according to the
 | 
			
		||||
// specified proto and addr.
 | 
			
		||||
// If the proto is unix (using a unix socket to communicate) or npipe the
 | 
			
		||||
@@ -17,17 +21,9 @@ const defaultTimeout = 32 * time.Second
 | 
			
		||||
func ConfigureTransport(tr *http.Transport, proto, addr string) error {
 | 
			
		||||
	switch proto {
 | 
			
		||||
	case "unix":
 | 
			
		||||
		// No need for compression in local communications.
 | 
			
		||||
		tr.DisableCompression = true
 | 
			
		||||
		tr.Dial = func(_, _ string) (net.Conn, error) {
 | 
			
		||||
			return net.DialTimeout(proto, addr, defaultTimeout)
 | 
			
		||||
		}
 | 
			
		||||
		return configureUnixTransport(tr, proto, addr)
 | 
			
		||||
	case "npipe":
 | 
			
		||||
		// No need for compression in local communications.
 | 
			
		||||
		tr.DisableCompression = true
 | 
			
		||||
		tr.Dial = func(_, _ string) (net.Conn, error) {
 | 
			
		||||
			return DialPipe(addr, defaultTimeout)
 | 
			
		||||
		}
 | 
			
		||||
		return configureNpipeTransport(tr, proto, addr)
 | 
			
		||||
	default:
 | 
			
		||||
		tr.Proxy = http.ProxyFromEnvironment
 | 
			
		||||
		dialer, err := DialerFromEnvironment(&net.Dialer{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								vendor/github.com/docker/go-connections/sockets/sockets_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										20
									
								
								vendor/github.com/docker/go-connections/sockets/sockets_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -3,11 +3,31 @@
 | 
			
		||||
package sockets
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)
 | 
			
		||||
 | 
			
		||||
func configureUnixTransport(tr *http.Transport, proto, addr string) error {
 | 
			
		||||
	if len(addr) > maxUnixSocketPathSize {
 | 
			
		||||
		return fmt.Errorf("Unix socket path %q is too long", addr)
 | 
			
		||||
	}
 | 
			
		||||
	// No need for compression in local communications.
 | 
			
		||||
	tr.DisableCompression = true
 | 
			
		||||
	tr.Dial = func(_, _ string) (net.Conn, error) {
 | 
			
		||||
		return net.DialTimeout(proto, addr, defaultTimeout)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
 | 
			
		||||
	return ErrProtocolNotAvailable
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DialPipe connects to a Windows named pipe.
 | 
			
		||||
// This is not supported on other OSes.
 | 
			
		||||
func DialPipe(_ string, _ time.Duration) (net.Conn, error) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								vendor/github.com/docker/go-connections/sockets/sockets_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/docker/go-connections/sockets/sockets_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -2,11 +2,25 @@ package sockets
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func configureUnixTransport(tr *http.Transport, proto, addr string) error {
 | 
			
		||||
	return ErrProtocolNotAvailable
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
 | 
			
		||||
	// No need for compression in local communications.
 | 
			
		||||
	tr.DisableCompression = true
 | 
			
		||||
	tr.Dial = func(_, _ string) (net.Conn, error) {
 | 
			
		||||
		return DialPipe(addr, defaultTimeout)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DialPipe connects to a Windows named pipe.
 | 
			
		||||
func DialPipe(addr string, timeout time.Duration) (net.Conn, error) {
 | 
			
		||||
	return winio.DialPipe(addr, &timeout)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/docker/go-connections/sockets/tcp_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/docker/go-connections/sockets/tcp_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -7,7 +7,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NewTCPSocket creates a TCP socket listener with the specified address and
 | 
			
		||||
// and the specified tls configuration. If TLSConfig is set, will encapsulate the
 | 
			
		||||
// 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)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										56
									
								
								vendor/github.com/docker/go-connections/sockets/unix_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										56
									
								
								vendor/github.com/docker/go-connections/sockets/unix_socket.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,30 +1,26 @@
 | 
			
		||||
// +build linux freebsd solaris
 | 
			
		||||
// +build !windows
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
func NewUnixSocket(path string, gid int) (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 {
 | 
			
		||||
	if err := os.Chown(path, 0, gid); err != nil {
 | 
			
		||||
		l.Close()
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -34,47 +30,3 @@ func NewUnixSocket(path, group string) (net.Listener, error) {
 | 
			
		||||
	}
 | 
			
		||||
	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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								vendor/github.com/docker/go-connections/tlsconfig/BUILD
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/docker/go-connections/tlsconfig/BUILD
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -3,12 +3,14 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
 | 
			
		||||
go_library(
 | 
			
		||||
    name = "go_default_library",
 | 
			
		||||
    srcs = [
 | 
			
		||||
        "certpool_go17.go",
 | 
			
		||||
        "certpool_other.go",
 | 
			
		||||
        "config.go",
 | 
			
		||||
        "config_client_ciphers.go",
 | 
			
		||||
        "config_legacy_client_ciphers.go",
 | 
			
		||||
    ],
 | 
			
		||||
    visibility = ["//visibility:public"],
 | 
			
		||||
    deps = ["//vendor/github.com/Sirupsen/logrus:go_default_library"],
 | 
			
		||||
    deps = ["//vendor/github.com/pkg/errors:go_default_library"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
filegroup(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								vendor/github.com/docker/go-connections/tlsconfig/certpool_go17.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/docker/go-connections/tlsconfig/certpool_go17.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
// +build go1.7
 | 
			
		||||
 | 
			
		||||
package tlsconfig
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/x509"
 | 
			
		||||
	"runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// SystemCertPool returns a copy of the system cert pool,
 | 
			
		||||
// returns an error if failed to load or empty pool on windows.
 | 
			
		||||
func SystemCertPool() (*x509.CertPool, error) {
 | 
			
		||||
	certpool, err := x509.SystemCertPool()
 | 
			
		||||
	if err != nil && runtime.GOOS == "windows" {
 | 
			
		||||
		return x509.NewCertPool(), nil
 | 
			
		||||
	}
 | 
			
		||||
	return certpool, err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								vendor/github.com/docker/go-connections/tlsconfig/certpool_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/docker/go-connections/tlsconfig/certpool_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
// +build !go1.7
 | 
			
		||||
 | 
			
		||||
package tlsconfig
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/x509"
 | 
			
		||||
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// SystemCertPool returns an new empty cert pool,
 | 
			
		||||
// accessing system cert pool is supported in go 1.7
 | 
			
		||||
func SystemCertPool() (*x509.CertPool, error) {
 | 
			
		||||
	return x509.NewCertPool(), nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										180
									
								
								vendor/github.com/docker/go-connections/tlsconfig/config.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										180
									
								
								vendor/github.com/docker/go-connections/tlsconfig/config.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -8,11 +8,12 @@ package tlsconfig
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/tls"
 | 
			
		||||
	"crypto/x509"
 | 
			
		||||
	"encoding/pem"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/Sirupsen/logrus"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Options represents the information needed to create client and server TLS configurations.
 | 
			
		||||
@@ -29,6 +30,14 @@ type Options struct {
 | 
			
		||||
	InsecureSkipVerify bool
 | 
			
		||||
	// server-only option
 | 
			
		||||
	ClientAuth tls.ClientAuthType
 | 
			
		||||
	// If ExclusiveRootPools is set, then if a CA file is provided, the root pool used for TLS
 | 
			
		||||
	// creds will include exclusively the roots in that CA file.  If no CA file is provided,
 | 
			
		||||
	// the system pool will be used.
 | 
			
		||||
	ExclusiveRootPools bool
 | 
			
		||||
	MinVersion         uint16
 | 
			
		||||
	// If Passphrase is set, it will be used to decrypt a TLS private key
 | 
			
		||||
	// if the key is encrypted
 | 
			
		||||
	Passphrase string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Extra (server-side) accepted CBC cipher suites - will phase out in the future
 | 
			
		||||
@@ -46,62 +55,170 @@ var acceptedCBCCiphers = []uint16{
 | 
			
		||||
// known weak algorithms removed.
 | 
			
		||||
var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers...)
 | 
			
		||||
 | 
			
		||||
// ServerDefault is a secure-enough TLS configuration for the server TLS configuration.
 | 
			
		||||
var ServerDefault = tls.Config{
 | 
			
		||||
	// Avoid fallback to SSL protocols < TLS1.0
 | 
			
		||||
	MinVersion:               tls.VersionTLS10,
 | 
			
		||||
	PreferServerCipherSuites: true,
 | 
			
		||||
	CipherSuites:             DefaultServerAcceptedCiphers,
 | 
			
		||||
// allTLSVersions lists all the TLS versions and is used by the code that validates
 | 
			
		||||
// a uint16 value as a TLS version.
 | 
			
		||||
var allTLSVersions = map[uint16]struct{}{
 | 
			
		||||
	tls.VersionSSL30: {},
 | 
			
		||||
	tls.VersionTLS10: {},
 | 
			
		||||
	tls.VersionTLS11: {},
 | 
			
		||||
	tls.VersionTLS12: {},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClientDefault is a secure-enough TLS configuration for the client TLS configuration.
 | 
			
		||||
var ClientDefault = tls.Config{
 | 
			
		||||
	// Prefer TLS1.2 as the client minimum
 | 
			
		||||
	MinVersion:   tls.VersionTLS12,
 | 
			
		||||
	CipherSuites: clientCipherSuites,
 | 
			
		||||
// ServerDefault returns a secure-enough TLS configuration for the server TLS configuration.
 | 
			
		||||
func ServerDefault() *tls.Config {
 | 
			
		||||
	return &tls.Config{
 | 
			
		||||
		// Avoid fallback to SSL protocols < TLS1.0
 | 
			
		||||
		MinVersion:               tls.VersionTLS10,
 | 
			
		||||
		PreferServerCipherSuites: true,
 | 
			
		||||
		CipherSuites:             DefaultServerAcceptedCiphers,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClientDefault returns a secure-enough TLS configuration for the client TLS configuration.
 | 
			
		||||
func ClientDefault() *tls.Config {
 | 
			
		||||
	return &tls.Config{
 | 
			
		||||
		// Prefer TLS1.2 as the client minimum
 | 
			
		||||
		MinVersion:   tls.VersionTLS12,
 | 
			
		||||
		CipherSuites: clientCipherSuites,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// certPool returns an X.509 certificate pool from `caFile`, the certificate file.
 | 
			
		||||
func certPool(caFile string) (*x509.CertPool, error) {
 | 
			
		||||
func certPool(caFile string, exclusivePool bool) (*x509.CertPool, error) {
 | 
			
		||||
	// If we should verify the server, we need to load a trusted ca
 | 
			
		||||
	certPool := x509.NewCertPool()
 | 
			
		||||
	var (
 | 
			
		||||
		certPool *x509.CertPool
 | 
			
		||||
		err      error
 | 
			
		||||
	)
 | 
			
		||||
	if exclusivePool {
 | 
			
		||||
		certPool = x509.NewCertPool()
 | 
			
		||||
	} else {
 | 
			
		||||
		certPool, err = SystemCertPool()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("failed to read system certificates: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pem, err := ioutil.ReadFile(caFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Could not read CA certificate %q: %v", caFile, err)
 | 
			
		||||
		return nil, fmt.Errorf("could not read CA certificate %q: %v", caFile, err)
 | 
			
		||||
	}
 | 
			
		||||
	if !certPool.AppendCertsFromPEM(pem) {
 | 
			
		||||
		return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile)
 | 
			
		||||
	}
 | 
			
		||||
	logrus.Debugf("Trusting %d certs", len(certPool.Subjects()))
 | 
			
		||||
	return certPool, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// isValidMinVersion checks that the input value is a valid tls minimum version
 | 
			
		||||
func isValidMinVersion(version uint16) bool {
 | 
			
		||||
	_, ok := allTLSVersions[version]
 | 
			
		||||
	return ok
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// adjustMinVersion sets the MinVersion on `config`, the input configuration.
 | 
			
		||||
// It assumes the current MinVersion on the `config` is the lowest allowed.
 | 
			
		||||
func adjustMinVersion(options Options, config *tls.Config) error {
 | 
			
		||||
	if options.MinVersion > 0 {
 | 
			
		||||
		if !isValidMinVersion(options.MinVersion) {
 | 
			
		||||
			return fmt.Errorf("Invalid minimum TLS version: %x", options.MinVersion)
 | 
			
		||||
		}
 | 
			
		||||
		if options.MinVersion < config.MinVersion {
 | 
			
		||||
			return fmt.Errorf("Requested minimum TLS version is too low. Should be at-least: %x", config.MinVersion)
 | 
			
		||||
		}
 | 
			
		||||
		config.MinVersion = options.MinVersion
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsErrEncryptedKey returns true if the 'err' is an error of incorrect
 | 
			
		||||
// password when tryin to decrypt a TLS private key
 | 
			
		||||
func IsErrEncryptedKey(err error) bool {
 | 
			
		||||
	return errors.Cause(err) == x509.IncorrectPasswordError
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// getPrivateKey returns the private key in 'keyBytes', in PEM-encoded format.
 | 
			
		||||
// If the private key is encrypted, 'passphrase' is used to decrypted the
 | 
			
		||||
// private key.
 | 
			
		||||
func getPrivateKey(keyBytes []byte, passphrase string) ([]byte, error) {
 | 
			
		||||
	// this section makes some small changes to code from notary/tuf/utils/x509.go
 | 
			
		||||
	pemBlock, _ := pem.Decode(keyBytes)
 | 
			
		||||
	if pemBlock == nil {
 | 
			
		||||
		return nil, fmt.Errorf("no valid private key found")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var err error
 | 
			
		||||
	if x509.IsEncryptedPEMBlock(pemBlock) {
 | 
			
		||||
		keyBytes, err = x509.DecryptPEMBlock(pemBlock, []byte(passphrase))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errors.Wrap(err, "private key is encrypted, but could not decrypt it")
 | 
			
		||||
		}
 | 
			
		||||
		keyBytes = pem.EncodeToMemory(&pem.Block{Type: pemBlock.Type, Bytes: keyBytes})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return keyBytes, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// getCert returns a Certificate from the CertFile and KeyFile in 'options',
 | 
			
		||||
// if the key is encrypted, the Passphrase in 'options' will be used to
 | 
			
		||||
// decrypt it.
 | 
			
		||||
func getCert(options Options) ([]tls.Certificate, error) {
 | 
			
		||||
	if options.CertFile == "" && options.KeyFile == "" {
 | 
			
		||||
		return nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	errMessage := "Could not load X509 key pair"
 | 
			
		||||
 | 
			
		||||
	cert, err := ioutil.ReadFile(options.CertFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrap(err, errMessage)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prKeyBytes, err := ioutil.ReadFile(options.KeyFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrap(err, errMessage)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prKeyBytes, err = getPrivateKey(prKeyBytes, options.Passphrase)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrap(err, errMessage)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tlsCert, err := tls.X509KeyPair(cert, prKeyBytes)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrap(err, errMessage)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return []tls.Certificate{tlsCert}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Client returns a TLS configuration meant to be used by a client.
 | 
			
		||||
func Client(options Options) (*tls.Config, error) {
 | 
			
		||||
	tlsConfig := ClientDefault
 | 
			
		||||
	tlsConfig := ClientDefault()
 | 
			
		||||
	tlsConfig.InsecureSkipVerify = options.InsecureSkipVerify
 | 
			
		||||
	if !options.InsecureSkipVerify && options.CAFile != "" {
 | 
			
		||||
		CAs, err := certPool(options.CAFile)
 | 
			
		||||
		CAs, err := certPool(options.CAFile, options.ExclusiveRootPools)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		tlsConfig.RootCAs = CAs
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if options.CertFile != "" || options.KeyFile != "" {
 | 
			
		||||
		tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("Could not load X509 key pair: %v. Make sure the key is not encrypted", err)
 | 
			
		||||
		}
 | 
			
		||||
		tlsConfig.Certificates = []tls.Certificate{tlsCert}
 | 
			
		||||
	tlsCerts, err := getCert(options)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	tlsConfig.Certificates = tlsCerts
 | 
			
		||||
 | 
			
		||||
	if err := adjustMinVersion(options, tlsConfig); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &tlsConfig, nil
 | 
			
		||||
	return tlsConfig, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Server returns a TLS configuration meant to be used by a server.
 | 
			
		||||
func Server(options Options) (*tls.Config, error) {
 | 
			
		||||
	tlsConfig := ServerDefault
 | 
			
		||||
	tlsConfig := ServerDefault()
 | 
			
		||||
	tlsConfig.ClientAuth = options.ClientAuth
 | 
			
		||||
	tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -111,12 +228,17 @@ func Server(options Options) (*tls.Config, error) {
 | 
			
		||||
		return nil, fmt.Errorf("Error reading X509 key pair (cert: %q, key: %q): %v. Make sure the key is not encrypted.", options.CertFile, options.KeyFile, err)
 | 
			
		||||
	}
 | 
			
		||||
	tlsConfig.Certificates = []tls.Certificate{tlsCert}
 | 
			
		||||
	if options.ClientAuth >= tls.VerifyClientCertIfGiven {
 | 
			
		||||
		CAs, err := certPool(options.CAFile)
 | 
			
		||||
	if options.ClientAuth >= tls.VerifyClientCertIfGiven && options.CAFile != "" {
 | 
			
		||||
		CAs, err := certPool(options.CAFile, options.ExclusiveRootPools)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		tlsConfig.ClientCAs = CAs
 | 
			
		||||
	}
 | 
			
		||||
	return &tlsConfig, nil
 | 
			
		||||
 | 
			
		||||
	if err := adjustMinVersion(options, tlsConfig); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return tlsConfig, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user