Commit graph

378 commits

Author SHA1 Message Date
Jakub Nyckowski bae67b3c95
Add support for MariaDB (#9409)
Add support for MariaDB client and update documentation.
2022-01-10 20:12:31 -05:00
STeve Huang 52395be1f2
truncate Labels for tsh db ls (#9671) 2022-01-06 21:05:15 +00:00
Alex McGrath 18d27232f0 Truncate label output in tsh ls and tsh app ls commands 2022-01-05 14:30:10 +00:00
Andrew Burke 61a4f35af0
Forward TELEPORT_HOME to kubeconfig (#9546)
This change fixes `tsh kube login` to respect TELEPORT_HOME when it's set.
2021-12-30 01:20:07 +00:00
Marek Smoliński 31d0990c03
Fix tsh db connect mongo dbuser logic (#9196) 2021-12-22 11:55:14 +01:00
Edoardo Spadolini 4e8e7c38fd
Deduplicate access request IDs before signing certificates (#9453)
* Dedup incoming access request IDs, show access requests in tsh status
2021-12-17 13:45:42 +00:00
Alex McGrath d89dfe967e tool/tsh: support ID for tsh play -f json 2021-12-16 13:09:51 +00:00
Edoardo Spadolini c3dee235a2
Ensure we don't miss the resolution of an access request (#9193)
This makes it so that tsh will watch for access request resolution on the
correct (root) cluster, and it will not create access requests before the event
watcher is ready.


Fixes #9003 and #9244.
2021-12-10 08:09:36 +00:00
Chongyang d19fe1cc99 Run tsh play requests with correct CLI context 2021-12-09 21:58:58 -08:00
STeve Huang 4e3f795e8f
Add --cluster flag to all tsh db subcommands, Add "--diag_addr" flag to teleport db/app start (#9220)
* add diag to teleport db/app start

* db --cluster flag supports

* add some ut and fix issue ~/.tsh get removed during test

* working mongodb

* fix logout

* fix ut

* code review comment

* fix mysql
2021-12-09 11:24:39 -05:00
Jakub Nyckowski ef66ba793e
Fix custom tsh home dir for some tsh commands. (#9240)
TELEPORT_HOME now should work for all tsh commands.
2021-12-08 11:58:20 -05:00
Marek Smoliński 8a3a164510
Fix tsh ssh proxy for openssh client (#9219) 2021-12-06 13:47:57 -08:00
Jakub Nyckowski e9382011da
tsh db connect do not respect TELEPORT_HOME (#9226)
Fix the issue where `tsh db connect` looks for home directory in `~/.tsh` even when TELEPORT_HOME environment variable is set.
2021-12-06 13:28:12 -05:00
Zac Bergquist 53562aadb0
Use t.Setenv in tests (#9154)
This new feature in Go 1.17 automatically restores the environment
variable to its previous value when a test ends, making it simpler
to set up the environment for tests and less likely that we accidentally
leave behind global state.

Also convert some of the remaining uses of check to standard Go tests.
2021-12-01 10:43:12 -07:00
Marek Smoliński 71396872f1
Fix KUBECONFIG server name (#8940) 2021-11-12 22:32:42 +01:00
Marek Smoliński 760cb10ca0
Merge 'config-proxy' and 'proxy ssh' commands logic (#8920) 2021-11-12 13:25:38 +01:00
Marek Smoliński c335534e02
Fix tsh ssh proxy (#8826) 2021-11-05 13:30:10 +01:00
Marek Smoliński cc3c38d780
Fix MFA for DB Access (#8796) 2021-11-05 01:35:40 -07:00
Roman Tkachenko d87ee8f640
Fix mongo access with mfa and add tests (#8799) 2021-11-02 12:06:58 -07:00
Marek Smoliński 59633e4747
Align SNI routing logic (#8689) 2021-10-22 17:04:36 +02:00
Marek Smoliński 32d48745d7
Align the user message printed during the 'tsh proxy db' command (#8681) 2021-10-22 13:10:43 +02:00
Marek Smoliński 17a5cadabb
Add Proxy listener mode and proxy v2 configuration (#8511) 2021-10-21 14:45:47 +02:00
Marek Smoliński 7606d330e9
AWS CLI access (#8151) 2021-10-19 10:43:53 +02:00
Roman Tkachenko 36998cf566
Add CockroachDB support (#8505) 2021-10-12 14:30:59 -07:00
Zac Bergquist 01ced111f4
Add RBAC for Windows desktop access (#8520)
* Add RBAC for Windows desktop access

This commit adds RBAC checks for Windows Desktops as described in
RFD 33 and RFD 34:

- add Windows desktop logins & labels to role definition
- introduce new file config for host labels based on a regexp match
- auth server API performs access checking for Windows desktop resources
- add RDP client callback to authorize the user
- support user/role locks
- respect the client idle timeout setting

Note: in cases where an connection is terminated to to RBAC, the web UI
currently displays "websocket connection failed" because the connection
is closed from the server. We'll need to follow up with a nice error
message for the client side to improve the UX here.

Other changes:

* Remove OSS RBAC migration marked for deletion
* Stop creating a default admin role
* add wildcard desktop access to the preset access role

Updates #7761
2021-10-12 14:52:59 -06:00
Marek Smoliński 56c536e61f
ALPN DB Proxy fix insecure flag (#8440) 2021-10-08 14:38:51 +02:00
Marek Smoliński 700f9f71e5
Add support for MFA for DB access (#8270) 2021-10-06 13:59:35 -07:00
Alan Parra 16a5c336ef
Adjust tsh language in regards to Webauthn (#8451)
This is a collection of a few small changes related to user presentation of
WebAuthn/MFA in tsh. The intent is to make tsh language match ongoing Web UI
changes.

* Make use of preferred MFA in `tsh mfa add`
* Tweak prompt error message

    Old:
    ERROR: "U2F\n" is not a valid option, please specify one of [TOTP, WEBAUTHN]

    New:
    ERROR: "U2F" is not a valid option, please specify one of [TOTP, WEBAUTHN]

* Directly mention WebAuthn when prompting for challenges
* Fix typo on godoc
* Print devices sorted by name on `tsh mfa ls`
* Address origin validation TODOs

    For registration and a few other use cases the original error is relayed
    back to the client, so there is already a good indicator that it failed
    due to origin woes.

    For login we purposefully obsfucate errors. To address that I've added a
    few debug-level server-side log statements; it seems best to not make
    further changes in this case.

* Amend preferred device type logic
* Adjust PromptMFAChallenge message
2021-10-06 10:54:50 -07:00
Marek Smoliński e8f9220fe7
Fix ALPN SNI Proxy TLS termination for DB connections (#8303) 2021-09-24 09:42:13 +02:00
Alan Parra 5574cc52c4
Add the DeviceType proto to Auth Service (#8336)
Replaces the local device type in AddMFADeviceRequestInit for a global enum.
Useful for future RPCs.

* Add the DeviceType proto to Auth Service
* Generate protos
* Use new DeviceType in implementations
2021-09-22 15:36:33 -03:00
Alan Parra c8e9ce2deb
Add Webauthn devices via tsh mfa add (#8310)
Introduce client-side registration for Webauthn and ensures `tsh mfa` commands
are compatible.

* Implement client-side Webauthn registration
* Add Webauthn devices via `tsh mfa add`
* Add Webauthn devices to ValidateMFADevice
* Add a brief explanation about CheckAuthenticate's usage
* Use constants for CLI device types
2021-09-20 18:37:20 -03:00
Roman Tkachenko e1c3f80aa0
Fixes for cert checker and Postgres config builder (#8251) 2021-09-17 13:28:40 -07:00
Tim Buckley 01acea141a
Add support for tsh ssh on Windows (#7790)
* Add support for `tsh ssh` on Windows

This adds Windows session support to tsh, taking advantage of ANSI
terminal support and VT emulation added in recent versions Windows
10. On supported Windows versions (Windows 10 1607+), `tsh ssh`
should work as expected in `cmd.exe`, PowerShell, and the new
Windows Terminal app.

* Address a few review comments

* Remove significant chunks of unnecessary tncon code.

Removes the global buffer, `GetVTSeqFromKeyStroke`, and several
ancillary headers and functions that aren't needed for our (current)
use-case. Also removes mouse and focus events.

* Refactor OS-specific terminal handling

This significantly simplifies OS-specific terminal behavior:
 * Move OS specific terminal code into a new `terminal` package
 * Remove `session_windows.go` in favor of an OS-independent
   `session.go`, defer to terminal package for OS specific
   functionality.
 * Remove ConPTY since it's not needed.
 * Always wait for the terminal and ssh session to fully close before
   quitting.
 * Refactor tncon; ensure the raw reader can be closed and reopened,
   remove lots of unnecessary C code.

* Revert dependency changes

* Use WindowsOS constant.

* Fix `tsh play` on Windows

This fixes `tsh play` on Windows by using the new `terminal` module to
initialize the terminal for raw input in a cross-platform way.

Additionally, this simplifies `terminal.New()` since in practice we never
want interactive mode at init time, and  fixes a broken unit test.

* Use correct log library

* Fix `tsh play` player controls on Windows

This fixes the console player controls on Windows as well as the timestamp
writer.

* Clean up lints

* Add missing license header

* Fix broken unit test

* Fix cross-compile builds on Linux/Docker

We need windows.h, which is not capitalized in the mingw packages
(and is case insensitive on Windows).

* Address code review feedback

 - Rename `Terminal.InitInteractive` to `Terminal.InitRaw`
 - Ensure goroutines terminate on close
 - Fix outdated godoc comments
 - Ensure Terminal event subscribers are cleared (and their channels
   are closed)
 - Ensure terminal output mode is reset on error in initTerminal
 - Bubble up errors in Terminal.Close()
 - Add author notice to tncon.c re: our changes
 - Add go-ansiterm as a direct dependency
 - Run `make update-vendor`

* Add constants and a small player.go TODO.

* Clear linter warning
2021-09-16 15:53:08 -06:00
Marek Smoliński c142b656c8
ALPN SNI Proxy (#7524) 2021-09-13 11:54:49 +02:00
Roman Tkachenko 4ea2ecdcfc
Introduce app server and app resources (#8140) 2021-09-09 14:19:02 -07:00
Zac Bergquist 8a15c9a3a6
Require that public TLS and SSH keys are provided to register via token (#8135)
* Require that public TLS and SSH keys are provided to register via token

The original behavior attempted to make providing public keys optional,
and would generate keys if they were not provided. This had several
problems:

- The auth server is generating private keys for nodes and is
  potentially able to share them over the network.
- The return value for keys.Key would sometimes be set and sometimes
  be empty (the key is only set if the auth server generated it and
  knows what the key is)
- We only ever relied on this behavior as a shortcut in test code.
  In the production code this behavior was never used (and actually
  never worked due to a bug that would overwrite and discard the
  generated private key)

This commit requires that public keys are always provided, ensuring
that the private key is generated locally and never known by the
auth server.

It also results in a cleaner error message when either or both of the
public keys are missing from the request.

* Address review comments

* Fix tests that relied on certs being generated
2021-09-08 10:17:37 -07:00
Tim Buckley 6f56aa5c4f
Generate Windows-compatible OpenSSH config in tsh config (#7848)
* Generate Windows-compatible OpenSSH config in `tsh config`

This tweaks `tsh config` to generate OpenSSH config blocks compatible
with Windows. It works around several issues:
 * Hosts must be translated from a full hostname (e.g.
   `node.foo.example.com`) to a Teleport node name (`node`). On Unix
   clients we can use a bash subshell snippet to extract the cluster
   domain but this isn't possible on Windows. Instead, this adds a
   hidden tsh subcommand (`tsh config-proxy`) to act as a
   `ProxyCommand` that manipulates the strings as necessary.
 * Windows does not have an ssh-agent enabled by default. This
   configures `IdentityFile` and `CertificateFile` so no ssh-agent
   is needed. This should also improve the experience for users
   without a compatible ssh-agent (e.g. GNOME).
 * Windows requires a full executable path in `ProxyCommand`
   directives.

* Remove unnecessary conversion

* Use /usr/bin/ssh explicitly in `tsh config` template for Unix

* Remove special case for leaf clusters; always require a SiteName

* Apply suggestions from code review

Co-authored-by: Andrew Lytvynov <andrew@goteleport.com>

* Pass through remote login name

This should improve compatibility with OIDC and other users with
federated Teleport usernames. The teleport proxy should always accept
a remote username for which the user's certificate is valid.

* Use `exec.LookPath` to resolve the ssh path

This prefers whichever `ssh` exists on the PATH for all OSes. After some
testing, Git for Windows SSH works just as well as Microsoft's, so we don't
need to overspecify things.

Also, quotes the tsh.exe path in generated config. Git for Windows' ssh
didn't autoescape the Windows paths.

Co-authored-by: Andrew Lytvynov <andrew@goteleport.com>
2021-09-02 15:47:43 -06:00
Roman Tkachenko 3410bc8594
Dynamically register/unregister database resources (#7957) 2021-09-01 15:27:02 -07:00
Brian Joerger a95b3ae066
Add kube-cluster env for tsh (#7867) 2021-08-30 14:28:24 -07:00
Brian Joerger 2d7bfe311c
Add support for a profile specific kubeconfig file. (#7840) 2021-08-24 10:28:26 -07:00
Brian Joerger 928aaf2f91
Add support for nowait on requests. (#7895) 2021-08-18 17:01:05 -07:00
Roman Tkachenko 629042ed30
Decouple database server from database (#7771) 2021-08-05 01:50:21 -07: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
Tim Buckley 9a9562ba35
Add tsh config helper to generate OpenSSH client configuration (#7437)
* Add `tsh config ssh` helper to generate OpenSSH client configuration

This adds a new subcommand, `tsh config ssh`, to generate OpenSSH
client configuration snippets that allow users to connect directly to
nodes using the standard `ssh` client.

To support this change, tsh's `known_hosts` file has been modified to
match the format required by OpenSSH when verifying hosts against
certificates. Old-style `known_hosts` entries will be automatically
replaced and pruned when the end user first logs in with an updated
`tsh`. Small changes were additionally made to the keystore and key
agent to pass the proxy host into `AddKnownHostKeys` and to support
wildcard hostnames in `known_hosts` entries.

* Fix broken link to Trusted Clusters documentation

* Use text/template for SSH config generation; wrap all errors.

* Rename config helper from `config ssh` to just `config`

This changes the config helper to use just `tsh config` per
suggestion from @r0mant.

* Fix known_hosts_migrate_test after rebase

* First pass at review feedback

* Update docs/pages/server-access/guides/openssh.mdx

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

* Ensure top-level hostnames never match wildcard patterns

* Add additional host count check to `canPruneOldHostsEntry`.

* Replace excess call to `isOldStyleHostsEntry` with documented invariant

* Trim trailing dots on absolute hostnames in `matchesWildcard`

Co-authored-by: Roman Tkachenko <roman@gravitational.com>
2021-07-22 13:40:02 -07:00
Trent Clarke 9b7002cf9c
Fixes racey tests in tsh (#7416)
Multiple routines were fighting over the global logrus `Logger`
instance, causing the race detector to trip roughly once in every 10
test runs.

This patch addresses this race condition by supplying each of the
competing processes an entirely separate logger, and ensuring that
these log instances are plumbed through to the code that would otherwise
trip the race detector.
2021-06-25 17:44:42 -07:00
Roman Tkachenko 6b9726f961
Add MongoDB database access support (#7213) 2021-06-21 22:54:05 -07:00
Brian Joerger bd07d7be20
CheckAndSetDefaults sets all defaults. (#6846) 2021-06-18 12:57:29 -07:00
Andrew Lytvynov d4247cb150
hsm: migrate CA storage schema (#7245)
* hsm: migrate CA storage schema

Migrate types.CertAuthorityV2 schema according to
https://github.com/gravitational/teleport/blob/master/rfd/0025-hsm.md#backend-storage

Includes proto changes, types.CertAuthority wrapper changes and data
migration.

Note that we keep and update the old fields for backwards-compatibility.
If a cluster is upgraded to v7 and then downgraded back to v6,
everything should keep working.

* Address review feedback
2021-06-16 12:17:03 -05:00
Roman Tkachenko 0ac7334939
Better handle database access HA scenario (#7293) 2021-06-15 13:35:49 -05:00