summaryrefslogtreecommitdiffhomepage
path: root/ssh/tailssh/tailssh.go
AgeCommit message (Collapse)AuthorFilesLines
2023-06-21ssh/tailssh: fix double race condition with non-pty command (#8405)Joe Tsai1-18/+40
There are two race conditions in output handling. The first race condition is due to a misuse of exec.Cmd.StdoutPipe. The documentation explicitly forbids concurrent use of StdoutPipe with exec.Cmd.Wait (see golang/go#60908) because Wait will close both sides of the pipe once the process ends without any guarantees that all data has been read from the pipe. To fix this, we allocate the os.Pipes ourselves and manage cleanup ourselves when the process has ended. The second race condition is because sshSession.run waits upon exec.Cmd to finish and then immediately proceeds to call ss.Exit, which will close all output streams going to the SSH client. This may interrupt any asynchronous io.Copy still copying data. To fix this, we close the write-side of the os.Pipes after the process has finished (and before calling ss.Exit) and synchronously wait for the io.Copy routines to finish. Fixes #7601 Signed-off-by: Joe Tsai <joetsai@digital-static.net> Co-authored-by: Maisem Ali <maisem@tailscale.com>
2023-06-09ssh/tailssh: add support for remote/reverse port forwardingMaisem Ali1-3/+20
This basically allows running services on the SSH client and reaching them from the SSH server during the session. Updates #6575 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-05-22ssh/tailssh: add ssh session recording failed event typeCharlotte Brandhorst-Satzkorn1-2/+11
This change introduces a SSHSessionRecordingFailed event type that is used when a session recording fails to start or fails during a session, and the on failure indicates that it should fail open. Updates tailscale/corp#9967 Signed-off-by: Charlotte Brandhorst-Satzkorn <charlotte@tailscale.com>
2023-05-18ssh/tailssh: close tty on session closeMaisem Ali1-2/+13
We were only closing on side of the pty/tty pair. Close the other side too. Thanks to @fritterhoff for reporting and debugging the issue! Fixes #8119 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-05-08ssh/tailssh: support LDAP users for Tailscale SSHBrad Fitzpatrick1-14/+3
Fixes #4945 Change-Id: Ie013cb47684cb87928a44f92c66352310bfe53f1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-05-05ssh/tailssh,tailcfg: add connID to ssheventnotifyrequest and castheaderCharlotte Brandhorst-Satzkorn1-13/+16
This change adds a ConnectionID field to both SSHEventNotifyRequest and CastHeader that identifies the ID of a connection to the SSH server. Updates tailscale/corp#9967 Signed-off-by: Charlotte Brandhorst-Satzkorn <charlotte@tailscale.com>
2023-05-05ssh/tailssh: send ssh event notifications on recording failuresCharlotte Brandhorst-Satzkorn1-10/+86
This change sends an SSHEventNotificationRequest over noise when a SSH session is set to fail closed and the session is unable to start because a recorder is not available or a session is terminated because connection to the recorder is ended. Each of these scenarios have their own event type. Updates tailscale/corp#9967 Signed-off-by: Charlotte Brandhorst-Satzkorn <charlotte@tailscale.com>
2023-05-03ssh/tailssh: restore support for recording locallyMaisem Ali1-32/+64
We removed it earlier in 916aa782af5d43ccfa92f6245201796df212fb8a, but we still want to support it for some time longer. Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-05-01ssh/tailssh: improve debug logging around revoked sessionsTom DNetto1-0/+11
Updates https://github.com/tailscale/corp/issues/10943 Signed-off-by: Tom DNetto <tom@tailscale.com>
2023-04-25ssh/tailssh: also handle recording upload failure during writesMaisem Ali1-15/+30
Previously we would error out when the recording server disappeared after the in memory buffer filled up for the io.Copy. This makes it so that we handle failing open correctly in that path. Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-04-22ssh/tailssh: handle dialing multiple recorders and failing openMaisem Ali1-64/+143
This adds support to try dialing out to multiple recorders each with a 5s timeout and an overall 30s timeout. It also starts respecting the actions `OnRecordingFailure` field if set, if it is not set it fails open. Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-04-17various: add golangci-lint, fix issues (#7905)Andrew Dunham1-2/+2
This adds an initial and intentionally minimal configuration for golang-ci, fixes the issues reported, and adds a GitHub Action to check new pull requests against this linter configuration. Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I8f38fbc315836a19a094d0d3e986758b9313f163
2023-04-04ssh/tailssh: make Tailscale SSH work on gokrazyBrad Fitzpatrick1-0/+11
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-03-28ssh/tailssh: fix race in errors returned when starting recorderMaisem Ali1-2/+13
There were two code paths that could fail depending on how fast the recorder responses. This fixes that by returning the correct error from both paths. Fixes #7707 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-25ssh/tailssh: add tests for recording failureMaisem Ali1-3/+25
Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-23ssh/tailssh: handle session recording when running in userspace modeMaisem Ali1-3/+26
Previously it would dial out using the http.DefaultClient, however that doesn't work when tailscaled is running in userspace mode (e.g. when testing). Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-23ssh/tailssh: enable recording of non-pty sessionsMaisem Ali1-4/+1
Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-23ssh/tailssh: add docs to CastHeader fieldsMaisem Ali1-18/+51
Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-23ssh/tailssh: use background context for uploading recordingsMaisem Ali1-1/+6
Otherwise we see errors like ``` ssh-session(sess-20230322T005655-5562985593): recording: error sending recording to <addr>:80: Post "http://<addr>:80/record": context canceled ``` The ss.ctx is closed when the session closes, but we don't want to break the upload at that time. Instead we want to wait for the session to close the writer when it finishes, which it is already doing. Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-21ssh/tailssh: allow recorders to be configured on the first or final actionMaisem Ali1-4/+16
Currently we only send down recorders in first action, allow the final action to replace them but not to drop them. Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-21ssh/tailssh: add more metadata to recording headerMaisem Ali1-7/+18
Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-21ssh/tailssh: stream SSH recordings to configured recordersMaisem Ali1-31/+50
Updates tailscale/corp#9967 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-03-09ssh/tailssh: use context.WithCancelCauseMaisem Ali1-12/+31
It was using a custom implmentation of the context.WithCancelCause, replace usage with stdlib. Signed-off-by: Maisem Ali <maisem@tailscale.com>
2023-01-27all: update copyright and license headersWill Norris1-3/+2
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
2023-01-09ssh/tailssh: add OpenBSD support for Tailscale SSHBrad Fitzpatrick1-1/+1
And bump go.mod for https://github.com/u-root/u-root/pull/2593 Change-Id: I36ec94c5b2b76d671cb739f1e9a1a43ca1d9d1b1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-12-20ssh/tailssh: fix typo in error messageBrad Fitzpatrick1-2/+2
"look up" is the verb. "lookup" is a noun. Change-Id: I81c99e12c236488690758fb5c121e7e4e1622a36 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-11-16ssh/tailssh: only call CloseWrite when both stdout and stderr are doneMaisem Ali1-1/+12
Updates #5209 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-11-10ssh/tailssh: add Tailscale SSH (server) support on FreeBSDPat Maddox1-1/+1
Change-Id: I607194b6ef99205e777f3df93a74ffe1a2e0344c Signed-off-by: Pat Maddox <pat@ratiopbc.com>
2022-11-04all: remove old +build tagsBrad Fitzpatrick1-1/+0
The //go:build syntax was introduced in Go 1.17: https://go.dev/doc/go1.17#build-lines gofmt has kept the +build and go:build lines in sync since then, but enough time has passed. Time to remove them. Done with: perl -i -npe 's,^// \+build.*\n,,' $(git grep -l -F '+build') Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-11ssh/tailssh: add password-forcing workaround for buggy SSH clientsBrad Fitzpatrick1-6/+52
If the username includes a suffix of +password, then we accept password auth and just let them in like it were no auth. This exists purely for SSH clients that get confused by seeing success to their initial auth type "none". Co-authored-by: Maisem Ali <maisem@tailscale.com> Change-Id: I616d4c64d042449fb164f615012f3bae246e91ec Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-10all: fix more resource leaks found by staticmajorEmmanuel T Odeke1-1/+7
Updates #5706 Signed-off-by: Emmanuel T Odeke <emmanuel@orijtech.com>
2022-10-09ssh/tailssh: close sshContext on context cancellationMaisem Ali1-1/+1
This was preventing tailscaled from shutting down properly if there were active sessions in certain states (e.g. waiting in check mode). Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-10-09ssh/tailssh: add support for sending multiple bannersMaisem Ali1-53/+23
Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-10-09ssh/tailssh: add TestSSHAuthFlowMaisem Ali1-11/+22
Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-10-09ssh/tailssh: do the full auth flow during ssh authMaisem Ali1-217/+216
Fixes #5091 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-10-07ssh/tailssh: do not send EOT on session disconnectionMaisem Ali1-3/+0
This was assumed to be the fix for mosh not working, however turns out all we really needed was the duplicate fd also introduced in the same commit (af412e8874e94dc3ac57c37c3ec5e0606aa08fbb). Fixes #5103 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-10-04go.mod, ssh/tailssh: fix ImplictAuthMethod typoBrad Fitzpatrick1-1/+1
Fixes #5745 Change-Id: Ie8bc88bd465a9cb35b0ae7782d61ce96480473ee Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-09-29all: fix spelling mistakesJosh Soref1-4/+4
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-15refactor: move from io/ioutil to io and os packagesEng Zer Jun1-2/+1
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Reference: https://golang.org/doc/go1.16#ioutil Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-09-15envknob: support changing envknobs post-initBrad Fitzpatrick1-7/+6
Updates #5114 Change-Id: Ia423fc7486e1b3f3180a26308278be0086fae49b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-08-04syncs, all: move to using Go's new atomic types instead of oursBrad Fitzpatrick1-4/+4
Fixes #5185 Change-Id: I850dd532559af78c3895e2924f8237ccc328449d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-08-02all: migrate more code code to net/netip directlyBrad Fitzpatrick1-3/+2
Instead of going through the tailscale.com/net/netaddr transitional wrappers. Updates #5162 Change-Id: I3dafd1c2effa1a6caa9b7151ecf6edd1a3fda3dd Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-08-02ssh/tailssh: fix deadlock in expandDelegateURLMaisem Ali1-4/+2
Also rename it to expandDelegateURLLocked, previously it was trying to acquire the mutex while holding the mutex. Fixes #5235 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-07-25all: convert more code to use net/netip directlyBrad Fitzpatrick1-4/+4
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.) perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. ) goimports -w . Then delete some stuff from the net/netaddr shim package which is no longer neeed. Updates #5162 Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25all: use various net/netip parse funcs directlyBrad Fitzpatrick1-1/+2
Mechanical change with perl+goimports. Changed {Must,}Parse{IP,IPPrefix,IPPort} to their netip variants, then goimports -d . Finally, removed the net/netaddr wrappers, to prevent future use. Updates #5162 Change-Id: I59c0e38b5fbca5a935d701645789cddf3d7863ad Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25net/netaddr: start migrating to net/netip via new netaddr adapter packageBrad Fitzpatrick1-8/+8
Updates #5162 Change-Id: Id7bdec303b25471f69d542f8ce43805328d56c12 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-21ssh/tailssh: add "ssh" to conn logsMaisem Ali1-1/+1
Fixes #5089 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-07-21ssh/tailssh: handle not-authenticated-yet connections in matchRuleMaisem Ali1-13/+57
Also make more fields in conn.info thread safe, there was previously a data race here. Fixes #5110 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-07-15ssh/tailssh: better handling of signals and exitsMaisem Ali1-8/+15
We were not handling errors occurred while copying data between the subprocess and the connection. This makes it so that we pass the appropriate signals when to the process and the connection. This also fixes mosh. Updates #4919 Co-authored-by: James Tucker <raggi@tailscale.com> Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-06-27ssh/tailssh: fix logging typoMaisem Ali1-1/+1
Signed-off-by: Maisem Ali <maisem@tailscale.com>