Commit Graph
304 Commits
Author SHA1 Message Date
Andrew LeFevre 3064f7e44d Add agentless connection integration test (#23120)
* add agentless connection integration test

* address feedback
2023-03-16 15:20:31 +00:00
rosstimothy b0dc78610e Migrate upserting CAs to gRPC (#23140)
Adds `UpsertCertAuthority` to the `teleport.v1.trust.TrustService`
and deprecates the HTTP api. The `services.Trust` interface was
also updated to include a `context.Context` in both
`CreateCertAuthority` and `UpsertCertAuthority.

To ensure backwards compatibility the `auth.Client` will first
attempt to use the gRPC client and if that fails with a not
implemented error it will fallback to using HTTP.

Part of #6394
2023-03-16 14:46:43 +00:00
rosstimothy f02468e9fb Migrate the delete ca api to gRPC (#23070)
Adds `DeleteCertAuthority` to the trust grpc service and deprecates
the legacy HTTP api. Additionally the `DeleteCertAuthority` method
in the `services.Trust` interface now takes a `context.Context` as
the first parameter. In order to plumb the context through from all
the call sites `DeleteRemoteCluster` from `services.Presence` was
also modified to take a `context.Context` as the first parameter.
2023-03-15 13:11:37 +00:00
Tiago Silva 674a3a1ec1 Removes deprecated KindKubeService objects (#22663)
This PR removes the `types.KindKubeService` objects that were
deprecated in Teleport 11.

Teleport 12 removed the double heartbeat and for Teleport 13 we can
safely drop the support of the old hearbeat based on `types.Server`
objects.

Clients older than Teleport 12 connecting to a Teleport 13 server will
fail since they cannot heartbeat using the old mechanism.
2023-03-13 10:55:39 +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
Tobiasz Heller 0b3a67f69f Remove GetSessionEvents from external loggers (#22071) (#22703)
Remove GetSessionEvents from external loggers
2023-03-07 15:48:00 +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 96d10f0d83 Add MaxRetryPeriod for cachePolicy config to use in tests (#22656)
This fixes couple of flaky tests that surfaced after recent changes to the
retry logic/timeouts.
2023-03-06 19:00:17 +00:00
Jakub Nyckowski 8329021148 Skip building webassets in CI (#22549)
* Skip building webassets in CI

Building webassets is not always needed and many of our CI build just builds them and ends up not using them after.
This PR skips building the webassets for all pipelines where they are not needed. This should save us some time and $$.

* Make some changes to trigger CI

* Create the missing directory
2023-03-03 15:14:25 +00:00
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +00:00
STeve (Xin) Huang fd98549e45 Skip deleting server heartbeats during in-process restart (#21648)
* Skip deleting server heartbeats during in-process restart

* context.TODO() -> context.Background()

* fix lint
2023-02-14 14:10:31 +00:00
Noah Stride 476a4a7e82 context.TODO() tidying (#21288)
* Use `ctx` rather than `context.TODO()` where available

* Further propagation of context

* Use `context.Background()` instead of `context.TODO()` where appropriate in tests

* Further remove `context.TODO` from tests

* Appease linter on parameter order
2023-02-07 09:01:35 +00:00
rosstimothy b17f687f5f Track active ssh sessions established via the web (#20231)
* Track active ssh sessions established via the web

Adds open session tracking in `web.Handler` and introduces a new
 `web.Server` to prevent closing the web `http.Server` during
a graceful shutdown if there are still open sessions. From the
`http.Server/Shutdown` docs:

> Shutdown does not attempt to close nor wait for hijacked
> connections such as WebSockets. The caller of Shutdown should
> separately notify such long-lived connections of shutdown and wait
> for them to close, if desired.

Because the web sessions use WebSockets, `Shutdown` will not
wait for them to be idle before terminating. This used to work due
to the fact that web sessions dialed the Proxy SSH Port  to establish the
SSH session. Which meant that all accounting of active user connections
by `sshutils/server.go` was accurate. But now that sessions are
established directly via the `proxy.Router` the web sessions were
unaccounted for.

The `web.Server` now mimics the behavior of `sshutils/server.go` for
Shutdown. Only once all the active web sessions have been terminated
will the underlying http.Server be shutdown.

Fixes #20227
2023-01-27 14:38:39 +00:00
rosstimothy 362cb46412 Add test that verifies connectivity when Auth is down (#20450)
Ensures that if a user has a valid certificate and Auth is down
that they can still establish a session to nodes.
2023-01-24 21:07:11 +00:00
Edward Dowling 3cd847e3ff Allow updating of trusted cluster role maps (#18168) 2023-01-13 19:06:17 +00:00
Jakub NyckowskiandHugo Shaka 4e5a776c43 Temporary skip TestReverseTunnelCollapse (#20198)
* Temporary skip TestReverseTunnelCollapse

Co-authored-by: Hugo Shaka <hugo.hervieux@goteleport.com>
2023-01-13 17:04:02 +00:00
Sam Freiberg bd5853a3b2 Remove default type from cert rotation (#20059)
* Make `all` cert rotations explicit and mark as deprecated
2023-01-12 21:14:02 +00:00
rosstimothy 3aa295c87c Convert usages of types.NewRoleV3 to types.NewRole (#19793)
Closes #14345
2023-01-11 16:58:22 +00:00
rosstimothy 54b8fce42b Multiplex Proxy SSH port (#19813) 2023-01-06 11:54:05 -05:00
Tiago Silva 40861809a6 Add RoleV6 resource type (#19324)
This PR includes a new Role resource version that is compatible with V5 spec.

The new resource introduces the `kubernetes_resources` definition that allows operators to limit the Kubernetes resources that each member can access. The `kubernetes_resources` entries must follow the following format: `{"kind":"<kind>", "namespace":"<namespace>","name":"<pod>"}`. Currently, it only supports objects of `kind` `pod`. Valid examples `<namespace>/<name>:
- `*/*`: matches all pods in all namespaces.
- `default/*`: matches all pods in the `default` namespace.
- `*/nginx-*`: matches every pod prefixed with `nginx-` in every namespace.

For older resource versions - V5, V4, V3 - `kubernetes_resources` is automatically populated with `{"kind":"pod","namespace":"*","name":"*"}` to keep compatibility. For the newest version, it's mandatory to define its value otherwise access to pods will be denied.

Part of #18434
2023-01-05 09:58:12 +00:00
STeve (Xin) Huang 39cee50cc9 Fix Too many requests error in github actions test (#19606) 2022-12-23 03:47:02 +00:00
Russell Jones 7895fddc57 Added the ability to supply Access Request TTLs
Added the ability to specify two CLI flags for Access Requests:
"--request-ttl" and "--session-ttl".

Updated "CreateAccessRequest" to adhere to the following rules.

If an Access Request does not have a TTL set (expiration time
types.AccessRequest resource itself), a default of 1 hour is used. Next,
the request value is truncated by the lifetime of the certificate,
requested expiration, and then strictest session TTL on all roles
requested.

Similar logic is followed for the expiration time of the elevated
certificate that will be issued if the Access Request is approved. First
the requested value is truncated by the lifetime of the certificate,
requested expiration, and then strictest session TTL on all roles
requested.

The output of "tsh requests ls" and "tctl requests ls" has been updated
to display the TTL values.
2022-12-14 15:18:33 -08:00
Brian Joerger a3bd4650d0 Provide proxy address when beginning a node session (#18579) 2022-12-02 01:56:22 +00:00
Jakub Nyckowski 655dfa2aa7 Adjust integration test timeouts (#18331)
* Adjust integration test timeouts

* Skip TestProxyTunnelStrategyProxyPeering
2022-11-24 18:47:49 +00:00
rosstimothy 6005078a71 Allow connections to nodes when Auth is offline (#18302)
* Allow connections to nodes when Auth is offline

`tsh ssh user@foo` currently fails if Auth is unreachable. Prior to
connecting to the target, `tsh` sends a `proto.AuthService/IsMFARequired`
request to determine if per-session MFA is required. If necessary, the MFA
ceremony then occurs before `tsh` attempts to connect to the node.

However, nodes ultimately makes the decision on whether the user has
access. To both increase availability of nodes and reduce initial
connection latency, `tsh` can first attempt to connect to a node and
fallback to checking if per-session MFA is required and then performing
the ceremony if necessary followed by attempting another connection to the
node. The major tradeoff is now when per-session MFA is required, `tsh`
will connect to the target **twice**. The added latency is likely to be
minimized by the amount of time it takes to perform the MFA ceremony.

## Connection flows prior to this change:

### Auth online and per-session MFA required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: yes
    tsh->>+Auth: perform mfa ceremony
    Auth-->>+tsh: issue challenge
    tsh-->>+Auth: challenge response
    Auth-->>+tsh: issue certificates
    tsh->>+Node: Connect
    Node-->>+tsh: Success
```

### Auth online and per-session MFA not required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: no
    tsh->>+Node: Connect
    Node-->>+tsh: Success
```

### Auth offline and per-session MFA not required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: Error
```

### Auth offline and per-session MFA required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: Error
```

## Connection flows after this change:

### Auth online and per-session MFA required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Node: Connect
    Node-->>+tsh: Access Denied
    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: yes
    tsh->>+Auth: perform mfa ceremony
    Auth-->>+tsh: issue challenge
    tsh-->>+Auth: challenge response
    Auth-->>+tsh: issue certificates
    tsh->>+Node: Connect
    Node-->>+tsh: Success
```

### Auth online and per-session MFA not required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Node: Connect
    Node-->>+tsh: Success
```

### Auth offline and per-session MFA not required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Node: Connect
    Node-->>+tsh: Success
```

### Auth offline and per-session MFA required
```mermaid
sequenceDiagram
    participant tsh
    participant Auth
    participant Node

    tsh->>+Node: Connect
    Node-->>+tsh: Access Denied
    tsh->>+Auth: IsMFARequired
    Auth-->>-tsh: Error
```
2022-11-17 21:10:57 +00:00
Steven Martin 00728c4f63 spell fixes (#18545) 2022-11-17 16:28:05 +00:00
Zac Bergquist da7680ad0b Use x/exp/slices instead of home grown utilities (#18524)
We were inconsistent throughout the codebase and would sometimes
use the slices package and other times use our own equivalents
in api/.

This removes our versions in favor of the golang.org/x package that
does the same, which has the added benefit of reducing the surface
area of the public API module.

Note: despite existing uses of the slices package, for some reason
it didn't show up in go.mod or go.sum. Fixed that too.
2022-11-17 15:25:46 +00:00
Jakub Nyckowski 08863c4237 Enable and fix AuditOn. (#17687)
This change re-enables the AuditOn system test and fixes the TTY connection between the Teleport parent and child process. It should allow the child to send the error code to the parent, which should fix the test.
2022-11-14 23:07:58 +00:00
Jakub Nyckowski 0f51099e3b Skip AuditOn test (#17813) 2022-10-26 18:22:04 +00:00
Zac Bergquist 1a62376b78 Fix uses of require in goroutines (#16953)
The require checks from testify call (*testing.T).Fail, which should
only be called from the test goroutine.
2022-10-05 19:14:30 +00:00
Noah Stride eb42cabbea Revert "Introduce ProvisionTokenV3 (#16361)" (#16934)
This reverts commit 3fba50261f.
2022-10-03 14:14:01 +00:00
Nic Klaassen 60950a9aa0 security: log non-interactive SSH commands at beginning of session (#16872)
* include exec command in session.start.initial_command

* trim oversized events
2022-09-30 19:57:01 +00:00
Ryan Clark 806a568ada Introduce config v3, add auth_server and proxy_server, remove auth_addresses (#15761) 2022-09-28 15:30:15 +00:00
Noah Stride 3fba50261f Introduce ProvisionTokenV3 (#16361)
* Introduce proto types for ProvisionTokenV3

* Add methods to ProvisionTokenV3 to support ProvisionToken iface

* Start building v3 support into the client

* add support for mashalling and unmarshalling ProvisionTokenV3

* Start unit testing ProvisionTokenV3

* Remove oneof to support yaml marshal/unmarshal

* Client should try V3 methods and fallback to v2

* More tests

* Fix join tests

* Fix integration tests

* Switch integration tests to use v3 spec

* Switch iam tests to use ProvisionTokenV3

* Change ec2 join tests to use V3 tokens

* Fix events tests for V3 token

* support ProvisionTokenV3 within API client events handler

* Explicitly specify JoinMethod

* Tidy up final usage of NewProvisionTokenV2FromSpec in tests

* Improve proto docs on ProvisionTokenV3

* Fix bot join tests

* Clarify error message for invalid join method

* Adjust resource version comment

* Fix comments and return error rather than bool in V2() method

* Catch incompatible conversions case

* Include V2 ProvisionToken in tests and add appropriate DELETE IN notes

* Fix linter warnings/unit test failures

* Use nolint rather than lint:ignore

* Add more DELETE IN notes

* Run goimports on join_ec2_test.go

* Address PR comments from tim.

* Add more deprecation/delete in notices

* Improve godoc comments on checkAndSetDEfaults for provider config

* Simplify implementation by dropping client-ahead compatability

* Add some support for client-ahead but with conversion to v3

* Update code comments to include responsible party

* Rename `Role` to `RoleARN` in EC2 configuration for clarity

* Fix tests for Role -> RoleARN rename

* Move MustCreateProvisionToken out of API and into test packages

* Properly go imports files
2022-09-27 17:05:32 +00:00
rosstimothy 649958b6e3 Reduce number of auth dials for tsh commands (#16367)
* Reduce number of auth dials for tsh commands

One of the major areas of latency for `tsh ssh` is creating multiple
auth clients. Since the auth client is lazy and only actually performs
the dial on first use we can create an auth client once and simply
reuse it. This is done by adding an `auth.ClientI` to `ProxyClient`
which is created via `connectToProxy`. All attempts to connect to
the current auth server via the `ProxyClient` will be given the
cached `auth.ClientI`.

The new method of retrieving the current auth client also allowed
to remove a number of calls to `GetSites` which were used to obtain
the current cluster name. The local profile already contains the name
of the cluster and calls to `GetSites` were unnecessary. All instances
which relied on the site name now retrieve from information that the
`ProxyClient` already has.

In an effort to reduce ambiguity and confusion `CurrentClusterAccessPoint`
and `ClusterAccessPoint` were also removed. AccessPoint denotes that
you are connecting to a cache, but the `ProxyClient` is always going
to be hitting the auth server directly. The two have been replaced
with `CurrentCluster` and `ConnectToCluster`, which they were merely
wrappers for anyhow.
2022-09-27 15:37:51 +00:00
Zac Bergquist 149e61b7db Disable ControlMaster test for proxy recording mode (#16720)
Control master functionality is currently broken in proxy recording
mode. We're aware of the issue and will disable the test until we
are able to fix the underlying issue.

Updates #16224
2022-09-26 18:05:53 +00:00
Trent Clarke 0136f8a0ab Remove more integration test port list allocations (#16266)
Following on from #13658, this patch removes more (but unfortunately not
all) usages of the deprecated, list-based port-allocation scheme.

This patch:

1. Updates the integration test `TeleInstance` fixture to use injected 
   listeners rather than static ports when creating a new proxy node in
   a cluster,
2. Updates tests affected by (1) to pre-allocate and inject listeners,
   including handling caching the listener FDs between proxy restarts
3. Removed unnecessary port allocations when creating LoadBalancer 
   fixtures, and 
4. Moved the remaining list-base port allocation functions out of helpers
   and back into integrations and made private. These functions should 
   never be used by more than one test package concurrently or there is a
   very high chance of a port collision. Rather than just write that rule
   down in the comments, I have contained the deprecated code into the
   affected package made the compiler enforce the rule for us.

See-Also: #12421
See-Also: #13658
See-Also: #14408
2022-09-14 06:53:19 +00:00
Trent Clarke 948417257f Split out appaccess and proxy integration tests (#16232)
* Proxy tests running

* rollback

* whitespace  fix

* Rollback port fix

* Linter appeasement

* License fix

* Update signals.go
2022-09-08 08:27:51 -06:00
Trent Clarke 9514a313c3 Break DB integration tests out into their own package (#16133)
Making all of our integration tests run in entirely parallel requires
a large engineering effort to enforce test isolation and remove all race
conditions between tests.

A lower-effort alternative may be to split apart the various test suites
into their own Go packages, and test those packages in parallel, even if
the tests inside are still executed serially. Auditing the test suites
for races on system-level resources (e.g. files, ports) is much easier
than chasing down every p[ossible race in the testing system.

This patch acts as a trial run, breaking a fairly well-defined and
self-contained test suite out into its own package. Note that the goal of
this change is not necessarily to shave minutes off the build (although
that would be nice), but to act as an illustration of how other, less
well-formed test suites might be broken apart.

See-Also: #12421
See-Also: #14408
2022-09-07 11:04:35 +10:00
Brian Joerger 3a5a285883 Generalize private keys in tsh (PIV integration) (#15334)
Primary Changes:
 - Remove reliance on Private Key PEM:
 - Update native and keygen packages to return PrivateKey instead of PEM key
 - Add new PrivateKey interface which implements crypto.Signer
 - Replace PEM encoded private key usage where possible
 - Replace calls to tls.(Load)X509KeyPair with keys.(Load)X509KeyPair in
client packages

Minor Changes:
 - Remove unused agent.AddedKey return from LoadKey
 - Simplify sshutils and removed unused code paths
 - Add ecdsa and ed25519 key support
2022-08-25 23:26:44 +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
Joel f2dd75801a Remove legacy session service (#15155) 2022-08-12 16:39:45 +00:00
Ryan Clark 29175e57d3 Use a getter/setter for reading the token value from the config (#14080) 2022-08-10 08:50:21 +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
Gabriel Corado ced6276c7b Use waitForError instead of require.Eventually in SessionRecordingModes integration tests (#15212) 2022-08-04 20:51:34 +00:00
Forrest Marshall 142333e509 fix peer addr for in-memory control stream 2022-08-04 09:43:31 -07: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
Edoardo Spadolini fa65fd02b1 Refactor Supervisor.WaitForEvent (#14940) 2022-07-28 13:34:27 +00:00
Joel b7a319d40d Correctly propagate information about the target during forwarding (#14564) 2022-07-28 11:05:45 +00:00