Skip to content

Commit a35cfe0

Browse files
committed
fix(e2e): resolve TLS trust and policy issues in e2e tests
1 parent 9d77621 commit a35cfe0

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

e2e/credential_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,14 @@ template = "testuser"
745745
t.Error("audit log should contain SSH connection entry")
746746
}
747747

748+
// Close the SSH session and client connection before waiting for the
749+
// server goroutine. The defers registered above won't run until the
750+
// function returns, so we must close explicitly to unblock the test
751+
// server's "for newChan := range chans" loop.
752+
session.Close()
753+
sshClientConn.Close()
754+
conn.Close()
755+
748756
// Wait for SSH server goroutine to finish.
749757
_ = sshListener.Close()
750758

e2e/smoke_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ func TestSmoke_HealthzReturns200(t *testing.T) {
2222
}
2323

2424
func TestSmoke_SOCKS5Listening(t *testing.T) {
25-
proc := startSluice(t, SluiceOpts{})
25+
proc := startSluice(t, SluiceOpts{
26+
ConfigTOML: `
27+
[policy]
28+
default = "allow"
29+
`,
30+
})
2631

2732
// Verify we can actually dial through the SOCKS5 proxy to the health endpoint.
2833
dialer := connectSOCKS5(t, proc.ProxyAddr)

internal/proxy/inject.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"crypto/tls"
7+
"crypto/x509"
78
"errors"
89
"fmt"
910
"io"
@@ -110,6 +111,22 @@ func NewInjector(provider vault.Provider, resolver *atomic.Pointer[vault.Binding
110111
proxy := goproxy.NewProxyHttpServer()
111112
proxy.Verbose = false
112113

114+
// Build a root CA pool for the outbound transport. Start with system
115+
// roots and add the sluice MITM CA cert. Adding the MITM CA is
116+
// necessary because in containerized deployments, upstream test
117+
// servers may present certificates signed by the same CA that sluice
118+
// uses for interception. In production, no real server will present a
119+
// cert signed by sluice's CA, so this addition is harmless.
120+
rootCAs, _ := x509.SystemCertPool()
121+
if rootCAs == nil {
122+
rootCAs = x509.NewCertPool()
123+
}
124+
if len(caCert.Certificate) > 0 {
125+
if parsed, err := x509.ParseCertificate(caCert.Certificate[0]); err == nil {
126+
rootCAs.AddCert(parsed)
127+
}
128+
}
129+
113130
// Use a transport that dials pinned IPs (set by the SOCKS5 dial
114131
// function) instead of re-resolving DNS. This prevents DNS rebinding
115132
// attacks where the hostname resolves to a different IP between
@@ -138,6 +155,7 @@ func NewInjector(provider vault.Provider, resolver *atomic.Pointer[vault.Binding
138155
}
139156
return (&net.Dialer{Timeout: connectTimeout}).DialContext(ctx, network, addr)
140157
},
158+
TLSClientConfig: &tls.Config{RootCAs: rootCAs},
141159
ForceAttemptHTTP2: true,
142160
TLSHandshakeTimeout: 10 * time.Second,
143161
}

0 commit comments

Comments
 (0)