27 Commits
Author SHA1 Message Date
Brian Joerger fcb15368f1 Fix flaky test TestIntegrations/AuditOn (#64544)
* Fix flaky tests caused by early dial failures.

* Add startSessionAndWaitForTracker to unmask session creation failures in audit tests.

* Fix test agentless server to accept more than one connection to enable readiness probe.

* Address comments.

* Address comments.
2026-05-06 17:33:49 +00:00
rosstimothy 6590c944b6 Inject modules into keygen (#62843)
Contributes to #62799.
2026-01-16 18:52:50 +00:00
rosstimothy 30d1f17dbf Improve reliability of waitForSessionToBeEstablished (#61736)
Several integration tests make use of the function to
know that a session was created, a SessionTracker was
created in the backend, and to retrieve the session id.

The function polled the backend for session trackers
until the context deadline set in individual tests
was exceeded. In an effort to reduce flakiness and
make the API easier for callers the helper has been
rewritten. It now leverages a require.Eventually
internally, has a hardcoded limit of 30s instead of
allowing each test to define their own, and validates
the number of expected participants in a session.


Closes https://github.com/gravitational/teleport/issues/17224.
Closes https://github.com/gravitational/teleport/issues/36959.
2025-11-25 16:37:19 +00:00
Luke Okraszewski 6d8fca2157 [chore] disable debug service in integration tests (#61529)
The datadir in this test consists of TempDir
and typically suffix which exceeds the
BSD socket limits causing the test to fail on MacOS.

This commit disables the debug service in the failing tests,
for testing the debug service specifically it should be
enabled in the test itself.
2025-11-19 17:55:41 +00:00
Rafał Cieślak db823a3b37 TestIntegrations/PortForwarding: Increase timeout for waitForSessionToBeEstablished (#59424)
* PortForwarding test: Increase timeout for `waitForSessionToBeEstablished`

* Use t.Context instead of context.WithCancel
2025-09-29 16:19:16 +00:00
rosstimothy 7541d6d7d0 Introduce logtest package (#56741)
Moves all test related logger initialization and creation to the
logtest package to reduce testing symbols in production code. The
existing helpers in lib/utils have been left in place until the
enterprise references can be converted.

Updates #51023.
2025-07-15 18:11:10 +00:00
rosstimothy 43d15d355f Reduce testing symbols in production binaries (#55360)
* Move lib/srv/mock to lib/srv/mock_test.go

* remove testify from lib/srv/db/redis

* remove lib/auth/test package

* Move lib/utils/testhelpers.go to lib/utils/testutils

* duplicate auto upgrades server mock

* remove testing from fake podman server

* remove lib/fixtures/plugin.go

* remove test assertions from lib/fixtures

* remove depguard exceptions that no longer apply

* fix: comments
2025-06-09 16:51:12 +00:00
rosstimothy 852fc7d605 Remove unused servicecfg.Config.Console field (#50944)
Depends on https://github.com/gravitational/teleport.e/pull/5829
2025-01-13 16:58:27 +00:00
rosstimothy 2c764e14b5 Reduce reliance on servicecfg.Config logrus logger (#50817)
Converts most items to use servicecfg.Config.Logger instead of
servicecfg.Config.Log. The deprecated logrus logger unfortunately
cannot be removed yet as it's still used in e. Additionally all
logging within the config package was converted to use slog.
2025-01-07 20:09:30 +00:00
Andrew Burke 18572bc034 Fix remote port forwarding with separate login (#43069)
This change fixes a bug where remote port forwarding would fail if
the local login the user is SSHing with doesn't match the local user
running the node.
2024-06-25 21:34:21 +00:00
rosstimothy 16c59959c7 Remove lib/shell from lib/client (#43119)
The shell package requires cgo and by importing it in lib/client,
which all client tools have in their dependency tree, it prevents
them  from building without GCO_ENBALED=1.

Updates https://github.com/gravitational/teleport/issues/43112.
2024-06-17 21:46:37 +00:00
rosstimothy e95f3d3ed5 Start using authclient.Client/ClientI/NewClient (#41539)
Consumes the new auth client created in #41460. The changes introduced
were performed with a series of gofmt rewrite rules.

```bash
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "ClientI -> authclient.ClientI" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "Client -> authclient.Client" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "NewClient -> authclient.NewClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.ClientI -> authclient.ClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.Client -> authclient.Client" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.NewClient -> authclient.NewClient" {} \;
```
2024-05-15 14:09:14 +00:00
Andrew Burke cc013e69a4 Add -R flag to tsh ssh (#38829) 2024-03-15 23:23:10 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <[email protected]>
2023-12-01 17:48:14 +00:00
rosstimothy 96f8c17f75 Fix port forwarding when using a label based target (#26394)
Label based connections that do not provide a command and open a
shell for the first match were only performing a portion of the logic
that non label based interactive sessions were. Instead of connecting
directly to a host and opening a session, `tc.runShellOrCommandOnSingleNode`
is called to achieve the same behavior as non label based connections.

In addition to fixing #23261 this should also add support for `-N` in
the same scenario.
2023-05-22 16:15:01 +00:00
ef8da1724e Security fixes 03/23 (#23864)
* Prevent tunneling if the os login doesn't exist

A user.Lookup was added to srv.RunForward to prevent dialing
and forwarding any data if the os login is not found. The check
alone only terminates the direct-tcpip ssh channel and not the
underlying ssh connection.

In order for the parent process to determine if the ssh connection
should be terminated it needs to know why the child exited. That was
not possible by looking at the exit code and any data written to
standard error of the child process was forwarded to standard error
on the parent; which was used to simply log the error and move on.
To pass more detailed errors to the parent, the child process spawned
by srv.RunForward now json marshals the trace.Error to standard
error which is then decoded by the parent process. If the parent
detects the error was due to a missing user it terminates the ssh
connection.

tsh ssh -N was also modified to terminate if the command context
of tsh OR the ssh connection to the node is closes. Prior, it
only terminated if the user cancelled the process by blocking on
ctx.Done(). While this was necessary to end session if the os
login does not exit, it also forces tsh to exit if the node
goes offline.

Note: This does not include any propagation of error messages to the user,
so there won't be any indication from tsh about why the connection was closed.
The session also will not be terminated until the first attempt to forward data and
NOT when the session is created due to the way -N is implemented.

Fixes #217

* Prevent unauthorized access to kube clusters by upserting kube_servers

This PR changes the behavior of the kubernetes_service when validating access
to kubernetes clusters. Previously, the kubernetes_service would use the first
kubernetes cluster it found in the Auth server backend to validate access. This was
problematic because if the first kubernetes cluster was upserted with a
the same name as a kubernetes cluster the user was trying to access but
with different labels, the user would be able to access the cluster even
though they shouldn't be able to.

This PR changes the behavior of the kubernetes_service to use the
in memory kubernetes cluster representation used for heartbeats
instead of relying on the information received from the auth server. This would
block the user from accessing the cluster if the cluster was upserted
with a different set of labels since the kubernetes_service would not
have the updated labels in memory and would deny access.

Fixes #469

---------

Co-authored-by: Tim Ross <[email protected]>
Co-authored-by: Tiago Silva <[email protected]>
2023-03-31 21:55:13 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +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
Joel f2dd75801a Remove legacy session service (#15155) 2022-08-12 16:39:45 +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
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
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
Russell Jones 0534d43939 Cleaned up NewClient in integration tests.
Updated "NewClient" in integration tests to not take testing.T and
return an error.
2022-02-08 16:29:48 -08:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Brian Joerger bd07d7be20 CheckAndSetDefaults sets all defaults. (#6846) 2021-06-18 12:57:29 -07:00
Trent Clarke 52fb813390 Adds per-node ability to disable ssh TCP forwarding (#6989)
Prior to this change, TCP forwarding over SSH could only be disallowed
by user-based rules, rather than by individual target nodes.

This change adds:
  * the`port_forwarding` key to the yaml SSH config block, with a boolean value
  * Plumbing to pipe the resulting config value through to the SSH server
  * A predicate check in the SSH server to [dis]allow port forwarding based on the setting.

This change also:
    * adds a common way for integration tests to await the establishment of an SSH session
    * refactors several integration tests to use this new method rather than manually waiting
    * adds some marshaling code to move errors from spawned goroutines back into the 
      main test routine in verifySessionJoin()

See-Also: Issue #6783
2021-06-16 20:17:26 -05:00