Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for empty ClusterNames, ServerHostname in retrieving sessions #4027

Merged
merged 5 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,14 @@ func (h *Handler) siteSessionGet(w http.ResponseWriter, r *http.Request, p httpr
if err != nil {
return nil, trace.Wrap(err)
}

// DELETE IN: 5.0.0
// Teleport Nodes < v4.3 does not set clusterName with new sessions,
// which 4.3 UI client relies on to set clusterId in URL.
if sess.ClusterName == "" {
sess.ClusterName = p.ByName("site")
}

return *sess, nil
}

Expand Down
33 changes: 33 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,39 @@ func (s *WebSuite) TestActiveSessions(c *C) {
c.Assert(sess.ClusterName, Equals, s.server.ClusterName())
}

// DELETE IN: 5.0.0
// Tests the code snippet from apiserver.(*Handler).siteSessionGet that
// tests empty clusterName is set to URL params "site".
func (s *WebSuite) TestEmptySessionClusterNameIsSet(c *C) {
nodeClient, err := s.server.NewClient(auth.TestBuiltin(teleport.RoleNode))
c.Assert(err, IsNil)

// Create a session with empty ClusterName.
sid := session.NewID()
date := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
sess := session.Session{
ClusterName: "",
ID: sid,
Namespace: defaults.Namespace,
Login: "foo",
Created: date,
LastActive: date,
TerminalParams: session.TerminalParams{W: 100, H: 100},
}
err = nodeClient.CreateSession(sess)
c.Assert(err, IsNil)

// Retrieve the session with the empty ClusterName.
pack := s.authPack(c, "foo")
res, err := pack.clt.Get(context.Background(), pack.clt.Endpoint("webapi", "sites", s.server.ClusterName(), "namespaces", "default", "sessions", sid.String()), url.Values{})
c.Assert(err, IsNil)

// Test that empty ClusterName got set to value of the "site" param of URL.
var result *session.Session
json.Unmarshal(res.Bytes(), &result)
c.Assert(result.ClusterName, Equals, s.server.ClusterName())
}

func (s *WebSuite) TestCloseConnectionsOnLogout(c *C) {
sid := session.NewID()
pack := s.authPack(c, "foo")
Expand Down