Commit Graph
60 Commits
Author SHA1 Message Date
Jakub Nyckowski c1f59a1803 Disconnect moderated session on Ctrl+C (#20580)
* Disconnect moderated session on Ctrl+C

* Add moderated session to the test plan.
2023-01-24 01:37:34 +00:00
Brian Joerger 2922ad009a Allow non-standard agent keys. (#18449) 2023-01-13 17:59:51 +00:00
Steven Martin e1ebc332f8 spell fixes (#19419) 2022-12-16 19:01:28 +00:00
rosstimothy 4092acaf87 Improve web ui ssh performance (#18656)
Reduces latency creating ssh sessions via the web ui by:

1) No longer uses `TeleportClient.SSH` to establish a session
2) Reuses the user auth client for the web session to perform MFA ceremony
3) Ensures that connection attempts follow the flow outlined in RFD 93

The web api server now leverages the `proxy.Router` and `srv.SessionController`
directly, instead of doing so indirectly via `TeleportClient.SSH`. Using
the `TeleportClient` required an ssh connection to be established from the web
api server to the proxy ssh server, which are in the same process. This added
overhead can be avoided now that the routing logic and session control logic
exists in a reusable component. To create an interactive session on the node
once the connection is established, `client.NodeClient` is used. A new constructor
was added to facilitate creating one and remove duplicated creation code and a
`RunInteractiveShell` receiver method was added to allow callers outside of
`lib/client` to spawn a session.

`TerminalHandler.issueSessionMFACerts` used to check if per-session mfa was enabled
and perform the mfa ceremony via the `client.ProxyClient` which was constructed
with the `TeleportClient` established from connecting to the proxy ssh server.
This would dial the Auth server under the hood directly and call `IsMFARequired`
and do the ceremony if required. Each web session established via the web ui
already established an auth client with the credentials of the logged in user.
Again overhead is removed by leveraging the existing auth client and performing
the mfa ceremony manually.

Finally `TerminalHandler.makeClient` always attempted to perform the mfa ceremony
prior to returning the `TeleportClient`. As outlined in [RFD 93](https://github.com/gravitational/teleport/blob/master/rfd/0093-offline-access.md),
this causes additional latency and requires Auth connectivity to connect to nodes.
The connection flow is now modified to attempt connection to the nodes first, and
fall back to the mfa ceremony and reconnecting only if the node denies access.

Partially addresses #15167
2022-11-28 14:00:51 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Steven Martin 6040d0f4f6 Spell fixes (#17090) 2022-10-14 00:50:27 +00:00
Jakub NyckowskiandRoman Tkachenko 0df39758a0 Refactor OpenSSH config generation (#17138)
Unify OpenSSH config generation between tsh and tbot.

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-10-07 18:11:57 +00:00
Nic Klaassen ab9168c0b6 fix: data race in NodeSession.runCommand (#17048) 2022-10-05 11:30:56 +00:00
rosstimothy ae1eb1b450 Allow tsh to retrieve cluster details in one request (#16456)
* Allow tsh to retrieve cluster details in one request

Prior to connecting to a node via `tsh ssh` we  need two bits of
information about the cluster:
 1) The session recording mode
 2) Whether FIPS is enabled

In order to retrieve the information `tsh` first would send the
global ssh request `RecordingProxyReqType` to determine the
session recording mode. Later on `tsh` would Ping the auth
server to determine if the cluster was running in FIPS mode.

In an effort to reduce the number of round trips to retrieve
this data, a new global ssh request `ClusterDetailsReqType` is
introduced that returns both the session recording mode and
whether FIPS is enabled. This allows `tsh` to leverage the new
request to get all the information it needs, and is extensible
in case more information is needed` in one request which helps
reduce latency for `tsh ssh`.
2022-09-27 14:00:24 +00:00
rosstimothy 6e5c9a7c85 Prevent ssh.Session SendRequest from wrapping payload twice (#16018)
* Prevent ssh.Session SendRequest from wrapping payload twice

Payloads were inadvertently being wrapped twice by sessions making
the ssh server unable to parse the request payload. This is largely
only an issue for window-change requests, as they are the only request
being sent directly via a session that contains a payload. All window-change
requests now use ssh.Session WindowChange instead or sending the request
manually.
2022-09-06 18:43:30 +00:00
rosstimothy 1973fcee24 Span improvements (#15388)
* Add spans to TeleportClient/ProxyClient/NodeSession

* Improve dialer tracing

* Alter default http client span name to include path

* propagate tracing options in NewClientConn
2022-08-18 21:29:03 +00:00
rosstimothy 0cb248ddd3 Trace ssh sessions (#14966)
Adds a wrapper around `ssh.Session` which injects tracing context
in a similar manner to the `ssh.Client` wrapper. All usages of
`ssh.Session` have now been replaced and have the appropriate
`context.Context` passed along

Part of #12241
2022-08-04 22:14:37 +00:00
Joel 63e17f8a0f Honor --no-enable-escape-sequences in tsh (#13507) 2022-07-13 11:48:21 +00:00
rosstimothy e5c745f331 Add manual tracing instrumentation to tsh (#13204)
Create spans for all public facing TeleportClient,
ProxyClient, and NodeClient methods. This makes
correlating spans easier to reason about when
looking at `tsh` traces. As a result of creating
spans, some additional context propagation is
required as well to ensure that spans are linked
properly.

This also removes the unused `quiet` argument from
`ConnectToCluster`. It's usage was not consistent
by existing callers, and it was ignored, so in order
to avoid confusion in future calls, it was removed.

#12241
2022-06-11 15:34:40 +00:00
Zac Bergquist c8af176828 Remove more deprecated code (#13132)
* Remove more deprecated code

In the case where we were using the PostalCode, StreetAddress,
and Province fields rather than ASN.1 extensions we could have
removed more code, but I opted for a phase approach where we stop
populating the fields in v10 (but still accept them), and then
stop reading them entirely in v11.

* Fix lints and remove more unused code

* Restore StreetAddress / PostalCode

We don't yet have dedicated extensions for these
2022-06-07 03:38:33 +00:00
rosstimothy 9f094aaef6 Add tracing instrumentation for ssh clients/servers (#12434)
* Add tracing instrumentation for ssh clients/servers

Add tracing context to the existing ProxyHelloSignature to provide
span information across ssh connections. To add span context per
ssh session on top of new connections, the same tracing context is
passed in the first global request of the session.

In order to ensure that tracing context is pulled from and inserted
into the proper context.Context, some interfaces and methods were
changed to take one as the first argument.
2022-05-25 12:24:02 +00:00
Joel 652536f4e5 Don't enforce standard k8s and ssh auth mechanisms when joining sessions (#11144) 2022-05-05 19:42:57 +00:00
Joel 30630a1ecf Pipe terminal stdin to session in kubernetes peer mode (#11288) 2022-04-01 17:48:40 +00:00
Andrew Burke 4e3bd6c647 Clear terminal when auth server is in FIPS mode (#10095)
This change clears the terminal at the end of a session when the auth server is in FIPS mode, even if tsh isn't.
2022-02-17 10:16:36 -08:00
Joel ea810d30d9 Implement Moderated Sessions (#8563)
* Implement Moderated Sessions
2022-02-15 17:02:10 +01:00
Brian Joerger d33f51d17f x11 forwarding (#9897) 2022-02-04 23:47:03 +00:00
699f588072 Clear web terminal when session ends (#8850)
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web.

Co-authored-by: Grzegorz <grzegorz.zdunek@goteleport.com>
Co-authored-by: Russell Jones <russjones@users.noreply.github.com>
2021-12-02 12:48:27 -08:00
Tim Buckley 01acea141a Add support for tsh ssh on Windows (#7790)
* Add support for `tsh ssh` on Windows

This adds Windows session support to tsh, taking advantage of ANSI
terminal support and VT emulation added in recent versions Windows
10. On supported Windows versions (Windows 10 1607+), `tsh ssh`
should work as expected in `cmd.exe`, PowerShell, and the new
Windows Terminal app.

* Address a few review comments

* Remove significant chunks of unnecessary tncon code.

Removes the global buffer, `GetVTSeqFromKeyStroke`, and several
ancillary headers and functions that aren't needed for our (current)
use-case. Also removes mouse and focus events.

* Refactor OS-specific terminal handling

This significantly simplifies OS-specific terminal behavior:
 * Move OS specific terminal code into a new `terminal` package
 * Remove `session_windows.go` in favor of an OS-independent
   `session.go`, defer to terminal package for OS specific
   functionality.
 * Remove ConPTY since it's not needed.
 * Always wait for the terminal and ssh session to fully close before
   quitting.
 * Refactor tncon; ensure the raw reader can be closed and reopened,
   remove lots of unnecessary C code.

* Revert dependency changes

* Use WindowsOS constant.

* Fix `tsh play` on Windows

This fixes `tsh play` on Windows by using the new `terminal` module to
initialize the terminal for raw input in a cross-platform way.

Additionally, this simplifies `terminal.New()` since in practice we never
want interactive mode at init time, and  fixes a broken unit test.

* Use correct log library

* Fix `tsh play` player controls on Windows

This fixes the console player controls on Windows as well as the timestamp
writer.

* Clean up lints

* Add missing license header

* Fix broken unit test

* Fix cross-compile builds on Linux/Docker

We need windows.h, which is not capitalized in the mingw packages
(and is case insensitive on Windows).

* Address code review feedback

 - Rename `Terminal.InitInteractive` to `Terminal.InitRaw`
 - Ensure goroutines terminate on close
 - Fix outdated godoc comments
 - Ensure Terminal event subscribers are cleared (and their channels
   are closed)
 - Ensure terminal output mode is reset on error in initTerminal
 - Bubble up errors in Terminal.Close()
 - Add author notice to tncon.c re: our changes
 - Add go-ansiterm as a direct dependency
 - Run `make update-vendor`

* Add constants and a small player.go TODO.

* Clear linter warning
2021-09-16 15:53:08 -06:00
rosstimothy 7c327ee296 Fix interactive sessions always exiting with code 0 (#8081)
* propogate error codes from interactive ssh sessions correctly (#3202)
2021-09-13 13:41:59 -04:00
Trent Clarke 540906768b Making log lines proper sentences. (#6772) 2021-05-13 15:02:52 +10:00
Trent Clarke 769b4b5eec Implements RFD-0022 - OpenSSH-compatible Agent Forwarding (#6525)
Prior to this change, `tsh` will only ever forward the internal key
agent managed by `tsh` to a remote machine.

This change allows a user to specify that `tsh` should forward either
the `tsh`-internal keystore, or the system key agent at `$SSH_AUTH_SOCK`.

This change also brings the `-A` command-line option into line with
OpenSSH.

For more info refer to RFD-0022.

See-Also: #1571
2021-05-06 17:17:50 -07:00
Andrew Lytvynov 5265688fc8 Revert "Node session race (#6195)"
This reverts commit 4acf50902c.
2021-04-26 17:24:06 +00:00
a-palchikovandAndrew Lytvynov 4acf50902c Node session race (#6195)
* Attempt to isolate and improve state handling of a NodeSession.

* Add terminal close for kube terminal tests

* Address review comments

* Small tweaks

Co-authored-by: Andrew Lytvynov <andrew@goteleport.com>
2021-04-22 17:16:28 -07:00
Andrew Lytvynov efc99a068c Update Go dependencies
Several dependencies can't be updated due to breakages (etcd and grpc
for example).

Also updated ttlmap usage since their API changed.
2021-02-23 18:04:55 -08:00
Andrew Lytvynov 3ba6502a05 tsh: add --no-enable-escape-sequences flag
In case our escape sequence support is buggy, let users opt out of it to
mitigate. By default escape sequences are enabled.
2020-06-02 00:29:36 +00:00
Andrew Lytvynov e99b04d1d6 Implement OpenSSH-like escape sequences in tsh
Only applies to interactive sessions.
Watch the user keyboard input for one of:
- `~?`: print help output for escape sequences
- `~.`: disconnect the current session (for example when stuck due to
  traffic getting black-holed)

The full list of OpenSSH sequences is here:
https://man.openbsd.org/ssh#ESCAPE_CHARACTERS
We only support the two mentioned above for now. If the need arises, it
should be easy to add.

The implementation ended up pretty complicated, read the comment on
`escape.NewReader` for some info and reasoning.

Fixes #2555
2020-06-02 00:29:36 +00:00
Andrew Lytvynov 3c94003379 errcheck: fix findings in lib/backend, lib/client 2020-06-01 20:16:16 +00:00
Russell Jones 6f96595e99 Send UUIDv1 session IDs to legacy servers.
Before establishing a session, request the server version. If the server
replies false, that means it does not support that request type and is
an older server version which needs UUIDv1 format session IDs.
2019-09-11 13:50:00 -07:00
Russell Jones ec7e53370d Fix formatting issues. 2018-10-19 16:25:01 -07:00
Russell Jones f603bd1c5a Refactoring of SOCKS5 server. 2018-10-15 11:52:02 -07:00
Russell Jones 87fe7a397d Added tsh for Windows. 2018-08-03 11:06:08 -07:00
Justin Gerace 7cfc78bafc Add Windows-specific code to enable building on Windows 2018-08-03 11:06:08 -07:00
Russell Jones a4b070c750 Fixed vendoring issues.
* Changed import path from github.com/moby/moby to canonical path of
    github.com/docker/docker.
  * Updated dependency for github.com/docker/docker/pkg/term.
  * Updated dependency for github.com/Azure/go-ansiterm.
2018-07-25 13:51:50 -07:00
Russell Jones 876e04af07 * Push window size changes to clients instead of polling.
* Cache services.ClusterConfig within srv.ServerContext for the duration
  of a connection.
* Create a single websocket between the browser and the proxy for all
* terminal bytes and events.
2018-05-04 18:28:36 +00:00
Russell Jones 3c80ce1c62 Fixed SIGINT handling when no network connectivity exists and when
running an "exec" request without a TTY.
2018-04-04 18:02:37 +00:00
Russell Jones 3b51d608cf Consolidated terminal request handling. 2017-12-21 11:53:21 -08:00
Russell Jones 7018852c5d Added forwarding SSH server. 2017-12-04 17:01:52 -08:00
Russell Jones 9ad600d39b Forwarding to proxy is controlled by a global out-of-band
request. Always forward Teleport agent to node in Web UI.
Support the -A flag in tsh to optionally forward agent to
node in CLI.
2017-11-16 00:11:25 +00:00
Sasha Klizhentas 8b81a0c384 Migrate to golang/dep for dependency management
Update following packages:

* Replace Sirupsen/log with sirupsen/log everywhere
* Update etcd client to 3.2.4
* Update docker/term to moby/term
* Update kr/pty to v1.0.0 release
* Update K8s client to 2.0
2017-08-22 15:30:30 -07:00
Sasha Klizhentas cea133f27c fix bench goroutine leak and add more stats 2017-05-14 12:47:04 -07:00
Ev Kontsevoy 7d534a7c50 Fixed window resize problems 2017-02-04 01:02:23 -08:00
Ev Kontsevoy f67d9c4ddf Error printing fixes
Teleport client would sometimes default to stdout, instead of the
defined-by-configuration io.Writer
2017-02-03 23:28:08 -08:00
Ev Kontsevoy 3b9b78ff19 Polish CLI client integration into web terminal 2017-02-03 17:35:52 -08:00
Ev Kontsevoy c3b57a8bb5 Removed the old web-based client code 2017-02-03 12:08:09 -08:00
Ev Kontsevoy 4a07dd3e22 Improved CLI login procedure
This commit adds several improvements to how CLI SSH login works

- Validated keys are added to the SSH agent [1]
- tsh will does not verify host keys twice anymore
- error messages for "access denied" look clean now

[1] This is huge. This means that tsh login can "feed" the keys to the
    built-in SSH agents of the OS and OpenSSH can fetch them from there.

QUESTION: why do we even need `tsh agent` option then? ssh-agent is
installed on every Linux/OSX machine.
2017-01-24 19:54:41 -08:00