Commit graph

510 commits

Author SHA1 Message Date
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
Mike Wilson 31859e5d30 Ensure audit logging of tsh app login.
Application sessions were previously only logged when launching an application
session via the UI, and not from the `tsh app login` command. This has been
corrected. The AppName and AppURI are now passed in as part of the gRPC
request to the auth server, which is then used to emit the audit event.
2022-09-30 12:53:13 -04:00
Andrew Burke ac257084a7
Automatically import Azure tags (#16218)
This change lets Teleport automatically import tags from the Azure instance it's running on.
2022-09-28 23:40:13 +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
Brian Joerger 4c0a6ff5b1
tsh PIV login integration (#15335)
* Add Yubikey PrivateKey implementation for use by Teleport clients.

  - Add yubikey login logic, reusing previously stored private keys.

  - Fix identity file decoding with PIV keys, which sign ecdsa certificates.

  - Add libpcsclite-dev pre-req for building on linux.

  - Remove unnecessary keys.Signer interface and move its functionality to keys.PrivateKey.

  - Move retry and jitter utils to new api/utils/retryutils package.
2022-09-23 19:44:10 +00:00
Marek Smoliński cbfd90601d
Fix flaky integration test: TestAppServersHA/RootServer (#16628) 2022-09-23 13:01:52 +02:00
Alan Parra fe3f9332ee
Update WebAuthn and U2F dependencies (#16572)
Update `duo-labs/webauthn` up to `20220122034320`, which is the latest version
we can get without dipping into dependency hell (`etcd` and `opentelemetry` woes
ensue after [2365c59d9f][1]).

`tstranex` could be dropped for a while now (we moved on to WebAuthn-like
interfaces for mocks). `cfssl` was only imported due to what I assume was an
IDE mishap.

I've elected to keep `fxamacker/cbor`, instead of trying to move to
[webauthncbor][2]. fxamacker is solid, past v0, seems more appropriate for
client-side libs and still backs webauthncbor.

There are no updates for `flynn/hid` and `flynn/u2f`.

Release notes for fxamacker/cbor:
https://github.com/fxamacker/cbor/releases/tag/v2.4.0.

[1]: 2365c59d9f
[2]: https://pkg.go.dev/github.com/duo-labs/webauthn@v0.0.0-20220815211337-00c9fb5711f5/protocol/webauthncbor

* Drop tstranex/u2f dependency
* Drop direct dependency to cloudflare/cfssl
* Update fxamacker/cbor/v2 to v2.4.0
* Update duo-labs/webauthn to 2022-01-22
* Fix: Make sure all credentials are set in the user
* Simplify: Drop now unnecessary AuthenticationSelection copy
2022-09-22 17:08:47 +00:00
rosstimothy ebfbfd496e
Use testauthority instead of native to generate keys in tests (#16486)
* use test authority

* use testauthority for InitConfig RSAKeyPairSource

* add named returns to test authority
2022-09-21 20:53:09 +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
Roman Tkachenko 29e46a2a6a
buddy: Fix incorrect use of loop variables (#16306)
* Fix incorrect use of loop variables

This commit fixes a few occurrences of loop variables being
incorrectly used in the context of Go-routines or (most frequently)
parallel tests. To fix the issues, we create a local copy of the range
variables before the parallel tests (or Go-routine), as suggested in
the documentation of the `testing` package:

https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks

Issues were found using the `loopvarcapture` linter.

Signed-off-by: Roman Tkachenko <roman@goteleport.com>

* fix TestTraceProvider/spans_exported_with_gRPC+TLS

* run TestSSH serially

* operator: Conserve 'created_by' data in user spec

Signed-off-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Renato Costa <renato@cockroachlabs.com>
Co-authored-by: Tim Ross <tim.ross@goteleport.com>
Co-authored-by: Hugo Hervieux <hugo.hervieux@goteleport.com>
2022-09-14 14:31:56 +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
STeve (Xin) Huang 8394f4fb48
ALPN connection upgrade for MySQL behind ALB (#15669) 2022-09-01 16:05:03 +00:00
Gabriel Corado a3a65e863b
TLS routing ping for database protocols (#14887) 2022-08-26 16:42:23 +00: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 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
Roman Tkachenko 22dc9dceef
Deflake TestEC2Hostname (#15794) 2022-08-24 17:17:58 +00:00
Marco André Dinis 4163bbb1d7
Ignore Logins when listing Nodes (#15597)
Currently, we require users to have at least one Allowed Login in order
for them to list/read nodes.

This is different from the other resources.
In those, only the `<resource>_labels` needs to match what the roleset
allows/denies to the user.

This could lead to, for example, not being able to list Nodes even
though the user had a role allowing them to access any Node (ie
```
NodeLabels:
  - '*' : '*'
```

### When we don't have any login:
We can list the servers:
![image](https://user-images.githubusercontent.com/689271/185152432-8508df7c-774e-4d41-963f-f94d5edda114.png)

Trying to ssh into a node returns an error (web ui and `tsh`)
```bash
$ tsh --insecure --proxy 127.0.0.1.nip.io:3080 ssh marco@lenix
ERROR: access denied to marco connecting to lenix on cluster lenix
```

![image](https://user-images.githubusercontent.com/689271/185938766-ba6db481-8ccd-4d13-8c21-51e1cc01f544.png)


Adding a single login and then trying to login with a different login
(in this case we added a `andre` login but tried to login as `marco`)
```bash
$ tsh --insecure --proxy 127.0.0.1.nip.io:3080 ssh marco@lenix
ERROR: access denied to marco connecting to lenix on cluster lenix
```
![image](https://user-images.githubusercontent.com/689271/185939601-83210370-97ad-4d25-aba2-d565785de1bf.png)

Setting the `marco` as a denied login, we can't use it anymore even if it's part of the allowed logins:
```bash
$ tsh --insecure --proxy 127.0.0.1.nip.io:3080 ssh marco@lenix
Enter password for Teleport user marco:
WARNING: You are using insecure connection to SSH proxy https://127.0.0.1.nip.io:3080
ERROR: access denied to marco connecting to lenix on cluster lenix
```

![image](https://user-images.githubusercontent.com/689271/185940230-1dfe2afb-7909-4c75-8ebc-bad1dc5b69c1.png)
![image](https://user-images.githubusercontent.com/689271/185940272-ca948272-eefc-4e6b-be8d-d59b17dcffec.png)

Removing the login denial allows for a successful login:
![image](https://user-images.githubusercontent.com/689271/185940527-0acba499-541a-4ef8-ba6b-fb8bc9c867af.png)
2022-08-24 09:13:54 +00:00
Roman Tkachenko 31b4a00a86
(buddy) Pass JWT headers on websocket requests (#15667)
* transport: Rewrite headers, including JWTs, for websockets.

Applications can otherwise 401 on websocket requests, as they do not
present any authentication headers.

docs: Fix the reserved JWT header name.

Signed-off-by: Roman Tkachenko <roman@goteleport.com>

* Add test for JWT header in websocket apps

Signed-off-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Alex Vandiver <alex@chmrr.net>
2022-08-22 20:43:50 +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
NajiObeid 787395395a
Add config setting for proxy peering public addr (#14905)
* peer proxy public addr config

* address pr comments

* address pr comments

* address pr comments
2022-08-09 15:16:22 +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
Edoardo Spadolini 58b01b964b
Embed auth.Cache in auth.Server (#14698)
* Embed auth.Cache in auth.Server

* Hit the backend during Auth initialization

* Bypass the cache when rotating CAs

* Services.UpsertTrustedCluster is different

* Bypass the cache in waitForTunnelConnections

* Fix infinite recursion

* More cache bypassing during init and rotations

* Rename Services to Uncached in auth.Server

* Further cleanups

* Don't start the auth cache immediately

* Go back to Services rather than Uncached

* Comments and a missing method
2022-07-27 21:05:53 +00:00
Roman Tkachenko 38b8bb4307
Add support for proxying TCP apps (#13455)
Add support for proxying tcp apps
2022-07-26 19:01:39 +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
Marco Dinis 5effbd8359 Add Teleport operator
This commit adds the Teleport operator. The operator reconciles
TeleportUsers and TeleportRoles Kubernetes resources with Users and
Roles Teleport resources.
2022-07-25 15:27:10 -04:00
Zac Bergquist 13d68af6f4
Ensure that the WindowsDesktopReady event is emitted (#14804)
When desktop access is enabled, the TeleportReady event will not
be emitted until the WindowsDesktopReadyEvent is emitted, and it
turns out we have *never* emitted a WindowsDesktopReadyEvent.

This is likely due to desktop access being copied from kube access
since the very beginning. The same issue was recently fixed for
kube access in #9418.
2022-07-22 20:41:36 +00:00
Trent Clarke 1686a71c8a
Remove centralised port allocation for tests (#13658)
Ports used by the unit tests have been allocated by pulling them out of a list, with no guarantee that the port is not actually in use. This central allocation point also means that tests cannot be split into separate packages to be run in parallel, as the ports allocated between the various packages will be allocated multiple times and end up intermittently clashing.

There is also no guarantee, even when the tests are run serially, that the ports will not clash with services already running on the machine.

This patch (largely) replaces the use of this centralised port allocation with pre-created listeners injected into the test via the file descriptor import mechanism use by Teleport to pass open ports to child processes.

There are still some cases where the old port allocation system is still in use. I felt this was already getting beyond the bounds of sensibly reviewable, so I have left those for a further PR after this.

See-Also: #12421
See-Also: #14408
2022-07-20 12:04:54 +10:00
David Boslee 27c04c5f94
Fix TestProxyTunnelStrategyAgentMesh flakiness (#14398)
Fixes an issue where the agentpool backoff channel would be redefined 
each time an event was received while waiting for the backoff to complete.
This could lead to a longer backoff period than expected.

Waits for each resource to connect individually by splitting up the test into
multiple runs ran in parallel
2022-07-14 10:49:11 -06: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
Joel 63e17f8a0f
Honor --no-enable-escape-sequences in tsh (#13507) 2022-07-13 11:48:21 +00:00
Alex McGrath 59063b1078
Replace occurences of . and ~ with _ when creating sudoers files. (#14300) 2022-07-12 09:22:38 +00:00
Marek Smoliński a47b62d60f
Boost database integration tests (#14226)
* Boost database integration tests

* Make linter happy again

* update
2022-07-11 07:38:34 +00:00
Andrew LeFevre a150b0c8e1
SFTP server side support (#13491)
add sftp server functionality
2022-07-07 20:08:26 +00:00
Zac Bergquist 75fa968e28
Make proxy peering an enterprise only feature (#14155) 2022-07-06 23:49:00 +00:00
Zac Bergquist 3d72b702db
Make source IP-pinning an enterprise feature (#14141) 2022-07-06 17:25:31 +00:00
Gavin Frazar 187d2e04d3
Gavinfrazar/start postgres listener with no tls no mux (#13998)
* Start postgres without TLS when multiplexing is disabled

* Add integration test for starting postgres with --insecure-no-tls

* Fix dupe postgres listener mistake

* Log the actual address of listeners

* Remove unnecessary error checking
2022-07-06 02:33:47 +00:00
Gabriel Corado fec42e3895
Wait for application servers tunnel connection before integration tests (#14084) 2022-07-06 00:31:04 +00:00
David Boslee 0f7762c41b
Fix agent mesh integration test (#13954)
By using a randomized load balancer we improve the chances of an agent
connecting to all proxy servers within the given time period.
2022-07-05 16:01:03 +00:00
Alex McGrath aee44e5678
Prefix sudoers lines with the user that is logging in instead of requiring a trait be templated. (#14007)
Prefix sudoers lines with user being logged in as
2022-07-01 09:28:14 +00:00
Russell Jones c0cd120820 Fixed TestAppServersHA. 2022-06-30 16:59:11 -07:00
STeve (Xin) Huang 86d9e30765
Fix an issue DB rotation event get send to older remote cluster (#13857) 2022-06-30 21:16:12 +00:00
Marek Smoliński 86ac49b10e
Try to fix TestAppServersHA flakiness (#13992) 2022-06-30 15:41:39 +02:00
Forrest Marshall b0bac8e546 fix ec2 join check 2022-06-28 18:05:30 -07:00
Marek Smoliński 20b63e071e
Fix JumpHost TLSRouting flow when root cluster is offline (#13791) 2022-06-28 14:09:37 +02:00
Roman Tkachenko 3ba3c429f4
Speed up app access integration tests (#13867) 2022-06-25 13:20:12 +00:00
Gavin Frazar 1858aafa15
Fix http proxy basic auth (#13140)
* Fix http proxy basic auth

* Update docs about HTTP CONNECT env var formats
2022-06-23 00:27:29 +00:00
Noah Stride 5e8cfb345c
Correct terminology from SSHAddr to ListenAddr for Auth server (#13725)
Rename auth SSHAddr to ListenAddr
2022-06-22 23:03:08 +00:00
Nic Klaassen a3e8bdcdc6
serialize hsm tests (#13632) 2022-06-18 00:02:45 +00:00
Forrest Marshall 31f258fec9 inventory control stream & certs 2022-06-15 22:26:24 -07:00
Nic Klaassen 77a90c1f8e
improve HSM test reliability (#13504) 2022-06-15 18:30:13 +00:00
Trent Clarke 3ff6889389
Split integration test fixtures into a package (#13465)
As a prelude to breaking individual integration test suites out into
their own packages (in order to make them more amenable to running
in parallel), this patch extracts the common test fixtures and places
them in a common `helpers` package.

This will allow the integration test package to share common
infrastructure and vocabulary once they are split out.
2022-06-15 17:07:26 +10:00
rosstimothy e5c745f331
Add manual tracing instrumentation to tsh (#13204)
Create spans for all public facing TeleportClient,
ProxyClient, and NodeClient methods. This makes
correlating spans easier to reason about when
looking at `tsh` traces. As a result of creating
spans, some additional context propagation is
required as well to ensure that spans are linked
properly.

This also removes the unused `quiet` argument from
`ConnectToCluster`. It's usage was not consistent
by existing callers, and it was ignored, so in order
to avoid confusion in future calls, it was removed.

#12241
2022-06-11 15:34:40 +00:00
Andrew Burke 9af04f4502
Fix dependencies in integration tests (#13321)
This change moves some type/function definitions in integration tests to fix compilation.
2022-06-10 22:41:29 +00: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
Przemko Robakowski 951aff47ed
IP-based validation for SSH (#13243)
This change adds IP-based validation for SSH certificates.
There's new option in role definition:

kind: role
metadata:
  name: dev
spec:
  options:
    pin_source_ip: true
When that is set to true client IP must be the same when generating certificates and using them. It uses source_address critical option that should be supported by both teleport and sshd and only applies to certificates we send to user (like in tsh login), we don't pin IP in certificates issued for web UI as they can't leak.
This change also omits machine ID (it uses different code path) - it will be added in separate PR.

Most of the lines changed are from regenerating types.proto, change itself is not that big

Relates #11719
2022-06-08 22:49:37 +00:00
Jakub Nyckowski c30eee366e
Move SetTestTimeouts() to TestMain (#13312) 2022-06-08 17:05:06 -04:00
Andrew Burke 870ac4ca9b
tsh list resources accross proxies and clusters (#12934)
This change adds the --all/-R flag to tsh ls, tsh apps ls, tsh db ls, and tsh kube ls, which lets tsh list resources from across all clusters and logged in proxies.
2022-06-08 18:42:25 +00:00
Brian Joerger 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 McGrath 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
Andrew Burke 22c0fccba7
Restore HTTP_PROXY for multi-port mode (#13048)
This change undoes the changes in #11990 and #12335 for Teleport going forward.
2022-06-07 11:57:16 -07:00
Gabriel Corado c459ddbbe6
SSH Session recording modes (#12916) 2022-06-06 20:29:35 +00:00
Marco André Dinis 306d011151
Deprecate ca_signature_algo config (#13033)
After the merge of https://github.com/gravitational/teleport/pull/12674 we no longer use the following configuration:
```yaml
teleport:
    ca_signature_algo: "rsa-sha2-512"
```
As we now rely upon the `x/crypto` package to choose the signing algorithm (it defaults to `rsa-sha2-512`)

**Demo**
If we set `ca_signature_algo` (the value is irrelevant) and start `teleport` we get:
```shell
root@marco:/workspace# teleport start --debug
2022-06-02T09:33:58Z WARN             ca_signing_algo config option is deprecated and will be ignored, we'll always default to rsa-sha2-512. config/configuration.go:348
2022-06-02T09:33:58Z INFO             Generating new host UUID: b001159a-10e0-49a7-b4dc-61c73fbe9e42. service/service.go:726
...
```

Fixes #12905
2022-06-06 16:18:15 +01:00
Marek Smoliński f22d8e9723
Fix Audit Event max event size flow (#12352) 2022-06-06 09:58:48 +02:00
rosstimothy 25ec2c8a39
Add client side circuit breaker to auth clients (#10282)
* Add client side circuit breaker to auth clients

In order to apply back pressure we can utilize a circuit breaker that
monitors error responses from auth server. When tripped it will prevent
all outbound requests to auth for a period of time. This can also help
prevent a potential thundering heard when auth is in an unhealthy state.
By default the circuit breaker will only be tripped if 90% of the
requests made in the monitoring interval fail.
2022-06-03 11:55:56 -04:00
Andrew Burke 7f730d2a58
Add disabled imds client by default for integration tests (#13109)
The instance metadata client added in #12593 significantly slows down integration tests. This change adds a disabled client to integration tests to improve performance.
2022-06-02 12:52:41 -07: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 230692f769
Fix EC2 labels concurrent write (#13072)
This change fixes a bug in EC2 labels (#12593) involving concurrent writes to the labels map. This is fixed by making EC2.Get() return a copy instead of the actual label map.
2022-06-01 21:26:28 +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
Marco André Dinis ba7a3204f6
Improve error msg when client fails to auth in Teleport (#12677)
When the client connects to teleport with invalid credentials (eg
expired ones) it will retry multiple times until the context deadline is
reached.
When it happens, we receive the generic error: context deadline
exceeded.
However, we can ask for the latest connection error, one which will give
us more information on why it happened.
To ask for this extra error we need to add the following
grpc.DialOption: grpc.WithReturnConnectionError()

After doing this, we will get the errors that happenned when trying to
connect to the grpc Server.

This should help us debug possible connection problems.

We had to refactor a little bit the way we handle the parallel
connection attempts to receive all the connection errors from the
multiple flows.
2022-05-31 15:24:57 +00:00
Marco André Dinis 2493448cbd
Bump x/crypto to 20220518 and remove custom algorithm signer (#12674)
This commit upgrades the version of x/crypto we use, to the current latest
`go get -u golang.org/x/crypto`

We also replaced the deprecated variables and updated the tests to match the
current default KEX Algos

The x/crypto didn't support RSA-SHA2 algos, so we developed our own algorithm
signer. This is no longer the case, and after upgrading x/crypto to 20220518 we
can safely remove the custom code we have.


From OpenSSH 8.8+, it works if we explicitly add the older algorithm
Somthing like this: `./ssh -vvv -oPubkeyAcceptedAlgorithms=+ssh-rsa-cert-v01@openssh.com teleportadmin@moon.marco.mydemo`
2022-05-25 14:47:00 +01: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
Noah Stride 2f1675e480
Run HSM integration tests in parallel (#12470)
* run HSM tests in parallel

* add missing punctuation to commit

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
2022-05-19 13:41:34 +00:00
Marek Smoliński 275a443f19
Upgrade MySQL driver to v1.5.0 (#12667) 2022-05-18 11:27:10 +02:00
rosstimothy 1ac0957d0e
Improve CertAuthorityWatcher (#10403)
* Improve CertAuthorityWatcher

CertAuthorityWatcher and its usage are refactored to allow for
all the following:
 - eliminate retransmission of the same CAs
 - reduce memory usage by having one local watcher per proxy
 - adds the ability to filter only the CAs that are desired
 - reduce the time required to send the first CAs

watchCertAuthorities now compares all CAs it receives from the
watcher with the previous CA of the same type and only sends to
the remote site if they are not identical. This is to reduce
unnecessary network traffic which can be problematic for a
root cluster with a larger number of leafs.

The CertAuthorityWatcher is refactored to leverage a fanout
to emit events to any number of watchers, each subscription
can be for a subset of the configured CA types. The proxy
now has only one CertAuthorityWatcher that is passed around
similarly to the LockWatcher. This reduces the memory usage
for proxies, which prior to this has one local CAWatcher per
remote site.

updateCertAuthorities no longer waits on the utils.Retry it
is provided with before starting to watch CAs. By doing this
the proxy no longer has to wait ~8 minutes before it even
starts to watch CAs.
2022-05-17 19:06:41 +00:00
Andrew Burke e1e6437879
Ignore HTTP_PROXY in reverse tunnels, part 2 (#12335)
This change disables HTTP_PROXY in a few places that were missed in #11990.
2022-05-11 23:00:58 +00:00
Roman Tkachenko 0b6fe7257d
App access JWT header improvements (#12567) 2022-05-11 22:15:11 +00:00
Zac Bergquist a7ab44f15b
Fix linter after Go 1.18 upgrade (#12585)
* Update golangci-lint

To accomodate the recent Go 1.18 upgrade

* Fix new lint warnings as a result of linter upgrade

* Set golangci-lint to Go 1.18 mode

golangci-lint will automatically skip linters that don't have support
for Go 1.18.

See: https://github.com/golangci/golangci-lint/issues/2649
2022-05-11 21:53:37 +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
Marek Smoliński 158a70a7d5
Fix flaky integration test: increase deadline (#12449) 2022-05-05 21:31:00 +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
Joel 21ff6221ad
Limit Kubernetes connections (#12275) 2022-05-02 17:24:09 +02:00
Jakub Nyckowski d5d2a72ace
Advertise correct MySQL server version (#12196)
Teleport now will try to extract MySQL server version from initial handshake package instead of sending `8.0.0-Teleport` every time. This string can be overridden by new configuration option `mysql.server_version`. On DB service start Teleport will also try to fetch the current version from MySQL/MariaDB instance. After that the server version will be updated on every successful connection to keep it up to date.

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2022-04-29 22:22:11 +00:00
Edoardo Spadolini 39ffa56766
Specify the NodeName in auth.ReRegister (#12272)
* Specify the NodeName in auth.ReRegister

* Make cleanup consistent
2022-04-29 18:05:08 +00:00
Roman Tkachenko d78f6925a4
Revert readyz changes (#12244)
* Revert "Make `PortList.Pop()` thread-safe (#11799)"

This reverts commit a17337d1a1.

* Revert "Ensure stateOK is reported only when all components have sent updates (#11249)"

This reverts commit b749302e2c.

* Revert "Throw startup error if `TeleportReadyEvent` is not emitted (#11725)"

This reverts commit 933e247287.

* Revert "Fix ProxyKube not reporting its readiness (#12150)"

This reverts commit 6cdcfe7721.
2022-04-26 22:16:55 +00:00
rosstimothy 71dea2df4c
Speed up TestAppServersHA (#12128)
* Speed up TestAppServersHA

Allow test cases to be run in parrallel and allow app servers to
be spawned in parrallel to reduce test time from ~99s to ~20s.
2022-04-26 15:05:24 -04:00
Joel 99116409d4
Remove needlessly complex key generation scheme (#12113) 2022-04-25 09:26:10 +00:00