Code Monkey home page Code Monkey logo

go-connections's Introduction

GoDoc

Introduction

go-connections provides common package to work with network connections.

Usage

See the docs in godoc for examples and documentation.

License

go-connections is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

go-connections's People

Contributors

abronan avatar akerouanton avatar aluzzardi avatar calavera avatar cpuguy83 avatar creack avatar crosbymichael avatar dhrp avatar duglin avatar ehazlett avatar estesp avatar jamtur01 avatar kencochrane avatar lk4d4 avatar metaliveblog avatar metalivedev avatar moxiegirl avatar mzdaniel avatar rhatdan avatar runcom avatar samalba avatar shin- avatar svendowideit avatar thajeztah avatar tianon avatar tiborvass avatar unclejack avatar vbatts avatar vdemeester avatar vieux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-connections's Issues

Investigate why `TestConfigServerExclusiveRootPools` is broken on Windows / MacOS builds

  • Related to #104
  • TestConfigServerExclusiveRootPools: see
    if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
    // FIXME: see https://github.com/docker/go-connections/issues/105.
    t.Skip("FIXME: failing on Windows and darwin")
    }
  • TestConfigClientExclusiveRootPools: see
    if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
    // FIXME: see https://github.com/docker/go-connections/issues/105.
    t.Skip("FIXME: failing on Windows and darwin")
    }

Both tests break with the following error:

Unable to verify certificate 1: x509: certificate signed by unknown authority

certificate 1 being systemRootTrustedCert:

systemRootTrustedCert = `
-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI
U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs
N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv
o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU
5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy
rqXRfboQnoZsG4q5WTP468SQvvG5
-----END CERTIFICATE-----
`

As noted in d5807de commit message:

The (*Certificate).Verify() method from crypto/x509 special-case
windows, darwin and ios GOOS to use a OS-specific verification process.
This process seems to consider root CAs as invalid for some unknown
reasons.

So either the syscall made by Verify() to retrieve the system-wide cert bundle return an empty set, it's out-of-date, or something else happen.

SortPortMap function: Not valid sorting in case of empty bindings

SortPortMap function in sort.go file invalid sorts ports array in case if binding is empty array. This leads to incorrect behaviour in Docker and ErrPortAlreadyAllocated (“Bind for %s:%d failed: port is already allocated”) error during container startup.

This may happen, for example, if following HostConfig has been sent to Docker API during container creation:

"HostConfig":{"PortBindings":{"443/tcp":null,"80/tcp":null,"8443/tcp":[{"HostIp":"10.4.62.92","HostPort":"32768"}]}

In this case empty bindings will be created for 443 and 80 ports.

I’m ready to provide patch for this issue (just add && len(binding) > 0 check), but want to discuss this first.

Certificate used in tlsconfig/config_test.go expired

According to this comment in the code:

// This is the currently active LetsEncrypt IdenTrust cross-signed CA cert. It expires Mar 17, 2021.

The certificate expired Mar 17, 2021. Due to that, TestConfigServerExclusiveRootPools and TestConfigClientExclusiveRootPools are failing. Take a look at this test log in the Ubuntu infrastructure:

https://objectstorage.prodstack4-5.canonical.com/v1/AUTH_77e2ada1e7a84929a74ba3b87153c0ac/autopkgtest-groovy/groovy/amd64/g/golang-github-docker-go-connections/20210319_032851_d71cb@/log.gz

Configuration option or disable vulnerable TLS versions

The issue we are experiencing is when a security scan is issued against our docker hosts, they are found vulnerable to TLS version 1.0 and 1.1 on port 2376. We are using a self signed certificate.

Perhaps a daemon configuration option could be added to disable/enable TLS versions or just remove support for the vulnerable versions of TLS for the daemon.

openssl s_client -connect dockerhost01:2376 -tls1

New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-SHA
Server public key is 2048 bit
**Secure Renegotiation IS supported**
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1
~~~~ output omitted ~~~~


_openssl s_client -connect dockerhost01:2376 -tls1_1_
~~~~ output omitted ~~~~
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-SHA
Server public key is 2048 bit
**Secure Renegotiation IS supported**
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.1
~~~~ output omitted ~~~~

use if net.OpError.Err == syscall.EIPE, but net.OpError.Err never eq to syscall.EPIPE

	broker := func(to, from *net.TCPConn) {
		written, err := io.Copy(to, from)
		if err != nil {
			// If the socket we are writing to is shutdown with
			// SHUT_WR, forward it to the other end of the pipe:
			if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
				_ = from.CloseRead()
			}
		}
		_ = to.CloseWrite()
		event <- written
	}

net.OpError.Err is *os.SyscallError, os.SyscallError.Err can not be syscall.Errno

maybe this is expected behavior

	broker := func(to, from *net.TCPConn) {
		written, err := io.Copy(to, from)
		if err != nil {
			// If the socket we are writing to is shutdown with
			// SHUT_WR, forward it to the other end of the pipe:
			var errno syscall.Errno
			if errors.As(err, &errno) && errno == syscall.EPIPE {
				_ = from.CloseRead()
			}
		}
		_ = to.CloseWrite()
		event <- written
	}

why udp proxy forward data like stream?

		read, err := proxyConn.Read(readBuf)
		// ....
		for i := 0; i != read; {
			written, err := proxy.listener.WriteToUDP(readBuf[i:read], clientAddr)
			if err != nil {
				return
			}
			i += written
		}

