Commit Graph
150 Commits
Author SHA1 Message Date
Zac Bergquist 2ae9d770fc Refactor tctl's dependencies (#22693)
* Move configuration from lib/service to lib/service/servicecfg

The new servicecfg package will hold only configuration for services.
This will allow other packages (like tctl and tsh) to depend on
servicecfg without pulling in all of lib/service (which has a number
of platform-specific details).

This is the first step towards being able to build tctl for Windows.

* Move PAM and BPF config into servicecfg

This breaks a compile-time dependency on BPF/PAM for tctl.
2023-03-09 17:48:36 +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
Forrest aaee695927 node hb and watcher scalability improvements (#21490)
* node hb and watcher scalability improvements

* ensure that node has ample time to hb

* fix degraded state

* hbv2 test cov
2023-03-03 17:39:00 +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
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
rosstimothy f43a269960 Stop heartbeating during graceful shutdown (#20199)
Ensures that active connections during a graceful shutdown don't
inadvertently prolong the heartbeat.

The added ReadyEvents ensure that TeleportReady is broadcast if 
either the tracing_service or metrics_service is enabled. Not emitting 
them prevents graceful shutdown from completing because the uploader
 service requires the TeleportReady event before it can complete initialization.
2023-01-13 21:57:39 +00:00
Alan Parra 473969a700 Log trusted device in UserMetadata audit events (#20082)
Log the trusted device along with UserMetadata audit events.

Complements #20081.

gravitational/teleport.e#514
2023-01-12 18:30:30 +00:00
Tobiasz Heller 5f07b284b0 security: Prevent access to SSH nodes using SessionJoinPrincipal 2022-12-28 09:24:02 -08:00
rosstimothy 28ea98151c Remove deprecated RecordingProxy request (#19505)
RecordingProxy was replaced by ClusterDetails and can safely be
removed for v12.
2022-12-21 18:18:02 +00:00
rosstimothy 3cca37fff6 Fix web ssh session with proxy recording mode (#18910)
* Fix web ssh session with proxy recording mode

The agent was not being propagated when establishing an ssh session
via the web which resulted in the error described in #18850. Providing
the agent was straightforward, however, due to the changes from #18656
when using the forward server, as is required with proxy recording mode,
the ssh connection is now being performed directly over a `net.Pipe`.
Due to the synchronous nature of `net.Pipe` this causes a deadlock when
performing the ssh handshake. To mitigate the deadlocks, `DualPipeNetConn`
was changed to leverage `syscall.Socketpair` instead of `net.Pipe`.

`TestTerminal` now has two cases, one for node recording mode and another
for proxy recording mode. In order for the proxy recording mode test to pass
the fake clock used in the test needed to be properly propagated to the
`ssh.CertChecker` and `forward.ServerConfig`.

Fixes #18850
2022-12-02 19:45:02 +00:00
rosstimothy 7f118b34da Make session control logic reusable (#18565)
Session control logic existed within `HandleNewConn` of `srv/regular.Server`.
This prevented any of it from being used by other components that
also needed to enforce session control.

All the logic from within `HandleNewConn` was refactored to a new
`srv.SessionController` object which the `regular.Server` now uses
to perform session control. There were a few additional changes
needed to accomadate that session control now exists outside
the server and to make tests easier to write. Namely, altering
`srv.ComputLockTargets` to not take a `Server` as a parameter and
leveraging a clock within `services.SemaphoreLock`.

This is step 2 in addressing #15167. Before the web apiserver can
leverage the newly introduced proxy.Router and bypass making ssh
connections to the proxy ssh server it needs to be able to perfrom
session control.
2022-11-21 17:11:19 +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
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Andrew LeFevre e916d0d258 block SFTP connections when moderated sessions are enforced (#17679)
Fixes #17341
2022-10-24 15:25:09 +00:00
Alex McGrath f0bad6b226 Create the temporary user early if agent forwarding is being used (#16832) 2022-10-19 14:32:24 +00:00
Jakub Nyckowski 716c2bdbf9 Fix BPF (#17269)
* Revert "Refactor bpf/restrictedsession usage in lib/srv (#15824)"

This reverts commit 769951fe4b.

* Remove unused Linux BPF includes

* Fix linter issue
2022-10-12 18:41:26 +00:00
Brian Joerger ce20b20753 PIV login enforcement (#15874)
Add private key policy enforcement.

  - Add private key policy cert extensions and enforcement.

  - Add private key policy settings and attestation logic.

  - Wire attestation request through login endpoints.

  - Store attestation data for reissue requests.

  - Add private key policy discovery and logic.

  - Relogin on hardware key policy errors.

  - Include integration with Teleport Connect.
2022-09-30 23:27:48 +00:00
Andrew Burke ce94f93ad1 Fix client idle timeout ending sessions too early (#16392)
This change fixes a bug with client idle timeouts that could cause sessions to end too early.
2022-09-29 23:53:53 +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
rosstimothy ae1eb1b450 Allow tsh to retrieve cluster details in one request (#16456)
* Allow tsh to retrieve cluster details in one request

Prior to connecting to a node via `tsh ssh` we  need two bits of
information about the cluster:
 1) The session recording mode
 2) Whether FIPS is enabled

In order to retrieve the information `tsh` first would send the
global ssh request `RecordingProxyReqType` to determine the
session recording mode. Later on `tsh` would Ping the auth
server to determine if the cluster was running in FIPS mode.

In an effort to reduce the number of round trips to retrieve
this data, a new global ssh request `ClusterDetailsReqType` is
introduced that returns both the session recording mode and
whether FIPS is enabled. This allows `tsh` to leverage the new
request to get all the information it needs, and is extensible
in case more information is needed` in one request which helps
reduce latency for `tsh ssh`.
2022-09-27 14:00:24 +00:00
Alex McGrath e2fab63ba9 Introduce discovery_service and automatically run an SSM Document on discovered EC2 nodes (#14094)
* Add initial version of installer

* Resolve comments

- Use aws waiters when checking commands
- Use SSMRunRequest rather than passing instances
- General comments

* Resolve comments, (rebase) pass scriptname parameter

This resolves comments regarding running on multiple ec2 instances at
once by adding state to the instances cache to check if the instance
is known about and how far into installation it is

* Revert cache

* Dont cache on non discovery nodes

* Resolve some comments

* Move discovery out to its own serviec

* Add a `discovery_service` section

* Fix messed up conflict merge

* Make starting a standalone discovery agent work

* Resolve comments

* Resolve comments

- use a regular events.Emitter
- resolve a thousand typos :)

* Resolve comments

* resolve comments, fix a bad merge

* Fail when a non ec2 matcher type is configured

* fix lint-go

* Resolve comments

* Resolve comments, add initial test (currently broken)

* Fix log string so only 1 pair of [] are used

* Chunk instances for sending commands

* add 'isInitialized' to watchers

* Add test for chunked discovery, log output

* lints

* explicetly set matcher.Tags to "*":"*" if its unset
2022-09-21 12:23:06 +00:00
rosstimothy 769951fe4b Refactor bpf/restrictedsession usage in lib/srv (#15824)
Invert the relationship of `lib/srv` and `lib/bpf`,
`lib/restrictedsession` such that `lib/bpf` is only imported in
`lib/srv/regular`. Since not everything is built with the `bpf`
tag it's important to reduce the surface area of `lib/bpf` such
that it isn't inadvertantly imported. For instance it was entirely
possible to import a package in `tsh` that transitively
depends on `lib/bpf` - which breaks the build since `tsh` is not
compiled with the `bpf` tag.

By refactoring the `srv.Server` interface not to use the `bpf.BPF`
and `restrictedsession.Manager` interfaces directly anything that
imports `lib/srv` now won't require that `-tags=bpf` is set in
order to compile.
2022-09-07 14:49:28 +00:00
Andrew LeFevre 7edf9c333f Merge pull request #15144 from gravitational/capnspacehook/file-copy-role-option
Added file copying role option and node config option
2022-08-24 20:13:41 +00:00
Alex McGrath 122bda9ad0 Add an AWS EC2 instance fetcher (#13886)
* Add an AWS EC2 instance fetcher

* Resolve comments

- Remove leftover VPCID stuff
- Document public functions
- Return a notfound when there are no nodes fetched instead of nil nil

* Resolve comments

* Fix fileconf_test.go
2022-08-19 10:52:42 +00:00
Joel f2dd75801a Remove legacy session service (#15155) 2022-08-12 16:39:45 +00:00
rosstimothy c469a34994 Move prometheus collectors from utils to metrics (#15288) 2022-08-09 17:35:19 +00:00
Zac Bergquist d1c6b0618e Fix lint warnings (#15312)
Mostly duplicated imports and redundant types in struct literals.
2022-08-08 20:20:29 +00:00
rosstimothy 0cb248ddd3 Trace ssh sessions (#14966)
Adds a wrapper around `ssh.Session` which injects tracing context
in a similar manner to the `ssh.Client` wrapper. All usages of
`ssh.Session` have now been replaced and have the appropriate
`context.Context` passed along

Part of #12241
2022-08-04 22:14:37 +00:00
Tiago Silva 037daad083 Introduce dedicated server type for Kubernetes resources (#14389)
## What

First part of the Kubernetes [Discovery RFD](https://github.com/gravitational/teleport/pull/13376/) to introduce a Kubernetes server per cluster. 

This PR introduces a separate Kubernetes server that uses the already introduced `KubernetesClusterV3`. 

## Compatibility

In previous versions, Kubernetes Clusters were part of regular `ServerV2` resource and this refactoring deprecates the `ServerV2` usage but keeps them for compatibility with previous version.

Everything is backward compatible, so v10 kubernetes agents and trusted clusters can connect fine.

## Next steps

Once this is merged, a new PR will introduce dynamic registration for Kubernetes Clusters discovered through EKS Discovery.
2022-08-04 14:21:11 +00:00
Joel b7a319d40d Correctly propagate information about the target during forwarding (#14564) 2022-07-28 11:05:45 +00:00
rosstimothy 9b22af6a5e SSH request tracing (#14124)
* SSH request tracing

Add tracing support for ssh global requests and  channels. Wrappers
for `ssh.Client`, `ssh.Channel`, and `ssh.NewChannel` provide a
mechanism for tracing context to be propagated via a `context.Context`.

In order to maintain backwards compatibility the ssh.Client wrapper
tries to open a TracingChannel when constructed. Any servers that
don't support tracing will reject the unknown channel. The client
will only provide tracing context to servers which do NOT reject
the TracingChannel request.

In order to include pass tracing context along all ssh payloads
are wrapped in an Envelope that includes the original payload
AND any tracing context. Servers now try to unmarshal all payloads
into said Envelope when processing messages. If there is an Envelope
provided, a new span will be created and the original payload will
be pass along to handlers.

Part of #12241
2022-07-27 14:56:06 +00:00
rosstimothy fba159e9c4 Add context.Context to session.Service inteface (#14668)
* Add context.Context to session.Service interface

Updates GetSessions, GetSession, CreateSession, UpdateSesion, and
DeleteSession to take a context.Context. All call paths are updated
to properly pass along a real context instead of relying on a
to eliminate context.TODOs.
2022-07-25 22:05:09 +00:00
Nic Klaassen 59baa34e79 Fix possible deadlock during server close (#14813)
fix server close deadlock
2022-07-23 03:27:44 +00:00
Alex McGrath 80baab8ce5 Add AWS matchers to the ssh_service section of the fileconf (#13787)
Update file conf with AWS discovery on SSH nodes
2022-07-08 09:24:30 +00:00
Andrew LeFevre a150b0c8e1 SFTP server side support (#13491)
add sftp server functionality
2022-07-07 20:08:26 +00:00
Nic Klaassen 76aced4968 Fix segfault in Server.Serve (#14173) 2022-07-07 18:34:21 +00:00
Joel 74f2440683 Always allow session owners to join own sessions + only list active trackers in WebUI (#13660) 2022-06-22 19:56:45 +00:00
Forrest Marshall 31f258fec9 inventory control stream & certs 2022-06-15 22:26:24 -07:00
Alex McGrath 502b001130 Add sudoers provisioning support (#12061)
* Add sudoers provisioning support

* Add a fix for macos tests
2022-06-09 16:06:18 +00:00
2717c1d2e0 Security fixes (#13298)
* Add CSRF mitigations

This commit includes two fixes:

1. Enforce an application/json Content-Type server-side.
2. When checking the bearer token, verify that the user
   associated with the token matches the user associated
   with the cookie.

* Fix TEL-Q122-13: Access Requests Denial Of Service Via Request Reason (#125) (#127)

* Ignore input when data flow is off in TermManager

When data flow is disabled in TermManager (at the beginning or when TermManager.Off was called) we should ignore all input we receive (currently we buffer it)

* Agent forwarding socket security fix.

Co-authored-by: Lisa Kim <lisa@goteleport.com>
Co-authored-by: Joel <jwejdenstal@icloud.com>
Co-authored-by: Przemko Robakowski <przemko@przemko-robakowski.pl>
2022-06-08 18:12:45 +00:00
Alex McGrathandEdoardo Spadolini 581efdc60f Add support for automatic user provisioning (#11830)
* Add support for automatic user provisioning

* Add UID parker to reexec

* Add a `teleport park` subcommand that does nothing

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2022-06-08 12:24:13 +00:00
Nic Klaassen 814664ab66 [Search-based access requests] Enforce resource access restrictions (#12651) 2022-06-03 00:04:44 +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
Andrew Burke a8ed7bd1fd Automatically import EC2 tags (#12593)
This change allows Teleport to automatically import EC2 tags when running in an EC2 instance.
2022-05-31 23:19:16 +00:00
rosstimothy 9f094aaef6 Add tracing instrumentation for ssh clients/servers (#12434)
* Add tracing instrumentation for ssh clients/servers

Add tracing context to the existing ProxyHelloSignature to provide
span information across ssh connections. To add span context per
ssh session on top of new connections, the same tracing context is
passed in the first global request of the session.

In order to ensure that tracing context is pulled from and inserted
into the proper context.Context, some interfaces and methods were
changed to take one as the first argument.
2022-05-25 12:24:02 +00:00
Gus Luxton 4af0edd06e ssh: Ignore PuTTY-specific channel requests (#12372)
When proxying connections, PuTTY automatically requests the 'simple@putty.projects.tartarus.org' channel
type to indicate that this is a "simple" connection which will not be requesting other channel formats.
A request to Teleport for this channel currently results in the connection being terminated. A better
idea is just to ignore this request.
2022-05-14 03:39:16 +00:00
Joel 652536f4e5 Don't enforce standard k8s and ssh auth mechanisms when joining sessions (#11144) 2022-05-05 19:42:57 +00:00
Joel 3120876aea Only acquire semaphore lease if maxconnections is configured (#12462) 2022-05-05 17:42:07 +00:00
rosstimothy fa12352214 Stop loading the enitre node set into memory per tsh ssh connection (#12014)
* Prevent proxy from loading entire node set into memory more than once

When establishing a new session to a node, the proxy would load the 
entire node set into memory in an attempt to find the matching host. For
smaller clusters this may not be that problematic. But on larger clusters,
loading >40k nodes into memory from the cache can be quite expensive.
This problem is compounded by the fact that it happened**per** session,
which could potentially cause the proxy to consume all available memory 
and be OOM killed.

A new `NodeWatcher` is introduced which will maintain an in memory list
of all nodes per process. The watcher leverages the existing resource 
watcher system and stores all nodes as types.Server, to eliminate the
cost incurred by unmarshalling the nodes from the cache. The `NodeWatcher`
provides a way to retrieve a filtered list of nodes in order to reduce the number 
of copies made to only the matches.
2022-05-02 15:59:56 -04:00