Commit Graph
79 Commits
Author SHA1 Message Date
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 c2fc9a9375 Add idle connection timeouts to http clients and servers (#22885)
Sets `http.Server.IdleTimeout` and `http.Client.IdleConnTimeout`
on clients and servers which didn't have them set. A default of
360s was chosen to be on par with the default of an NLB without
being identical.

This was added as another safety measure to prevent leaking any
idle connections indefinitely as seen in #22757.

`apidefaults.DefaultDialTimeout` was also renamed to
`apidefaults.DefaultIOTimeout` to better reflect its usage.
2023-03-10 16:47:06 +00:00
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
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
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
Sam Freiberg aba69dfd99 Minor code cleanups (#21006)
* Replace sleep with empty select

* Allow IPv6 in tunnel

* Revert "Replace sleep with empty select"

This reverts commit 9d7dc5f667.

* Add warning to runPark
2023-02-02 21:05:56 +00:00
Tobiasz Heller 5f07b284b0 security: Prevent access to SSH nodes using SessionJoinPrincipal 2022-12-28 09:24:02 -08: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
Jakub Nyckowski d68c90929f Fix compatibility with sshd 7.x (#18181)
This change introduces a workaround for OpenSSH 7.x bug related to SHA-2 signed certificates. Teleport signs all certificates with SHA-2-512, which prevents us from connecting to older sshd. As a workaround, we will send the same certificate signed with SHA-2-512 (as we do right now) and SHA-1 if the first authentication fails. We always send the SHA-2 certificates first, so newer OpenSSH versions should always use SHA-2 certs as they do right now.
2022-11-10 22:50:06 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +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
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
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
Joel f2dd75801a Remove legacy session service (#15155) 2022-08-12 16:39:45 +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
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
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
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
rosstimothy c3736c7c70 Span forwarding (#12980)
* Span forwarding

Modifies the auth grpc server to implement the OTLP Collector
RegisterTraceServiceServer API (https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/trace/v1/trace_service.proto).
This allows the auth server to receive spans from other services
like `tsh`, `tctl`, and `tbot`. Any spans received by the auth
server will be forwarded to the exporter configured via the
`tracing_service` if it is enabled. All received spans will be
dropped in the event that the`tracing_service` disabled. By
forwarding spans to the auth server, `tsh` doesn't need to
be provided with any of the telemetry backend information
to have its spans exported.

Adds a new `--trace` flag to `tsh` to enable collecting and
forwarding spans to the auth server. When set, the tracing
provider is initialized with a sampling rate of 1.0 to force
all spans to be recorded. Teleport respects the sampling rate
from remote spans, which means that when `--trace` is set, all
spans from `tsh` and any downstream Teleport services will be
recorded and exported regardless of the sampling rate that each
Teleport service is configured with.
2022-06-02 09:28:30 -04: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
Joel 652536f4e5 Don't enforce standard k8s and ssh auth mechanisms when joining sessions (#11144) 2022-05-05 19:42:57 +00:00
Brian Joerger 2292be1f08 SSH Session fixes (#11717) 2022-04-28 00:25:51 +00:00
Brian Joerger 93f6f61386 Fix flaky test - TestAuditOn (#12101) 2022-04-21 01:20:26 +00:00
Joel ea810d30d9 Implement Moderated Sessions (#8563)
* Implement Moderated Sessions
2022-02-15 17:02:10 +01:00
Brian Joerger d33f51d17f x11 forwarding (#9897) 2022-02-04 23:47:03 +00:00
Edoardo Spadolini 2598401589 Add access requests to audit events (#9758)
* Refactor most uses of `UserMetadata` into a handful of functions

* Add access requests to `UserMetadata`

* Explanation for the reserved field in SessionStart
2022-01-25 16:56:18 +00:00
JoelandZac Bergquist 62173e096b use google/uuid instead of pborman/uuid (#9793)
* replace imports

* use google/uuid

* fix test

* reverse changelog changes

* update gomod

* zac steps

* tidy

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-01-19 23:44:48 +00:00
rosstimothy 5cd7c3c294 Split auth.AccessPoint into variant specific interfaces (#8471) 2021-11-04 09:42:14 -04:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Andrej Tokarčík d5ca862280 Apply locks to connections tracked by srv.Monitor (#7506) 2021-07-23 14:11:50 +02:00
Eugene Yakubovich 67c0eb3b4c Add restricted session
Adds the ability to block network traffic on SSH sessions.
The deny/allow lists of IPs are specified in teleport.yaml file.
Supports both IPv4 and IPv6 communication.

This feature currently relies on enhanced recording for
cgroup management so that needs to be enabled as well.

-- Design rationale:
This patch uses Linux Security Module (LSM) hooks, specifically
security_socket_connect and security_socket_sendmsg, to control
egress traffic. The LSM provides two advantages over socket filtering
program types.
- It's executed early enough that the task information is available.
  This makes it easy to report PID, COMM, etc.
- It becomes a model for extending restrictions beyond networking.

The set of enforced cgroups is stored in a BPF hash map and the
deny/allow lists are stored in BPF trie maps. An IP address is
first checked against the allow list. If found, it's checked for
an override in the deny list. The policy is default deny. However,
the absence of the NetworkRestrictions API object is allow all.

IPv4 addresses are additionally registered in IPv6 trie (as mapped)
to account for dual stacks. However it is unclear if this is sufficient
as 4-to-6 transition methods utilize a multitude of translation and
tunneling methods.
2021-07-16 16:49:04 -07:00
Brian Joerger 4d36870ff0 Remove remaining API aliases (#7137) 2021-06-08 12:08:55 -07:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Roman Tkachenko b4bc767a7c Buddy: https://github.com/gravitational/teleport/pull/6250 (#7165) 2021-06-03 11:37:10 -07:00
NajiObeid 86a6abcfcb lazy init of prometheus collectors (#6561)
* lazy init of prometheus collectors

* incorporate metrics intorduced in #6271

* linting

* tests

* pr changes

* tests

* pr changes
2021-05-19 11:53:36 -04:00
Andrej Tokarčík ad00c6c789 Introduce ClusterNetworkingConfig extracting fields from ClusterConfig (#6638) 2021-05-07 13:54:08 +02:00
Brian Joerger 2beb991598 API client connection overhaul (#5625)
* Added support for connecting API client through tunnel proxy and web proxy addresses (with identity file).

* Added concurrent dialing logic to dial several possible dialing combinations and seamlessly return the first client to connect.
2021-03-23 14:39:20 -07:00
Alexander Klizhentas f17625c1a8 Adds controls for impersonation requests. (#6009) (#6073)
Fixes #5352

```yaml
allow:
  impersonate:
    users: ['alice', 'bob']
    roles: ['*']
    where: 'contains(user.spec.traits["groups"], impersonate_role.traits)'
```

Adds "impersonator" to all X.509 and SSH client certs
issued using impersonation and does best effort to track
requests by impersonators in audit events.

Limits certs TTL to the impersonator's max session TTL.

Prevents impersonating users to recursively impersonate
other users.

Allows impersonating users to renew their own certificate,
for example to set route to cluster.

Adds missing token permission for editor role.
2021-03-19 16:04:43 -07:00
Acrimon 324ccda21f Implemented utmp/wtmp support. 2021-02-15 20:58:30 +01:00
Russell Jones b8c0b96415 Fixed panic when NewServerContext returns error.
If "NewServerContext" returns an error, then the error is logged using
the returned context which is nil causing a panic.

This change always uses the logger attached to the server instead.
2021-01-15 17:11:01 -08:00
a-palchikov 6684c37103 Use fake clock consistently in units tests. (#5263)
Use fake clock consistently in units tests.
2021-01-12 12:10:00 +01: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 ae2336dfd0 concurrent session control
Adds support for Concurrent Session Control and a new
semaphore API.  Roles now support two new configuration
options, `max_ssh_connections` and `max_ssh_sessions`
which correspond to the total number of authenticated
ssh connections per cluster, and the number of ssh sessions
within a connection respectively.  Attempting to exceed
these limits generate variants of the `session.rejected`
audit event and cause the connection/session to be
rejected.
2020-09-17 11:02:35 -07:00
Forrest Marshall c3210b7a12 fix racy logging & session channel rejection 2020-09-17 11:02:35 -07:00
Andrew Lytvynov b839da9eb6 Track SSH client activity per ssh.Channel
This is the lowest-level transport we have after SSH session is
established. Any data going either direction indicates some activity.

Note: we also track writes from server to client as activity. If a user
starts a script that prints something every minute and steps away, the
session should keep going as long as `client_idle_timeout > 1m`.

This also fixes things like large SCP transfers.
2020-08-11 22:11:56 +00:00
Forrest Marshall dfd40d21f5 proxy X11 forwarding support
- Role options now include a `permit_x11_forwarding` bool
which is set to `false` by default.

- Recording proxies now forward X11 requests and channels
when when permitted by RBAC.

- User certs will now include the `permit-X11-forwarding`
extension when permitted by RBAC.

- If X11 forwarding is requested for a session a new `x11`
audit event is emitted by recording proxies.
2020-06-24 11:40:47 -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