Commit Graph
1067 Commits
Author SHA1 Message Date
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
Edoardo Spadolini 33e80cd8f2 Support dynamic SSH host signers (#41227)
* Add a host signers callback to sshutils.Server

* Lift host signers callback into regular.Server

* Lift host signers callback into reversetunnel.Server
2024-05-13 13:11:44 +00:00
rosstimothyandEdoardo Spadolini 7a7f982ed9 Add tbot ssh-proxy-command (#41346)
The new subcommand is meant to be a replacement for tbot proxy ssh
which does the ssh proxying entirely within tbot to reduce resource
consumption. The old mechanism spawned a tsh process to perform the
proxying which leads to increased CPU and memory consumption - which
can be quite problematic when used as an OpenSSH ProxyCommand for
an ansible playbook.

The new command also deviates in behavior from tsh proxy ssh in that,
for the moment, it requires users to explicitly dictate whether
tls routing, alpn connection upgrades instead of guessing by making a
call to webapi/ping. This again turns out to be quite resource
intensive when tbot is used as an OpenSSH ProxyCommand for an ansible
playbook.

In the future tbot can look this information up out of band and store
it in the proper location so that tbot ssh-proxy-command can consume
it directly without users needing to provide it. The behavior as is
provides a path toward the future while also allowing users to gain
the performance improvements now.

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2024-05-10 21:05:47 +00:00
39478f3570 Add backend handler for Web UI kube exec functionality. (#41144)
* Add backend handler for Web UI kube exec functionality.

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Log error on sending it to websockete connection.

* Remove duplicate user key creation.

* Use scoped context.

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Use local site cache.

* Simplify creating rest kube rest config.

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* Don't set stdErr on pod execution options, if it's interactive shell.

* Don't use public proxy addr when getting kubeconfig server address/name.

* Don't set stdErr on stream options if it's interactive shell.

* Provide local host CA to podHandler directly, instead of access point.

* Add integration test for kube exec handler.

* Use read deadline instead of closing reader.

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
2024-05-10 19:10:57 +00:00
Alex McGrath 65459e872e Remove support for disabling second factor authentication (#40956)
* dont allow disabling second factor

* update docs for 2fa change

* add environmental variable to work around disabled 2fa

* check if its cloud

* update todos

* add a test

* introduce insecure test mode

* fixes for tests
2024-05-10 11:57:34 +00:00
Gavin Frazar 9723fd096f cleanup after db ca split (#41351)
* remove database client CA event filter injection

* remove tctl database client CA fetch fallback

* remove sqlserver database client CA fetch fallback

* remove database client CA migration

* cleanup tests and mocks
2024-05-09 19:51:27 +00:00
Gavin Frazar ed7d0d223e support gcloud spanner in tsh and web UI (#41129)
* add spanner to tsh and teleterm

* handle spanner events in web ui

* update web audit events test snapshot

* customize web ui connect for spanner

* update ConnectDialog snapshot
2024-05-07 23:17:03 +00:00
Gabriel Coradoandrosstimothy 55e2ea204f Implement debug service and its CLI commands (#39865)
* feat: debug service

* fix(service): lint and test assertion

* refactor: code review suggestions

* chore(service): update change log level log message

* fix(service): wrong error assertion

* fix(service): unable to set trace log level

* chore(utils): rename SupportedLogLevelsString

* refactor(teleport): change `seconds` default value

* fix(teleport): remove trailing line on profiles file

* chore(teleport): add profile examples

* refactor(service): use marshal/unmarshal log level functions

* fix(teleport): fix tarball file timestamps

* refactor: move debug service + constants to a separate package

* test(debug): move request to a helper

* chore(debug): remove leftover file

* chore(log): typo

* refactor: move package from lib/debug to lib/srv/debug

* refactor: code review suggestions

* fix(service): socket file consistency

* test(common): use one temporary directory per socket test

* chore(tool): update debug service connection error message

* refactor(debug): use enhanced serve mux

* chore(teleport): fix usage examples

* Apply suggestions from code review

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* refactor: code review suggestions

* refactor(debug): move marshal/unmarshal text log level to debug

* refactor: code review suggestions

* refactor: move debug service client to lib/client/debug/

* refactor: code review changes

* feat(debug): progress on collect profiles

* refactor: code review suggestions

* chore(gomod): update

* fix(debug): set log level validations

* refactor(debug): move client interface

* feat(debug): add limit reader for collect profiles

* refactor(debug): remove progress bar

* Revert "chore(gomod): update"

This reverts commit 8dbebbf69f.

* refactor: remove debug service endpoints constants

* test(service): fix wrong constant

* refactor(debug): remove collect profiles limit reader

* chore(debug): make client struct public

* refactor(debug): change collect time to 0

* test(service): deflake test

* test(service): add missing auth config

* test(debug): fix missing assertion

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2024-05-07 19:41:55 +00:00
Brian Joerger 8c328a880b MFA for App Access - tsh proxy app and Teleport Connect (#40857)
* Add key.DBTLSCert and key.AppTLSCert helper methods.

* Add TSH_APP_LOCAL_PROXY user certs requester option.

* Break up app login into multiple methods.

* Generalize cert checker local proxy middleware and add an app cert implementation.

* Use AppCertChecker for tsh proxy app.

* Add test check for proxy mfa certs being kept off disk.

* Apply changes to Teleport Connect.

* Addressed bl-nero's comments.

* Address comments from ravicious.

* Add proxy app cert ttl test.

* Restore v15 fallback for tsh proxy app session creation; Minor naming refactors.

* Add cluster flag to app logout.

* Refactor teleterm test to cleanup session MFA requirement.

* Address comments.
2024-05-06 19:29:53 +00:00
Brian Joerger ac4870cacd MFA for App Access - tsh app login (#40846)
* Generate MFA verified certs with tsh app login.

* Add TestAppCommands with per-session MFA tests.

* Add --cluster flag to tsh proxy app; Add tsh proxy app tests with per session MFA subtests.

* Clean up test cases.

* Fix unit tests.

* Disable session recording and use shorter poll_stream_period by default for tests.

* Resolve comments; Fix tsh app config --cluster=leaf.

* Resolve comment.

* Fix TestFormatAppConfig.
2024-05-02 20:20:44 +00:00
Andrew Burke cb8e50eba8 Improve error message for SSO logins with hardware keys (#40641)
This change updates the error message shown when a user logs in
to tsh with SSO and requeres hardware key input.
2024-04-25 17:14:35 +00:00
Brian Joerger 12c7689df5 Refactor GenerateUserCerts to create App Sessions (#39970)
* Add CreateAppSessionFromReq.

* Deprecate passing route_to_app.session_id in cert requests.

* Automatically create app sessions for app cert requests.

* Deprecate client use of CreateAppSession for app cert requests.

* Fix affected tests.

* Use traits and roles from existing user certificate for app sessions.

* Fix app access integration tests.

* go mod tidy.

* Fix TestTCP.

* Fix TestALPNSNIProxyAppAccess.

* Revert "go mod tidy."

This reverts commit cc6caa2485.
2024-04-25 05:13:55 +00:00
rosstimothy d0b8f78c3f Remove client.ProxyClient (#40565)
Closes #38239
2024-04-23 18:30:09 +00:00
STeve (Xin) Huang 26bdf3d0b7 Fix an issue tsh db ls shows one entry per db server instead of db name (#40784) 2024-04-22 20:21:40 +00:00
Noah Stride 0bd99702a1 Switch existing error reporting for tracing to use new helper (#40662)
* Switch existing trace error reporting to use `apitracing.EndSpan`

* Add deferred trace error reports to tbot

* Optimize for @espadolini limited horizontal editor length
2024-04-19 14:45:39 +00:00
Brian Joerger 9479f7fa53 Remove extraneous App Session watch logic (#40092)
* Remove WaitforAppSession logic.

* Remove WaitForSnowflakeSession logic.

* Decrease log severity of web session cache readthrough to debug.
2024-04-17 19:03:59 +00:00
rosstimothy 5a64d1fb8d Convert tsh recursive listing to connect to Proxy via gRPC (#40268)
* Convert recursive listing to use Proxy gRPC API

Removes deprecated usage of ProxyClient in getClusterClients used
for tsh ls -R and tsh db ls -R.

* Remove unsued helper functions

* Replace removed test

* Remove unused db listing function

* convert tsh apps ls -R and tsh kube ls -R

* remove unused function and tweak IsExpired

* create common testcase for listing resources
2024-04-12 20:19:11 +00:00
rosstimothy ad26913c71 Load appropriate TLS config for clusters (#40293)
Updates the proxy.Client to allow loading specific tls.Config for
individual clusters. This prevents issues when trying to access
leaf resources via the root cluster if WithAllCAs is not set.
2024-04-09 16:02:28 +00:00
rosstimothy 185586c70d Convert kube mfa presence to user ClusterClient (#40271)
Replaces the legacy ssh connection mechanism to the proxy for kube
presence checks with the new gPRC mechanism. In the future the
handleMFA function should be refactored to be passed in an auth
client instead of creating a new connection to the proxy and auth
server to reduce latency.
2024-04-05 20:34:15 +00:00
rosstimothy 58ced9cd6e Convert WithRootClusterClient to use ClusterClient (#40168)
Replaces the deprecated SSH connection mechanism to the cluster
in favor of using the gRPC mechanism. The WithRootClusterClient
has also been deprecated as it requires at worst two dials to
a Teleport cluster for a single function. Callers should instead
explicitly create and reuse clients where possible so that no
extraneous dialing is required for each action being performed
against a cluster.
2024-04-04 15:08:36 +00:00
rosstimothy 55c5cbab2b Add equivalent of (ProxyClient) IssueUserCertsWithMFA to ClusterClient (#40081)
Updates the ClusterClient to support issuing user certificates,
possibly with MFA, for all protocols. This should be the last
bit of functionality required to allow Connect to convert to
using the ClusterClient. Once that is done the deprecated
ProxyClient should be one step closer to deletion.

Updates #38239
2024-04-03 14:15:52 +00:00
rosstimothy 5b4c43f202 Add reissuing user certificates to the ClusterClient (#40042)
Updating the ClusterClient to support generating new user certs
covers some of the exiting missing functionality that is required
by some components to migrate fully off of the deprecated ProxyClient.
The ClusterClient implementation is almost a verbatim copy from
the ProxyClient.

The ProxyClient method was not removed because Connect does not
use the ClusterClient yet. That will be addressed after the
ClusterClient has complete feature parity with the ProxyClient.

Updates #38239.
2024-04-01 13:20:49 +00:00
Brian Joerger 4690eeab10 Keep App Session secrets secret (#39853)
* Don't reveal app session secrets to users.

* Fix panic in WebSessionV2.WithoutSecrets.

* Use client's key for azure jwt tokens

Proxy verifies and signs jwt tokens

Ensure backwards compatibility

* Remove unused GetAppSession methods.

* Move azure jwt token resigning logic into the session transport's
rewriteRequest method with an improved Azure app check

Fix GetAppSession backward compatibility check

* Add test.

* Address lint comments.

* Address parseBearerToken comment.

* apply suggestion about indentation.
2024-03-29 23:31:31 +00:00
Rafał Cieślak 584fd5def7 Use dbcmd.WithPrintFormat only for preview of teleterm gateway command (#39906)
* Use dbcmd.WithPrintFormat only for preview of teleterm gateway command

* Update comments for GatewayCLICommand message

* Mark check funcs as helpers, verify args length first
2024-03-29 15:35:52 +00:00
Noah Stride 56ac818561 Add tls-spiffe support to tctl auth export and /webapi/auth/export (#39879) 2024-03-29 09:46:49 +00:00
rosstimothy 10da1b3b9e Display available allowed logins for leaf resources in root web ui (#39579)
The Proxy web api now requests that Auth include allowed logins
per resource instead of guessing logins per resource based on the
information it has cached. However, due to the way SSH sessions
are authorized, the logins are not provide to users verbatim.

Any sessions created via the root web ui to a leaf resource will use
the SSH certificate created for that user in the root cluster. New
certificates are not minted per leaf cluster. This is important
because the nodes only allow os logins for a session if they are
present in the valid prinicpals of the SSH certificate. So even
though we are now capabale of displaying all allowed logins for
leaf SSH servers in the root web ui, the user is only able to use
a subset of them. To avoid any odd UX, the Proxy will filter out
any allowed logins which do not exist in the principals of the
root SSH certificate.

The above only holds for SSH, windows desktops are not as strict
and any allowed login from a leaf cluster is now visible in the
root web ui.

Fixes https://github.com/gravitational/teleport/issues/5041
2024-03-25 16:34:51 +00:00
Edoardo Spadolini 270205f4af Add CORS headers to the tsh login callback (#39696)
* Add CORS headers to the tsh login callback

* Use wildcard origin, remove draft header
2024-03-22 12:49:47 +00:00
Brian Joerger 703f8b2c25 Support IsMFARequired for App Access (#39649)
* Add RouteToApp to IsMFARequireRequest.

* Add implementation of IsMFARequiredRequest_App.
2024-03-21 18:55:06 +00:00
Brian Joerger b88251a278 CreateAppSession with MFA (#39650)
* Replace types.CreateAppSessionRequest with proto.CreateAppSessionRequest.

* Add MFA response proto.CreateAppSessionRequest.

* Verify MFA response in CreateAppSession.
2024-03-21 17:18:08 +00:00
rosstimothy 8abd04571f Improve node listing in tsh and tctl (#39458)
Converts both tools to use the ListUnifiedResources RPC instead of
the ListResources RPC to improve performance. While there may only
be marginal gains when listing the entire set of nodes, there are
substantial improvements when filtering via predicate, labels, or
search.

tctl was also changed slightly to make use of server side filtering
when tctl get node/foo is run. Prior to this change the entire node
set was always retreived and tctl performed the filter client side
if the user provided a hostname or UUID.
2024-03-19 13:58:17 +00:00
Andrew Burke cc013e69a4 Add -R flag to tsh ssh (#38829) 2024-03-15 23:23:10 +00:00
rosstimothy 20888bf130 Convert SetAuthPreferences usages to new Create/Update/Upsert API (#38895)
Migrates callers off the deprecated API and onto the new API so that
AuthPreferences can be protected via optimistic locking when appropriate.
2024-03-14 22:05:20 +00:00
Hugo Shaka ab2f9a5a5e Support tsh login -i (#39024)
* Add tsh flatten command

* apply suggestions

* revert rogue checkout

* address feedback + add tests

* fix tests

* apply sugestions: allow overwriting existing profile + opportunistic proxy reuse from existing profile

* Convert `tsh flatten` into `tsh login -i`

* fix tests + address roman's feedback
2024-03-14 20:03:47 +00:00
rosstimothy 1aec5414f1 Replace constants from trace with equivalents defined in teleport (#39307)
* Remove logging from circuit breaker

The logging is never output, and if it was would be very verbose.
Instead of dropping the level down to trace the logger is removed
entirely.

* Add constants from trace library

The logging functionality in trace is being removed in an upcoming
release. To prepare the logging component keys are copied from trace
into teleport.

* Convert trace.ComponentFields to teleport.ComponentFields

* Replace trace.Component with teleport.ComponentKey

* Replace trace logging constants
2024-03-14 13:04:29 +00:00
Brian Joerger 6cd713f667 Fix ssh -X -oControlMaster to agentless nodes. (#38779)
* Fix X11 forwarding with OpenSSH option control master when connecting through the Proxy ssh forwarding service.

* Add X11Forwarding integration test with ControlMaster subtest.

* Refactor forwarding server to always forward x11 channel requests.

* Address comments.

* Fix x11 forwarding integration tests.
2024-03-12 17:45:54 +00:00
Noah Stride 0e203e513f Replace auth.ClientI references in tool/tctl (#39059)
* Replace `auth.ClientI` references in `tool/tctl`

* Remove references in test files

* Fix linter complaints revealed by refactor

* Remove unnecessary interface cast
2024-03-07 16:59:24 +00:00
Noah StrideandEdoardo Spadolini c11bddc5f2 Refactor Presence service to add ListRemoteClusters, context.Context and returning updated/created RemoteClusters (#38694)
* Wire context/returning through local svc and add ListRemoteCluster

* Propagate changes through to cache

* Propagate changes up

* Remove marshal options from GetRemoteCluster

* Fix tests in lib/services/local

* Fix tests

* Add test for PresenceService_ListRemoteClusters

* Add removal TODO

* Add retry to UpdateRemoteCluster

* Fix more tests

* Fix linting

* Remove unused Create and DeleteAll RPCs

* Fix test

* Add GetAndUpdateRemoteCluster

* Add test for GetAndUpdateRemoteCluster

* Update lib/services/local/presence.go

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

* Update lib/services/local/presence.go

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

* Update lib/services/local/presence.go

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

* Rename GetAndUpdate to Patch

* Exit early if we know conditional update will fail

* prevent modifying revision

* Update tests

* Add `clear()`

* Fix test/lint failures

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2024-03-05 15:56:00 +00:00
Brian Joerger a496c3fcd0 Fix relogin on hardware key policy errors (#38713)
* Fix relogin on hardware key policy errors.

* Add regression test.
2024-02-29 21:20:24 +00:00
Brian Joerger b01f2c342c Require admin MFA for get/list CAs with secrets (#38529)
* Require admin MFA to list cert authority secrets.

* Allow reuse of Admin MFA for GetCertAuthorities.

* Add tctl tests.

* Reuse MFA for tctl auth export with keys and add tests.

* Fix lint; fix test panic.

* Check for admin MFA after RBAC check.
2024-02-29 01:29:34 +00:00
Grzegorz Zdunek 54e331a69c Treat "expired certs" errors returned from RPCs as retryable on the client side (#38668)
* Handle "expired certs" errors that come from the server

* Review comments
2024-02-27 16:25:29 +00:00
Zac Bergquist 425f1e4765 tsh: skip invalid profiles instead of failing (#38330)
The tsh status command attempts to decode one profile per YAML
file in $TSH_HOME. If an error is encountered along the way,
the entire command fails and tsh does not display information
about any profiles.

An especially confusing corner case is when a user mistakenly
places tsh's configuration at $TSH_HOME/config.yaml instead of
$TSH_HOME/config/config.yaml. In this case, the config file is
assumed to be a profile and the user is presentedc with a
confusing error message.

Fix this by skipping over profiles that fail to load but continuing
to report on the ones that load successfully.

Closes #38302
2024-02-21 16:28:06 +00:00
rosstimothy a3d65adb62 Deprecate (TeleportClient) ConnectToProxy (#38219)
This legacy connection mechanism uses SSH to connect to the Proxy
and tunnel the Auth connection. It was replaced by the
(TeleportClient) ConnectToCluster which uses gRPC to reduce latency
when connecting to the cluster.
2024-02-15 16:48:59 +00:00
STeve (Xin) Huang e192ad386e Propagate user-agent from GRPC for cert.create events (#37726)
* Add user-agent to cert.create event

* fix tctl and minor stuff

* fix integration test
2024-02-08 20:39:43 +00:00
Zac Bergquist 4e0968c0a5 Fix data race in test (#37885)
newTestListener would call (*testing.T).Log when the Accept call
fails. This resulted in racy behavior due to the log sometimes
happening after the test completes (it's normal for accept to
return an error after the listener is closed, which we do on
test cleanup).
2024-02-08 15:49:25 +00:00
Steven Martin b78c27ea16 Correct tsh join error when attempting to join a kubernetes session (#29678)
* Correct tsh join error when attempting to join a kubernetes session

* logic structure change for joining check
2024-02-06 17:13:23 +00:00
rosstimothy b7318b5c7e Enable errorlint via golangci-lint (#37669)
Adds the new linter and configures it to prevent direct error
comparisions and type assertions in favor of errors.Is and errors.As.
All current violations caught by the linter have been updated
accordingly.
2024-02-02 15:59:24 +00:00
Alan Parra 446505674b chore: Remove the AuthenticationSettings.DeviceTrustDisabled field (#37595) 2024-01-31 18:56:38 +00:00
Brian Joerger a0ba1d4e21 Fix error message tsh ssh with no MFA device registered (#37223)
* Restore ErrNoMFADevices error message for tsh ssh.

* Revert server change to prevent regression and add TODO.

* Update lib/auth/auth.go

* Move condition to fix test.
2024-01-29 18:58:57 +00:00
Noah Stride 41b36aafe3 tsh proxy kube should support Machine ID credentials (#36914)
* Properly load Kubernetes certs from identityfile

* Set correct environment variables
2024-01-24 10:25:07 +00:00
Zac Bergquist 2dffe4c014 Fix whitespace in tsh version warning (#36861)
The multiline string was indented in such a way that made the source
code look nice, but also put 3 leading tabs on each line, which
renders awkwardly in the terminal.
2024-01-23 20:42:14 +00:00