Skip to content
Merged
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
4 changes: 2 additions & 2 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
// SSHTeleportUser is the current Teleport user that is logged in.
SSHTeleportUser = "SSH_TELEPORT_USER"

// SSHSessionWebproxyAddr is the address the web proxy.
SSHSessionWebproxyAddr = "SSH_SESSION_WEBPROXY_ADDR"
// SSHSessionWebProxyAddr is the address the web proxy.
SSHSessionWebProxyAddr = "SSH_SESSION_WEBPROXY_ADDR"

// SSHTeleportClusterName is the name of the cluster this node belongs to.
SSHTeleportClusterName = "SSH_TELEPORT_CLUSTER_NAME"
Expand Down
30 changes: 16 additions & 14 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2075,15 +2075,15 @@ func enterInput(ctx context.Context, person *Terminal, command, pattern string)
}
}

// TestInvalidLogins validates that you can't login with invalid login or
// with invalid 'site' parameter
// testEnvironmentVariables validates that session specific environment
// variables set by Teleport are present.
func testEnvironmentVariables(t *testing.T, suite *integrationTestSuite) {
ctx := context.Background()
tr := utils.NewTracer(utils.ThisFunction()).Start()
defer tr.Stop()

s := suite.newTeleport(t, nil, true)
defer s.StopAll()
t.Cleanup(func() { require.NoError(t, s.StopAll()) })

// make sure sessions set run command
tc, err := s.NewClient(helpers.ClientConfig{
Expand All @@ -2094,25 +2094,27 @@ func testEnvironmentVariables(t *testing.T, suite *integrationTestSuite) {
})
require.NoError(t, err)

// if SessionID is provided, it should be set in the session env vars.
tc.SessionID = uuid.NewString()
cmd := []string{"printenv", sshutils.SessionEnvVar}

// The SessionID and Web address should be set in the session env vars.
cmd := []string{"printenv", sshutils.SessionEnvVar, ";", "printenv", teleport.SSHSessionWebProxyAddr}
out := &bytes.Buffer{}
tc.Stdout = out
tc.Stdin = nil
err = tc.SSH(ctx, cmd, false /* runLocally */)

require.NoError(t, err)
require.Equal(t, tc.SessionID, strings.TrimSpace(out.String()))

// The proxy url should be set in the session env vars.
cmd = []string{"printenv", teleport.SSHSessionWebproxyAddr}
out = &bytes.Buffer{}
tc.Stdout = out
err = tc.SSH(ctx, cmd, false /* runLocally */)
output := out.String()
require.Contains(t, output, tc.SessionID)
require.Contains(t, output, tc.WebProxyAddr)

term := NewTerminal(250)
tc.Stdout = term
tc.Stdin = strings.NewReader(strings.Join(cmd, " ") + "\r\nexit\r\n")
err = tc.SSH(ctx, nil, false /* runLocally */)
require.NoError(t, err)
require.Equal(t, tc.WebProxyAddr, strings.TrimSpace(out.String()))
output = term.AllOutput()
require.Contains(t, output, tc.SessionID)
require.Contains(t, output, tc.WebProxyAddr)
}

// TestInvalidLogins validates that you can't login with invalid login or
Expand Down
2 changes: 1 addition & 1 deletion lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,7 @@ func (tc *TeleportClient) runCommandOnNodes(ctx context.Context, clt *ClusterCli

func (tc *TeleportClient) newSessionEnv() map[string]string {
env := map[string]string{
teleport.SSHSessionWebproxyAddr: tc.WebProxyAddr,
teleport.SSHSessionWebProxyAddr: tc.WebProxyAddr,
}
if tc.SessionID != "" {
env[sshutils.SessionEnvVar] = tc.SessionID
Expand Down
15 changes: 9 additions & 6 deletions lib/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,12 @@ func NewNodeClient(ctx context.Context, sshConfig *ssh.ClientConfig, conn net.Co
close(emptyCh)

nc := &NodeClient{
Client: tracessh.NewClient(sshconn, chans, emptyCh),
Namespace: apidefaults.Namespace,
TC: tc,
Tracer: tc.Tracer,
FIPSEnabled: fipsEnabled,
Client: tracessh.NewClient(sshconn, chans, emptyCh),
Namespace: apidefaults.Namespace,
TC: tc,
Tracer: tc.Tracer,
FIPSEnabled: fipsEnabled,
ProxyPublicAddr: tc.WebProxyAddr,
}

// Start a goroutine that will run for the duration of the client to process
Expand Down Expand Up @@ -1617,7 +1618,9 @@ func (c *NodeClient) RunInteractiveShell(ctx context.Context, mode types.Session

// Overwrite "SSH_SESSION_WEBPROXY_ADDR" with the public addr reported by the proxy. Otherwise,
// this would be set to the localhost addr (tc.WebProxyAddr) used for Web UI client connections.
env[teleport.SSHSessionWebproxyAddr] = c.ProxyPublicAddr
if c.ProxyPublicAddr != "" && c.TC.WebProxyAddr != c.ProxyPublicAddr {
env[teleport.SSHSessionWebProxyAddr] = c.ProxyPublicAddr
}

nodeSession, err := newSession(ctx, c, sessToJoin, env, c.TC.Stdin, c.TC.Stdout, c.TC.Stderr, c.TC.EnableEscapeSequences)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func onStatus() error {
sshClient := os.Getenv("SSH_CLIENT")
systemUser := os.Getenv("USER")
teleportUser := os.Getenv(teleport.SSHTeleportUser)
proxyAddr := os.Getenv(teleport.SSHSessionWebproxyAddr)
proxyAddr := os.Getenv(teleport.SSHSessionWebProxyAddr)
clusterName := os.Getenv(teleport.SSHTeleportClusterName)
hostUUID := os.Getenv(teleport.SSHTeleportHostUUID)
sid := os.Getenv(teleport.SSHSessionID)
Expand Down
2 changes: 1 addition & 1 deletion tool/tsh/common/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4634,7 +4634,7 @@ func setEnvFlags(cf *CLIConf, getEnv envGetter) {
// When using Headless, check for missing proxy/user/cluster values from the teleport session env variables.
if cf.Headless || cf.AuthConnector == constants.HeadlessConnector {
if cf.Proxy == "" {
cf.Proxy = getEnv(teleport.SSHSessionWebproxyAddr)
cf.Proxy = getEnv(teleport.SSHSessionWebProxyAddr)
}
if cf.Username == "" {
cf.Username = getEnv(teleport.SSHTeleportUser)
Expand Down
8 changes: 4 additions & 4 deletions tool/tsh/common/tsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,7 @@ func TestEnvFlags(t *testing.T) {
Headless: false,
},
envMap: map[string]string{
teleport.SSHSessionWebproxyAddr: "proxy.example.com",
teleport.SSHSessionWebProxyAddr: "proxy.example.com",
teleport.SSHTeleportUser: "alice",
teleport.SSHTeleportClusterName: "root-cluster",
},
Expand All @@ -2508,7 +2508,7 @@ func TestEnvFlags(t *testing.T) {
Headless: true,
},
envMap: map[string]string{
teleport.SSHSessionWebproxyAddr: "proxy.example.com",
teleport.SSHSessionWebProxyAddr: "proxy.example.com",
teleport.SSHTeleportUser: "alice",
teleport.SSHTeleportClusterName: "root-cluster",
},
Expand All @@ -2524,7 +2524,7 @@ func TestEnvFlags(t *testing.T) {
AuthConnector: constants.HeadlessConnector,
},
envMap: map[string]string{
teleport.SSHSessionWebproxyAddr: "proxy.example.com",
teleport.SSHSessionWebProxyAddr: "proxy.example.com",
teleport.SSHTeleportUser: "alice",
teleport.SSHTeleportClusterName: "root-cluster",
},
Expand All @@ -2543,7 +2543,7 @@ func TestEnvFlags(t *testing.T) {
SiteName: "root-cluster",
},
envMap: map[string]string{
teleport.SSHSessionWebproxyAddr: "other.example.com",
teleport.SSHSessionWebProxyAddr: "other.example.com",
teleport.SSHTeleportUser: "bob",
teleport.SSHTeleportClusterName: "leaf-cluster",
},
Expand Down