Commit Graph
47 Commits
Author SHA1 Message Date
rosstimothy e95f3d3ed5 Start using authclient.Client/ClientI/NewClient (#41539)
Consumes the new auth client created in #41460. The changes introduced
were performed with a series of gofmt rewrite rules.

```bash
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "ClientI -> authclient.ClientI" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "Client -> authclient.Client" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "NewClient -> authclient.NewClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.ClientI -> authclient.ClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.Client -> authclient.Client" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.NewClient -> authclient.NewClient" {} \;
```
2024-05-15 14:09:14 +00:00
Noah Stride 0bd99702a1 Switch existing error reporting for tracing to use new helper (#40662)
* Switch existing trace error reporting to use `apitracing.EndSpan`

* Add deferred trace error reports to tbot

* Optimize for @espadolini limited horizontal editor length
2024-04-19 14:45:39 +00:00
Forrest 82281e1191 route based on match quality score (#40559) 2024-04-18 23:02:26 +00:00
Nic Klaassenandrosstimothy 680ac535ce fix: return OpaqueAccessDenied for NotFound remote cluster errors (#40571)
* fix: return OpaqueAccessDenied for NotFound errors

This commit modifies OpaqueAccessDenied to return an identical generic
NotFound error whether the input error is NotFound or AccessDenied.
The commit also updates all call sites of OpaqueAccessDenied to use it in
the paths where there is any error fetching the resource as well as when
access is denied.

It doesn't do much good to return AccessDenied errors as NotFound, if
they don't match the NotFound error you would get if the resource really
didn't exist.
It's trivial to tell the errors apart and discover the existence of a
resource you shouldn't be allowed to access.
The commit attempts to mitigate that issue and properly hide the
existence of resources the user should not be allowed to list.

* remove changes unrelated to remote clusters

* improve doc comment

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

* make sure gRPC errors match

* fix integration test

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2024-04-18 19:01:01 +00:00
Edoardo Spadolini e96f103954 Fix some gRPC-tunneled connections (#40632)
* Fix some gRPC-tunneled connections

* Fix tests checking the return value of dial()
2024-04-18 16:11:00 +00:00
rosstimothy 1aec5414f1 Replace constants from trace with equivalents defined in teleport (#39307)
* Remove logging from circuit breaker

The logging is never output, and if it was would be very verbose.
Instead of dropping the level down to trace the logger is removed
entirely.

* Add constants from trace library

The logging functionality in trace is being removed in an upcoming
release. To prepare the logging component keys are copied from trace
into teleport.

* Convert trace.ComponentFields to teleport.ComponentFields

* Replace trace.Component with teleport.ComponentKey

* Replace trace logging constants
2024-03-14 13:04:29 +00:00
Edoardo Spadolini 6629d9a5df Remove MaxConcurrentStreams in proxy peering (#39218) 2024-03-12 02:38:39 +00:00
Noah StrideandEdoardo Spadolini c11bddc5f2 Refactor Presence service to add ListRemoteClusters, context.Context and returning updated/created RemoteClusters (#38694)
* Wire context/returning through local svc and add ListRemoteCluster

* Propagate changes through to cache

* Propagate changes up

* Remove marshal options from GetRemoteCluster

* Fix tests in lib/services/local

* Fix tests

* Add test for PresenceService_ListRemoteClusters

* Add removal TODO

* Add retry to UpdateRemoteCluster

* Fix more tests

* Fix linting

* Remove unused Create and DeleteAll RPCs

* Fix test

* Add GetAndUpdateRemoteCluster

* Add test for GetAndUpdateRemoteCluster

* Update lib/services/local/presence.go

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

* Update lib/services/local/presence.go

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

* Update lib/services/local/presence.go

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

* Rename GetAndUpdate to Patch

* Exit early if we know conditional update will fail

* prevent modifying revision

* Update tests

* Add `clear()`

* Fix test/lint failures

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2024-03-05 15:56:00 +00:00
rosstimothy d7b814010e Add ClusterNetworkingConfig support to cluster configuration RPC service (#38590)
* Remove marshal options from GetClusterNetworkingConfig

* Add ClusterNetworkingConfig support to cluster configuration RPC service

Extends the clusterconfigv1.Service to implement RPCs for interacting
with ClusterNetworkingConfig. The various GetClusterNetworkingConfig
interfaces were also all updated to remove the marshal options since
they were never used and served no purpose.
2024-02-27 22:29:53 +00:00
rosstimothy ab9fe0e735 Increment connect_to_node_attempts_total during dial attempts (#36633)
During refactoring performed in #18370 the counter was moved but
never used outside of registration. This restores incrementing the
counter for dial attempts and improves error reporting in traces
in the router.
2024-01-16 14:11:33 +00:00
Alex McGrath 4437c66cf6 Remove TELEPORT_UNSTABLE_UNLISTED_AGENT_DIALING option (#36517)
* remove `TELEPORT_UNSTABLE_UNLISTED_AGENT_DIALING` option

* remove TestSSHLoadAllCAs test

* update test plan
2024-01-10 17:56:09 +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
Mike Jensen 05adc2d422 Limit GRPC Active streams (#33936)
Originally there was a default limit of 100 max concurrent streams, however in 2017 the GRPC team removed this default: https://github.com/grpc/grpc-go/pull/1624

With the recent HTTP/2 Rapid Reset DoS, it is now being encouraged to re-introduce a limit.  The fix requires this value to be configured in fact: https://github.com/grpc/grpc-go/pull/6703
2023-10-27 15:26:07 +00:00
fd73320933 Require SSH prefix in router.DialHost connections (#33000)
* Require SSH prefix in proxySubsys connections

* Move prefix assertion into router.DialHost()

* Wrap conn separately

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

* Allow multiple writes to satisfy prefix requirement

* Add comment about concurrent calls

* Advance pointer even when err != nil

* Minimize code for finding smaller entity

* Use pointer to advance

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

* Test in parallel

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

* Wrap the error.

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

* Wrap the error.

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

* More specific error assertions

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-10-18 20:43:46 +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
Alex McGrathandForrest Marshall e0086909cc Dont allow directly dialing to servers not in inventory (#30323)
* Dont allow directly dialing to servers not in inventory

add direct dial escape hatch

* Fix failing unit test

* Fix TestProxySSH

* Fix TestTraitsPropagation

* resolve comment

* fix non-multiplexed trusted cluster setup in tsh test suite

* Fix TestProxySSH

* wait on nodes

* Skip the flaky check for TestSSHLoadAllCAs

---------

Co-authored-by: Forrest Marshall <forrest@goteleport.com>
2023-08-29 11:52:55 +00:00
Brian Joerger a33d8caa70 Remove gRPC error interceptor aliases; update e ref. (#31011) 2023-08-25 02:43:02 +00:00
Brian Joerger cf6473feb9 Add gRPC error interceptors to API client (#30578)
* Move gRPC error intercetpors to api/utils/grpc/interceptors.

* Use error interceptors in api client and mock server.

* Apply suggestions from CR.

* Unwrap FromGRPC errors in middleware.

* Use gRPC auth service in tests instead of external example service.

* It's gRPC!!!

* Fix unit test.

* Add error interceptor to proxy client.

* Fix merge conflict.
2023-08-24 23:27:06 +00:00
Marco André Dinis 859898635f Use Amazon EICE to connect into EC2 instances (#30632)
* Use Amazon EICE to connect into EC2 instances

This PR adds a new method to SSH into EC2 instances.
It uses the Amazon EC2 Instance Connect Endpoint to do so.

You can read more about the capabilities/limitations of this feature
here
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html

From the Teleport point of view, this uses the AWS OIDC Integration to
call the AWS APIs.
This connection mode is similar to the Agentless mode, where Teleport
connects to the OpenSSH daemon on the target server.
Except, that with this mode there's no required set up on the target
machine (no CAs are being used).

An overview of the flow when the user tries to SSH into a node:
- an SSH Public Key is sent to the target EC2 Instance
- a connection is made to the EC2 Instance Connect Endpoint using
  websockets, which in turn pipes the connection to the Private IP of
  the EC2 Instance

* review pt1

* pass CA for tests

* add godocs to OpenTunnelEC2

* fetch proxy public address jit

* add docs and move key generation to native package

* remove tcp socket
2023-08-24 16:38:51 +00:00
Forrest 4e66a6fc67 support case-insensitive routing option (#29320)
* support case-insensitive routing option

* update docs
2023-08-17 00:48:19 +00:00
Anton Miniailo 419b88eb91 Remove returning Teleport version on dialing a host (#29799)
It was required for compatibilty reasons - v13 proxy could connect to v12 agents,
which didn't support signed PROXY headers. But we don't need it in v14.
2023-08-03 02:40:44 +00:00
rosstimothy 20559218ad Fix tsh windows builds (#28357)
#24864 added a dependency of lib/web into tsh which broke windows
tsh builds because lib/web transiently depends on lib/srv which
has linux specific code. This shuffles around a few things so
that lib/web is no longer importing lib/srv at all by:

- Indirectly using the srv.SessionController to apply session
control for web ssh sessions

- Moving the common reversetunnel interfaces into
reversetunnelclient since lib/reversetunnel imports
lib/srv/forward which imports lib/srv.

- Directly converting mysql client errors in the connection
tester instead of calling a common function.
2023-06-30 17:12:12 +00:00
Zac Bergquist 29e5a0c473 Make tctl build for Windows (#25447)
* Add a no-op syslog impl for Windows

* Break tctl's dependency on lib/srv

tctl's auth client depends on the lib/reversetunnel package in order
to dial the auth server via reverse tunnel. This package in turn
depends on lib/srv/forward and lib/srv, which is a bunch of
Linux-specific code for Teleport services (re-exec, etc).

By extracting the client side code for dialing via reverse tunnels
into its own package, we can now build tctl for Windows with the
following incantation:

    CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -o tctl.exe ./tool/tctl
2023-05-24 20:44:18 +00:00
Andrew LeFevre 68feffbf82 fix connecting to agentless leaf nodes (#25206)
* fix connecting to agentless leaf nodes

Pass user and role information to Auth server signing OpenSSH cert
so avoid user/role lookup errors if the target node is on a leaf
cluster. Also use role and trait information from the current
connection rather than the backend to support role impersonation.

* make protobuf changes backwards-compatible
2023-05-02 17:39:47 +00:00
rosstimothy a5898a2a99 Convert tsh ssh to use the proxy transport service instead of ssh (#23228)
* Convert tsh ssh to use the proxy transport service instead of ssh

In an effort to reduce latency establishing sessions `tsh ssh` is
migrating away from connecting to the Proxy via SSH in favor of
using gRPC. The SSH handshakes with the Proxy increase latency in
situations where the distance between geolocations of the client
and Proxy are large. TLS handshakes used by the gRPC service have
proven to reduce latency by ~20% in the same scenario.

A new `lib/client.ClusterClient` has been introduced that should
be used instead of `lib/client.ProxyClient` to connect to a Teleport
cluster. Most of the functionality within the `ClusterClient` was
a direct copy from the `ProxyClient`.

The `lib/client.TeleportClient` now has a `ConnectToCluster` method
which will connect to both the Proxy and Auth service via the
`api/client.ProxyClient` which first attempts to use gRPC and reverts
back to SSH to preserve backwards compatability. The `ClusterClient`
should be passed around and reused instead of following the
established pattern of `tc.ConnectToProxy` followed by a
`proxy.ConnectToCluster` to get an `auth.ClientI`.

Additionally some of the `agentless` package was refactored to reduce
dependencies and allow it to work with connections to the Proxy that
originated via gRPC instead of SSH.

Changes to the integration tests are mostly to accomodate IP Pinning
and ensure that it works for both connections established via SSH
and gPRC.

This is the final PR needed to complete #19812.

* fix typos and unify span attributes

* pass node name to ConnectToNode

* simplify jump host resetting
2023-04-04 21:31:39 +00:00
rosstimothy 7573204fef Validate proxy peer identity (#23392)
Closes #23230

Proxy peer clients now validate that any connections established to
a peer have the expected UUID. This prevents clients from connecting
to incorrect peers if the `peer_public_addr` is shared by multiple
proxies, or is a load balancer.

In the event that a connection is established to an incorrect peer
the connection is closed and a error is written to the logs. The
gRPC connection should be attempted multiple times and eventually
land on the correct peer. However there may be some degradation
of service until the peer connections are all properly established.
2023-03-23 13:12:59 +00:00
rosstimothy 1427e194af Refactor stream.Source implementations (#23351)
The interface smuggling within `stream.ReadWriter.Close` now checks
for `io.Closer` instead of `grpc.ClientStream` to allow clients
that need to perform additoinal closing logic besides sending a
`CloseSend` message to do so. All existing client implementations
of `stream.Source` now implement `io.Closer` so they are still
cleaned up properly.

The multiplexed ssh streams are now tied together to prevent attempts
to send a message at the same time. In addition, the client ssh
streams have been updated to only send a single `CloseSend` on which
ever protocol is terminated first.
2023-03-22 14:33:16 +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
rosstimothy a8568adb82 Make the NodeWatcher more robust (#22877)
Prior to the NodeWatcher being successfully initialized, or when
it became stale any calls to `GetNodes` would return no data or
stale data. This behavior results in the problems described in
#22672.

The NodeWatcher will now fallback to pulling data from the cache
in the event that it has no data or stale data when callers attempt
to retrieve nodes. This should reduce the time that it takes the
a new Proxy or a Proxy with intermittent connectivity issues to
Auth be able to route to nodes.

The impact of this change should be noticeable in tests that
create a Proxy and several Nodes and then immediately try to
open a session on the Nodes.

Closes #22672
2023-03-10 18:34:17 +00:00
Andrew LeFevre 948c1db915 preform RBAC checks before connecting to registered OpenSSH nodes (#21938)
The RBAC logic assumes that SSH connections to registered OpenSSH nodes
will always be proxied and terminated, which will come in a future PR.

Part of implementing #19261.
2023-03-03 17:29:53 +00:00
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +00:00
rosstimothy 89606e07f0 Add ProxySSH implementation to transportv1.Service (#21728)
Completes the service implementation of the transportv1.Service.
Ensures that both SSH and SSH Agent protocols are multiplexed
correctly over the gRPC stream via TestService_ProxySSH.

Part of #19812
2023-02-23 21:04:23 +00:00
rosstimothy 9440763235 Implement transport client (#21947)
Provides a client that can be used to connect to and interact with
the transport service in `lib/srv/transport`. The client abstracts
the fact that a gRPC stream is being used for the `net.Conn` created
by `DialCluster` and `DialHost`.

This also moves `lib/utils/grpc/stream` to `api/utils/grpc/stream`
so that the client and server can make use of the same stream
abstractions.

Part of #19812
2023-02-21 14:38:57 +00:00
rosstimothy 294be31933 Add Proxy Transport service (#20784)
The first step in implementing the teleport.proxy.v1.ProxyServic
as defined in RFD 100. This includes part of the service
implementation and a stream abstraction to allow transporting
payloads for frames over a gRPC stream.

The proxy peering specific implementation of the stream abstraction
was refactored into `lib/utils/grpc/stream` so that other services
can make use of it.

Part of #19812
2023-02-08 13:40:03 +00:00
rosstimothy 70c0c87678 Move connection metrics to proxy.Router (#20646)
Migrates metrics counting proxied connections and connection attempts
from `regular/proxy.go` to `proxy.Router` so that connections via
the web UI, tsh ssh via the Proxy ssh and grpc servers are all
accounted for.
2023-01-25 14:36:47 +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
rosstimothy e4e7f538ce Make proxy routing logic reusable (#18370)
* create  package to contain proxy peering code

* Refactor proxy routing logic into a reusable object

Routing logic existed within an unexported handler of ssh subsystem
requests, which prevented it from being reused by other components
within the proxy, like the webapi server. This causes significant
latency issues for web sessions because the web apiserver is required
to dial the proxy ssh server to determine how to route to the host.
Since the web apiserver and the proxy ssh server exist in the same
process this is an entirely unnecesarry step that could be avoided
if the routing and ability to established connections were shared
throughout the proxy.

A new `proxy.Router` object is introduced which contains all the
logic that used to exist in `regular.proxySubsys` for determining
how to connect to servers and clusters. All routing within the
`regular.proxySubsys` now leverages the `proxy.Router` to dial
the target.

This is step 1 in addressing #15167. Now that the `proxy.Router`
exists `web.APIServer` will be able to make use of it to avoid
dialing the same process to establish connections.
2022-11-18 13:11:32 +00:00
Steven Martin 00728c4f63 spell fixes (#18545) 2022-11-17 16:28:05 +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
rosstimothy c469a34994 Move prometheus collectors from utils to metrics (#15288) 2022-08-09 17:35:19 +00:00
David Boslee 40ade0bbc8 Attempt to connect to additional peer proxies on failure (#14954)
* Previously additional peer proxies were only attempted if the stream
failed to be created. Now any failure for example a missing reverse
tunnel will also attempt additional peer proxies.

* Shuffle the order in which proxy connections are used.
2022-08-08 15:42:10 +00:00
Noah Stride 02b4f8575f Configure linter to catch British 🇬🇧 spellings 🇺🇸 🦅 📖 (#14363)
* configure golangci-lint misspell to check for anglicized spellings

* Americanize spellings

* fix aws constant value with british spelling 🇬🇧

* update api types with americanized spellings

* use american spellings .cloudbuild/scripts
2022-07-14 10:51:23 +00:00
David Boslee 5f59164af5 Fix proxy peering message size buckets (#14158)
This changes the message size buckets from the default of .005-10 to
32-65536.
2022-07-08 17:19:29 +00:00
NajiObeid 423dcdc2fd fix race in proxy peer tests (#13371)
* fix race in proxy peer tests

* improve proxy ca change test
2022-06-14 03:04:49 +00:00
David Boslee 32695a2f05 Add proxy peering support (#12359)
This adds proxy peering support. A configurable setting that allows for agents 
to connect to a subset of proxies and be reachable through any proxy in the
cluster. This is achieved by creating grpc connections between each proxy
server. Client connections can then be passed between proxies to the desired
agent.
2022-06-02 17:08:24 +00:00