Commit Graph
61 Commits
Author SHA1 Message Date
Vitor EnesandAlan Parra 702a3ebd32 Deduplicate multiplexer detection errors over 1-minute windows (#20694)
* Deduplicate multiplexer detection errors over 1-minute windows

This commit deduplicates errors  returned by `Mux.detect` (which detects
the type of a new connection just established) over 1-minute windows.

This ensures that health checkers / malicious actors cannot pollute /
overpower the logs with warnings when such connections are invalid or
unknown to the multiplexer.

* Improve error message

* Fix lint

* Add `TestErrorDeduplicator`

* Multi-line Sprintf

* ErrorDeduplicator -> LogLimiter

* Improve `LogLimiter.Log` API

* Fix typo

* Remove `windowInfo`

* Improve test assertions

* Use new log limiter API

* Remove unnecessary append

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

* Fix `toLogMessages`

* Start log limiter in `Mux.New`

* Use public API in tests

* Make `Config` field private

* Improve godoc

* Remove channel size from log limiter config

* Use `assert` instead of `require` for log assertions

* Revert "Start log limiter in `Mux.New`"

This reverts commit 3554daa6db.

* Use mutex instead of `entryCh`

* Start log limiter goroutine in `loglimit.New`

* Use `context.Background` as default.

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

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-03-08 20:32:44 +00:00
Anton MiniailoandZac Bergquist 91d200f280 Don't allow different tcp version IP addresses in signed PROXY headers (#22716)
* Don't allow different tcp version IP addresses in signed PROXY headers

* Change test name

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-03-07 22:56:45 +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
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +00:00
Anton Miniailo 2f0c97d276 Correctly handle LOCAL command of PROXY protocol v2 in multiplexer (#22086) 2023-02-21 17:00:52 +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
Anton Miniailo 8bbe8fad63 Change signing cert format from PEM to DER for signed PROXY headers (#20146)
That way we can send less data over the connection.
2023-01-13 02:36:09 +00:00
Anton Miniailo 50aeb630cb Correctly set protocol version in signed PROXY header based on source address (#19707) 2022-12-29 17:04:36 +00:00
Anton Miniailo a039ce1cf9 Add secure IP propagation from teleport proxy to auth server via ALPN (#19008)
* Add secure IP propagation from proxy to auth server when using ALPN

We're using PROXY protocol extensions called TLVs to send
signed JWT and proxy's certificate to the auth server. Auth
validates JWT using provided signing certificate and host CA
to make sure that IP information comes from our internal proxy.
2022-12-23 22:12:42 +00:00
Jakub Nyckowski 9379243390 Use pre-generated RSA keys in tests (#18750)
Many of our tests (db package, I'm looking at you) generate many RSA keys. This has two main side effects; makes our tests slow and flaky as CPU usage spikes in random moments when the tests are run in parallel.
This change pre-generates RSA keys at the beginning of each test module and reuse them in randomized order to reduce the situation that one key has been used multiple times in one test.
I had to move a few files to avoid circular dependencies.
2022-12-05 19:33:49 +00:00
Anton Miniailo 7f852b4d58 Add TLV support to ProxyLine (#18494)
Add TLV support to ProxyLine

TLV (Type-Length-Value) is a way to to send custom data through PROXY
protocol defined in the spec, end of section 2.2
2022-11-21 16:17:03 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Gavin Frazar a6c7107ebd handle postgres GSSEncRequest startup message (#17614)
* Recognize GSSEncRequest as postgres proto

* Respond to GSSEncRequest with 'N' for 'not supported' in postgres engine

* Add test for GSSEncRequest to postgres via proxy

* Save gssencmode=disable in .pg_service.conf and test it

* Check for repeated startup encryption request

* Refactor postgres startup test code into its own test

* Test covers all code paths in the proxy startup handler

* Make postgres proxy tests run in parallel

* Reduced test execution time from 15 seconds to 4.5 seconds.
* Ran with race detector and all tests passed.

* Make sure we read at least one byte

* Fix lint

* Fix lint

* Change err to bad parameter

* Update test
2022-10-25 02:35:02 +00:00
Alan Parra b289295f93 Move away from deprecated protoc-gen-go plugin (#17267)
Moves from github.com/golang/protobuf protoc-gen-go plugin to google.golang.org/
plugins.

This change was a long-time coming, but is now possible to do since our
dependencies are up-to-date.

* Move away from deprecated protoc-gen-go plugin
* Embed unimplemented server in handler.Handler
* Embed unimplemented server in multiplexer_test.go
* Update generated protos
2022-10-13 14:01:44 +00:00
Alan Parra 8a25dc9755 Add Device Trust protobuf definitions (#17302)
Add definitions for Device Trust RPCs.

DeviceTrustService is fairly isolated from other services, so it is generated
using plain `protoc-gen-go` instead of Gogo.

teleport.e#514

* Add Device Trust proto definitions
* Allow proto generation without gogo
* Drop Gogo from lib/multiplexer protos
* Update generated protos
* Tidy modules
2022-10-11 22:21:38 +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
Alan Parra f447b99c63 Use Buf to build/lint/format lib/ protos (#15870)
Similarly to #15856, moves lib/ protos (except for Connect) under the proto/ tree.

The intended layout is a mirror of api:

```
teleport-root
  proto/         <- root for protos and proto imports
    teleport/
      lib/...
  gen/proto/go/  <- ideal root for generated protos
```

#15187

* Move lib/ protos under the proto/ tree
* Reformat protos
* Update generated protos
2022-08-29 17:44:18 +00:00
Roman Tkachenko 3d420394c0 Remove TestMux/Timeout reliance on real time (#15826) 2022-08-25 00:10:29 +00:00
Andrew Burke 9607fdd78c Allow reverse tunnel join without exposing the web API (#13598)
This change allows agents to join over a reverse tunnel (port 3024 by default) only, instead of also requiring access to the web API (port 3080).
2022-08-15 21:28:24 +00:00
Noah Stride af5e2517de Proxy Protocol support for Proxy SSH listener (#14712)
* Add additional debug logging for instantiation of ssh server conn

* Rough out introducing mux to ssh listener

* Catch errors from multiplexer serve

* Adapt multiplexer to support ProxyHelloSignature

* Adjust logging for ssh conn creation

* Adjust tests to use semantically correct assert/require helpers

* Address PR comments

* Check Client addr is properly propagated in mux test
2022-08-01 14:18:34 +00:00
Nic Klaassen c29c5db68c Fix TestMux/Timeout (#14208) 2022-07-12 02:00:56 +00:00
Andrew LeFevre 39212518bf Match full magic byte sequences with detectProto (#12426)
Previously, 8 bytes was always passed into 'detectProto'. But assumptions
were made that the input was only 3 bytes, causing 'detectProto' to match
against inputs that were prefixed with a part of a magic byte sequence.
Magic byte sequences by definition need to be fully present in order to be
effective, so don't match against truncated magic byte sequences, and
do an extra read if necessary to match the ProxyV2 protocol. The length of
the magic bytes of that protocol is 12 bytes, but many other protocols will
only send 8 bytes at first, so only do an extra read if we're reasonably sure
the input is using ProxyV2 to avoid EOF errors.
2022-06-01 21:55:31 +00:00
Przemko Robakowski 8b601f9cde Read all PROXYv2 header bytes (#12861)
In PROXYv2 protocol there can be more bytes after IP/ports data that can be ignored but need to be consumed. This change handles that.
2022-05-25 01:34:35 +00:00
Przemko Robakowski 17fc073379 Support proxy protocol v2 in MySQL (#12424)
#11684 added support for proxy protocol v2 for SSH and Postgres but MySQL uses different code path and it was missing. This change fixes that.
It also adds tests for v2 protocol support for MySQL, Postgres, Mongo and Redis
2022-05-18 16:04:10 +00:00
Edoardo Spadolini 875dcf7ebc Listener hygiene (#12540) 2022-05-17 08:16:31 +00:00
Edoardo Spadolini 9d91466a0e Proxy restart fixes (#11802)
* Remove unused backend wrapper from Cache

* Remove double printShutdownStatus

* Fix readyz race condition

* Test coverage for the readyz.monitor fix

* Close listeners immediately in proxy.shutdown

* Use and handle net.ErrClosed correctly

This adapts utils.IsUseOfClosedNetworkError to check for net.ErrClosed
even inside trace.Aggregate errors, makes it so that we always return
something that would pass errors.Is(err, net.ErrClosed) when returning
from a (net.Listener).Accept(), and handles closed listeners within our
various Serve() loops so that we don't hit spurious backoff waits while
shutting down.

* Close listeners early and emitters late

* Test coverage for the proxy listener changes

* Revert some errors back to trace.ConnectionProblem

* Reduce PR scope to just the proxy, add comments

* Improve error logging.
2022-05-06 18:12:11 +02:00
Przemko Robakowski 3ff19cf7c4 Support proxy protocol v2 (#11684)
This change add multiplexer support for proxy protocol v2 (binary).

Closes #4904
2022-04-05 00:48:16 +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
Jim Bishopp 805239952f Fix race condition in multiplexer tests (#9660)
Some tests in multiplexer passed connections to Mux before registering
to handle a specific type of connection (TLS, Postgres, etc). When the
Mux Serve function handles the connection before the type of connection
is registered to be handled, it will close the connection.

Race condition:
1. create Mux
2. send new connection to Mux listener
3. register DB listener and receive conn

Fixed race:
1. create Mux
2. register DB listener
3. send new connection to Mux listener
4. receive conn from DB listener
2022-01-05 18:30:34 -05:00
Jim Bishopp bcba332c4d Fix goroutine/socket leak in multiplexer (#9507)
Fixes gravitational/teleport-private#78
LAT-APP21-3

Change the multiplexer from opt-out to opt-in for protocol listeners.

The multiplexer previously always created new listeners for each protocol (SSH, TLS, DB) and its Config contained opt-out configurations (DisableTLS, DisableSSH, DisablePostgres). When callers didn't explicitly disable a protocol, new connections for that protocol would never close and leak a goroutine. This exposed a 3-line DoS whereby multiple connections could be passed to the multiplexer for a protocol that was not being serviced, eventually resulting in file descriptor limits being hit, which then prevented the teleport process from operating (see example in issue).

Changing to opt-in means new protocols can be added to the multiplexer without requiring all existing callers to be changed (to opt-out of the new protocol). Forgetting to opt-out would expose new code to DoS without compile-time, test, or operational notification.

Rather than rely on opt-out flags in the config, this change creates listeners only when explicitly requested by callers. The existing getter methods on multiplexer were changed to create listeners when called. And multiplexer protocol detection now closes connections when a listener hasn't been created. This also allowed for the protocol detection routine to be simplified.
2021-12-23 19:04:16 +00:00
Marek Smoliński d24ae5b1ce Add ability to run Postgres proxy on separate listener (#8323) 2021-12-10 11:05:19 +01:00
Roman Tkachenko e1c3f80aa0 Fixes for cert checker and Postgres config builder (#8251) 2021-09-17 13:28:40 -07:00
Marek Smoliński c142b656c8 ALPN SNI Proxy (#7524) 2021-09-13 11:54:49 +02:00
Alan Parra dba49bfad6 Lint and fix missing license headers (#8075)
Introduce new make targets to check and add license headers to files
("make lint-license" and "make fix-license"). License checking is now a part of
"make lint" as well.

Initial attempts used goheader, but it caused "make lint-go" to become about 9x
slower (if not more), plus it only targets go files. Google's addlicense is fast
enough and targets however many file types we want.

Existing files that were missing licenses got the header added, using the
current year as the license date.

* Introduce lint-license and fix-license make targets
* Ignore generated files
* Add license to go files
* Replace irregular licenses with standard copyright/license
* Add license to proto files
* Install addlicense in build.assets Dockerfile
2021-08-30 09:44:09 -07:00
Roman Tkachenko ebc882c80d Use web listener for web server (#7619) 2021-07-21 09:53:33 -07:00
Roman Tkachenko 6b9726f961 Add MongoDB database access support (#7213) 2021-06-21 22:54:05 -07:00
Russell Jones 64696ca632 Updated TLS handshake timeout.
Updated TLS handshake timeout. During some operations, Teleport can
flood the network with traffic which causes the TLS handshake to occur
slower than 1 second.

One example is during SSO login. The initial connection is an
unauthenticated connection, and upon successful SSO login a "types.User"
is created and replicated to all nodes. For large clusters this can mean
10k+ "types.User" objects getting replicated at the same time the user
attempts to re-establishing another connection to Auth this time with
valid identity credentials. This connection sometimes can take longer
than the original 1 second timeout.
2021-05-04 16:41:07 -07:00
Roman Tkachenko d0cfc8a66b Proxy line support for mysql (#6594) 2021-04-29 18:03:10 -07:00
Andrew Lytvynov eee051c4a6 grpc: use the regular buildbox and bump gogoproto version (#5879)
An extra dockerfile for gRPC generation is extra maintenance burden. It
was also using a really old base image that has a ton of known vulns.

Also, update GOGO_PROTO_TAG to match the version we have vendored via
go.mod.
2021-03-10 11:16:08 -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
Andrew Lytvynov 4b5bb54bf4 u2f: restructure MFA backend to support multiple devices (#5404)
Each user can now have multiple devices. This commit only changes the
backend structure to support it, the client and API haven't been updated
yet.

Also added a migration for existing MFA data on auth server startup.
2021-02-01 17:30:39 -08:00
Roman Tkachenko 127693c315 Refactor db proxy/engine for easier reuse (#5325) 2021-01-21 15:34:12 -08:00
Roman Tkachenko 8e1865464b Database access (#5005) 2021-01-14 18:21:38 -08:00
Andrew Lytvynov 566b7cc457 RFD 1: user testify/require instead of testify/assert
`require` is a sister package to `assert` that terminates the test on
failure. `assert` records the failure but lets the test proceed, which
is un-intuitive.

Also update all existing tests to match.
2020-10-16 00:15:25 +00:00
Sasha Klizhentas c1b1c6a154 Improves logging and error handling in filesessions.
Adds chaos tests for async file upload.

Fixes playback for legacy sessions stored unpacked on disk
2020-10-06 13:41:17 -07:00
Sasha Klizhentas d160507430 Session streaming
This commit introduces GRPC API for streaming sessions.

It adds structured events and sync streaming
that avoids storing events on disk.

You can find design in rfd/0002-streaming.md RFD.
2020-09-28 23:08:56 -07:00
Forrest Marshall acde213069 Make agent channel setup lazy.
Changes agent channel setup behavior to be consistent
openssh by having servers lazily request agent channels
when they are needed, rather than immediately starting a
single connection-wide channel as soon as forwarding is
requested.  Fixes an issue introduced in #3613 which
caused openssh clients to hang on exit due to persistent
agent channel.
2020-06-10 14:15:51 -07:00
Andrew Lytvynov b6ca22fbd2 errcheck: add missing error checks in lib/multiplexer 2020-06-01 17:00:07 +00:00
Andrew Lytvynov 4efbf621d3 Auto assign listening port in lib/multiplexer tests 2020-05-21 20:38:37 +00:00
Forrest Marshall c341d2bc15 fix agent forwarding for multi-session connections
Changes the lifetime of agent forwarding to be scoped
to the underlying ssh connection, instead of the
specific ssh channel which initially passed the agent
forwarding request.
2020-04-28 17:45:29 -07:00