Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/kube-integration-tests-non-root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,6 @@ jobs:
chown -Rf ci:ci ${GITHUB_WORKSPACE} $(go env GOMODCACHE) $(go env GOCACHE)
continue-on-error: true

- name: Install Docker CLI
run: |
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce-cli

- name: Create KinD cluster
uses: helm/kind-action@v1.5.0
with:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ replace (
github.com/microsoft/go-mssqldb => github.com/gravitational/go-mssqldb v0.11.1-0.20230331180905-0f76f1751cd3
// replace module github.com/moby/spdystream until https://github.com/moby/spdystream/pull/91 merges and deps are updated
// otherwise tests fail with a data race detection.
github.com/moby/spdystream => github.com/tigrato/spdystream v0.0.0-20230506141330-3473c0b0cd14
github.com/moby/spdystream => github.com/gravitational/spdystream v0.0.0-20230511102044-2597ad437553
github.com/sirupsen/logrus => github.com/gravitational/logrus v1.4.4-0.20210817004754-047e20245621
github.com/vulcand/predicate => github.com/gravitational/predicate v1.3.0
// Use our internal crypto fork, to work around the issue with OpenSSH <= 7.6 mentioned here: https://github.com/golang/go/issues/53391
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ github.com/gravitational/redis/v9 v9.0.0-teleport.3 h1:Eg/j3jiNUZ558KDXOqzF682EF
github.com/gravitational/redis/v9 v9.0.0-teleport.3/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
github.com/gravitational/roundtrip v1.0.2 h1:eOCY0NEKKaB0ksJmvhO6lPMFz1pIIef+vyPBTBROQ5c=
github.com/gravitational/roundtrip v1.0.2/go.mod h1:fuI1booM2hLRA/B/m5MRAPOU6mBZNYcNycono2UuTw0=
github.com/gravitational/spdystream v0.0.0-20230511102044-2597ad437553 h1:C/2iznTqtvoa00hHwcqeYzgAS3tvaNBXWXIbdeGCxvM=
github.com/gravitational/spdystream v0.0.0-20230511102044-2597ad437553/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/gravitational/trace v1.2.1 h1:Iaf43aqbKV5H8bdiRs1qByjEHgAfADJ0lt0JwRyu+q8=
github.com/gravitational/trace v1.2.1/go.mod h1:n0ijrq6psJY0sOI/NzLp+xdd8xl79jjwzVOFHDY6+kQ=
github.com/gravitational/ttlmap v0.0.0-20171116003245-91fd36b9004c h1:C2iWDiod8vQ3YnOiCdMP9qYeg2UifQ8KSk36r0NswSE=
Expand Down Expand Up @@ -1317,8 +1319,6 @@ github.com/thales-e-security/pool v0.0.2/go.mod h1:qtpMm2+thHtqhLzTwgDBj/OuNnMpu
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tigrato/spdystream v0.0.0-20230506141330-3473c0b0cd14 h1:N8tOYijlRgnmoTATYMODVD+QhlYN01fVALMxaQPnFTE=
github.com/tigrato/spdystream v0.0.0-20230506141330-3473c0b0cd14/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb h1:Ywfo8sUltxogBpFuMOFRrrSifO788kAFxmvVw31PtQQ=
Expand Down
13 changes: 13 additions & 0 deletions integration/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,16 @@ func MakeTestDatabaseServer(t *testing.T, proxyAddr utils.NetAddr, token string,

return db
}

// MustCreateListener creates a tcp listener at 127.0.0.1 with random port.
func MustCreateListener(t *testing.T) net.Listener {
t.Helper()

listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

t.Cleanup(func() {
listener.Close()
})
return listener
}
7 changes: 7 additions & 0 deletions integration/helpers/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@ type ProxyConfig struct {
SSHAddr string
// WebAddr the address the web service should listen on
WebAddr string
// KubeAddr is the kube proxy address.
KubeAddr string
// ReverseTunnelAddr the address the reverse proxy service should listen on
ReverseTunnelAddr string
// Disable the web service
Expand Down Expand Up @@ -1281,17 +1283,21 @@ func (i *TeleInstance) NewUnauthenticatedClient(cfg ClientConfig) (tc *client.Te

var webProxyAddr string
var sshProxyAddr string
var kubeProxyAddr string

switch {
case cfg.Proxy != nil:
webProxyAddr = cfg.Proxy.WebAddr
sshProxyAddr = cfg.Proxy.SSHAddr
kubeProxyAddr = cfg.Proxy.KubeAddr
case cfg.ALBAddr != "":
webProxyAddr = cfg.ALBAddr
sshProxyAddr = cfg.ALBAddr
kubeProxyAddr = cfg.ALBAddr
default:
webProxyAddr = i.Web
sshProxyAddr = i.SSHProxy
kubeProxyAddr = i.Config.Proxy.Kube.ListenAddr.Addr
}

fwdAgentMode := client.ForwardAgentNo
Expand All @@ -1311,6 +1317,7 @@ func (i *TeleInstance) NewUnauthenticatedClient(cfg ClientConfig) (tc *client.Te
Labels: cfg.Labels,
WebProxyAddr: webProxyAddr,
SSHProxyAddr: sshProxyAddr,
KubeProxyAddr: kubeProxyAddr,
InteractiveCommand: cfg.Interactive,
TLSRoutingEnabled: i.IsSinglePortSetup,
TLSRoutingConnUpgradeRequired: cfg.ALBAddr != "",
Expand Down
78 changes: 78 additions & 0 deletions integration/helpers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
package helpers

import (
"context"
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"net/url"
"sync"
"testing"
"time"

"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/api/fixtures"
"github.com/gravitational/teleport/lib/utils"
)

type ProxyHandler struct {
Expand Down Expand Up @@ -201,3 +209,73 @@ func MakeProxyAddr(user, pass, host string) string {
userPass := url.UserPassword(user, pass).String()
return fmt.Sprintf("%v@%v", userPass, host)
}

// MockAWSALBProxy is a mock proxy server that simulates an AWS application
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved from integration/proxy, no change.

// load balancer where ALPN is not supported. Note that this mock does not
// actually balance traffic.
type MockAWSALBProxy struct {
net.Listener
proxyAddr string
cert tls.Certificate
}

func (m *MockAWSALBProxy) serve(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
default:
}

conn, err := m.Accept()
if err != nil {
logrus.WithError(err).Debugf("Failed to accept conn.")
return
}

go func() {
defer conn.Close()

// Handshake with incoming client and drops ALPN.
downstreamConn := tls.Server(conn, &tls.Config{
Certificates: []tls.Certificate{m.cert},
})

// api.Client may try different connection methods. Just close the
// connection when something goes wrong.
if err := downstreamConn.HandshakeContext(ctx); err != nil {
logrus.WithError(err).Debugf("Failed to handshake.")
return
}

// Make a connection to the proxy server with ALPN protos.
upstreamConn, err := tls.Dial("tcp", m.proxyAddr, &tls.Config{
InsecureSkipVerify: true,
})
if err != nil {
logrus.WithError(err).Debugf("Failed to dial upstream.")
return
}
utils.ProxyConn(ctx, downstreamConn, upstreamConn)
}()
}
}

// MustStartMockALBProxy creates and starts a MockAWSALBProxy.
func MustStartMockALBProxy(t *testing.T, proxyAddr string) *MockAWSALBProxy {
t.Helper()

cert, err := tls.X509KeyPair([]byte(fixtures.TLSCACertPEM), []byte(fixtures.TLSCAKeyPEM))
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

m := &MockAWSALBProxy{
proxyAddr: proxyAddr,
Listener: MustCreateListener(t),
cert: cert,
}
go m.serve(ctx)
return m
}
82 changes: 72 additions & 10 deletions integration/kube_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/breaker"
"github.com/gravitational/teleport/api/constants"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/profile"
"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -1641,15 +1642,27 @@ func testKubeJoin(t *testing.T, suite *KubeSuite) {
return true
}, 10*time.Second, time.Second)

stream, err := kubeJoin(kube.ProxyConfig{
T: teleport,
Username: participantUsername,
KubeUsers: kubeUsers,
KubeGroups: kubeGroups,
}, tc, session)
require.NoError(t, err)
var stream *client.KubeSession
t.Run("join KubeProxyAddr", func(t *testing.T) {
stream, err = kubeJoin(kube.ProxyConfig{
T: teleport,
Username: participantUsername,
KubeUsers: kubeUsers,
KubeGroups: kubeGroups,
CustomTLSServerName: "",
}, tc, session)
require.NoError(t, err)
})
defer stream.Close()

// Tests other connection methods.
t.Run("join WebProxyAddr", func(t *testing.T) {
testKubeJoinByWebAddr(t, teleport, participantUsername, kubeUsers, kubeGroups, session)
})
t.Run("join WebProxyAddr with connection upgrade", func(t *testing.T) {
testKubeJoinByALBAddr(t, teleport, participantUsername, kubeUsers, kubeGroups, session)
})

// We wait again for the second user to finish joining the session.
// We allow a bit of time to pass here to give the session manager time to recognize the
// new IO streams of the second client.
Expand All @@ -1667,8 +1680,57 @@ func testKubeJoin(t *testing.T, suite *KubeSuite) {
participantStdoutW.Close()
})

