Commit graph

992 commits

Author SHA1 Message Date
Alan Parra 9c89c00806
Build tsh with static libfido2 in buildbox and Centos7 (#11849)
Build `tsh` with static `libfido2`, `libcbor`,`libcrypto` and `libudev-zero`.

Dockerfiles for buildbox and Centos7 changed. FIPS and macOS to be addressed at
a later date.

Add the `tsh fido2 diag` hidden command for ease of testing.

#9160

* Update go-libfido2 and tidy modules
* Add a fido2 diagnostic command to tsh
* Add a few build artifacts to .gitignore
* Build tsh with static libfido2 in buildbox
* Build tsh with static libfido2 in centos7
* Add a few relevant cmake flags
* Use illiliti/libudev-zero
* Do multi-stage build on centos7, image tweaks
* Add `make enter/centos7`
* s/OFf/OFF/g
2022-04-18 14:07:10 +00:00
Tim Buckley c90d59a121
Improve error handling in tbot start (#11756)
* Improve error handling in `tbot start`

This attempts to improve a number of error handling issues while
loading the bot identity from storage in `tbot start`:
1. Identity loading errors are silently ignored and the bot
   always attempts to generate a new identity from token. This isn't
   always correct and is impossible to debug as the true error is
   never logged. We now debug log these errors.
2. `LoadIdentity()` doesn't properly account for existing-but-empty
   identity files and happily tries to load empty identities from
   `tbot init`. This isn't hugely harmful, but produces nonsensical
   error logs once #1 is fixed.

* Use `O_RDWR` instead of `O_WRONLY` in `botfs.openStandard()`

This behaves the same as the fs_linux secure implementation in
all cases, and moves the open mode to a shared constant for good
measure.

* Add a small unit test for symlinks mode read/write.

* Fail on non-NotFound errors while reading an Identity.

* Add small unit test for empty identities.

* Remove outdated TODO comment

* Apply suggestions from code review

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address review feedback

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
2022-04-15 20:53:12 +00:00
Nic Klaassen 0cecbf99bc
Implement "tsh request search" (#11836) 2022-04-14 23:31:11 +00:00
Zac Bergquist 6747a8d92b Remove calls of deprecated strings.Title
To be most accurate, you're supposed to use golang.org/x/text/case
instead (it has a bunch of language-specific logic).

In our case, we only used strings.Title:

- in log messages (for this we just log the original string instead)
- to process system roles, which are all one word (so we just capitalize
  the first letter ourselves)
2022-04-14 09:25:41 -06:00
Zac Bergquist 663e3d04c5 Remove calls to depreated pool.Subjects() method
This deprecation was kind of a pain, because x509.CertPool becomes
a black box - there is no public API to determine how many certs
have been added to the pool. To account for this, some of our method
signatures needed to be updated to report the number of certs that
were added.
2022-04-14 09:25:41 -06:00
Krzysztof Skrzętnicki 6bd7bf95c3
Make tsh db ls lists available db users. (#10458)
* Show available db users in "tsh db ls".

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-04-14 09:45:40 +00:00
Rafał Cieślak 60f59725a9
Generate DB CLI commands for Teleterm from tsh daemon (#11835)
* Extract dbcmd.go into a new package under lib/client/db/dbcmd

* Use dbcmd to generate CliCommand for gateways

* Return relative db command from tsh daemon

* Add WithTolarateMissingCLIClient func to dbcmd
2022-04-14 08:29:26 +00:00
STeve (Xin) Huang fcd1916e9d
Quote postgres connection string for printing to terminals (#11843) 2022-04-11 13:42:33 -04:00
Alan Parra 9abdb2a118
Make relogin attempts use the strongest auth method (#11781)
Fixes a potential stdin hijacking bug by making relogin attempts default to a
single MFA method (the strongest available).

The problematic scenario is as follows:

1. User has both OTP and security keys registered
2. "Relogin" is triggered via a tsh command (say,
   `tsh logout; tsh ssh --proxy=example.com llama@myserver`)
3. User is prompted to pick either OTP or security key ("Tap any security key or
   enter a code from a OTP device")
4. An stdin read is fired in the background to read the OTP code (via
   prompt.Stdin)
5. User picks the security method, thus the stdin read is "abandoned"

In most cases this is fine, as the program ends right after. The issue is when a
relogin is triggered by a long living tsh invocation (again, `tsh ssh ...`): in
this case the stdin hijack causes input to be swallowed.

Forcing a single MFA option avoids the potential stdin hijack, fixing the
problem for all relogin invocations. `tsh login` behavior remains the same.

Note that we have to default to cluster's most secure method _without_ checking
the user devices. The user is not logged in yet, thus the backend cannot reveal
any information about that user.

Fixes #11709.

* Add UseStrongestAuth flag to PromptMFAChallenge
* Add TeleportClient.UseStrongestAuth and set it true for relogin
* Proper testing
* Address review comments
2022-04-08 17:54:45 -03:00
Jeff Pihach c0a0a6c3c7
Return error message if supplied auth connector name doesn't match registered names. (#11800)
* Include the possible connector values if supplied value is invalid.

* Update messaging for auth flag.

* Return error message from failed ping response.

* Collect the connector names in the existing loops.
2022-04-07 22:29:06 +00:00
Roman Tkachenko 97c0b5cb83
Add auth'd tunnel mode to tsh proxy db command (#11720) 2022-04-07 18:33:39 +00:00
Alex McGrath 32cb76e26a
Fix key principals not being used when identity files are being used (#11609) 2022-04-07 09:20:59 +00:00
Jakub Nyckowski 1aa38f4bc5
Create Database CA (#9593)
Introduce Database Certificate Authority. New CA is used by Database Access to sign database certificates making them independent from Host CA. 

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-04-05 19:44:46 +00:00
Gabriel Corado 6f971d1fb7
Generate database access credentials with tctl auth sign command (#10785)
* feat(tctl): sign command to generate database access credentials

* feat(tctl): make auth sign parameters app-name and db-name mutually exclusive

* feat(tctl): add flag db-user to auth sign command

* test(tctl): remove references to deprecated package ioutil

* test(tctl): update test to check error type

* chore(tctl): add godoc to `getDatabaseServer` function

* refactor(tctl): rename database-related flags in auth sign

* refactor(tctl): rename flag from `db` to `db-service`
2022-04-04 18:21:23 +00:00
Joel 30630a1ecf
Pipe terminal stdin to session in kubernetes peer mode (#11288) 2022-04-01 17:48:40 +00:00
Marek Smoliński dc09f6f2c2
Add support for backward compatible API Client behavior (#11567) 2022-04-01 14:38:28 +02:00
Alexey Kontsevoy 4d0c0b2c84 teleterm (alpha) 2022-04-01 13:02:56 +02:00
Marco André Dinis 1aadd4abc2
fix tsh config test (#11603)
check for error when writing to a file
2022-04-01 09:41:23 +01:00
Alan Parra 9cb462887f
Allow single-touch bio authentication (#11588)
Introduce the concept of an "optimistic assertion", which allows us to skip
credential listing (saving a touch) and go directly for an authenticator
assertion.

The downside of an optimistic assertion is that the authenticator picks the
credential, meaning that we can't guarantee or choose the user. This should be
fine for most people, as they are unlikely to have multiple Teleport users in a
single cluster. If the --user flag is explicitly provided we'll honor it and do
the two-touch ceremony instead.

Optimistic assertions are only applied for biometric authenticators; we already
do single-touch for PINs if possible.

This is a bit of an experimental change. It should improve the experience in
most scenarios, but we may elect to rollback if the underlying assumption proves
itself to be poor.

Note that we now depend on gravitational/go-libfido2, as the upstream
go-libfido2 doesn't yet return the credential ID and user ID in assertions.

#9160

* Alias keys-pub/go-libfido2 to gravitational/go-libfido2
* Add LoginOpts to wancli.Login
* Allow optimistic assertions for bio devices
* Use optimistic assertions if the user is not provided
* Pull optimistic assertion check to deviceCallback
* Tweak OptimisticAssertion godoc
2022-03-31 22:47:48 +00:00
Marco André Dinis 83a32f49e1
tsh: ignore empty or non-existing config files (#11495)
If the newly created config.yaml didnt exist we would load the default
values and continue the flow
However, we were not resetting the `err`'s value and would have an ERROR
message at the end and an invalid exit code

Most of the commands would reset that variable to the output of the
command's execution
One of them was not: `tsh version`
The version command has no return value, so the program would execute
as expected until the last statement: `trace.Wrap(error)` which would
re-use the `err` variable whose value is the result of the `loadConfig`
method.

We could either reset the `err`s value inside the `PrintVersion` switch
case block or reset it right after we check for `IsNotFound`.

We ended up picking the first option as it seems cleaner

```
 # before
$ make full > /dev/null; build/tsh version
Teleport v10.0.0-dev git:v8.0.0-alpha.1-899-g335adf1f4 go1.18
ERROR: open /home/marco/.tsh/config/config.yaml: no such file or directory

 # after
$ make full > /dev/null; build/tsh version
Teleport v10.0.0-dev git:v8.0.0-alpha.1-899-g335adf1f4 go1.18
```
2022-03-30 16:58:27 +01:00
Alan Parra eb05138563
Perform single-touch PIN authentication if possible (#11520)
During passwordless logins, if the only candidate device is PIN protected, we
can ask for the PIN right away, saving a touch.

The timing for the the initial touch prompt is now dictated by
wancli.Login/wancli.Register, as the touch is not necessarily the first
operation to happen anymore.

#9160

* Move initial prompt to wancli callbacks
* Eagerly ask for PIN in certain situations
* Rename func to "shouldDoEagerPINPrompt"
2022-03-30 14:13:17 +00:00
Alex McGrath e510bd0de9 tctl: respect TELEPORT_HOME variable when reading profiles 2022-03-29 14:26:12 +01:00
Alan Parra 70a0ad132e
Consistently prompt for OTPs as password (#11346)
Introduce the prompt.Password function and use it consistently whenever we read
a password, OTP or PIN.

The PR makes it easy to support PINs during MFA authentication, so now we do so.
It also adds the capability to mock prompt.Stdin() for tests, adding a uniform
way to fake user input in tests without having to swap functions.

Complements #10953 and #9160.

* Prompt for OTPs as passwords (take 1), read PINs on MFA authentication
* Add the prompt.Password method
* Add Stdin mocking capabilities to the prompt package
* Delegate password reads to prompt.Stdin().ReadPassword()
* Remove stdinHijack from PromptMFAChallenge
* Change api_login_test.go to FakeReader
* Change tsh_test.go to FakeReader
* Retire client.ReadPassword in favor of prompt.Password
2022-03-28 17:16:00 +00:00
Alan Parra f4afd00fb0
Respect context cancellation during FIDO2 callbacks (#11467)
A few FIDO2 scenarios are not respecting cancellation, causing problems in
certain `tsh` flows.

The PR fixes the issue above and sneaks a small fix in `tsh mfa add` as well.

#9160

* Add tests for various cancel conditions
* Respect context cancellation during select and PIN steps
* Do not ask for passwordless for non-webauthn devices
2022-03-28 13:15:05 +00:00
Marek Smoliński 9e1b887d94
Fix TLS Routing jumphost flow (#11282) 2022-03-28 12:31:05 +02:00
Alan Parra 5a11006f81
Add ReadPassword functionality to ContextReader (#11436)
This changes prompt.ContextReader in the following ways:

Reads only happen as a response to Read methods being called. This allows
ContextReader to coexist with other readers as long as no reads are abandoned.
ReadPassword is now available, the underlying implementation being
term.ReadPassword. An abandoned password read may be turned into a clean read.
This gives us some UX flexibility when callers abandon password reads (looking
at you, PromptMFAChallenge). Turning clean reads into password reads is not
supported. It's tricky and I have a few ideas, but it's not paramount at this
moment.

This solves the woes caused by abandoned OTP reads followed by PIN reads in
different packages, such as client.PromptMFAChallenge followed by tsh mfa add's
implementation.

#9160

* Move ContextReader to its own file
* Refactor ContextReader and implement ReadPassword
* Test ReadPassword
* Fix typos
* Remove prompt.StdinSync()

prompt.Stdin() has the same behavior for non-abandoned reads.

* Group /x/term methods under a type
2022-03-25 17:17:20 +00:00
Joel 445d40d8a8
Sort sessions by creation date (#11345) 2022-03-24 12:58:49 +00:00
STeve (Xin) Huang 3d7de736e3
Improve cli usage when command name is long (#10981) 2022-03-23 19:08:42 +00:00
Alan Parra b2c5c8ecb0
Add FIDO2 passwordless login and registration to tsh (#11321)
Passwordless login is enabled by the global `--pwdless` flag. Registration gets
a new prompt and an `--allow-passwordless` flag.

UX messages were tweaked to follow the descriptions on RFD 53: Passwordless
FIDO2[1].

Passwordless login requires two touches for all devices (both PIN and biometric).
I'd like to get it down to a single touch, at least for the most common
situations, but that'll be a follow up to this work.

Passwordless support requires `tsh` to be compiled with the `libfido2` tag, try
`go build -tags=libfido2 ./tool/tsh`.

#9160

[1] https://github.com/gravitational/teleport/blob/master/rfd/0053-passwordless-fido2.md#ux

* Allow reuse of devices for passwordless
* Implement passwordless registration in tsh
* Add better tracing to FIDO2 filters
* Implement passwordless logins in tsh
* Make --pwdless a global flag
* Fix lint errors
* Fix U2F tests
* Use initClient's URL as origin
* Distinguish whether --allow-passwordless is set or unset
2022-03-23 18:38:10 +00:00
Alex McGrath 3d35263a6c Add a .tsh/config file and add support for configuring custom http headers 2022-03-23 14:19:07 +00:00
Tim Buckley b70c1d6d63
Add a note to tctl/main.go about updating tctl Enterprise. (#11168) 2022-03-22 23:36:36 +00:00
Zac Bergquist 55cbd0ac97
Remove use of deprecated ioutil package (#11296)
* Remove use of deprecated ioutil package
* Add lint rule to check for ioutil imports
2022-03-21 18:00:34 +00:00
Krzysztof Skrzętnicki 82bcbc4b60
Show usage on invalid command line invocation. (#11174) 2022-03-21 17:31:31 +00:00
Zac Bergquist c9c35a1791
Update descriptions in our --help messages (#11267) 2022-03-21 15:28:16 +00:00
Alan Parra 023f533be2
Wire FIDO2 into tsh login and registration (#11241)
Seamlessly change the public API of lib/auth/webauthncli to use the
libfido2-backed implementation, as long as the binary was compiled with the
libfido2 build tag.

A few adjustments are necessary to "wancli" methods to allow users to provide
prompt callbacks and to return the credential user (not applicable here, but
will be in following PRs).

Additional changes are made to tsh mfa add in order to avoid stdin hijacking by
ContextReader, since we now may require PIN reads for authenticators.

#9160

* Move U2F logic to u2f_* files
* Split U2F API from general l/a/webauthncli API
* Move FIDO2 public API to fido2_common.go, introduce IsFIDO2Available
* Introduce prompt.SyncReader

Sync reads allow prompt calls to be mixed with term.ReadPassword calls.

* Wire FIDO2 into MFA login
* Wire FIDO2 into MFA registration
2022-03-21 14:35:08 +00:00
Russell Jones 70474d9871 Added Machine ID CLI and configuration references.
Added Machine ID CLI and configuration references.

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2022-03-18 14:19:58 -07:00
Edoardo Spadolini 160df0086a
Support role bootstrapping in OSS (#11175)
* Add role bootstrapping

* Test coverage

* Better variable names

* Remove spurious log, add better error messages
2022-03-17 10:12:18 +00:00
Jakub Nyckowski 1ab20d6631
Improve tsh error message if mysql client is missing (#11204) 2022-03-17 00:50:37 +00:00
Tim Buckley dba79e8c7e
Fix improper default value check in tbot's FromCLIConf() (#11169)
The default `join_method` value was improperly assumed to be "" which
caused any onboarding config from the config file to be overwritten.

This uses the correct default and allows bots to be fully onboarded
via config file.

Fixes #11099
2022-03-16 21:46:19 +00:00
Tim Buckley 254f89f2ff
Fix outdated CLI help for tbot init --owner (#11158)
The inferred default was changed without updating the flag's help
message. This updates the help message to explain the new default
value of `--owner`.
2022-03-15 21:55:31 +00:00
Zac Bergquist 74bc1fbed9
Remove mention of max ttl for tctl tokens command (#11148)
The 48h maximum is enforced for `tctl users add`,
not `tctl tokens add`.

Fixes #11137
2022-03-15 20:46:10 +00:00
Alex McGrath 40200e8536 Reslove comments, move all occurences of teleport.dev to use a constant 2022-03-15 13:22:45 +00:00
Alex McGrath a4c94e4637 Add configurable verbosity to tctl get roles 2022-03-15 13:22:45 +00:00
Alex McGrath 19270c1e71 Resolve comments 2022-03-15 13:22:45 +00:00
Alex McGrath b6df9a742a Add verbosity to tctl * ls commands and resource get. 2022-03-15 13:22:45 +00:00
Alex McGrath ad41b3c154 Move 'MakeTableWithTruncatedColumn' to asciitable and truncate labels 2022-03-15 13:22:45 +00:00
Alex McGrath cdae4e3ee2 ls consistency: add support for tctl desktop ls
```
Host Public Address       AD Domain   Labels               Version
---- -------------------- ----------- -------------------- ---------
corn 192.168.122.144:3389 example.com teleport..3 (9       9.0.0-dev
corn 192.168.122.51:3389  example.com teleport.rd Evle.com 9.0.0-dev
```

```yaml
kind: windows_desktop
metadata:
  expires: "2022-02-18T16:12:52.422659238Z"
  id: 1645200172423989197
  labels:
    teleport.dev/computer_name: WIN-LA2V0OD7SK0
    teleport.dev/dns_host_name: WIN-LA2V0OD7SK0.example.com
    teleport.dev/is_domain_controller: "true"
    teleport.dev/origin: dynamic
    teleport.dev/os: Windows Server 2012 R2 Standard Evaluation
    teleport.dev/os_version: 6.3 (9600)
    teleport.dev/windows_domain: example.com
  name: WIN-LA2V0OD7SK0-example-com
spec:
  addr: 192.168.122.51:3389
  domain: example.com
  host_id: 2c807641-92ae-4c70-88fe-b93e7b0aa179
version: v3
```
2022-03-15 13:22:45 +00:00
Alex McGrath 1627d79275 ls consistency: add tctl kube ls command
```
Cluster     Labels Version
----------- ------ -------------
minikube           8.0.0-alpha.1
honkcluster        8.0.3
```

```yaml
kind: kube_service
metadata:
  expires: "2021-12-16T16:07:14.898611765Z"
  id: 1639670234899200604
  name: 7b3ca8d8-710c-4305-aa29-e73628ac572c
spec:
  addr: 127.0.0.1:3027
  hostname: ""
  kube_clusters:
  - name: minikube
  rotation:
    current_id: ""
    last_rotated: "0001-01-01T00:00:00Z"
    schedule:
      standby: "0001-01-01T00:00:00Z"
      update_clients: "0001-01-01T00:00:00Z"
      update_servers: "0001-01-01T00:00:00Z"
    started: "0001-01-01T00:00:00Z"
  version: 8.0.0-alpha.1
version: v2
---
kind: kube_service
metadata:
  expires: "2021-12-16T16:10:13.068855399Z"
  id: 1639670413069866294
  name: 9153a5a9-e85e-4972-8c50-6fa8923282b2
spec:
  addr: remote.kube.proxy.teleport.cluster.local
  hostname: ""
  kube_clusters:
  - name: honkcluster
  rotation:
    current_id: ""
    last_rotated: "0001-01-01T00:00:00Z"
    schedule:
      standby: "0001-01-01T00:00:00Z"
      update_clients: "0001-01-01T00:00:00Z"
      update_servers: "0001-01-01T00:00:00Z"
    started: "0001-01-01T00:00:00Z"
  version: 8.0.3
version: v2
```yaml
2022-03-15 13:22:45 +00:00
Alex McGrath 5fcc19789f ls consistency: make tctl db ls output consistent
```
Host Name     Protocol URI          Labels                          Version
---- -------- -------- ------------ ------------------------------- -------------
corn postgres postgres 0.0.0.0:5432 teleport.dev/origin=config-file 8.0.0-alpha.1
```
2022-03-15 13:22:45 +00:00
Alex McGrath cff5165ad3 ls consistency: make tctl apps ls output consistent
```
Host Name        Public Address       URI                 Labels                          Version
---- ----------- -------------------- ------------------- ------------------------------- -------------
corn example-app example-app.corn.lan http://0.0.0.0:8000 teleport.dev/origin=config-file 8.0.0-alpha.1
```
2022-03-15 13:22:45 +00:00
Alex McGrath 23731673d9 ls consistency: Make tctl nodes ls output consistent, support yaml
New format:
```
Host UUID                                 Public Address Labels                    Version
---- ------------------------------------ -------------- ------------------------- -------------
corn 7b3ca8d8-710c-4305-aa29-e73628ac572c 127.0.0.1:3022 env=example,hostname=corn 8.0.0-alpha.1
```

With `--yaml`
```yaml
kind: node
metadata:
  expires: "2021-12-16T15:26:44.887862347Z"
  id: 1639667804888460055
  labels:
    env: example
  name: 7b3ca8d8-710c-4305-aa29-e73628ac572c
spec:
  addr: 127.0.0.1:3022
  cmd_labels:
    hostname:
      command:
      - hostname
      period: 1m0s
      result: corn
  hostname: corn
  public_addr: corn.lan:8443
  rotation:
    current_id: ""
    last_rotated: "0001-01-01T00:00:00Z"
    schedule:
      standby: "0001-01-01T00:00:00Z"
      update_clients: "0001-01-01T00:00:00Z"
      update_servers: "0001-01-01T00:00:00Z"
    started: "0001-01-01T00:00:00Z"
  version: 8.0.0-alpha.1
version: v2
```
2022-03-15 13:22:45 +00:00
Alex McGrath 39977efc00 Add tests for motd fixes
Part of this includes renaming export_test.go to export.go so I could
test the MOTD outside of lib/client/export.go
2022-03-15 12:18:39 +00:00
Alex McGrath de9bdf086d Fix MOTD not showing up on tsh login with certain arguments
- changes to configuration.go: fixes tsh login in first test case
  `tsh login --insecure --proxy=127.0.0.1:3080 --user=test`
- changes to apiserver.go fixes `--auth` not showing motd
2022-03-15 12:18:39 +00:00
Tim Buckley 9769698daf
Silence false positive lints from staticcheck in tbot/init.go (#11084)
`staticcheck` does not seem to appreciate our nop implementations for
non-Linux OSes and produces several noisy warnings about it. This
disables the lints as precisely as possible.
2022-03-14 16:55:22 +00:00
Lisa Kim 628564c801
Update 'tctl apps/db/nodes ls' to accept filter flags (#11003) 2022-03-11 17:57:40 +00:00
Joel 92543d9b3e
Moderated Sessions improvements (#10991) 2022-03-10 23:04:12 +00:00
Tim Buckley bea5f7fde4
UX improvements for tbot (#10833)
* UX improvements for tbot

A last batch of UX tweaks for 9.0:
 - rename --renew-interval -> renewal-interval
 - add `--oneshot` mode to fetch one set of certs and exit (client
   side only, no server enforcement yet)
 - add `tbot version`
 - add unix signal handling: graceful exit on SIGINT, reload on
   SIGHUP/SIGUSR1
 - make auth server an optional config option and check it only when
   needed (i.e. `tbot start`)

* Remove `--auth-server` flag from `tbot init` example

* Add `cut` workaround to allow connecting to nodes without DNS

* Update product name in tbot CLI help

* Add `--format=json` support to `tctl bots add`

* Detect OpenSSH version and conditionally remove the RSA deprecation workaround

* Fix failing unit test after rename

* Update tool/tbot/config/configtemplate_ssh.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address review feedback

* Apply suggestions from code review

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

* Document IncludeRSAWorkaround and address review comments

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-03-10 20:41:10 +00:00
rosstimothy 550d23d15d
Fix goroutine and memory leak in watchCertAuthorities (#10871)
* Fix goroutine and memory leak in watchCertAuthorities

The CA Watcher was blocking both on writing to a channel when the watcher
was closed and on HTTP calls that had no request timeout or context passed
to cause cancellation.

All resourceWatcher implementations that had a bug which may cause them to block
on writing to a channel forever were fixed by selecting on the write and ctx.Done.

Adding context.Context to all Get/Put/Post/Delete methods on the auth HTTPClient to
force callers to propagate context. Prior all calls used context.TODO which
prevents requests from being properly cancelled.

Add context propagation to RotateCertAuthority, RotateExternalCertAuthority,
GetCertAuthority, GetCertAuthorities. This is needed to get the correct ctx
from the CertAtuhorityWatcher all the way down to the HTTPClient that makes
the call.

Closes #10648
2022-03-10 11:05:39 -05:00
Tim Buckley 32e48017d3
Implement tbot init subcommand and ACL management (#10289)
* Add certificate renewal bot

This adds a new `tbot` tool to continuously renew a set of
certificates after registering with a Teleport cluster using a
similar process to standard node joining.

This makes some modifications to user certificate generation to allow
for certificates that can be renewed beyond their original TTL, and
exposes new gRPC endpoints:
 * `CreateBotJoinToken` creates a join token for a bot user
 * `GenerateInitialRenewableUserCerts` exchanges a token for a set of
   certificates with a new `renewable` flag set

A new `tctl` command, `tctl bots add`, creates a bot user and calls
`CreateBotJoinToken` to issue a token. A bot instance can then be
started using a provided command.

* Cert bot refactoring pass

* Use role requests to split renewable certs from end-user certs
* Add bot configuration file
* Use `teleport.dev/bot` label
* Remove `impersonator` flag on initial bot certs
* Remove unnecessary `renew` package
* Misc other cleanup

* Do not pass through `renewable` flag when role requests are set

This adds additional restrictions on when a certificate's `renewable`
flag is carried over to a new certificate. In particular, it now also
denies the flag when either role requests are present, or the
`disallowReissue` flag has been previously set.

In practice `disallow-reissue` would have prevented any undesired
behavior but this improves consistency and resolves a TODO.

* Various tbot UX improvements; render SSH config

* Fully flesh out config template rendering
* Fix rendering for SSH configuration templates
* Added `String()` impls for destination types
* Improve certificate renewal logging; show more detail
* Properly fall back to default (all) roles
* Add mode hints for files
* Add/update copyright headers

* Add stubs for tbot init and watch commands

* Add gRPC endpoints for managing bots

* Add `CreateBot`, `DeleteBot`, and `GetBotUsers` gRPC endpoints
* Replace `tctl bot (add|rm|ls)` implementations with gRPC calls
* Define a few new constants, `DefaultBotJoinTTL`, `BotLabel`,
  `BotGenerationLabel`

* Fix outdated destination flag in example tbot command

* Bugfix pass for demo

* Fixed a few nil pointer derefs when using config from CLI args
* Properly create destination if `--destination-dir` flag is used
* Remove improper default on CLI flag
* `DestinationConfig` is now a list of pointers

* Address first wave of review feedback

Fixes the majority of smaller issues caught by reviewers, thanks all!

* Add doc comments for bot.go functions

* Return the token TTL from CreateBot

* Split initial user cert issuance from `generateUserCerts()`

Issuing initial renewable certificate ended up requiring a lot of
hacks to skip checks that prevented anonymous bots from getting
certs even though we'd verified their identity elsewhere (via token).

This reverts all those hacks and splits initial bot cert logic into a
dedicated `generateInitialRenewableUserCerts()` function which should
make the whole process much easier to follow.

* Set bot traits to silence log messages

* tbot log message consistency pass

* Implement `tbot init` subcommand

This adds a new CLI subcommand to initialize a tbot destination
directory by creating required files ahead of time and assigning
proper permissions (and ACLs, where possible).

* Resolve lints

* Add config tests

* Remove CreateBotJoinToken endpoint

Users should instead use the CreateBot/DeleteBot endpoints.

* Create a fresh private key for every impersonated identity renewal

* Hide `config` subcommand

* Rename bot label prefix to `teleport.internal/`

* Use types.NewRole() to create bot roles

* Clean up error handling in custom YAML unmarshallers

Also, add notes about the supported YAML shapes.

* Fetch proxy host via gRPC Ping() instead of GetProxies()

* Update lib/auth/bot.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Fix some review comments

* Add renewable certificate generation checks (#10098)

* Add renewable certificate generation checks

This adds a new validation check for renewable certificates that
maintains a renewal counter as both a certificate extension and a
user label. This counter is used to ensure only a single certificate
lineage can exist: for example, if a renewable certificate is stolen,
only one copy of the certificate can be renewed as the generation
counter will not match

When renewing a certificate, first the generation counter presented
by the user (via their TLS identity) is compared to a value stored
with the associated user (in a new `teleport.dev/bot-generation`
label field). If they aren't equal, the renewal attempt fails.
Otherwise, the generation counter is incremented by 1, stored to the
database using a `CompareAndSwap()` to ensure atomicity, and set on
the generated certificate for use in future renewals.

* Add unit tests for the generation counter

This adds new unit tests to exercise the generation counter checks.

Additionally, it fixes two other renewable cert tests that were
failing.

* Remove certRequestGeneration() function

* Emit audit event when cert generations don't match

* Fully implement `tctl bots lock`

* Show bot name in `tctl bots ls`

* Lock bots when a cert generation mismatch is found

* Make CompareFailed respones from validateGenerationLabel() more actionable

* Update lib/services/local/users.go

Co-authored-by: Nic Klaassen <nic@goteleport.com>

* Backend changes for tbot IoT and AWS joining (#10360)

* backend changes

* add token permission check

* pass ctx from caller

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

* fix comment typo

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

* use UserMetadata instead of Identity in RenewableCertificateGenerationMismatch event

* Client changes for tbot IoT joining (#10397)

* client changes

* delete replaced APIs

* delete unused tbot/auth.go

* add license header

* don't unecessarily fetch host CA

* log fixes

* s/tunnelling/tunneling/

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* auth server addresses may be proxies

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* comment typo fix

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* move *Server methods out of auth_with_roles.go (#10416)

Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address another batch of review feedback

* Addres another batch of review feedback

Add `Role.SetMetadata()`, simplify more `trace.WrapWithMessage()`
calls, clear some TODOs and lints, and address other misc feedback
items.

* Fix lint

* Add missing doc comments to SaveIdentity / LoadIdentity

* Remove pam tag from tbot build

* Update note about bot lock deletion

* Another pass of review feedback

Ensure all requestable roles exist when creating a bot, adjust the
default renewable cert TTL down to 1 hour, and check types during
`CompareAndSwapUser()`

* Remove ModeHint

* Rename Identity.Cert and Identity.XCert

* Add `symlinks` flag to tbot config

The optional symlinks flag for directory destinations allows users to
opt in / out of whichever symlink attack hardening mode is selected
by default.

* Add mostly-working secure implementation of botfs.Create/Write

This adds symlink mode selection (secure, try-secure, insecure) and
Linux `Create()`/`Write()` implementations to open files safely.

* Add configurable ACL modes and verify ACL support in tbot init

* Initialize destinations at startup and test before renewal

This initializes destinations at startup (to create directories if
not using `tbot init`) and tests them to ensure the bot can write
_before_ attempting to renew certificates; this should prevent most
accidental generation counter locks.

* Hide watch for now

* Issue a new identity if a token change is detected

* Warn if identity appears to be expired on startup

* Fully implement ACL Verify and Configure

 - Fully implements ACL support for Linux
 - Adds bot-side verification support to ensure ACLs are configured
   properly at runtime.
 - Gracefully falls back to no ACLs if the platform / filesystem
   doesn't support them
 - Clear up outstanding lints

* Make `tbot init` work without a config file

* Show init instructions in tctl bots add

Also:
 - Make --bot-user a flag in init (the tctl instructions were
   confusing otherwise)
 - Handle IsOwnedBy sanely on unsupported platforms
 - Add Bold colorizing support

* Clear some TODOs and rephrase tctl help

* Fix typo

* Fix token hash detection bug

* Actually read and write certs with symlink enforcement

Also, fix a config loading bug where CheckAndSetDefaults() wasn't
being called in all cases with CLI destinations.

* Add workaround for OpenSSH permissions check with ACLs

OpenSSH has an overly-paranoid permissions check that forces key
files to be exclusively owner-readable. Unfortunately, for POSIX
compatibility purposes, when ACLs are set, the ACL mask is set as
the group permissions. This effectively makes any ACL incompatible
with OpenSSH.

However, OpenSSH's check does have an escape hatch: it only applies
if the current user is the owner of the file. Therefore, this change
tweaks the `tbot init` flow to create files as root, owned by a
separate user (either `nobody` or even the bot user), with ACL
permissions granting both the bot and reader user access to the
certificates. This effectively bypasses OpenSSH's permissions check
and should preserve our security boundaries.

* Fix lints

* Fix an improper directory chmod to 0600 if ACL test fails

* First pass of tbot init unit tests

* Add symlink tests and fix bug with resolving the default owner

* Fix err misuse

* Fix an ACL error if the bot or reader user is the owner.

* Fix typo

* Fix missing error case in VerifyACL causing unreadable directories

* Address review feedback

- Rename ACLOn -> ACLRequired
- Simplify fs_linux.Read()
- Add missing fs_other.Read()
- Hoist renewal loop logic into its own function
- A few misc bugfixes

* Apply suggestions from code review

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

* Address review feedback

- Only log syscall warning once
- Formatting and wording changes
- Improve error handling for `--clean`

* Fix lint error

* Fix imports in fs_other

* Fix possible nil pointer deref if storage is unset

* Use the bot user as default owner

This is more likely to be a safe owner choice than `nobody:nobody`.

* Apply suggestions from code review

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

* Code review fixes

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-03-10 06:09:01 +00:00
Lisa Kim 350ea5bb95
Updates tsh ls for node/app/db/kube to accept new filter flags (#10980)
* Also adds a search keyword parser that takes in different
  delimiters (comma is used for tsh, space is used for web UI)

part of RFD 55
2022-03-09 23:56:55 +00:00
Brian Joerger 600022b290
Change NewRole to use V5 by default, old consumers now user NewRoleV3. (#10884) 2022-03-08 21:11:53 +00:00
Vitor Enes f314e59ad2
Default to https scheme for --proxy argument in tctl auth sign (#10844)
Before this commit, if `--proxy` was set, it would be passed as it to the kubeconfig file. Due to this, if the `--proxy` URL did not have a scheme, it would default to `http`,  leading to the issue reported in https://github.com/gravitational/cloud/issues/1358.

With this commit, we now try to parse the `--proxy` URL and set its scheme to `https` in case it's not set.
In case it's set, we only allow `--proxy` URLs with the `http` and `https` schemes.
2022-03-07 10:04:53 +00:00
Edoardo Spadolini 8983ededb4
Leaf cluster CA sanitizing (#10741)
* Enforce that a leaf cluster has sent us just a single host CA

* Test coverage for validateTrustedCluster

* Add `tctl rm cert_authority/kind/name`

* Check against existing trusted clusters
2022-03-03 11:46:19 +00:00
Matheus fe519a3211
Add proxy to instructions when creating a token for a node (#9539)
* Print proxy instead of auth server on join node instructions for Cloud instances
2022-03-02 10:20:35 -03:00
Nic Klaassen 6e16ad6627
IAM join method support for tbot (#10535) 2022-03-01 00:35:34 +00:00
Jakub Nyckowski 75e24cbd54
Display correct error message when host is missing in tctl auth sign (#10588) 2022-02-28 15:22:51 -05:00
Alan Parra bac0ccdc99
Remove U2F support (#10476)
Follows up on #10466 by removing remaining U2F references, including proto/gRPC
surface and the lib/auth/u2f package itself.

#10375

* Remove U2F from lib/auth/ (1)
* Remove U2F from lib/auth/ (2)
* Remove U2F from lib/auth/ (3)
* Remove U2F from lib/services/
* Remove U2F from tsh mfa add suggestions
* Remove U2F protos
* Update generated protos
* Cleanup a few stragglers
* Remove lib/auth/u2f package
* Fix references to auth.MFAAuthenticateChallenge
* Revert needless lib/auth/password.go change
* Update e/ to ad8fd4a (U2F cleanup)
* Fix stragglers from latest master rebase
* Fix lint and compile failures
2022-02-24 19:54:28 +00:00
Logan Davis 0602d7661f
Adds application proxy to tsh (#10509) 2022-02-23 20:29:54 -06:00
Tim Buckley bb121d7b1e
Certificate renewal bot (#10099)
* Add certificate renewal bot

This adds a new `tbot` tool to continuously renew a set of
certificates after registering with a Teleport cluster using a
similar process to standard node joining.

This makes some modifications to user certificate generation to allow
for certificates that can be renewed beyond their original TTL, and
exposes new gRPC endpoints:
 * `CreateBotJoinToken` creates a join token for a bot user
 * `GenerateInitialRenewableUserCerts` exchanges a token for a set of
   certificates with a new `renewable` flag set

A new `tctl` command, `tctl bots add`, creates a bot user and calls
`CreateBotJoinToken` to issue a token. A bot instance can then be
started using a provided command.

* Cert bot refactoring pass

* Use role requests to split renewable certs from end-user certs
* Add bot configuration file
* Use `teleport.dev/bot` label
* Remove `impersonator` flag on initial bot certs
* Remove unnecessary `renew` package
* Misc other cleanup

* Do not pass through `renewable` flag when role requests are set

This adds additional restrictions on when a certificate's `renewable`
flag is carried over to a new certificate. In particular, it now also
denies the flag when either role requests are present, or the
`disallowReissue` flag has been previously set.

In practice `disallow-reissue` would have prevented any undesired
behavior but this improves consistency and resolves a TODO.

* Various tbot UX improvements; render SSH config

* Fully flesh out config template rendering
* Fix rendering for SSH configuration templates
* Added `String()` impls for destination types
* Improve certificate renewal logging; show more detail
* Properly fall back to default (all) roles
* Add mode hints for files
* Add/update copyright headers

* Add stubs for tbot init and watch commands

* Add gRPC endpoints for managing bots

* Add `CreateBot`, `DeleteBot`, and `GetBotUsers` gRPC endpoints
* Replace `tctl bot (add|rm|ls)` implementations with gRPC calls
* Define a few new constants, `DefaultBotJoinTTL`, `BotLabel`,
  `BotGenerationLabel`

* Fix outdated destination flag in example tbot command

* Bugfix pass for demo

* Fixed a few nil pointer derefs when using config from CLI args
* Properly create destination if `--destination-dir` flag is used
* Remove improper default on CLI flag
* `DestinationConfig` is now a list of pointers

* Address first wave of review feedback

Fixes the majority of smaller issues caught by reviewers, thanks all!

* Add doc comments for bot.go functions

* Return the token TTL from CreateBot

* Split initial user cert issuance from `generateUserCerts()`

Issuing initial renewable certificate ended up requiring a lot of
hacks to skip checks that prevented anonymous bots from getting
certs even though we'd verified their identity elsewhere (via token).

This reverts all those hacks and splits initial bot cert logic into a
dedicated `generateInitialRenewableUserCerts()` function which should
make the whole process much easier to follow.

* Set bot traits to silence log messages

* tbot log message consistency pass

* Resolve lints

* Add config tests

* Remove CreateBotJoinToken endpoint

Users should instead use the CreateBot/DeleteBot endpoints.

* Create a fresh private key for every impersonated identity renewal

* Hide `config` subcommand

* Rename bot label prefix to `teleport.internal/`

* Use types.NewRole() to create bot roles

* Clean up error handling in custom YAML unmarshallers

Also, add notes about the supported YAML shapes.

* Fetch proxy host via gRPC Ping() instead of GetProxies()

* Update lib/auth/bot.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Fix some review comments

* Add renewable certificate generation checks (#10098)

* Add renewable certificate generation checks

This adds a new validation check for renewable certificates that
maintains a renewal counter as both a certificate extension and a
user label. This counter is used to ensure only a single certificate
lineage can exist: for example, if a renewable certificate is stolen,
only one copy of the certificate can be renewed as the generation
counter will not match

When renewing a certificate, first the generation counter presented
by the user (via their TLS identity) is compared to a value stored
with the associated user (in a new `teleport.dev/bot-generation`
label field). If they aren't equal, the renewal attempt fails.
Otherwise, the generation counter is incremented by 1, stored to the
database using a `CompareAndSwap()` to ensure atomicity, and set on
the generated certificate for use in future renewals.

* Add unit tests for the generation counter

This adds new unit tests to exercise the generation counter checks.

Additionally, it fixes two other renewable cert tests that were
failing.

* Remove certRequestGeneration() function

* Emit audit event when cert generations don't match

* Fully implement `tctl bots lock`

* Show bot name in `tctl bots ls`

* Lock bots when a cert generation mismatch is found

* Make CompareFailed respones from validateGenerationLabel() more actionable

* Update lib/services/local/users.go

Co-authored-by: Nic Klaassen <nic@goteleport.com>

* Backend changes for tbot IoT and AWS joining (#10360)

* backend changes

* add token permission check

* pass ctx from caller

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

* fix comment typo

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

* use UserMetadata instead of Identity in RenewableCertificateGenerationMismatch event

* Client changes for tbot IoT joining (#10397)

* client changes

* delete replaced APIs

* delete unused tbot/auth.go

* add license header

* don't unecessarily fetch host CA

* log fixes

* s/tunnelling/tunneling/

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* auth server addresses may be proxies

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* comment typo fix

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* move *Server methods out of auth_with_roles.go (#10416)

Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address another batch of review feedback

* Addres another batch of review feedback

Add `Role.SetMetadata()`, simplify more `trace.WrapWithMessage()`
calls, clear some TODOs and lints, and address other misc feedback
items.

* Fix lint

* Add missing doc comments to SaveIdentity / LoadIdentity

* Remove pam tag from tbot build

* Update note about bot lock deletion

* Another pass of review feedback

Ensure all requestable roles exist when creating a bot, adjust the
default renewable cert TTL down to 1 hour, and check types during
`CompareAndSwapUser()`

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-02-19 02:41:45 +00:00
Gabriel Corado df44457b02
feat: aws database configurator (#9145) 2022-02-18 21:15:54 +00:00
Alex McGrath 611c05106f
Add support for windows desktop services proxying different desktops (#10101)
* Add support for windows desktop services proxying different desktops

* Add filter to GetWindowsDesktops, remove GetWindowsDesktop and GetWindowsDesktopByName

* Cache cleanup

* Fix cache deletes for Windows desktops

For deletes, the cache only gets the backend key, not the entire
resource. Do what database access does, which is to extract the
host ID from the path, and stuff it in the description field of
the resource header.

* Godoc cleanup

* Fix lint

* Address review comments

* Send error message if no desktop found

* Revert to x/net/websocket

This got converted to gorilla/websocket as part of moderated sessions.
We'll do a more intentional conversion post-release.

* fix lint

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-02-18 00:01:08 +00:00
Roman Tkachenko 41899806fd
Add SQL Server support for database access (#10097) 2022-02-17 02:20:33 +00:00
Brian Joerger eeef122954
Check for shell user's home directory as that user (#10321) 2022-02-16 23:51:02 +00:00
Jakub Nyckowski 530ff4c402
Add Redis integration (#10053)
Add support for Database Access for Redis for standalone and cluster self-hosted instances. Teleport requires mTLS in order to connect to Redis instance which is only supported in Redis 6.0+. RESP2 is currently the only supported protocol.
2022-02-16 13:32:32 -05:00
Joel ea810d30d9
Implement Moderated Sessions (#8563)
* Implement Moderated Sessions
2022-02-15 17:02:10 +01:00
Marek Smoliński 84b64fe487
Fix tctl insecure flag when TLS Routing is enabled (#10297) 2022-02-15 10:45:47 +01:00
Gabriel Corado df68e73864
feat: add create database config command (#9618) 2022-02-10 17:56:42 +00:00
Steven Martin 824d9a3bd1
Remove Teleport DB Users only message for tctl users ls that is incorrect (#10181) 2022-02-09 04:38:57 +00:00
Brian Joerger d33f51d17f
x11 forwarding (#9897) 2022-02-04 23:47:03 +00:00
rosstimothy 6cb13715ba
Dynamically resolve reverse tunnel address (#9958)
* Dynamically resolve reverse tunnel address

The reverse tunnel address is currently a static string that is
retrieved from config and passed around for the duration of a
services lifetime. When the `tunnel_public_address` is changed
on the proxy and the proxy is then restarted, all established
reverse tunnels over the old address will fail indefinintely.
As a means to get around this, #8102 introduced a mechanism
that would cause nodes to restart if their connection to the
auth server was down for a period of time. While this did
allow the nodes to pickup the new address after the nodes
restarted it was meant to be a stop gap until a more robust
solution could be applid.

Instead of using a static address, the reverse tunnel address
is now resolved via a `reversetunnel.Resolver`. Anywhere that
previoulsy relied on the static proxy address now will fetch
the actual reverse tunnel address via the webclient by using
the Resolver. In addition this builds on the refactoring done
in #4290 to further simplify the reversetunnel package. Since
we no longer track multiple proxies, all the left over bits
that did so have been removed to accomodate using a dynamic
reverse tunnel address.
2022-02-03 16:24:48 +00:00
Marek Smoliński fbd5a2aafd
Fix tsh tctl do not load all CAS (#9357) 2022-01-31 13:35:15 +01:00
Garrett T d877354799
Add teleport proxy addr to the kubeconfig exec args when specified (#9899)
Because the `current-profile` file is used when `--proxy` is not
specified, it can be difficult to work with multiple clusters at once.
This allows the teleport proxy to be added as an exec arg to the kube
config, making opearting with multiple clusters as easy as changing the
kubectl context.

NOTE: Teleport already merges the kube config when `tsh login` is run
for different clusters. This change only improves the UX so that
updating `current-profile` is not required.

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
2022-01-28 18:37:55 +00:00
Steven Martin e1e86eeabd
Removes diagnosis address from being hidden (#9975)
no longer hide `--diag-addr` in help start
2022-01-28 04:05:43 +00:00
Edoardo Spadolini 95c53ad90e
Access request locks (#9478)
* Add access request locks

This only contains the internal part, no user-visible changes

* Add a `tctl lock` flag to specify an access request ID

* Tests for access request locks
2022-01-24 19:40:09 +00:00
Marek Smoliński 7c8dc2ba05
Fix TLS Router serverName 'kube.' prefix based routing logic (#9777) 2022-01-24 09:53:00 +01:00
Edoardo Spadolini e254076700
Improved Google OIDC connector (#9697)
* go get google.golang.org/api

go get: upgraded cloud.google.com/go v0.60.0 => v0.100.2
go get: upgraded github.com/golang/snappy v0.0.1 => v0.0.3
go get: upgraded github.com/googleapis/gax-go/v2 v2.0.5 => v2.1.1
go get: upgraded go.opencensus.io v0.22.5 => v0.23.0
go get: upgraded golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d => v0.0.0-20211104180415-d3ed0bb246c8
go get: upgraded google.golang.org/api v0.29.0 => v0.65.0

* Optionally fetch transitive groups in the Google OIDC connector

* Refactor the google workspace parts of the OIDC code

* Further refactoring

This undoes the user account impersonation changes, and always requires
an admin account again.

* Test coverage

* Address review comments

* Minor refactor and name changes

* Allow domain filtering, tests now bypass addGoogleWorkspaceClaims

* Update `OIDCConnectorV2` to `OIDCConnectorV3`

* Backwards compatibility for OIDCConnector v2

This also removes the extra boolean flag that was added previously.

* Update e-ref

Enterprise builds will break unless gravitational/teleport.e#385
is included.
2022-01-21 18:26:28 +00:00
Krzysztof Skrzętnicki f3364f77fd
[Breaking] Default to mongosh when connecting to MongoDB. (#8472) (#9754)
* Use `mongosh` client when available.

* Document `mongosh` as default client from 9.0 and `mongo` being the fallback.

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2022-01-21 15:04:23 +01:00
Joel 62173e096b
use google/uuid instead of pborman/uuid (#9793)
* replace imports

* use google/uuid

* fix test

* reverse changelog changes

* update gomod

* zac steps

* tidy

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-01-19 23:44:48 +00:00
Zac Bergquist 20c04df369
Clean up system role parsing (#9756)
* Add tests for ParseTeleportRoles

Updates #9752

* Be more tolerant when parsing system roles.

Our original attempt at canonicalizing roles didn't work for system
roles using camelcase, resulting in an awkward user experience.

Here we maintain a mapping of allowed inputs to their corresponding
system roles, and perform a case-insensitive lookup. This allows us
to support camelcase roles, and has the advantage of permitting
_ word separators as well.

Fixes #9752

* Refactor *SystemRole.Check()

Rather than having to list each role here, we rely on the new
roleMappings set to validate the role.

Additionally, remove the LegacyClusterTokenType role. This change
is guaranteed to be backwards compatible because we check for
RoleTrustedCluster everywhere we were checking for
LegacyClusterTokenType, and our roleMappings will convert the old
string that represented LegacyClusterTokenType to RoleTrustedCluster.
2022-01-14 00:13:59 +00:00
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
Carson Anderson 6e3c703ddb
Add teleport_build_info Prometheus metric to Teleport (#9595)
Adds teleport_build_info metric to Teleport providing the gitref, version, and Go version.
2022-01-05 21:17:54 +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
Zac Bergquist 7c96ba9177 Allow locking a desktop
Prior to this change, desktop access only respected locks
on users or roles. This introduces a desktop as a lock target,
preventing new connections and terminating existing connections
to a locked desktop.

Note: when a lock is created, connection attempts will fail
with the generic "websocket connection failed" error.
This will be addressed with #8584.

Updates #8742
2021-12-28 09:08:40 -07: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
Edoardo Spadolini 879a3c124a
Escape access request and access resolution reasons in tctl (#9381)
* Pass request and resolve reasons in tctl through %q like it's done in tsh

* Update tool/tctl/common/access_request_command.go

Co-authored-by: Andrew Burke <31974658+atburke@users.noreply.github.com>

Co-authored-by: Andrew Burke <31974658+atburke@users.noreply.github.com>
2021-12-16 16:16:46 +00:00
Alex McGrath d89dfe967e tool/tsh: support ID for tsh play -f json 2021-12-16 13:09:51 +00:00
Alex McGrath 3df447f19d Include --insecure options for teleport {db|app} 2021-12-13 23:22:15 +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
Alex McGrath 8fbcafe798 tool/tctl: Log when requested ttl isnt granted for a cert 2021-12-09 14:05:33 +00: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
Alan Parra f423f7fedc
Make the tctl users update command visible (#9080)
Make tctl users update visible and tweak language to match other commands.

* Make the `tctl users update` command visible
* Update public docs
* Document that --set-roles replaces the user roles
2021-11-24 07:48:43 -08:00
STeve Huang e8de91c98b
teleport configure: generate web_listen_addr (#9066) 2021-11-18 16:48:29 -08:00
STeve Huang e636398045
add --publid-addr --cert-file --key-file for teleport configure (#9033)
* add --web-addr --publid-addr --cert-file --key-file for teleport configure

* remove webaddr, and add acme conflict check

* review comments

* fix ut

Co-authored-by: Roman Tkachenko <roman@gravitational.com>
2021-11-18 11:59:21 -08: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
Justinas Stankevičius bcafd5e671
tctl: allow issuing app access certificates via tctl auth sign (#8717)
* tctl auth sign: allow signing app certificates

* Test app cert issuance

* Factor out getApplicationServer

* Inline app session ID initialization

* Use deep struct assertion for RouteToApp

* Use proper context in getApplicationServer

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

Co-authored-by: Roman Tkachenko <roman@gravitational.com>
2021-11-11 08:18:47 -08: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
Zac Bergquist 44045e20ae tctl: allow comma-separated --windows-logins
In order to be consistent with other CLI flags, we support both
--windows-logins=foo,bar as a shortcut for specifying multiple
values.
2021-10-14 11:09:25 -04:00
Zac Bergquist 85541510fe
Support traits for Windows Logins (#8585)
- Add --windows-logins flag to tctl users add command
- Support {{internal.windows_logins}} and external traits from IDP

This allows one to define a role allowing desktop access without
hard coding all allowed/denied Windows logins.

Updates #7761
Fixes #8578
2021-10-13 08:39:31 -07: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
Nic Klaassen 2d10515f19
Implement Simplified Node Joining (#8250) 2021-10-08 10:41:28 -07:00
Marek Smoliński 56c536e61f
ALPN DB Proxy fix insecure flag (#8440) 2021-10-08 14:38:51 +02:00
Andrew Lytvynov f2862537a2
Publish Teleport CA to NTAuth store over LDAP (#8438)
* Publish Teleport CA to NTAuth store over LDAP

Also, refactor the LDAP client.
Also also, implement more missing scard ioctls.

* Address review comments
2021-10-07 10:28:52 -07:00
Brian Joerger c6f0a8a2fe
Kube Proxy Forwarder handles kube services with same name (#8362)
Update Proxy kube forwarder to attempt to dial through all available
endpoints in a random order.
2021-10-06 16:01:08 -07: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
Roman Tkachenko 288c5519ce
Accept multiple SANs in tctl auth sign for databases (#8449) 2021-10-05 16:00:28 -07:00
Brian Joerger 2c8342c9de
Remove RoleConditions type alias from lib/services. (#8441) 2021-10-05 14:04:18 -07:00
Andrew Lytvynov 813dff20c1
PIV authentication for RDP (#8408)
* PIV authentication for RDP

This uncomfortably large change fully implements smartcard PIV
authentication for RDP clients using the Teleport CA:
- PIV applet implementation in emulated RDP smartcard
- generating Windows-compatible certificates using Teleport CA with a
  dedicated RPC
- generating dummy CRLs for Teleport CA and publishing it via LDAP

The CRLs are required by Windows for any smartcard login certificate, we
can't avoid that. But we can avoid making it public: the CRL can live in
ActiveDirectory instead of a public endpoint of a Teleport service.
Here, we use LDAP to publish the CRL on startup, valid for a year.

There are a few unhandled cases in the current implementation:
- LDAP server certificate is not validated when upgrading to TLS
- multiple active CAs (with HSMs) are not supported, only one CRL is
  published
- CA rotation is not supported, CRL is not re-published on rotation

All of the above issues will be handled in future PRs as this one is
already too large.

* Address review feedback

* Fix linter errors
2021-10-01 15:01:17 -07:00
Roman Tkachenko 9959ea381f
Auto-configure IAM for RDS databases (#8339) 2021-10-01 11:06:17 -07:00
rosstimothy fb0ab2b9b7
Watcher System Metrics (#8338)
* add event watcher prometheus metrics and a new tctl top tab to visualize them
2021-09-28 12:16:03 -04: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 6502a12f1f
Add API and CLI for managing application resources (#8185) 2021-09-20 08:44:13 -07: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
Zac Bergquist 839cdcfa97
Convert GenerateServerKeys to GRPC (#8193)
This commit contains 2 changes:

1. Rename GenerateServerKeys to GenerateHostCerts.
   This is a more accurate name and consistent with the existing
   GenerateUserCerts endpoint.
2. Change the request type to include a single role, rather than a
   list of roles. We only ever allowed a single role in the list
   anyway, so this change will prevent future mis-use of the API.

Note: a side effect of this change is we now have two similar endpoints:
- GenerateHostCert: old API that generates SSH cert only
- GenerateHostCerts: a newer API that generates SSH and TLS certs

To avoid making this change too big, we'll aim to deprecate
GenerateHostCert in the future.
2021-09-13 14:37:28 -07:00
Marek Smoliński c142b656c8
ALPN SNI Proxy (#7524) 2021-09-13 11:54:49 +02:00
Steven Martin 079c678ac5
Expand error message on tctl enterprise usage (#8093) 2021-09-09 19:51:58 -07: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
Andrej Tokarčík 138f8f8650
Fix session URL displayed by teleport status (#8072) 2021-09-02 10:01:14 -07:00
Roman Tkachenko 3410bc8594
Dynamically register/unregister database resources (#7957) 2021-09-01 15:27:02 -07:00