Commit graph

510 commits

Author SHA1 Message Date
Steven Martin e1ebc332f8
spell fixes (#19419) 2022-12-16 19:01:28 +00:00
Rafał Cieślak 519c9aa0df
Improve error handling in Connect gateway integration test (#19145)
mockTSHDEventsClient will most likely be called outside of the test
goroutine, so we shouldn't use require.NoError there.

helpers.SetupUserCreds returns an error which I did not inspect. The linter
didn't warn me about it for some reason.
2022-12-15 09:49:20 +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
Marco André Dinis 6fd0fa8ef3
Connection Diagnostics: Postgres Database tester (#18558)
* Connection Diagnostics: Postgres Database tester

When adding a new resource using the Web UI we want to allow users to
test connecting to it.

We have two connection testers already:
- for SSH Nodes
- for Kube clusters

This PR adds a third tester: Postgres Database.

Most of the required changes for any Database are already present but
we're focusing on Postgres for now. Other databases will be added as
future PRs.

Testing a Database is similar to the other tests:
- generate certs for the logged in user
- connect to the resource using those certs

When generating the certificate, we inject an ID so that the Database
Service can add Connection Diagnostic traces.
2022-12-13 18:55:40 +01:00
STeve (Xin) Huang 94e29f971b
Attempt to deflake TestDatabaseAccess/AgentState (#19169) 2022-12-08 14:39:38 +00:00
Michael Wilson 7d7e574aa4
Eventually require connection failure in TestTCPCertExpiration tests. (#18978)
The TestTCPCertExpiration test may have a race condition where the connection
made to the test application immediately after the cert expiry may succeed.
Due to the wonky nature of using the fake clock in this test, I'm introducing
a requires.Eventually here to hopefully mitigate this race.
2022-12-07 21:49:37 +00:00
Gavin Frazar ae2d4ca78c
Run main test (#19134) 2022-12-07 20:30:51 +00:00
Rafał Cieślak db09b3c4a2
Fix typo in integration/db.SetupDatabaseTest (#19095)
While working on integration tests, I noticed that testOptions.leafConfig
is simply ignored because after we set up the leaf cluster config, we call
testOptions.rootConfig instead.
2022-12-07 15:40:33 +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
Zac Bergquist c9e64e1c0e Make the uploader responsible for creating the directories it needs
This removes a bunch of custom code where we manually create uploader
directories in tests because the full uploader service is not running.
2022-12-04 11:50:29 -05:00
Zac Bergquist 2314ebf7e6 uploader: move corrupted uploads to separate directory
This ensures that the uploader won't busy loop over the same corrupted
upload file, while ensuring that the file is still preserved.

Fixes #18936
2022-12-04 11:50:29 -05:00
Brian Joerger a3bd4650d0
Provide proxy address when beginning a node session (#18579) 2022-12-02 01:56:22 +00:00
Tiago Silva da987dfc6b
Remove legacy heartbeat from Kubernetes Service (#18876)
With the arrival of Teleport 12, we stop supporting v10.x.x clients, and we no longer require the `types.KindKubernetesService` legacy heartbeat.

This change removes the legacy heartbeat from Kubernetes Service but keeps the legacy Auth Server CRUD methods and heartbeat support to maintain compatibility with Teleport 11 Kubernetes Service - Teleport 11 still heartbeats the legacy type.

We postponed the related `DELETES` to Teleport 13.
2022-12-01 13:16:41 +00:00
Zac Bergquist 166dc5a1be
Clean up defaults (#18860)
- Make vars const where possible
- Move constants that are only used by the audit log into lib/events
- Remove unused vars
2022-11-30 15:50:29 +00:00
Nic Klaassen fbed5c9684
test: add GCP KMS unit tests (#18245) 2022-11-29 00:16:59 +00:00
Michael Wilson f123dd125f
Ensure app session is in backend in app access integration tests. (#18744)
There is an occasional race condition where the app session does not appear to
be reflected in the backend after it's created by the time the test logic in
the app access integration tests is run. This will (hopefully) address this
issue.
2022-11-28 16:02:48 +00:00
Jakub Nyckowski 655dfa2aa7
Adjust integration test timeouts (#18331)
* Adjust integration test timeouts

* Skip TestProxyTunnelStrategyProxyPeering
2022-11-24 18:47:49 +00:00
Roman Tkachenko 3fd1cca5b2
Github Actions workflow (#18617)
Signed-off-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Victor Sokolov <gzigzigzeo@gmail.com>
2022-11-22 16:55:26 -05:00
rosstimothy 7f118b34da
Make session control logic reusable (#18565)
Session control logic existed within `HandleNewConn` of `srv/regular.Server`.
This prevented any of it from being used by other components that
also needed to enforce session control.

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

This is step 2 in addressing #15167. Before the web apiserver can
leverage the newly introduced proxy.Router and bypass making ssh
connections to the proxy ssh server it needs to be able to perfrom
session control.
2022-11-21 17:11:19 +00:00
Gavin Frazar 5e1b4528fd
Add mutex for certs in local proxy (#18278)
* Add mutex for certs in local proxy

* Update lib/srv/alpnproxy/local_proxy.go

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>

* Update lib/srv/alpnproxy/local_proxy.go

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>

* Update lib/srv/alpnproxy/local_proxy.go

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>

* Move cert checking out of middleware into local proxy

* Configure a logger for local proxy

* Fixup imports

* Add tests for local proxy

* test for data race
* test for cert checking

* Update integration test for local proxy

* Mark err assert fns as helpers

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>
2022-11-18 00:07:46 +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
Michael Wilson bd0ef3efad
Remove CertificateTTL from appaccess integration tests. (#18395)
The CertificateTTL causes problems after the introduction of the fake clock
into the appaccess tests due to the fake clock not being propagated properly
throughout the Teleport stack. Increasing the TTL should make this test much
less flaky.
2022-11-14 20:09:21 +00:00
Marek Smoliński a059d70ba8
Fix Flaky TestDatabaseRootLeafIdleTimeout test (#18202) 2022-11-14 10:09:33 +01:00
Nic Klaassen 962e5a25bc
plumb context to keystore methods (#18034)
* plumb context to keystore methods

Contexts are more relevant now with the GCP KMS keystore which makes
http requests, this commit makes sure they are passed everywhere they
are needed, with only a few `context.TODO`s sprinkled in.
2022-11-10 18:57:17 -08:00
Nic Klaassen bfbb71734d
feat: add GCP KMS support for Teleport CA key material (#17933)
* feat: add GCP KMS support for Teleport CA key material

This commit implements support for GCP KMS as a backend for CA
operations in Teleport.

This is able to take advantage of much of the infrastucture that we have
already created for HSM support, and simply appears as a new backend for
the private key material.

The necessary configuration parameters include only the name of the KMS
keyring to use, and the protection level (which can be HSM or SOFTWARE).
These are configured in the teleport.yaml directly, in a new section
under the existing `ca_key_params` used for HSM configuration.

The GCP credentials are expected to be provided to the Teleport auth
server via the
[Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc).
This means that it "just works" if the auth server is running on a GCP
compute instance with the correct attached role, and you can run tests
locally by authenticating with `gcloud auth login`.

This does not support Teleport Cloud, as our current HSM support does
not, because the Auth server needs the configuration and the access to
the GCP account. That would be a larger effort probably requiring a new
Teleport service.
2022-11-11 00:03:49 +00:00
Michael Wilson 607fefd7c8
Bump TCPCertExpiration test to advance 24 hours. (#18303)
Just to make sure that we're going beyond the cert's TTL, the
TestTCPCertExpiration test now advances 24 hours.
2022-11-09 23:17:20 +00:00
Nic Klaassen 46f0265546
cleanup: shrink/remove keystore interface (#17908)
* shrink/remove keystore interface

This commit introduces the keystore.Manager type to handle all
interaction between CA and the keystore backends.

Why:

* reduces the code that needs to be implemented per keystore backend to
  only the necessary operations
* separate concerns of managing key material and handling CA data
  structures
* define interfaces where they're used, not implemented
* delete net 245 lines of code
* reduce keystore.KeyStore stutter
2022-11-09 01:44:22 +00:00
Michael Wilson 85fac93653
Make TestTCP* tests in appaccess more deterministic. (#18233)
The appaccess TestTCP* tests are highly reliant on time. This has been
reduced (but not eliminated) by using a fakeClock and a channel for
signaling monitor triggered connection closures.
2022-11-08 21:40:54 +00:00
Gavin Frazar b48e711fdf
Fix flaky basic auth dialer test (#18239)
* Fix flaky basic auth dialer test

* Block on sending error to waiters in ProxyAuthorizer, to avoid racing
  against the waiter.
* Change the test to start the node in a separate goroutine and
  manipulate the auth creds while it is still attempting to connect.
  This will allow us to significantly speed up the test since we can
  verify that the proxy authorizer is rejecting bad credentials but then
  change the credentials to be valid afterwards, allowing the node to
  succeed in registering and avoid long wait for it to fail to register.

* Use buffered chan

* Move the stopall defer up in case the test fails earlier

* Remove extra zero count check
2022-11-08 02:32:25 +00:00
Michael Wilson 3d483e2d13
Add in app access connection monitoring. (#17436)
Application access connection monitoring has been introduced so that, when a
lock is created, application access connections will be interrupted until the
lock has been cleared. This includes web sockets and TCP applications.
2022-11-05 02:44:57 +00:00
rosstimothy 514bfc7ac6
Ensure invalid tunnel agent connections get closed (#17899)
* Ensure invalid tunnel agent connections get closed

Connections from reverse tunnel agents were being marked
as invalid by the proxy under certain conditions but would
ultimately never be closed. This could lead to scenarios where
the agent thought things were fine but the proxy considered
that agent unhealthy and unroutable.

Pruning of invalid connections used to occur when a proxy
tried to retrieve a connection for that tunnel. This also
further muddied the point in time at which the proxy could
close a connection as it never explicitly stopped tracking
the connection and closed it at the same time.

To remedy this, connections are explicitly closed by the proxy
and removed from the mapping to stop tracking immediately. In order
to prevent a connection that is servicing an active connection
from being closed the proxy now tracks which connections have
sessions. Closing does not occur when there are any active
sessions to prevent them from being force terminated.

When the proxy receives a heartbeat from an agent it now restores
the connection to a valid state. In the event that too many heart
beats have been missed for an agent, the proxy will now terminate
the connection, again only if it is not serving any sessions.

Fixes #15911
2022-11-04 18:05:13 +00:00
Gavin Frazar 6e316fcadb
fix test alpn proxy http proxy basic auth dial flakiness (#17909)
* Update proxy handler and authorizer mocks

* Use a condition variable to properly sync checks for the last error received

* Fix test to check for all 3 nodes registering correctly

* Update naming of LastError to be more descriptive

* Refactor authorizer to not use a condition variable

* Remove 3rd node to speed up test

* Make test more robust

* Remove the reset count func

* Close client conns before new requests to be sure

* Connection -> Request terminology

* Change test to not mutate the environment variable, but instead manipulate the auth proxy credentials

* this way we can be sure that the test will work correctly when the credentials match. If we mutate env, we don't know whether the callers are still holding a dialer using the old env variable

* Remove extra node

* fix lint

* Fix req waiting

* Change wording in debug message

* fix comment

* Update integration/helpers/proxy.go

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Fix defer func

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2022-11-02 01:45:55 +00:00
Jakub Nyckowski 0ee91f6c37
Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Jakub Nyckowski 0f51099e3b
Skip AuditOn test (#17813) 2022-10-26 18:22:04 +00:00
Jakub Nyckowski b30df65631
Fix UACC paths in Close() (#17812)
* Fix UACC paths in Close()

* Add Close() call to TestRootUsernameLimit test

* Add comment explaining the getDefaultPaths() behavior.
2022-10-26 01:07:58 +00:00
Gabriel Corado 65c022893d
Add Azure AD user managed identity authentication for SQL server (#17142) 2022-10-21 15:06:51 +00:00
Michael Wilson 756eb91ede
Add X-Forwarded-SSL and X-Forwarded-Port to appaccess. (#16965)
* Add X-Forwarded-SSL and X-Forwarded-Port to appaccess.

Application Access now adds in X-Forwarded-Ssl and X-Forwarded-Port headers.
Tests have been added and adjusted to look for these new headers as well.

* Update lib/srv/app/header_rewriter.go

Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>

* Update integration/appaccess/fixtures.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Remove common.XForwardedPort

* Change order of websocket delegates.

* Make ReservedHeaders more future-proofed.
2022-10-12 16:54:53 +00:00
Mike Wilson e15f4f351e Add traits to JWT payload.
The JWT payload now includes user traits.
2022-10-10 14:52:06 -04:00
Marek Smoliński 7aa224e430
Add Cassandra/Scylla database support (#15895) 2022-10-10 12:37:51 +02:00
Gavin Frazar ba7df65a0c
support proxy db tunnel mfa access (#16958)
* Add local proxy middleware for db cert checking

* Use tls conversion util instead of inline

* Add middleware to local proxy config

* Add middleware configuration in tsh

* Use route to database check and set defaults func

* Dont trigger normal db login flow if using local proxy tunnel

* Split out adding client creds into helper func for testing

* Add integration test for local proxy tunnel db cert middleware

* Add unit test for local proxy middleware

* Update comment

* Make middleware on new conn block

* godoc

* Make any cert check error trigger cert renewal in local proxy middleware

* Move dbcertchecker into lib/client

* Remove unneeded mutex in local proxy and unused func in lib/utils

* Make local proxy middleware integration test more robust

* Print message before mfa prompt in proxy tunnel

* Add before prompt option to test

* Remove unneeded comment

* Change local proxy messages to be more clear

* Pass local proxy opts by reference

* Pass certs in opts instead of cert/key file path

This is so we can check if the error is recoverable while preparing
local proxy options. A tunneled local proxy can ignore the error because
it does not rely on cert files - it can just renew its certs if
necessary.

* Move db route checking back to tsh

* Fix lint err

* Fix typo and print the hint to same writer as the mfa prompt
2022-10-07 21:29:51 +00:00
Jakub Nyckowski 0df39758a0
Refactor OpenSSH config generation (#17138)
Unify OpenSSH config generation between tsh and tbot.

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-10-07 18:11:57 +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
Andrew Burke db7fdff809
Add option for tsh to load all CAs (#15178)
This change adds an option to let tsh load CAs for all clusters when logging in, instead of just the current cluster.
2022-10-05 18:29:09 +00:00
Tiago Silva 1e415b33b8
Add a legacy Heartbeat to Kubernetes clusters to maintain support for older clients (#16977)
* Adds a legacy Heartbeat to Kubernetes clusters to maintain support for legacy clients
2022-10-05 10:45:21 +00:00
Mike Wilson a4af8ae256 Revert "Ensure audit logging of tsh app login."
This reverts commit 31859e5d30.
2022-10-04 11:14:12 -04:00
Noah Stride eb42cabbea
Revert "Introduce ProvisionTokenV3 (#16361)" (#16934)
This reverts commit 3fba50261f.
2022-10-03 14:14:01 +00:00