udp is datagram protocol, this code looks like readBuf is a stream of bytes. Sending a 10 byte datagram is different from sending two 5-byte datagrams

sockets_unix.go:24:28: undefined: context

Hi,

After last update an issue appear during my application compilation:

sockets_unix.go:24:28: undefined: context

in sockets_unix.go you are using context.Context but context package is not imported.

usage:

tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
    return dialer.DialContext(ctx, proto, addr)
}

import:

import (
	"fmt"
	"net"
	"net/http"
	"syscall"
	"time"
)

Unix transport used when HTTP host is specified

Here is a demo repo that demonstrates the bug. You can toggle on/off the replace in the go.mod in order to switch the bug on and off. The example uses the docker client. This problem doesn't exist in 0.4.0.

There's a problem in master currently where it overrides the proto and doesn't reset it when a new scheme is applied. This had the effect of making request to a unix socket even though an http endpoint was specified for the docker engine.

A debugging session indicated the problem was from a removal of piece of code in sockets.go, which was changed here: https://github.com/docker/go-connections/pull/61/files#r923998601

The issue seems possibly related to the following which also had trouble making TCP connections:

Don’t segfault when the CA certificate chains are missing

This error is reproducible with 0.3.0:

=== RUN   TestConfigServerTLSClientCASet
--- FAIL: TestConfigServerTLSClientCASet (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x548ecb]

goroutine 8 [running]:
testing.tRunner.func1(0xc4200a63c0)
	/usr/lib/go-1.9/src/testing/testing.go:711 +0x2d2
panic(0x58f140, 0x69df40)
	/usr/lib/go-1.9/src/runtime/panic.go:491 +0x283
crypto/x509.(*CertPool).AddCert(0x0, 0xc4200ea000)
	/usr/lib/go-1.9/src/crypto/x509/cert_pool.go:95 +0x6b
crypto/x509.(*CertPool).AppendCertsFromPEM(0x0, 0xc4200e0900, 0x620, 0x820, 0x820)
	/usr/lib/go-1.9/src/crypto/x509/cert_pool.go:128 +0x13a
github.com/docker/go-connections/tlsconfig.certPool(0x5c74d6, 0x2e, 0x5c7100, 0x2c, 0xc4200dca40, 0x1)
	/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src/github.com/docker/go-connections/tlsconfig/config.go:105 +0x283
github.com/docker/go-connections/tlsconfig.Server(0x5c74d6, 0x2e, 0x5c728d, 0x2d, 0x5c712d, 0x2c, 0x0, 0x3, 0x0, 0x0, ...)
	/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src/github.com/docker/go-connections/tlsconfig/config.go:232 +0x564
github.com/docker/go-connections/tlsconfig.TestConfigServerTLSClientCASet(0xc4200a63c0)
	/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src/github.com/docker/go-connections/tlsconfig/config_test.go:175 +0x109
testing.tRunner(0xc4200a63c0, 0x5ca8d8)
	/usr/lib/go-1.9/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
	/usr/lib/go-1.9/src/testing/testing.go:789 +0x2de
exit status 2
FAIL	github.com/docker/go-connections/tlsconfig	0.027s

Here's the full log (originally at buildd.debian.org). See also Debian bug #871651

Inconsistent Error Handling in nat Package

A minor inconsistency in error handling between two functions in the Port type.

In the Int function, there is a comment suggesting that the error should be ignored:

// Int returns the port number of a Port as an int
func (p Port) Int() int {
portStr := p.Port()
// 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, _ := ParsePort(portStr)
return port
}

However, in the Range function, there is no similar comment, and the error is returned, even though the same case applies here:

// Range returns the start/end port numbers of a Port range as ints
func (p Port) Range() (int, int, error) {
return ParsePortRangeToInt(p.Port())
}

Suggestion

For consistency and to adhere to the principle of least surprise, it would be beneficial to add a similar comment in the Range function and ignore the error.

tlsconfig should also support cert PEM in memory

Currently, tlsconfig only works by loading PEM data from files. In some scenarios, we might not want to let tlsconfig load PEM data itself (e.g.: because it is not stored in separate files), but provide it with already loaded PEM data.

A PR is coming to fix this issue.

build error

faddat@debian:~/.gvm/pkgsets/go1.8/global/src/github.com/sg3des/goatee$ make
go build -ldflags="-s -w"

github.com/mattn/go-gtk/gtk

could not determine kind of name for C.toGFontSelection
Makefile:9: recipe for target 'build' failed
make: *** [build] Error 2

go1.8

cannot bump go-connections version in docker due to compilation error

While trying to vendor go-connections in docker, as a follow up to #31, I get compilation errors.

This is because of a change to 'NewUnixSocket', changing the type of group argument from string to int.

// NewUnixSocket creates a unix socket with the specified path and group.
func NewUnixSocket(path string, gid int) (net.Listener, error) {

// NewUnixSocket creates a unix socket with the specified path and group. func NewUnixSocket(path string, gid int) (net.Listener, error) { if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {

The NewUnixSocket interface now expects an integer as gid, instead of group name, which was the previous signature of 'NewUnixSocket'.

This breaks docker/docker, as the code depends on the version that accepted a string as group:

https://github.com/docker/docker/blob/40c51569e2a557e6656ea4314c824fb1eabb2c4e/pkg/listeners/listeners_unix.go#L34

l, err := sockets.NewUnixSocket(addr, socketGroup)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.