Commit Graph
267 Commits
Author SHA1 Message Date
Andrew Burke 2277cf893d Add remote port forwarding for openssh servers (#38047)
This change adds server-side support for remote port forwarding
(ssh -R) for OpenSSH nodes.
2024-02-29 18:26:33 +00:00
Edoardo Spadolini bd47f0e02a Improve Teleport reload behavior (#37773)
* clean up pidfile and reloads

* reduce log spam during graceful shutdowns

* hold an exclusive advisory lock on the pidfile

* do systemd reloads with the pidfile rather than $MAINPID

* prioritize signals over internal restarts
2024-02-13 15:27:54 +00:00
rosstimothy b7318b5c7e Enable errorlint via golangci-lint (#37669)
Adds the new linter and configures it to prevent direct error
comparisions and type assertions in favor of errors.Is and errors.As.
All current violations caught by the linter have been updated
accordingly.
2024-02-02 15:59:24 +00:00
d25385dc3b SSH connection resumption (#36518)
* Add pre- and post-detect hooks to the multiplexer

This gets rid of the dedicated "already written" mechanism in
multiplexer.Conn.

* Add a way for net.Conn to override ServerVersion

* Resumption handshake, client and server

* Enable SSH resumption in teleport and tsh

* Disable resumption in a subtest of TestIntegrations/Disconnection

* Add back the removed tests

* minor refactor of runClientResumable

* Disable resumption for a different subtest

* Add an option to disable SSH connection resumption in Connect (#36712)

Co-authored-by: Rafał Cieślak <rafal.cieslak@goteleport.com>
Co-authored-by: Grzegorz Zdunek <gzdunek@users.noreply.github.com>

---------

Co-authored-by: Rafał Cieślak <rafal.cieslak@goteleport.com>
Co-authored-by: Grzegorz Zdunek <gzdunek@users.noreply.github.com>
2024-01-19 21:30:22 +00:00
Reed Loden d14548746c Update FIPS algorithms inline with upstream x/crypto/ssh proposed changes (#36685)
`x/crypto/ssh` is adding a `fipsonly` mode (similar to `crypto/tls/fipsonly`) in
golang/go#64769. Once this has landed and been released, we'll swap to using it.
In the meantime, update our hardcoded algorithm set to match the algorithms listed
in https://go-review.googlesource.com/c/crypto/+/550515.

The only difference is that `aes192-ctr` is kept in `FIPSCiphers`, as it seems to be
approved by NIST SP 800-131A rev 2 (page 17).

Additionally, we now define a list of approved public key authentication algorithms for
SSH server connections. This isn't configurable for normal use case (yet), only handled
for FIPS builds.
2024-01-15 17:36:35 +00:00
Reed Loden 95aa537f68 Increase minimum password length and account lock interval (#36389)
* Increase `MinPasswordLength` from 6 to 12 characters
  - PCI DSS v4.0 control 8.3.6 requires a minimum password length of 12 characters.
  - NIST SP 800-63B section 5.1.1.1 requires a minimum password length of 8 characters.

* Increase `AccountLockInterval` from 20 to 30 minutes
  - PCI DSS v4.0 control 8.3.4 requires a minimum lockout duration of 30 minutes.

This will contribute to better supporting customers to meet certain compliance requirements.

Ref #1936.
Ref #7687.
2024-01-10 04:11:28 +00:00
rosstimothy d81a4d95c6 Remove support for the deprecated SSH tracing channel and request (#36357) 2024-01-09 23:18:15 +00:00
Forrest cbbb7aad24 handle all direct-tcpip requests via single child per connection (#35148)
* handle all direct-tcpip requests via single child per connection

* implement uds helpers and rework forwarding
2023-12-19 03:35:36 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <fred.heinecke@goteleport.com>
2023-12-01 17:48:14 +00:00
Edoardo Spadolini 731b9bf52b Avoid using deadlines in ObeyIdleTimeout (#35006)
* Avoid using deadlines in ObeyIdleTimeout

* wrap the error on Close

* add test and fix a bug

* switch to just including a clockwork.Timer
2023-11-29 11:36:42 +00:00
fheinecke 83b6062220 Fixed additional license format issues (#34726) 2023-11-17 21:14:08 +00:00
Zac Bergquist f8c5164bbb Fix incorrect permissions for X11 Unix socket (#34613)
We were passing decimal 1777 instead of octal.

Closes #24819
2023-11-15 14:27:09 +00:00
rosstimothy d5a796c056 Enable testify lint (#34222)
Updates our golangci-lint configuration to enable testifylint and
fixes all issues found.

Bump e ref to include gravitational/teleport.e#2567
2023-11-06 20:38:38 +00:00
Edoardo Spadolini 21d86a9fcf Special case the subsystems handled by teleport exec (#34089)
* Special case the subsystems handled by teleport exec

This only applies to sftp, and lets us do a real reexec where that's
possible (i.e. launching /proc/self/exe on Linux), making sftp work even
if Teleport has been replaced by some wrapper or has been deleted.

* Delete leftover comment

* Update godoc for ExecCommand.Command
2023-11-02 08:50:09 +00:00
rosstimothy 24ebac905b Track user connections across clusters (#32688)
Ensure that `proxy_ssh_sessions_total` is incremented in both the
root and the leaf cluster if a session to a node in the leaf cluster
is established through the root cluster. This now also prevents
leaf clusters from terminating during a graceful shutdown if there
is an active connection that was created from the root.

Fixes #32605.
2023-10-04 15:35:11 +00:00
Andrew Burke cf3bf183b9 Drain unused SSH channels (#32505)
This change drains unused SSH channels and requests to prevent a
situation where an attacker could repeatedly open channels and
send data that won't be read, causing Teleport to eventually run
out of memory.
2023-09-27 17:05:48 +00:00
rosstimothy 22f28130ab Prevent zombie sessions being left behind for web sessions (#32141)
The ssh session was not being closed for web sessions which resulted
in zombie sessions being left around until the ssh service was
restarted. TestTerminal was updated to assert that the session
tracker eventually transitions to the terminated state when the
client terminates the web socket.

Fixes #32120
2023-09-20 13:45:55 +00:00
Anton Miniailoandrosstimothy b6bf8120c2 Make SSH node listener to use multiplexer to leverage parsing of signed PROXY headers (#30380)
* Make SSH node listener to use multiplexer to leverage parsing of signed PROXY headers

Before for backward compatibility reason we used regular listener and later
we wrapped connection into handler that could parse signed PROXY header or
proxyHelloSignature for getting correct user IP. But
after removal of proxyHelloSignature we don't need the wrapper anymore.

* Improve error message

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-08-26 03:47:10 +00:00
Alan Parra 0c964aab05 chore: Bump gravitational/trace to v1.3.0 (#30064)
* chore: Bump gravitational/trace to v1.3.0

* Replace `trace.IsEOF` with `errors.Is`

* Fix IsPermanentEmitError
2023-08-04 21:39:24 +00:00
Mike Jensen b90e362e7b Fuzz Test Improvements (#29918)
* Added Fuzz Seeds for services/fuzz_test.go

* Fuzzing improvements for `lib/srv/db` fuzzing

This ensures that all fuzzing under `lib/srv/db` has the following:
* Good seeds that provide basic levels of coverage
* Enabled in OSS-Fuzz

* Fuzzing improvements for `lib/sshutils`

This improves the fuzzing in `lib/sshutils/sftp/parse_test.go` and `lib/sshutils/x11/display_test.go`.
Seeds were added and additional local fuzzing was done.  In addition these functions are now enabled in `oss-fuzz`.
2023-08-02 18:55:55 +00:00
Alan Parra 5aac6d8bc5 Listen on "localhost" for tests (#29732)
* Listen on "localhost" for tests

Avoids popups on macOS.

* Revert changes on webclient_test.go

* Partially revert sshserver_test.go
2023-08-01 13:51:34 +00:00
Anton Miniailo 05e9d0499e Remove usage of TELEPORT_CLIENT_ADDR env var (#29751) 2023-07-29 18:25:40 +00:00
Anton Miniailo 885563c37b Remove ProxyHelloSignature (#29670) 2023-07-27 17:47:31 +00:00
Nic Klaassen 2568bff9db fix: use errors.Is for all EOF comparisons (#26012)
This commit updates all `err == io.EOF` comparisons to use
`errors.Is(err, io.EOF)`. This is necessary when the error may have been
wrapped and fixes at least one current breakage (in `tsh request ls`).

`golang.org/x/tools/refactor/eg` was very handy for this, I used the
following template:

```go
package teleport
import (
	"errors"
	"io"
)
func before(err error) bool { return err == io.EOF }
func after(err error) bool  { return errors.Is(err, io.EOF) }
```
2023-05-10 19:27:39 +00:00
Michael f814b2d510 Add sshserver file transfer handlers (#24580)
Add web terminal handlers for file transfer requests (#24581)
2023-05-03 20:53:57 +00:00
Andrew LeFevre a76e411a44 refactor how 'tsh scp' destinations are parsed (#24441)
A complex regex was previously used to parse 'tsh scp'
destinations, which was hard to understand and even harder
to maintain for those not intimately familiar with regex,
despite it being heavily commented. Instead parse destinations
directly and add more test cases and a fuzz test to ensure
parsing won't panic and the new parse function doesn't
have any regressions.
2023-04-19 22:17:47 +00:00
Andrew LeFevre 61f99cd724 let SFTP server figure out remote users home directories (#24254)
Previously a Teleport client using SFTP would resolve remote host user
home directories by making a subsystem request to a Teleport server
which would return the home directory. The problem was the subsystem
request counted as an open session, which could make the SFTP file
transfer fail. This was frustrating and didn't make much sense, but
after reading the SFTP specification again I realized that SFTP servers
are to handle relative paths by assuming they start at the user's home
directory. So let the server figure out the correct path and remove any
tilde prefixes from remote paths.
2023-04-14 16:23:14 +00:00
Andrew LeFevre 9ea710dc38 don't duplicate 'tsh scp' error messages (#18657) 2023-04-12 16:20:01 +00:00
Andrew LeFevre fedb62f573 fix SFTP regression where non-existent source paths would have no error reported (#24444) 2023-04-12 15:57:10 +00:00
Andrew LeFevre 268c3c8db2 refactor web UI file transfers to use sftp package (#24260)
The sftp package is where modern file transfer logic lives and is
being maintained. Make the web UI use this package to unify
how we transfer files.
2023-04-12 13:48:15 +00:00
Andrew LeFevre f29d83970c enable globbing when using 'tsh scp' (#23789)
* enable globbing when using 'tsh scp'

Also fix copying symlinked files.

* addressed feedback
2023-04-11 14:54:40 +00:00
Andrew LeFevre 40c113b8da refactor SFTP backend to use upstream dep, not our fork (#23786)
* refactor SFTP backend to use upstream dep, not our fork

This change also greatly reduces the number of SFTP audit logs.
Now SFTP events are only sent when files are opened or modified
in any way, instead of for *every* SFTP request.

* added to SFTP integration test

* fix error when handling setstat on dirs

* fix linter warning

* move file/dir permission constants to lib/defaults package
2023-04-07 01:51:22 +00:00
Anton Miniailo 05f46d2d45 Add missing continue and handle error in the test echo SSH server (#24224) 2023-04-06 20:09:16 +00:00
Michael 50826a1b41 Add FileTransferRequests to session for moderated scp (#23875)
Part of https://github.com/gravitational/teleport/pull/23546

This will add a fileTransferRequest to a session and allow environment variables to be passed from the webUI in order to validate a request that happens "outside" the moderated session (via HTTP request).
2023-04-06 18:21:58 +00:00
Tiago Silva 95ba631d29 Fix panic when incoming request is nil (#24188)
* Fix panic when incoming request is nil

This PR prevents a panic when the SSH request channel is closed by [`mux.loop`](https://github.com/gravitational/crypto/blob/c3f983bc73dcf711908e49d91bda9cffbecb13cd/ssh/mux.go#L197-L199) if it encounters a connection error.

Fixes #24186

* force connection close
2023-04-06 14:02:21 +00:00
Andrew LeFevre ff8818fb87 Fix SSH agent forwarding to agentless nodes (#22567)
* lazily forward SSH agents when connecting to agentless nodes

When connecting to unregistered OpenSSH nodes, the SSH agent is always
forwarded. When connecting to registered OpenSSH (agentless) nodes
however, the SSH agent doesn't *need* to be forwarded, so only do so
if the user explicitly asks to.

* test SSH agent forwarding in agentless integration test
2023-03-21 14:44:23 +00:00
Andrew LeFevre de2e55bb69 connect to registered OpenSSH nodes with certs signed by OpenSSH CA (#21953)
To prevent users from being able to directly connect to registered
OpenSSH (Agentless) nodes, the OpenSSH CA was introduced. When
connecting to Agentless nodes, the Proxy will forward the connection
so the session can be recorded. The forwarding SSH server is configured
to authenticate to the target node with a certificate signed by OpenSSH
CA, which users do not have access to.
2023-03-14 16:58:16 +00:00
a5370d58fc Allow node to handle old and new way of client IP propagation on the same listener (#22572)
* Allow node to handle old and new way of client IP propagation on same listener

With addition of signed PROXY headers, node was listening on multiplexer, but because
 of that it couldn't processing incoming connection from older proxies
 when ProxyHelloSignature was used, because
 both ends were waiting for the other side to send data first.
 Here we integrate ability to handle PROXY headers into connection itself,
 so we can start ssh server without waiting for multiplexer to detect connection

* Remove unneeded code

* Improve comment's wording

Co-authored-by: Michael Wilson <mike@mdwn.dev>

* Improve comment's wording

Co-authored-by: Michael Wilson <mike@mdwn.dev>

* Fix imports

* Unexport function

* Add godoc

* Remove unneeded comment

* Move ProxyHelloSignature to constants

* Check that proxyline is verified

* Use Warn() instead of Warnf()

* Move ProxyHelloSignature to api/constants

* Add timeout for getting host CA during proxyline verification.

* Rearrange conditions

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Clarify comment.

---------

Co-authored-by: Michael Wilson <mike@mdwn.dev>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-03-07 13:55:02 +00:00
Tobiasz Heller 770e74a31a refactor: audit interface (#22070)
* refactor: shrinker interface for external audit loggers

* move StreamSessionEvents from ExternalAuditLogger

* fix comment of getLocalLog

* Rename IauditLog into AuditLoggerSessionStreamer
2023-03-06 10:44:16 +00:00
Jakub Nyckowski a8a244a517 SCP - Change file attrs only when requested (#22579)
* SCP -Change file attrs only when requested

OpenSSH sets 0644 by default and allows copy the source permissions by passing `-p` flag.
Our current implementation sets the file permissions even when client didn't use `-p` flag which can fail if the user doesn't have permissions to set it. This patch matches the OpenSSH behavior.

* Fix formatting
2023-03-03 19:12:52 +00:00
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +00:00
Gus Luxton 880736463b sshserver: Correctly handle PuTTY winadj channel requests (#19468)
* sshserver: Correctly handle PuTTY winadj channel requests

Fixes #19365

* Actually send a failure

* dispatch changes

* Reimplement wantReply handling

* Also handle windadj in forwarding server

* lint: Fix typo

* lint: Invert return order to put err last

* Use nil return payload instead

* Use trace.ReplyAlreadyHandled instead

* Handle reply internally and set req.WantReply to false

* Use t.Cleanup()

* behaviour is not a misspelling but whatever makes you happy

* Suggestions from code review
2023-02-28 17:39:03 +00:00
Jakub Nyckowski 79ebdc89c8 Bump golangci-lint to v1.51.1 (#21440) 2023-02-08 00:44:08 +00:00
Andrew LeFevre d632c6ab71 improve 'tsh scp' error message when no remote path is specified (#21106)
While here, move package comment in SFTP client code to the specific
import it mentions.

Fixes #21052
2023-02-03 18:07:00 +00:00
David Boslee cc36d290a1 Add metrics to track connection ingress (#19734)
* Add metrics to track connection ingress

* Add connection unwrapping

* Add license

* Remove debug logging

* Add ingress reporter tests

* Remove circular dependency

* Fix import formatting

* Missing defer

* Fix spelling of accepted

* Add _total suffix to counters

* Add godocs and fix nits

* Add test for http conn state reporter

* Use loop to unwrap netConnGetters

* Test meterics after http conn closed

* Ensure conns implement conn getter interface
2023-02-01 23:45:34 +00:00
Andrew LeFevre 629d072797 Use 'path.Join' instead of 'filepath.Join' to build remote file paths (#20961)
* use 'path.Join' instead of 'filepath.Join' to build remote file paths

tsh on Windows when using 'filepath.Join' would create paths with forward
slashes in them, which non-Windows Nodes couldn't handle. Consistently use
'path.Join' to avoid issues.

Fixes #18919

* add comment explaining why 'path.Join' is used

* move comment to make linter happy
2023-01-31 15:56:14 +00:00
Jakub Nyckowski a98c43f6e8 Use concurrent streams for SFTP connections (#20751)
* Our current SFTP implementation uses a single channel to transfer data. Connections with a high latency cause very slow transfer. github.com/pkg/sftp allows transferring data using concurrent streams, which seems to solve the problem. In order to utilize the feature, the remote file must implement the WriteTo() or ReadFrom() and Stat() methods. I've moved the progress bar to relay the data from a local file, as we can still call Read() or Write() on it to update the progress.

This PR doesn't address the high CPU usage by github.com/pkg/sftp on low latency links.

Closes #20579

* Cleanup

* Fix fileTransferProgress

* Simplify interfaces

* Move helper to utils package
Add comments

* Added comments

* Change canceler implementation to return correct values from Read/Write

* Fix infinite recursive call in cancelWriter.
2023-01-30 20:41:21 +00:00
rosstimothy 3d5557d947 Add a connection limiting listener (#20130)
Introduces `limiter.Listener` to provide a consistent and reusable
mechanism for limiting incoming connections per client. The new
listener is used by `sshutils/server.go` instead of manually applying
limits in `HandleConnection`.

This is particularly important now that the Proxy SSH port multiplexes
both SSH and gRPC. Each listener is now wrapped in a `limiter.Listener`
that uses the same `limiter.ConnectionsListener` to ensure that the
connection limits for the Proxy are enforced for all traffic on the
port.
2023-01-19 15:10:11 +00:00
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00
Jakub Nyckowski fc42dbb8df Fix casting on 32 bits (#19481)
Fix for the 32bits arch introduced by this change: https://github.com/gravitational/teleport/pull/19406/files#diff-a3a7eaca752e77262c79c696fd2e46062cd411b204295927dde865d1638c539c
2022-12-19 16:42:54 +00:00