Commit graph

803 commits

Author SHA1 Message Date
Steven Martin 287a68c0b7
provide warning on tsh sso login with Teleport user specified (#29203)
* provide warning on sso login with Teleport user specified

* verbiage update

* update verbiage

* Update output and comments

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-07-17 20:22:15 +00:00
Marco André Dinis 883cf1aeda
AWS DBs Heartbeat: return IAM status (#28952) 2023-07-17 11:36:06 +00:00
Gavin Frazar 2b2de5c6be
update tsh db resource selection (#28505)
* update tsh db resource selection

* add --labels and --query to tsh db subcommands
* tsh db [login | logout | env | config | connect]
* tsh proxy db

* add hasPrefix to predicate lang

* add teleport.dev/discovered-name
* print "discovered name" of databases discovered by discovery service,
  which is the name of the database resource in the cloud, when using
  tsh db ls without --verbose flag. This avoids printing verbose
  uniquely identifying names when discovery service is updated to append
  a uniquely identify suffix to discovered databases in AWS/Azure/GCP.
* tsh db ls --verbose ignores the label
* fix db connect string in tsh db ls

* select database by prefix, labels, and/or query predicate.
* chooses active database by exact match if the "prefix" matches exactly
  and no labels/predicate is given.
* logout of a subset of databases with tsh db logout.
* print an "ambiguous match" error if prefix/labels/query matches
  multiple databases where one is required.
* move all --labels cli flags to cf.Labels from cf.UserHost

* update tsh db tests
    * speedup slow tsh db tests
    * postgres/mysql profile respect home dir
    * rename test cases for consistency
    * test database listing uses discovered-name
    * test login/env/config/logout with prefix/label/predicate selectors
    * test active db filtering logic

* fix tests broken by merge
2023-07-14 23:41:32 +00:00
Steven Martin 8efa003e72
tsh recordings export session-id desc update (#29111)
* tsh recordings export session-id desc

The description of the session id is incorrect.

* verbiage update

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-07-14 14:54:04 +00:00
Tiago Silva 1ce5d86e46
Extend Resource Access Requests to all Kubernetes kinds (#28516)
This PR adds support for resource access requests for the following
Kubernetes kinds:

- KindKubeSecret
- KindKubeConfigmap
- KindKubeNamespace
- KindKubeService
- KindKubeServiceAccount
- KindKubeNode
- KindKubePersistentVolume
- KindKubePersistentVolumeClaim
- KindKubeDeployment
- KindKubeReplicaSet
- KindKubeStatefulset
- KindKubeDaemonSet
- KindKubeClusterRole
- KindKubeRole
- KindKubeClusterRoleBinding
- KindKubeRoleBinding
- KindKubeCronjob
- KindKubeJob
- KindKubeCertificateSigningRequest
- KindKubeIngress

It extends and generalizes existing support of KindKubePod.

Co-authored-by: Brian Joerger <bjoerger@goteleport.com>
2023-07-14 09:04:53 +00:00
Alex McGrath 9c49470e3d
Allow login and port to be specified when using tsh config to generate openssh configs (#28994)
* Include login in tsh config

* Allow custom ports
2023-07-13 16:09:04 +00:00
Gavin Frazar 2496e37124
update database and kube name validation (#28841)
* update database name validation

* move name validation into DatabaseV3 CheckAndSetDefaults
* replace use of DNS1305 name validation
  * remove 63 char length restriction
  * remove lowercase restriction

* fix failing tests

* update more tests

* update CHANGELOG.md
* explain breaking change to database discovery name validation
2023-07-12 21:24:25 +00:00
Forrest ae42a6e0d0
remove alert maximums (#28967) 2023-07-11 21:15:32 +00:00
Brian Joerger 8a13de3ef9
Fix ssh env var parsing by checking after cf.AuthConnector is guaranteed to be set. (#27970) 2023-07-10 17:29:04 +00:00
Tiago Silva 4da3e820ad
Deduplicate resources for tsh request search when replicas>1 (#28661)
When the number of replicas of a resource is bigger than 1 - i.e.
`kube_cluster`, `app`, `db` - `tsh request search` printed
all the registered resources instead of ignoring the repeated rows.

This PR excludes the repeated resource ids from the table and request
command.

Before:
```
$ tsh request search --kind kube_cluster
Name       Hostname Labels                                                             Resource ID
---------- -------- ------------------------------------------------------------------ -----------------------------------
local               env=tiago                                                          /tele.local/kube_cluster/local
my-cluster          teleport.internal/resource-id=89b78b53-600f-4545-922c-96d20ee15182 /tele.local/kube_cluster/my-cluster
my-cluster          teleport.internal/resource-id=89b78b53-600f-4545-922c-96d20ee15182 /tele.local/kube_cluster/my-cluster
my-cluster          teleport.internal/resource-id=89b78b53-600f-4545-922c-96d20ee15182 /tele.local/kube_cluster/my-cluster

To request access to these resources, run
> tsh request create --resource /tele.local/kube_cluster/local --resource /tele.local/kube_cluster/my-cluster --resource /tele.local/kube_cluster/my-cluster --resource /tele.local/kube_cluster/my-cluster \
    --reason <request reason>

```

After:

```
$ tsh request search --kind kube_cluster
Name       Hostname Labels                                                             Resource ID
---------- -------- ------------------------------------------------------------------ -----------------------------------
local               env=tiago                                                          /tele.local/kube_cluster/local
my-cluster          teleport.internal/resource-id=89b78b53-600f-4545-922c-96d20ee15182 /tele.local/kube_cluster/my-cluster

To request access to these resources, run
> tsh request create --resource /tele.local/kube_cluster/local --resource /tele.local/kube_cluster/my-cluster \
    --reason <request reason>

```
2023-07-10 13:55:55 +00:00
STeve (Xin) Huang a86283e261
Connect Kube gateway part 1: lib/teleterm/gateway (#28312)
* Connect Kube gateway part 1: lib/teleterm/gateway

* fix lint

* move IsDB/IsKube to resource URI

* address review comments

* config dir

* use ProfileDir instead of ConfigDir

* remove NewKubeForwardProxyWithListener
2023-07-10 12:58:23 +00:00
Tiago Silva f8c75a043d
Fix tsh kube credentials lock when no-login is required (#28435)
This PR moves the creation of the `lock` file right before the login
call is attempted instead of creating it for any call.

This fixes a problem where we create the lock file even if no login is
required which limits the number of parallel kubectl invocations.
2023-07-07 11:34:12 +00:00
Jakub Nyckowski 784e6197d2
Fix imports on non-linting files (#28752)
Our linter does not run on all files, so the incorrect sorting is not reported, but GCI keeps fixing these imports each time I run it, hence the PR.
2023-07-06 14:32:56 +00:00
Gus Luxton 8abbea6fec
tsh: Implement puttyconfig command to add saved PuTTY sessions to Windows registry (#19316)
* tsh: Implement puttyconfig command to add saved PuTTY sessions to Windows registry

* Addressed comments from code review

* Add support for leaf clusters

* Refactoring from code review

Also moved registry/hostname functions into external packages

* Address more feedback from code review

* Rebase following tsh/common changes

* Fix up putty_config_windows

* Reorder command

* Remove surplus comment

* Use a separate list instead of overloading the 'extra' key

* Address Tim's code review comments

* Address some of Zac's comments

* Refactor formatLocalCommandString to use text/template

* Refactor non-Windows logic into puttyhosts

* Fix subcommand name

* Fix test structure

* Add some more hostnames test cases

* Apply suggestions from code review

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Fix up

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-07-05 17:53:46 +00:00
rosstimothy 119dc7a3a3
Reduce login latency (#28499)
Reuse the root cluster auth client during the login process
to reduce latency.

Closes #26712.
Partially addresses #26712.
2023-07-05 15:51:56 +00:00
Jakub Nyckowski c29765b7d4
Add t.Parallel() to several tsh tests (#28470)
Added the `t.Parallel()` function call in each test function to enable parallel test execution. This should reduce the overall time it takes to run all these tests by enabling them to run concurrently.
2023-07-03 16:51:42 +00:00
rosstimothy 20559218ad
Fix tsh windows builds (#28357)
#24864 added a dependency of lib/web into tsh which broke windows
tsh builds because lib/web transiently depends on lib/srv which
has linux specific code. This shuffles around a few things so
that lib/web is no longer importing lib/srv at all by:

- Indirectly using the srv.SessionController to apply session
control for web ssh sessions

- Moving the common reversetunnel interfaces into
reversetunnelclient since lib/reversetunnel imports
lib/srv/forward which imports lib/srv.

- Directly converting mysql client errors in the connection
tester instead of calling a common function.
2023-06-30 17:12:12 +00:00
Steven Martin 2019e0d680
Update tsh scp command description to match ssh node commands (#28465) 2023-06-29 14:43:49 +00:00
Brian Joerger c8647a7508
Don't add keys to agent during headless login. (#27960) 2023-06-23 21:03:47 +00:00
Alan Parra 44960a89af
Warn about clamshell-related touch ID unavailability (#28175) 2023-06-23 16:45:59 +00:00
Marco André Dinis 48a113bb93
InstallScripts: pin teleport version using ServerVersion (#28149)
* InstallScripts: pin teleport version using ServerVersion

When Automatic Upgrades are enabled and the current installation is an
enterprise build, it will install teleport using:
- stable/cloud repo channel (yum, apt)
- pin the version to the one present at:
  https://updates.releases.teleport.dev/v1/stable/cloud/version

* improve comments
2023-06-23 15:45:36 +00:00
rosstimothy 2593843c6f
Support for benchmarking web sessions (#24864)
Adds `tsh bench web ssh` to allow benchmarking ssh sessions that are
created via the web api. To prevent import cycles between `lib/web`
and `lib/client` the cookie implementation in `lib/web/cookie.go`
was moved into its own package `lib/web/session`. There is curerntly
no support for SSO users - adding a local server to handle the login
was out of scope and can be added in the future.
2023-06-23 15:08:06 +00:00
Steven Martin d6205f50b7
update message on empty tsh ls results (#28095)
* update message on empty tsh ls results

* Update message to have no docs

* update verbiage

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>

---------

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2023-06-21 21:29:42 +00:00
Alex McGrath 0760bc9776
Allow setting max_session_ttl from clusterauth preferences (#26824)
Document `default_session_ttl` in the reference.
2023-06-21 10:39:34 +00:00
Alan Parra ec8594f96d
fix: Ignore staticcheck false positive on darwin (#28038) 2023-06-19 18:42:10 +00:00
Noah Stride 60a325aa7c
Device Trust: tsh privilege elevation for TPM enrollment (#27833)
* Start fleshing out UAC elevation

* Use `runas` and ShellExecuteW to open a child process with elevated privileges

* Add tsh command to re-execute

* Add method to be called in the elevated child process

* Ugly, but working, credential activation in UAC dialogued child

* Add TODO

* Add some further notes/explanation on windows.ShellExecute

* Change error message to match function name

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Improve comment

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Use `trace.BadParameter` instead of `Errorf`

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Use `tpm-activate-credential` instead of `activate-credential`

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Remove spurious newline

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Move towards more production ready elevated process

* Add stubs for darwin/other

* Use path in state dir for cred activation results

* Fix stub return values

* Fix test missing context.Context pass

* Add additional message when cred activation completes

* Use ShellExecuteExW to get handle to process to wait on

* Improve comment in windowsexec

* Minor stylistic changes from review

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Minor adjustments to error handling and logging

* Use `windows` over `syscall`

* Leverage `mkwinsyscall`'s error handling

* Missing param in test

* Always show error, not just when `-d` is provided

* Remove unnecessary trace.Wrap(err)

* Restore cf.Debug check

* Explicitly ignore return values from `FPrintln`

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Simplify code

* Add null check to `info.hProcess`

* Minor format changes from review

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-06-16 17:35:03 +00:00
Krzysztof Skrzętnicki 1b69fbcbed
OpenSearch AWS autodiscovery (#27537)
* OpenSearch AWS autodiscovery

* Normalize description, check err.

* Fix tests.
2023-06-16 12:56:53 +00:00
rosstimothy c78743c59b
Ensure SSH_SESSION_WEBPROXY_ADDR is set for all sessions (#27842)
Fixes a discrepancy in overwriting the environment value with the
address observed for the Web UI for sessions not originating from
the Web UI. All sessions will now use `tc.WebProxyAddr` as the
default value and *only* update if an override is provided.

`TestIntegrations/EnvironmentVars` was updated to ensure that the
expected environment variables are present in both interactive and
non-interactive sessions.
2023-06-14 19:47:32 +00:00
Brian Joerger e43ef74f36
Add skip-confirm flag for headless approval. (#27823) 2023-06-14 19:08:26 +00:00
STeve (Xin) Huang e677aadb9f
Fix an issue ALPN handshake test does not respect "HTTPS_PROXY" (#27583)
* Fix an issue ALPN handshake test does not respect "HTTPS_PROXY"

* address review comment

* remove simplehttsproxy

* Add context to IsALPNConnUpgradeRequired in ten thousand places

* add goc and dial with context
2023-06-13 15:30:48 +00:00
STeve (Xin) Huang 66f5b5510c
Fix an issue kube local proxy requirement is wrong in separate port mode (#27634)
* Fix an issue kube local proxy requirement is wrong in separate port mode

* move kube local proxy requirement check to api/profile
2023-06-12 13:49:09 +00:00
rosstimothy 553eb02bdf
Fix moderated session presence checking (#25988)
* Fix moderated session presence checking

Addresses all of the issues that were preventing presence checking during
moderated sessions from working as described in
[#18092](https://github.com/gravitational/teleport/issues/18092#issuecomment-1540900859).

Closes #18092

* make presence test clearer

* fix presence checking on the web ui

* Refactor web socket message handling

A single message processing loop handles retrieving the envelope
and passing it off to individual message handlers. This allows all
messages to be processed outside of `Read` which was dependent on
the terminal being active to process any messages.

The webauthn challenge response was also moved from a raw message
to a webauthn message. By sending it as a raw message it made
presence checking fail because the response has a `t` in it which
caused the session to be killed during moderated sessions.

* enforce mfa ceremony when joining and cluster wide mfa is enabled

* fix conflicts with master

* moderated tests

* Add moderated session tests for the UI

* Add moderated session integration test

* fix lints

* clean up presence test

* refactor envelope handling

* fix build

* fix: revert test debug timeout

* fix: use local context in tests

* simplify closing streams

* generalize waitForOutput to work with an io.Reader

* fix error handling in stream close

* unexport PresenceOptions

* Improve waitForOutput to match against output in successive reads
2023-06-08 20:27:13 +00:00
Nic Klaassen 21e38dc125
Enable use of user traits in label expressions (#27138)
* enable user traits in label expressions

* move accessChecker methods to access_checker.go
2023-06-08 06:21:11 +00:00
Brian Joerger 207c9136ab
Test tool/tsh/common in CI (#27579)
* Change tsh test directory referenced in makefile.

Fix proxy template test case.

* Fix TestWriteSSHConfig.

---------

Co-authored-by: Steven Martin <steven@goteleport.com>
2023-06-07 19:02:10 +00:00
Steven Martin 488bd91263
use proxy port in openssh config (#27536)
* use proxy port in openssh config

* update test record
2023-06-07 14:28:27 +00:00
Brian Joerger b7fed8ae72
Fix an unintended interaction between and Proxy Templates where the environment variable is prioritized over the template. (#27492) 2023-06-06 22:58:51 +00:00
Brian Joerger 193abfdf2c
Only fallback to SSH_TELEPORT_ env variables for proxy, user, and cluster name when used with headless. (#27057) 2023-06-06 19:53:45 +00:00
Gabriel Corado a200271ac5
Support authenticating with AWS IAM role for MongoDB Atlas (#26439)
* feat: support authenticating with AWS IAM for MongoDB Atlas

* chore(lint): fix errors

* test(tsh): add missing database field

* refactor(mongodb): check for error on each authenticator branch

* refactor(mongodb): update log messages and atlas check

* refactor(auth): use IsRoleARN helper instead of IsARN

* chore(db): remove unused line

* chore(mongodb): split authenticator func

* refactor(db): rename get atlas token function

* tests(db): reuse already existent auth property

* chore(mongodb): add docs reference

* refactor(db): support role chaining

* feat(types): "require" iam role for atlas users

* refactor(db): use external id only on the first session

* refactor(services): add new database matcher for regular users and aws

* chore(db): rename functions to be more assertive

* chore(types): fix lint

* test(db): remove duplicated test

The test being removed here is covered by `TestMongoDBAtlas`
(lib/srv/db/auth_test.go).
2023-06-06 14:57:27 +00:00
Brian Joerger 70c5ce7e8c
Add tsh e2e tests with various security features enabled (#26862)
* * Refactor tool/tsh to enable tsh e2e tests outside of the tsh package.

* Add tool/teleport/testenv to enable easier e2e tests from outside
  packages.

* Skip all flaky test checks when * is provided.
2023-06-06 01:25:09 +00:00
Anton Miniailo 8464dc2850
Add kube credentials lockfile to prevent possibility of excessive login attempts (#26102) 2023-06-05 12:56:43 +00:00
Brian Joerger a9823bf9f3
Fix headless server access requests (#27136)
* Fix headless server access requests and add test coverage.

* Refactor headless tests to appease the flaky test detector.
2023-06-01 18:01:12 +00:00
Krzysztof Skrzętnicki 2011f67a54
Implement leaf app access: tsh app login --cluster=leaf (#26614)
* Implement leaf app access: `tsh app login --cluster=leaf`

* Address review comments.

* Speedup test execution.

* Fix parallel test run.
2023-06-01 09:18:37 +00:00
STeve (Xin) Huang b51cef2e41
TLS Routing behind ALB: tsh kube subcommands UX (#26305)
* TLS Routing behind ALB: tsh kube subcommands

* fix lint and ut

* fix ut again

* review comment round 1

* fix an issue where local proxy should be not recreated on top a local proxy kubeconfig

* move maybeStartKubeLocalProxy to runKubectlReexec, remove os.Setenv

* use cf.Stdout

* revert kube util.pointer

* revert kube util.pointer

* Fix fullArgs vs args and remove old KUBECONFIG from env
2023-05-30 16:29:17 +00:00
Krzysztof Skrzętnicki 5204253a10
Apply --quiet on automatic cloud app login. (#27108) 2023-05-30 14:33:23 +00:00
rosstimothy 7cd49e9756
Fetch ClusterAlerts a single time during login (#26903)
`onLogin` was inadvertently retrieving ClusterAlerts twice by
explicitly retrieving them and by calling `onStatus`, which also gets
the alerts so they are shown when `tsh status` is invoked. The portion
of `onStatus` which prints the profile has been separated into
`outputProfiles` so that `onLogin` may call that directly instead
of `onStatus`.
2023-05-30 13:24:14 +00:00
rosstimothy 2f78bf4b7c
Extend AccessCapabilities (#26968)
`tsh login` was fetching each role for a user during login to perform
calculations required to determine if auto access requests were
required. To reduce some of the login latency this logic was moved
to `proto.AuthService/GetAccessCapabilities` so that only a single
RPC to Auth is required instead of one per role.
2023-05-26 18:09:06 +00:00
Gavin Frazar cf779f0082
Remove useProfileLogin from makeClient in tsh (#26814)
* Remove useProfileLogin from makeClient in tsh

* fix test
2023-05-25 20:08:09 +00:00
Brian Joerger 3e63df4870
Proxy Templates update: cluster switching and tsh ssh parity (#25286)
* Use web address when appropriate for a jump hosts

Determines whether the jump host provided via `tsh ssh -J` is belongs
to the Proxy SSH or Web server to ensure when using jump hosts that
connections are established directly on the target cluster.

Closes #25178

* Modify tsh tests to capture issues with jump hosts

Alters the root and leaf cluster and node names used by tsh tests
so that the root cluster is named `root` instead of `localhost` and
sets a unique `NodeName` for each cluster instead of reusing
`localnode` for both. This was masking problems in jump hosts tests
by connecting to the node in the root cluster instead of the leaf
cluster.

Some additional changes to tsh tests were made as a result of
changing the cluster and node names.

* fix proxy client tests

* update TestList to login once

* * Add cluster parsing to proxy templates

* Check ProxyTemplates even if -J is not provided

* Modify proxy templates logic to work with tsh ssh

* Apply suggestions from code review

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

---------

Co-authored-by: Tim Ross <tim.ross@goteleport.com>
Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>
2023-05-24 17:23:41 +00:00
Tiago Silva 4f545f11a8
Add tsh kubectl support for tracer exporter (#26708)
* Add `tsh kubectl` support for tracer exporter

This PR adds support for `--trace` exporter when running `tsh kubectl`.
It allows any user to automatically export traces from `tsh`.

* Update tool/tsh/kubectl.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* apply feedback

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-05-24 08:24:52 +00:00
Steven Martin f990da9c5c
include db in tsh play and consistent description ends (#26803) 2023-05-24 02:42:41 +00:00