participantOutput, err := io.ReadAll(participantStdoutR)
t.Run("verify output", func(t *testing.T) {
participantOutput, err := io.ReadAll(participantStdoutR)
require.NoError(t, err)
require.Contains(t, string(participantOutput), "echo hi")
require.Contains(t, out.String(), "echo hi2")
})
}

func testKubeJoinByWebAddr(t *testing.T, teleport *helpers.TeleInstance, username string, kubeUsers, kubeGroups []string, session types.SessionTracker) {
t.Helper()

tc, err := teleport.NewClient(helpers.ClientConfig{
Login: username,
Cluster: helpers.Site,
Host: Host,
Proxy: &helpers.ProxyConfig{
WebAddr: teleport.Config.Proxy.WebAddr.Addr,
KubeAddr: teleport.Config.Proxy.WebAddr.Addr,
},
})
require.NoError(t, err)

stream, err := kubeJoin(kube.ProxyConfig{
T: teleport,
Username: username,
KubeUsers: kubeUsers,
KubeGroups: kubeGroups,
CustomTLSServerName: constants.KubeTeleportProxyALPNPrefix + Host,
}, tc, session)
require.NoError(t, err)
stream.Close()
}
func testKubeJoinByALBAddr(t *testing.T, teleport *helpers.TeleInstance, username string, kubeUsers, kubeGroups []string, session types.SessionTracker) {
t.Helper()

albProxy := helpers.MustStartMockALBProxy(t, teleport.Config.Proxy.WebAddr.Addr)
tc, err := teleport.NewClient(helpers.ClientConfig{
Login: username,
Cluster: helpers.Site,
Host: Host,
ALBAddr: albProxy.Addr().String(),
})
require.NoError(t, err)

stream, err := kubeJoin(kube.ProxyConfig{
T: teleport,
Username: username,
KubeUsers: kubeUsers,
KubeGroups: kubeGroups,
CustomTLSServerName: constants.KubeTeleportProxyALPNPrefix + Host,
}, tc, session)
require.NoError(t, err)
require.Contains(t, string(participantOutput), "echo hi")
require.Contains(t, out.String(), "echo hi2")
stream.Close()
}
Loading