[fix] allow IPv6 controllers, workers, and targets (#5221)
Co-authored-by: Damian Debkowski <damian.debkowski@hashicorp.com>
This commit is contained in:
1 parent
680bb02af9
commit
62c41191ff
42 files changed
+1996
-546
No files matched your search
@@ -5,6 +5,7 @@ package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
@@ -185,5 +186,14 @@ func (c *Connection) validateNewConnection(ctx context.Context) error {
|
||||
if c.UserClientIp == "" {
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing user client ip")
|
||||
}
|
||||
if ip := net.ParseIP(c.ClientTcpAddress); ip == nil {
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "given client tcp address is not an ip address")
|
||||
}
|
||||
if ip := net.ParseIP(c.EndpointTcpAddress); ip == nil {
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "given endpoint tcp address is not an ip address")
|
||||
}
|
||||
if ip := net.ParseIP(c.UserClientIp); ip == nil {
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "given user client ip is not an ip address")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -31,23 +31,24 @@ func TestConnection_Create(t *testing.T) {
|
||||
userClientIp string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *Connection
|
||||
wantErr bool
|
||||
wantIsErr errors.Code
|
||||
create bool
|
||||
wantCreateErr bool
|
||||
name string
|
||||
args args
|
||||
want *Connection
|
||||
wantErr bool
|
||||
wantIsErr errors.Code
|
||||
create bool
|
||||
wantCreateErr bool
|
||||
expectedErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid",
|
||||
name: "valid-ipv4",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "127.0.0.1",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "127.0.0.1",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "::1",
|
||||
userClientIp: "127.0.0.2",
|
||||
},
|
||||
want: &Connection{
|
||||
SessionId: s.PublicId,
|
||||
@@ -55,10 +56,134 @@ func TestConnection_Create(t *testing.T) {
|
||||
ClientTcpPort: 22,
|
||||
EndpointTcpAddress: "127.0.0.1",
|
||||
EndpointTcpPort: 2222,
|
||||
UserClientIp: "::1",
|
||||
UserClientIp: "127.0.0.2",
|
||||
},
|
||||
create: true,
|
||||
},
|
||||
{
|
||||
name: "valid-ipv6",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860:0:0:0:0:8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860:0:0:0:0:8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860:0:0:0:0:8885",
|
||||
},
|
||||
want: &Connection{
|
||||
SessionId: s.PublicId,
|
||||
ClientTcpAddress: "2001:4860:4860:0:0:0:0:8887",
|
||||
ClientTcpPort: 22,
|
||||
EndpointTcpAddress: "2001:4860:4860:0:0:0:0:8886",
|
||||
EndpointTcpPort: 2222,
|
||||
UserClientIp: "2001:4860:4860:0:0:0:0:8885",
|
||||
},
|
||||
create: true,
|
||||
},
|
||||
{
|
||||
name: "valid-abbreviated-ipv6",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860::8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860::8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860::8885",
|
||||
},
|
||||
want: &Connection{
|
||||
SessionId: s.PublicId,
|
||||
ClientTcpAddress: "2001:4860:4860::8887",
|
||||
ClientTcpPort: 22,
|
||||
EndpointTcpAddress: "2001:4860:4860::8886",
|
||||
EndpointTcpPort: 2222,
|
||||
UserClientIp: "2001:4860:4860::8885",
|
||||
},
|
||||
create: true,
|
||||
},
|
||||
{
|
||||
name: "invalid-[ipv6]-client-tcp-address",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "[2001:4860:4860:0:0:0:0:8887]",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860:0:0:0:0:8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860:0:0:0:0:8885",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given client tcp address is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "invalid-[ipv6]-endpoint-tcp-address",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860:0:0:0:0:8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "[2001:4860:4860:0:0:0:0:8886]",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860:0:0:0:0:8885",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given endpoint tcp address is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "invalid-[ipv6]-user-client-ip",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860:0:0:0:0:8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860:0:0:0:0:8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "[2001:4860:4860:0:0:0:0:8885]",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given user client ip is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "invalid-abbreviated-[ipv6]-client-tcp-address",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "[2001:4860:4860::8887]",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860::8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860::8885",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given client tcp address is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "invalid-abbreviated-[ipv6]-endpoint-tcp-address",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860::8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "[2001:4860:4860::8886]",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "2001:4860:4860::8885",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given endpoint tcp address is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "invalid-abbreviated-[ipv6]-user-client-ip",
|
||||
args: args{
|
||||
sessionId: s.PublicId,
|
||||
clientTcpAddress: "2001:4860:4860::8887",
|
||||
clientTcpPort: 22,
|
||||
endpointTcpAddress: "2001:4860:4860::8886",
|
||||
endpointTcpPort: 2222,
|
||||
userClientIp: "[2001:4860:4860::8885]",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
expectedErrMsg: "given user client ip is not an ip address",
|
||||
},
|
||||
{
|
||||
name: "empty-session-id",
|
||||
args: args{
|
||||
@@ -147,6 +272,9 @@ func TestConnection_Create(t *testing.T) {
|
||||
if tt.wantErr {
|
||||
require.Error(err)
|
||||
assert.True(errors.Match(errors.T(tt.wantIsErr), err))
|
||||
if tt.expectedErrMsg != "" {
|
||||
assert.ErrorContains(err, tt.expectedErrMsg)
|
||||
}
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
@@ -472,13 +472,9 @@ func newCert(ctx context.Context, jobId string, addresses []string, exp time.Tim
|
||||
|
||||
for _, addr := range addresses {
|
||||
// First ensure we aren't looking at ports, regardless of IP or not
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
host, _, err := util.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
host = addr
|
||||
} else {
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
// Now figure out if it's an IP address or not. If ParseIP likes it, add
|
||||
// to IP SANs. Otherwise DNS SANs.
|
||||
|
||||
Reference in new issue
Block a user