Commit graph

77 commits

Author SHA1 Message Date
Rafał Cieślak c4897417fe
Add integration test for deamon.Service.AddCluster (#20332)
* Add integration test for daemon.Service.AddCluster

* Call SaveProfile on clusterClient rather than cfg

This way we don't have to explicitly set ClientStore as
client.NewClient(cfg) does that for us.
2023-01-24 08:10:02 +00:00
Tiago Silva 10da451dd6
Add support for subResourceName to teleterm (#20541)
Initial support for `subResourceName` when listing resource access requests for `type=pod`.
2023-01-23 15:06:01 +00:00
Rafał Cieślak 129567994e
Storage.addCluster: Remove unnecessary fetch of web config (#20331)
Back in the day, the ping response didn't include the actual name of
the cluster. So instead we had to make a separate request for /web/config.js.

However, the ClusterName field was added to /webapi/ping in v10 (#12848).
Since we already ping the server, let's use the name from the ping response
instead.
2023-01-19 09:55:12 +00:00
Rafał Cieślak 613bc9ab63
Set up ClientStore when adding cluster in Connect (#20263) 2023-01-17 16:37:58 +00:00
Brian Joerger 2922ad009a
Allow non-standard agent keys. (#18449) 2023-01-13 17:59:51 +00:00
Grzegorz Zdunek 584e96efe0
Report Connect usage events (#19564) 2023-01-10 18:17:21 +01:00
Rafał Cieślak 50213556db
Use one Buf workspace instead of three (#19774) 2023-01-09 11:31:35 +00:00
Brian Joerger 488af75797
Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00
Grzegorz Zdunek 25507e6ccd
[Connect] Add authClusterId to cluster struct (#19829) 2023-01-04 14:05:02 +00:00
Michael 3877461d25
[Connect] Add SuggestedReviewers and RequestableRoles to LoggedInUser (#19466) 2023-01-03 16:01:56 -06:00
Alan Parra f28319a6b8
Add user-visible device trust settings (#19531)
Add device trust settings to teleport.yaml and cluster_auth_preference resource.

Example configuration (teleport.yaml):

```yaml
auth_service:
  authentication:
    device_trust:
      mode: "required"  # requires Teleport Enterprise
```

gravitational/teleport.e#514
2022-12-21 15:24:12 +00:00
Alan Parra 82e6fb9269
Wire device authentication into tsh (#19436)
Wire device authentication into `tsh`, so it attempts to acquire device
certificates after user login. This affects direct logins (`tsh login`),
indirect logins (RetryWithRelogin) and Connect.

If authentication fails (non-Enterprise cluster, device not enrolled, etc) `tsh`
proceeds as usual, but the final user certificate won't contain device
extensions.

gravitational/teleport.e#514
2022-12-20 20:53:45 +00:00
Michael 1b5bd9824d
[Connect] Add server hostnames in access request responses (#19258) 2022-12-20 14:33:47 -06:00
Rafał Cieślak aae077a672
daemon.Service: Rename GetCluster to ResolveFullCluster (#19180) 2022-12-08 15:34:52 +00:00
Rafał Cieślak cb3e4d99b7
Connect: Detect & reissue expired db certs (#17950)
* Add TTL field to integration/helpers.UserCredsRequest

This will let us create expired user certs by providing a negative TTL.

* Reissue gateway cert if middleware detects it expired

* Add integration test for gateway cert renewal
2022-12-06 12:32:04 +01:00
Jakub Nyckowski 9379243390
Use pre-generated RSA keys in tests (#18750)
Many of our tests (db package, I'm looking at you) generate many RSA keys. This has two main side effects; makes our tests slow and flaky as CPU usage spikes in random moments when the tests are run in parallel.
This change pre-generates RSA keys at the beginning of each test module and reuse them in randomized order to reduce the situation that one key has been used multiple times in one test.
I had to move a few files to avoid circular dependencies.
2022-12-05 19:33:49 +00:00
Rafał Cieślak 5ca68904c8
Connect: Set TeleportClient.AuthConnector before logging in (#18811) 2022-11-30 10:12:48 +00:00
Michael b578dbca0f
[Connect] Update create access request logic to differentiate between role/resource requests in tshd (#18867) 2022-11-29 19:34:17 +00:00
Rafał Cieślak 59a96be624
Connect: Check db cert before using it for local proxy (#18740) 2022-11-29 10:11:57 +00:00
Michael 5b43b61da6
Update GetDatabases to use the correct cluster uri (#18735) 2022-11-24 00:49:30 +00:00
Rafał Cieślak 8bfc14966c
Connect: Add prerequisites for gracefully handling expired db proxy certs (#18259)
* Log gateway.Close errors during test cleanups

Unless gateway.Close is called on a gateway that was already closed, it
shouldn't return an error.

However, when working on handling expired certs in Connect I ran into a
buggy test where that error from gateway.Close provided a crucial clue
in fixing the bug. But because initially it was simply ignored, it took
me a while to figure out what was going on.

That's why this commit adds logging around those errors.

2 out of those 3 places are helper functions which get used in a variety
of tests, hence why they call t.Cleanup. The other place does call
gateway.Close eventually but we still use t.Cleanup in case the
execution doesn't get to that point.

* Automatically add useful fields to gateway loggers

It's useful to see what resource the gateway is targeting and what is
the URI of the gateway.

Previously the field with URI was hardcoded in cluster_gateways.go or
added only when cfg.Log was nil, meaning that we weren't able to benefit
from it in places such as gateway_test.go.

This commit makes it so that the `resource` and `gateway` fields are
added to any logger that is passed through gateway.Config.

* Remove copylocks warning from Gateway.NewWithLocalPort

gateway.Gateway holds a mutex in one of its fields. NewWithLocalPort
accepted gateway by value so vet was issuing a warning about copying a
lock.

NewWithLocalPort doesn't actually use the copied lock. But it makes
sense to get rid of the warning anyway.

* Make ReissueDBCerts accept tlsca.RouteToDatabase as arg

ReissueDBCerts used to accept a full-blown types.Database object just to
read a couple of fields from it. In the context of Connect, such object
is obtainable only by making a request to the cluster.

However, in the upcoming PR we want to be able to reissue the cert
without having to perform an unnecessary request to the cluster.

gateway.Gateway already holds all data we need to reissue the cert, so
let's make ReissueDBCerts accept tlsca.RouteToDatabase instead of
types.Database to avoid making that extra request.

* Add Gateway.ReloadCert

In the upcoming PR, after we reissue the db cert, we need to be able to
update the cert used by the running alpn.LocalProxy. This commit exposes
exactly that functionality.

Also, this commit adds RWMutex to Gateway to avoid a situation where
multiple goroutines attempt to reload the cert. This shouldn't happen
under normal circumstances but better safe than sorry.

RWMutex is also used for any field on Gateway that has a setter.

* Add basic implementation of LocalProxyMiddleware

* Add OnExpiredCert callback to gateway.Config

This callback will let the layer above gateway.Gateway handle a
situation in which the cert used by the gateway has expired but there's
a client that tries to make a connection through the gateway.

gateway.Gateway doesn't have the ability to reissue the cert by itself,
hence why we need to accept a callback from above.
2022-11-22 12:56:34 +00:00
Rafał Cieślak 2e3367c8cd
Add tests for teleterm.Serve with TCP address (#18144)
* Refactor error handling for GetConfigForClient

If GetConfigForClient returns an error, the error is not visible in any
logs or by the client making the request.

Instead of failing, we return a config that doesn't let any client
through. It has ClientAuth set to RequireAndVerifyClientCert, but the
config lacks ClientCAs to verify the client cert against.

This also means that when a client with an invalid cert dials the server,
it's going to fail on net.Conn.Read and not tls.Dialer.DialContext. This
will help us add uniform tests in the next commit.

This use of GetConfigForClient is more similar to what we do in other
parts of the codebase, for example in lib/srv/db/proxyserver.go.

* Add tests for teleterm.Serve with TCP address

Previously we'd only test teleterm.Serve with a unix socket, meaning our
whole TCP setup would not be tested.

Testing the TCP server means that we need to set up proper TLS configs
for clients in tests.
2022-11-21 11:55:50 +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
Rafał Cieślak 769719f2ec
Connect: Set up tshd-initiated communication (#17660)
* Move cred generation one layer up

* Create tshd events client

* daemon.Service: Add closeContext for gRPC calls
2022-11-08 10:04:00 +00:00
Jakub Nyckowski 0ee91f6c37
Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Michael c8c02c4ff4
[Connect] Add Server Features to GetCluster (#17497)
To enable feature detection in the Connect application, we need to
ping the auth server to understand which features are enabled.
Previously, we could get away with any cluster information stored in the
cluster profile but a proxy dial is necessary now to get an auth ping response.
2022-10-20 20:21:58 +00:00
Rafał Cieślak 5adcebba91
Connect: Accommodate for making gRPC client creds from tshd key pair (#16782)
* Connect: Accommodate for making gRPC client creds from tshd key pair

For tshd-initiated communication, the tshd process will need to create a
client that will connect to a gRPC server operated by the renderer
process of the Electron app.

On Windows, we use gRPC over TCP with mTLS. Each process creates its own
keypair and saves the public key to a predetermined location.

The previous code assumes that tshd is only going to need server
credentials. This commit makes it possible to create client credentials
from the same key pair.

* Refactor server options

* Expand the comment for createServerCredentials

* Remove unnecessary filepath.Join

* generateAndSaveCert: Use os.CreateTemp
2022-10-20 12:38:25 +02:00
Alan Parra b289295f93
Move away from deprecated protoc-gen-go plugin (#17267)
Moves from github.com/golang/protobuf protoc-gen-go plugin to google.golang.org/
plugins.

This change was a long-time coming, but is now possible to do since our
dependencies are up-to-date.

* Move away from deprecated protoc-gen-go plugin
* Embed unimplemented server in handler.Handler
* Embed unimplemented server in multiplexer_test.go
* Update generated protos
2022-10-13 14:01:44 +00:00
Michael 87325be703
[connect] access requests for Teleport Connect (#16694)
* access requests for teleterm

* removed unused imports and named returns

* remove comment

* using timestamppb instead of string for access requests

* updated proto with some more comments

* updated protos with comments

* using clusterClient, comments, and moving validation to daemon for access request delete

* separated GetAccessRequests into separate RPCs

* protobuf updates

* moved requestid check before resolving cluster

* fullstops in comments

* used standard access_request_id through rpc messages

* updated protofiles

* updated daemon service types to match grpc

* added kube advanced search support

* updated protos for kubes in access requests

* testing tag build

* fix detached head

* new tag build

* protobuf update

* lint fixes

* allow drone windows Connect build to include webapps.e

* protobuf files

* remove drone changes and updated comment

* proto changes with comment fixes and changed field order

* protobuf updates
2022-10-11 18:52:16 -05:00
Alan Parra f9f0ca339e
Bump grpc-related dependencies (#17265)
Bumps:

* protoc to v3.20.3
* protoc-gen-go to v1.5.2 (github.com/google/protobuf version, Teleterm only)
* google.golang.org/grpc to v1.50.0
* google.golang.org/grpc/examples
2022-10-11 14:29:01 +00:00
Grzegorz Zdunek 2c6a898983
Add file transfer support to Connect (#16880) 2022-10-10 11:09:08 +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
Grzegorz Zdunek 399526cff2
Connect: Fix premature proxyClient.Close() when getting kube clusters (#16538) 2022-09-21 12:17:27 +02: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
Alan Parra fbc135e672
Add comment and import cycle proto linters (#16082)
Require top-level proto types to have comments and introduce import cycle linter.
2022-09-02 13:31:45 +00:00
Rafał Cieślak 9397d4a309
Connect: Add tests for ParseClusterURI (#15863) 2022-08-30 09:59:04 +00:00
Alan Parra 49e3c0d6d0
Use Buf linters and formatter on lib/teleterm protos (#15877)
Similarly to #15856, moves lib/teleterm fully to Buf.

#15187

* Fix buf lint warnings on lib/teleterm
* Enable buf build and lint for lib/teleterm
* Use buildbox Buf in Connect, enable build/lint/format
* Reformat protos
* Update generated protos
2022-08-29 19:45:03 +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
Grzegorz Zdunek bcd480ca08
Reorganize approach to cluster names in Connect (#15200) 2022-08-17 17:38:37 +02:00
Lisa Kim 13cc52f70d
Add passwordless login capability to Connect (#14759) 2022-08-05 17:11:28 +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
Grzegorz Zdunek 60d49671a8
Use IP as LocalAddress when gateway is created on Windows for SQL Server (#14930) 2022-07-28 15:27:33 +00:00
Grzegorz Zdunek d2d9fd4dad
Support TCP protocol in tshd (#14301) 2022-07-26 14:12:56 +00:00
Rafał Cieślak 9313899f28
Remove time.Sleep in teleterm tests (#14179)
* Set default shutdown signals for Teleterm

The server in tests was actually immediately shutting down because
Signal.Notify relayed all signals to it and thus closed the server
prematurely.

* Remove time.Sleep in teleterm tests

Also, rename Start() to Serve().
2022-07-25 11:37:39 +00:00
Rafał Cieślak 21b21bf069
Connect: Implement SetGatewayLocalPort RPC (#14690)
* Encapsulate rather than embed Config within Gateway

* Implement SetGatewayLocalPort RPC
2022-07-25 11:15:53 +00:00
Rafał Cieślak c934045b7b
lib/teleterm: Refactor daemon gateways to a hash map (#14296)
* daemon: Put gateway-related methods next to each other

* Remove unused fields from daemon.Config

* Make Config a private field instead of embedding it

* Add tests for gateway CRUD

* Remove unnecessary ctx and error from daemon.Service gateway methods

* Refactor daemon.Service.gateways to a hash map

* Add comment explaining error handling in removeGateway

Edoardo asked about it some time ago. I forgot to add the explanation to
the code.

https://github.com/gravitational/teleport/pull/14135#discussion_r914687662

* Do not return pointers from ListGateways()

* Remove FindGateway, fix lock issues in RestartGateway() and RemoveGateway()
2022-07-19 15:48:38 +00:00
Rafał Cieślak 80a4237bda
Connect: Fix premature proxyClient.Close() when getting db users (#14230)
In the previous version, the proxy client would be closed immediately
after addMetadataToRetryableError. This commit makes it so that the proxy
client is closed only after GetAllowedDatabaseUsers finishes.

When running Connect on Windows, Grzegorz ran into a problem where fetching
db users for MSSQL would fail but only on Windows and only for MSSQL:

    Failed to fetch current user information: connection error:
    desc = "transport: Error while dialing failed to dial: read tcp
    10.211.55.4:55519->52.14.45.73:3023: use of closed network
    connection". services\role.go:764

Other times the error would be

    connection error: desc = "transport: Error while dialing failed
    to dial: ssh: unexpected packet in response to channel open:
    <nil>"] apiserver\middleware.go:39

Surprisingly, `tsh db ls` didn't have this problem. So when thinking about
what we're doing differently than tsh and how it might be related to
a closed connection, I noticed that I made a bug in the code that closes
the proxy client.
2022-07-12 15:03:41 +00:00
STeve (Xin) Huang 13abca6638
Optimize tsh db ls performance (#14092) 2022-07-09 20:22:47 +00:00
Jakub Nyckowski c3dde989cc
Update protoc to v3.20.1 (#14097)
Co-authored-by: Rafał Cieślak <rafal.cieslak@goteleport.com>
2022-07-07 23:21:32 +00:00
Rafał Cieślak 15439227ea
Make it possible to test gateway opening/closing in Connect (#14135)
* Make it possible to test gateway opening/closing in Connect

Open() and Close() used to not return any error and Open() used to start
the gateway in a goroutine, making it rather hard to write tests for it.

This commit makes it so that Open() and Close() return errors and Open()
blocks.

Adjustments have been made to other places in lib/teleterm to account
for that missing goroutine and returned errors.

* Close httptest server in alpnproxy/local_proxy_test.go

While writing tests for the gateways, I was relying heavily on tests for
the local proxy. I noticed that it starts the server but doesn't close it
so I added an appropriate call to the cleanup function.

* Rename Gateway.Open to Gateway.Serve
2022-07-07 14:45:17 +00:00