Commit Graph
81 Commits
Author SHA1 Message Date
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
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
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
Jakub NyckowskiandAlan Parra 9c80f3802e Enable nolintlint linter (#19406)
* Enable nolintlint linter

* Fix nolint comments in the api package

* Fix RDP client comment

* Address review comment

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Allow unused for nolintlint linter

* Remove redundant casting

* Add comment on why allowed unused is enabled

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-12-16 21:13:58 +00:00
Mike Jensen 8c1e7be02d Security Response Header Uniformity Improvements (#18951)
Our need for customizing our security response headers primarily exists with the Content-Security-Policy.  Other headers can be applied more broadly to provide safe defaults across our service.

This commit changes httpheaders.go to allow for the CSP to be applied separate from the other headers.  Then the changes to httplib.go's handlers help make sure these headers are set generally (which we were already partially doing for caching directives).

Other changes were primarily making sure these tools are configured or used.  Or a removal of previous settings as this function is now being handled more centrally.
2022-12-06 00:56:59 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Andrew LeFevre 77f8a4ef10 Switch underlying protocol used for 'tsh scp' to SFTP (#16601)
* switch underlying protocol used for 'tsh scp' to SFTP

* address TODO

* appease linter

* add method to make it easier for other callers to transfer files

* add tests

* print transfer progress with progress bar by default

Also allow a SIGINT to gracefully stop the SFTP connection. This is
necessary  because the progress bar will ignore signals and prevent the
process from exiting.

* address SFTP fork issues

* make tests less flakey

* fix specifying dir for dst not copying files to correct paths

* make tests less flakey (again)

* don't check file access times, often differs when run in CI

* few small fixes from review, simplify Create method now that HTTP FS isn't needed

* create dst files and dirs with src mode

* improved error messages when doing file operations

* expand home dirs in remote paths

* addressed more feedback

* add license to get_home_dir.go

* address minor feedback of tests, add home dir expansion test

* update sftp fork to point to latest commit on master branch

* addressed feedback

* don't cache home dir lookups, only one remote path can ever be used
2022-09-28 16:37:18 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Zac Bergquist 55cbd0ac97 Remove use of deprecated ioutil package (#11296)
* Remove use of deprecated ioutil package
* Add lint rule to check for ioutil imports
2022-03-21 18:00:34 +00:00
dmitri ae4e5bfc97 Remove args as these can be deduced automatically 2021-03-03 17:49:12 -08:00
dmitri ca87f92ed5 Use non-greedy Mkdir variant and add a test-case for non-existing remote location with intermediate directories 2021-03-03 17:49:12 -08:00
dmitri ea4adc8b7e Add more test coverage for sink mode 2021-03-03 17:49:12 -08:00
dmitri fb8c71c6fa Check whether . is a base directory directly 2021-03-03 17:49:12 -08:00
dmitri 007235446f Use correct target directory path.
Handle target directory/file renames.

Fixes https://github.com/gravitational/teleport/issues/5695.
2021-03-03 17:49:12 -08:00
Andrew Lytvynov fc1c1dbd14 Move all utils.InitLoggerForTests calls to TestMain
This prevents data races between changing the standard logger and it
acutally being used.
2021-02-23 18:04:55 -08:00
a-palchikov e65eac59b0 tsh scp to use target directory correctly (#5501)
* Fixes the scp logic to take target directory into account in sink mode.
Also expose channel error in scp client so the error is more visible to
the user. Old behavior will only output the 'exit code n' if anything
breaks.

Fixes https://github.com/gravitational/teleport/issues/5497.

* Silence 'wait: remote command exited without exit status or exit signal' error when interrupting the scp session. Leave a TODO to fix properly in a future PR

* Address review comments
2021-02-11 19:35:40 +01:00
a-palchikov 43d142085e Wait on scp process at the end of the test. Service the stderr pipe to (#5418)
avoid 'broken pipe' in scp side.

Fixes https://github.com/gravitational/teleport/issues/5417.
2021-01-28 12:55:54 +01:00
a-palchikov 0ddde38df2 Suppress linter warning about unnecessary type conversion on darwin. (#5302) 2021-01-14 19:23:48 +01:00
a-palchikov 524c9483b3 Explicitly cast time values to int64 to enable 32-bit builds. (#5291)
Updates https://github.com/gravitational/teleport/pull/4764.
2021-01-14 11:10:47 +01:00
a-palchikov 72630d1df5 Implement support for preserving file times for 'tsh scp' (#4764)
* Add -p flag to scp
* Add support for preserving access/modification times on files/directories when copying files between hosts.
* lib/sshutils/scp: add time statting for directories
* Add directory handling for scp
* Rewrite scp tests with testify
* Address review comments
2021-01-06 13:21:06 +01:00
Andrew Lytvynov 92ed2db38a Fixing golint warnings, batch 1
Mostly cosmetic changes:
- making receiver names consistent
- renaming `foo.FooBar` to `foo.Bar` (using package name as prefix)
- removing redundant `else` branches
- changing `a += 1` to `a++`
2020-10-13 00:22:49 +00:00
Joshua Behrens 19d482dad3 Allow user with at sign in name (#4002)
* Allow @ in scp targets
* Allow @ in proxyjump usernames
* Allow @ in tsh usernames
2020-07-21 10:41:31 -03:00
Andrew Lytvynov dba7f8e563 Remove ineffectual assignments
Caught by `ineffassign` linter.

Note the change in lib/srv/regular/sshserver.go - looks like we
advertised the custom listening port (`aport`), if it differed from
regular listening port (`port`).
2020-05-11 16:44:27 +00:00
Andrew Lytvynov d40013f33b Send SCP error messages to receiver when upload fails
This serves two purposes:
1. on upload, the receiver (node) will exit with error and generate an
   SCP error audit event.
2. on download, the receiver (tsh) will print a meaningful message from
   the sender (node)

Fixes #2861
2020-05-06 00:03:30 +00:00
Andrew Lytvynov f8661edea3 Clean up dead code across the codebase
Spring cleaning!
A very mechanical cleanup using several linters (unused, deadcode,
structcheck). Build and tests still pass so no behavior should be
affected.
2020-04-09 21:10:12 +00:00
Russell Jones 9a237b7328 Print scp status without quotes.
Don't escape the final \n in the scp status message. This way the status
message will get printed without double quotes.
2019-12-06 18:14:26 -08:00
Russell Jones 1479dfc258 Always emit exec command and exit code.
Due to the scp being inherently vulnerable to command injection, always
make sure the full command and exit code is recorded in the Audit Log
for accountability purposes.

For more details about scp, see the following.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=327019
https://bugzilla.mindrot.org/show_bug.cgi?id=1998
2019-09-03 13:44:20 -07:00
Sasha Klizhentas ba1fcf5d77 Fix teleport parsing to support IPV6
This commit fixes #2124
2019-07-23 20:36:34 -07:00
Russell Jones 27f5ef8f88 Added support for directory mode to scp.
On the client side, make sure directory mode is requested when sending
multiple files. On the server side, when in directory mode, validate
that the target is a directory.
2019-02-11 16:05:41 -08:00
Russell Jones 599b8b73c9 Fix scp client vulnerabilities.
Fixed scp client vulnerabilities to a malicious server found by Harry
Sintonen. For more information, see the following:

https://sintonen.fi/advisories/scp-client-multiple-vulnerabilities.txt
2019-02-11 14:57:57 -08:00
Russell Jones cea10926a2 Convert "permission denied" errors into trace errors. 2019-02-04 10:10:37 -08:00
Cove Schneider 8b299e9c28 spelling cleanup 2018-11-15 12:44:51 -08:00
Russell Jones 9dbbefe316 Emit secure copy specific events instead of generic exec events when
using scp. Fix exec events to strip /bin/bash -c prefix when using
regular Teleport nodes.
2018-08-20 16:00:40 -07:00
Alexey Kontsevoy 7553f13256 fix handling of exitCodes during SCP 2018-07-25 16:07:16 -04:00
Alexey Kontsevoy ee98d7335d http files/separate remote location from file name in SCP requests 2018-07-18 19:05:00 -04:00
Alexey Kontsevoy 57b2789a49 http file transfer 2018-07-12 14:58:37 -04:00
mricher b58cb051e8 Correct various typos
This was fixed running the `misspell` linter in fix mode using
`gometalinter`. The exact command I ran was :
```
gometalinter --vendor --disable-all -E misspell --linter='misspell:misspell -w {path}:^(?P<path>.*?\.go):(?P<line>\d+):(?P<col>\d+):\s*(?P<message>.*)$' ./...
```

Some typo were fixed by hand on top of it.
2017-10-20 10:20:26 +02: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
Ev Kontsevoy cdfb15fd82 scp compatibility improvements 2017-06-09 10:48:21 -07:00
Ev Kontsevoy 0ce13c8b1b Fixed shell globbing for scp 2017-06-08 22:18:09 -07:00
Ev Kontsevoy 99672d09a7 Fixed scp regressions
In this commit:

1. Minor addition to Makefile to pull new .go files from
   tool/teleport/common

2. os.Glob() returns an empty list (instead of an error) if the
   file/pattern is not found, so added check for that.

3. sendFile was prematurely sending 'C' command before trying to open a
   file. This used to lead to creation of empty files for invlaid
   sources.

Also, removed some confusing comments.
2017-03-29 16:49:40 -07:00
Ev Kontsevoy a7aa9b4c93 Final cleanup in preparation for PR 2017-02-23 17:57:28 -08:00
Ev Kontsevoy 80df1bbc2d scp fixes
- added file globbing for "sink"
- added proper handling of directory copying into an existing target [1]

[1] compatible with OpenSSH behavior
2017-02-23 00:37:13 -08:00
Ev Kontsevoy f5022149c8 Fixed "double echo" scp issue
Refs #771
2017-02-18 23:52:56 -08:00
Ev Kontsevoy c6c77a183c SCP improvements
- Removed strange handling of the ending / symbol, causing directories
  not being created. Fixes #606

- Added per-file progress indicator (reports "XXX uploaded").
2016-11-03 20:06:43 -07:00
Ev Kontsevoy 380d2f366b Preliminary SCP work
1) -r flag handling

   Proper handling of `-r` flag on the tsh side (recursive).
   Prior to this commit it was all uploads were _always_ recursive.

2) less verbose logging.

   Replaced a bunch of log.Info() with log.Debug()
2016-11-03 18:07:39 -07:00
Ev Kontsevoy 7c3b74d8ff PR comments - implemented! 2016-05-27 11:26:48 -07:00
Ev Kontsevoy ce3bbbde3f SCP error messages are proper now
`tsh scp` now reports the same error messages as OpenSSH scp:

- when talking to Teleport servers
- when talking to OpenSSH servers
2016-05-26 18:00:40 -07:00
Ev Kontsevoy 48a74fbeca Intermediate commit (scp up/down works agaisnt openSSH servers) 2016-05-26 14:46:56 -07:00