Commit graph

964 commits

Author SHA1 Message Date
Nic Klaassen 4d76910b59
nicer ResourceID strings (#13093) 2022-06-03 01:33:11 +00:00
Nic Klaassen 814664ab66
[Search-based access requests] Enforce resource access restrictions (#12651) 2022-06-03 00:04:44 +00:00
Håkon Solbjørg 6f73b82935
fix(teleport/db-create): Use --proxy instead of --auth-server in example command (#12834)
`teleport db create` uses --proxy and not --auth-server.

See this example (some output removed for brevity):
```
$ tctl tokens add --type=db,node
*snip*
Or, generate the configuration and start a Teleport agent using it:

> teleport db configure create \
   --token=... \
   --ca-pin=... \
   --auth-server=my-server.example.org \
   --output file:///etc/teleport.yaml

> teleport start -c /etc/teleport.yaml

$ teleport db configure create \
>    --token=... \
>    --ca-pin=... \
>    --auth-server=my-server.example.org \
>    --output file:///tmp/foo.yml
teleport: error: unknown long flag '--auth-server'
```

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-06-02 22:46:39 +00:00
rosstimothy c3736c7c70
Span forwarding (#12980)
* Span forwarding

Modifies the auth grpc server to implement the OTLP Collector
RegisterTraceServiceServer API (https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/trace/v1/trace_service.proto).
This allows the auth server to receive spans from other services
like `tsh`, `tctl`, and `tbot`. Any spans received by the auth
server will be forwarded to the exporter configured via the
`tracing_service` if it is enabled. All received spans will be
dropped in the event that the`tracing_service` disabled. By
forwarding spans to the auth server, `tsh` doesn't need to
be provided with any of the telemetry backend information
to have its spans exported.

Adds a new `--trace` flag to `tsh` to enable collecting and
forwarding spans to the auth server. When set, the tracing
provider is initialized with a sampling rate of 1.0 to force
all spans to be recorded. Teleport respects the sampling rate
from remote spans, which means that when `--trace` is set, all
spans from `tsh` and any downstream Teleport services will be
recorded and exported regardless of the sampling rate that each
Teleport service is configured with.
2022-06-02 09:28:30 -04:00
Krzysztof Skrzętnicki 50c1de548a
Expose Config in SSOConfigureCommand (#13060) 2022-06-02 10:52:12 +02:00
Noah Stride 7e73d1a501
Convert GetDomainName and GetClusterCACert to gRPC (#12937)
* convert GetDomainNAme endpoint to gRPC

* migrate GetClusterCACert from http to grpc

* fix tests failing due to switch to gRPC transport

* Correct mispelt json tag

* remove `GetLocalClusterName` and `UpsertLocalClusterName` which are unused

* remove unused prefix constant from presence
2022-06-01 22:53:42 +00:00
Jeff Pihach ee255fa5de
Add new teleport node configure command (#13032)
* Add new 'teleport node configure' command to output a config that has all services but ssh disabled.
2022-06-01 20:56:10 +00:00
Andrew LeFevre 02f409b273
add labels to output of 'tsh kube ls' (#12753)
Fixes #11203.
2022-06-01 17:52:44 +00:00
Noah Stride 8b346ef06b
Refactor tbot (#12855)
* start refactoring tbot to have a core struct

* refactor tbot into lib/

* move `tbot` subpackages to `lib/tbot`

* remove mutex pointer

* move `tshwrap` to `lib/` from `/tool/tbot/`

* move new template ssh client render test to lib/

* address pr feedback

* add request changed
2022-06-01 17:15:26 +00:00
Noah Stride 18558b88e9
thread context.Context from tctl Run() to subcommands (#13029) 2022-06-01 12:49:59 +01:00
STeve (Xin) Huang 50dcd493df
Manage ElastiCache Users (#12709) 2022-06-01 01:10:56 +00:00
Tim Buckley b170837040
Fix broken version check in tbot's tshwrap (#13034)
`tshwrap` performs a tsh version check to ensure it has the
functionality we need. Unfortunately, during a final refactoring
before merging, we changed the function signature of `capture()` to
require an explicit path to a `tsh` binary but in a way that was
unfortunately not caught by the compiler. The previous syntax meant
we just tried to execute the first argument, i.e. `version`, which
is never what we want.

This PR correctly passes the tsh path to `capture()` to fix the
version check.
2022-05-31 18:23:15 +00:00
Brian Joerger 26bad238fa
OIDC multiple redirect URLs (#12054) 2022-05-31 17:52:04 +00:00
Alan Parra 8302d467d1
Improved touch ID availability and diagnostics (#12963)
Since #12794 we now build `tsh` binaries with touch ID capabilities. This calls
for a more sophisticated mechanism to determine if touch ID functions should be
enabled, as compile-time support only is not enough.

I've added the following checks, on top of compile-time / `touchid` build tag:

Binary is signed
Binary has entitlements
Machine is touch ID capable
Machine has a Secure Enclave
Put together this give us a much better proxy on whether to enable touch ID.

I've also added the `tsh touchid diag` command, mentioned in the Passwordless
macOS RFD (see
https://github.com/gravitational/teleport/blob/master/rfd/0054-passwordless-macos.md#tsh-support-commands).

#9160

* Improved touch ID availability and diagnostics
* Add the `tsh touchid diag` command
* Set min macOS version to 10.12 (macOS Sierra)
2022-05-31 17:10:06 +00:00
Noah Stride e1cd9e16cd
Demonstrate usage of golden for tbot template generation tests. (#12898) 2022-05-31 10:50:41 +00:00
Tiago Silva f984976dfb
Add cluster flag to tsh kube login/ls commands (#12748)
"--cluster" can be used to switch teleport cluster context

Fixes #10024
2022-05-28 12:46:47 +01:00
Tim Buckley 17dbc2d287
Re-add kinds config field to tbot with a deprecation warning (#12933)
* Re-add `kinds` config field with a deprecation warning

This re-adds the `kinds` config field with a deprecation warning. We
removed the field in #11596 but due to strict YAML parsing this
causes existing otherwise compatible configs to error out.

* Update tool/tbot/config/config_destination.go

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

* Use standardized deprecation comment formatting

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
2022-05-27 21:26:19 +00:00
Tim Buckley e8cfe5df6d
Fix missing SSH HostCA in tbot impersonated identities (#12932)
This fixes a bug where the SSH HostCA is missing in impersonated
identities. We only include it in primary identities via the
server-side `includeHostCA` flag which can't be directly set by
clients. Without this CA, impersonated identities can't successfully
connect to the auth server via an SSH tunnel, so database requests
fail when using IoT joining.

We fix this by instead copying SSH CAs from the primary identity.
2022-05-27 19:22:32 +00:00
Tim Buckley 8f36b9ca8f
Add tbot proxy and tbot db wrapper commands (#12687)
* Extend support for identity files in tsh

This enhances support for identity files in tsh, which previously only
worked for regular SSH access. The largest blocker for support is that
tsh uses profiles for all non-SSH resource access, and profiles have a
direct mapping to some on-disk resources. This patch works around this
in a few ways:
 * Virtual profiles: When an identity file is specified with `-i`, we
   use it to create an in-memory virtual profile using the cert as the
   root identity _and_ for every `RouteToDatabase` (and in the future,
   app) field contained in the cert.
 * Virtual profile paths: Certain profile operations require paths to
   valid certificates and other resources on disk, which may not exist
   inside the identity file.

   As the driving use-case for this change is integration with Machine
   ID, we can "cheat" and pass the correct paths to tsh via
   environment variables. A cooperating wrapper in `tbot` will execute
   `tsh` with appropriate flags and environment variables, which
   override tsh's usual certifiate paths. This allows commands like
   `tsh db connect ...` to work as expected.
 * Key stores: previously we used a `noLocalKeyStore{}` with which all
   lookups fail. This patch replaces it with an in-memory keystore if
   a client key is available.
 * Profile status: lastly, we add a new `StatusCurrentWithIdentity()`
   function to load virtual profiles where supported. Some commands
   are not supported in this PR (like `tsh app ...`), but others
   don't make sense to support (like cert reissuing).

   We might consider merging everything into the traditional
   `StatusCurrent()` when adding app support.

App access is still broken and will be addressed in a later change.

Partially fixes #11770

* Fix failing lint

* Add `tbot proxy` and `tbot db` wrapper commands

This adds new wrapper commands that leverage tsh for proxy and
database access.

It also adds a new `tshwrap` helper package which contains utilities
for locating the tsh executable, checking its version, and loading
all necessary data (certificates, destinations, etc) that will need
to be passed to tsh for wrapped commands to function.

* Fix failing unit test due to incorrect default IsVirtual profile flag

* Combine `StatusCurrentWithIdentity()` into `StatusCurrent()`

Additionally, log a warning when environment variable paths aren't
found.

* Fix virtual profile flag always being true

* Update lib/client/api.go

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>

* Address review feedback

* Use `tbot proxy` in generated `ssh_config`

* Add tests for mockable parts of our tsh integration

* Fix lints

* Clarify docstrings in CLIConf

* Tweak comment for clarity; fix typo in `onProxyCommand`

* Add missing copyright header

* Fix failing unit test and pass destination to `Describe()`

This fixes a failing unit test by making the description for
`ssh_config` match its behavior in practice. This necessitated
passing the destination to all templates, unfortunately.

* Add a few extra tests

* Apply suggestions from code review

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

* Address another batch of review comments

* Comment tweaks

* Refactor tshwrap to remove the Runner interface.

* Apply suggestions from code review

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

* Address review comments

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-05-27 18:25:36 +00:00
Jeff Pihach 8d4005b0a7
Add --node-labels support to teleport configure (#12878)
* Added node labels support to the configure command.

* added test for new config node labels flag.

* improve flag messaging for node-labels

* Fail with a help message if an invalid node label is provided to the configure command.

* Use = as a delimeter for label key=value instead of a : to be consistent with existing CLI commands.

* update tests to different label format.

* Wrap any returned error from the label parsing.
2022-05-27 17:08:51 +00:00
Krzysztof Skrzętnicki 9377f7c681
New commands: tctl sso test, tctl sso configure for GitHub (#12783)
* Implement `tctl sso` commands for GitHub auth.

* Mark RFDs as implemented.
2022-05-26 23:26:35 +00:00
Andrew LeFevre e18cbe5d19
Exit with an error if the auth server is too old (#12797)
If the auth server's major version is less than the connecting Teleport
agent, the agent will now log an error and exit to avoid cryptic errors like
in #11161. '--skip-version-check' flag was added so users can override this
behavior if they wish.

Fixes #11854.
2022-05-26 20:32:43 +00:00
Zac Bergquist a2450423ba tsh: clean up onPlay
The code for `tsh play` is a bit hard to follow
(it's a triple-nested switch statement) because
the command is overloaded to do lots of different
things.

Try to make things clearer by adding docs and breaking
the code up into separate functions.
2022-05-26 08:22:12 -06:00
Zac Bergquist 939bc8b061 tsh: add support for writing memory/CPU profiles
Profiles are enabled via hidden flags on the tsh app.
2022-05-26 08:22:12 -06:00
Zac Bergquist dc08501c5f Prefer signal.NotifyContext over the manual implementation 2022-05-26 08:22:12 -06:00
Zac Bergquist 2396281028 Remove tsh config-proxy
This was marked for deletion in Teleport 9, as the functionality
is now supported in tsh proxy ssh.
2022-05-26 08:22:12 -06:00
Noah Stride 0591c59919
ensure tctl outputs all debug log messages (#12807) 2022-05-25 18:01:16 +00:00
rosstimothy 9f094aaef6
Add tracing instrumentation for ssh clients/servers (#12434)
* Add tracing instrumentation for ssh clients/servers

Add tracing context to the existing ProxyHelloSignature to provide
span information across ssh connections. To add span context per
ssh session on top of new connections, the same tracing context is
passed in the first global request of the session.

In order to ensure that tracing context is pulled from and inserted
into the proper context.Context, some interfaces and methods were
changed to take one as the first argument.
2022-05-25 12:24:02 +00:00
Edward Dowling d1af32e8b8
Change tsh to only print non exit errors on exit 2022-05-25 09:07:59 +00:00
Tim Buckley d873ea4fa6
Extend support for identity files in tsh (#12686)
* Extend support for identity files in tsh

This enhances support for identity files in tsh, which previously only
worked for regular SSH access. The largest blocker for support is that
tsh uses profiles for all non-SSH resource access, and profiles have a
direct mapping to some on-disk resources. This patch works around this
in a few ways:
 * Virtual profiles: When an identity file is specified with `-i`, we
   use it to create an in-memory virtual profile using the cert as the
   root identity _and_ for every `RouteToDatabase` (and in the future,
   app) field contained in the cert.
 * Virtual profile paths: Certain profile operations require paths to
   valid certificates and other resources on disk, which may not exist
   inside the identity file.

   As the driving use-case for this change is integration with Machine
   ID, we can "cheat" and pass the correct paths to tsh via
   environment variables. A cooperating wrapper in `tbot` will execute
   `tsh` with appropriate flags and environment variables, which
   override tsh's usual certifiate paths. This allows commands like
   `tsh db connect ...` to work as expected.
 * Key stores: previously we used a `noLocalKeyStore{}` with which all
   lookups fail. This patch replaces it with an in-memory keystore if
   a client key is available.
 * Profile status: lastly, we add a new `StatusCurrentWithIdentity()`
   function to load virtual profiles where supported. Some commands
   are not supported in this PR (like `tsh app ...`), but others
   don't make sense to support (like cert reissuing).

   We might consider merging everything into the traditional
   `StatusCurrent()` when adding app support.

App access is still broken and will be addressed in a later change.

Partially fixes #11770

* Fix failing lint

* Combine `StatusCurrentWithIdentity()` into `StatusCurrent()`

Additionally, log a warning when environment variable paths aren't
found.

* Fix virtual profile flag always being true

* Update lib/client/api.go

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>

* Address review feedback

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>
2022-05-24 21:40:03 +00:00
Alan Parra 900f11c3db
Use a marker for Keychain labels (#12772)
Adding a "marker" to Keychain labels lets us detect unexpected entries (which I
did see happen) and gives us flexibility to change formats in the future.

A marker in the "label" field seems to be enough to achieve the purposes above,
so I stopped at that. Added a couple minor UX tweaks as well.

#9160

* Use a marker for Keychain labels
* Tweak: Rename "Key Handle" to "Credential ID" for consistency
* Tweak: Do not prompt MFA/OTP if doing Touch ID
* Use trace errors
2022-05-24 18:52:54 +00:00
Krzysztof Skrzętnicki 202c431530
Fix tsh db ls for remote clusters. (#12281)
* New method: GetCurrentUser().

GetCurrentUser returns current user as seen by the server.
Useful especially in the context of remote clusters which perform role and trait mapping.

* Fix "tsh db ls" for remote clusters.

Attempt to resolve remote roles and traits. Fail gracefully if this isn't possible.
2022-05-23 19:42:17 +00:00
Joel 756c5e5ee7
Improve performance using session trackers in large clusters (#12584) 2022-05-23 15:06:33 +00:00
Andrew LeFevre 8e92c40997
add cluster labels to 'tsh clusters' output (#12388) 2022-05-20 21:09:41 +00:00
Matheus ef70c29eaa
Chage teleport configure to accept non existent --data-dir directory (#12673) 2022-05-17 21:13:03 +00:00
Krzysztof Skrzętnicki 414c82a341
Changes for tctl sso test, tctl sso configure commands [OIDC] (#12519)
* Changes for tctl sso test, tctl sso configure commands [OIDC]

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-05-17 16:30:19 +00:00
Edward Dowling 64b86754f9
tctl: Respect TELEPORT_HOME value when grabbing profile (#12486)
Also when grabbing local key store
2022-05-14 09:34:57 +00:00
STeve (Xin) Huang 5c6deb7d9d
ElastiCache support - the basics (#12209) 2022-05-13 15:09:20 +00:00
Krzysztof Skrzętnicki 80bdb11c89
Implement global tsh config file: /etc/tsh.yaml (#12598)
* Implement global tsh config file: `/etc/tsh.yaml`. The default location can be changed with `TELEPORT_GLOBAL_TSH_CONFIG` env var.

* The user config file is merged with the global config file. The user config file has a higher priority.

* If the global config file is absent, no error is raised.
2022-05-13 07:31:48 +00:00
Brian Joerger b4eec0d3c5
Add Session tracker to DB, App, and Windows Desktop Sessions (#12304) 2022-05-12 17:03:32 +00:00
Nic Klaassen c379b174f0
Scope requested resource IDs by cluster and resource kind (#12490) 2022-05-12 00:18:50 +00:00
Alan Parra 0b34833f79
Add tsh touchid ls and rm commands (#12505)
Implement touch ID credential management via tsh touchid ls and tsh touchid rm.

Departs slightly from RFD command names in order to better match the tsh mfa.

See https://github.com/gravitational/teleport/blob/master/rfd/0054-passwordless-macos.md.

#9160

* Implement touch ID credential listing
* Add the `tsh touchid ls` command
* Implement touch ID credential deletion
* Add the `tsh touchid rm` command
* Delegate MFA prompts to WebAuthn
* Undo changes to tsh.go command switch
* Prompt newline. Trace errors.
* Update e/ to 6abb96b
* Var initialization. Guard against NULL. Return all credentials.
* Address review comments: simplifications and style
2022-05-11 12:25:47 -03:00
Jakub Nyckowski 1f7a934584
Use new TLS key to sign DB cert during rotation (#11879)
Why
---
Current CA rotation require you to rotate the key 3 times
* `init` - to add new CA to the DB
* `update_clients` - to generate new client certificate and add it to DB 
* `standby` to remove the old CA from DB.

If any of the steps is skipped the integration will stop working as either Teleport or DB are not able to authenticate the connection.

Solution
---
Signing the client certificate with the new CA will allow to reduce the number of certificate updates and potencial DB restarts/reloads that should make the procedure simpler and less error prone. From now on the certificate will only need to be updated on `init` phase and after `standby` to remove the old CA.

Co-authored-by: Jim Bishopp <jamesbishopp@gmail.com>
2022-05-10 20:18:43 +00:00
Noah Stride 2f00cb4670
tbot configure command for assisting Machine ID configuration (#12517)
* add `tbot configure` command

* introduce golden file test helper

* address PR comments by zmb
2022-05-10 09:04:54 +00:00
Andrew LeFevre 40b9b524f2
add --format flag to 'token add' and make the same flag visible for 'token ls' (#12327) 2022-05-09 21:28:15 +00:00
Alan Parra 68392918ef
Wire touch ID login and registration to tsh (#12475)
Add the --mfa-mode flag and wire touch ID into tsh authn/registration.

In the default MFA mode (auto), touch ID should be eager if there is a
credential present in the system. Users may change this behavior using other MFA
modes.

See https://github.com/gravitational/teleport/blob/master/rfd/0054-passwordless-macos.md.

#9160

* Add AuthenticatorAttachment/MFAMode to tsh
* Add support for touch ID in wancli.Login
* Warn users about passwordless in U2F mode
* Add support for touch ID in `tsh mfa add`
2022-05-09 14:44:28 +00:00
Tim Buckley 9f2f7bf529
Add new config templates to tbot for databases and identity files (#11596)
* Add new `identityfile` config template to `tbot`

This adds a new `identityfile` config template to tbot which
generates an identity file from any of the formats supported by
`tctl auth sign`.

It can be used by specifying one or more formats in the configuration
like so:

```yaml
destinations:
  - directory: /foo
    kinds: [ssh, tls]
    configs:
      - identityfile:
          formats: [file]
```

It requires both SSH and TLS certificates to work properly. App,
Kubernetes, and Database certs are unlikely to work as they have
additional cert requirements that will be added in separate PRs.

Multiple formats can be specified, and each will be written to its
own subdirectory within the destination using the name of the format.
The particular files written inside this directory depend on the
particular format selected, but n the above example, this means a
file named `/foo/file/identity` is written.

The files all have an `identity` prefix at the moment. This could be
made configurable if desired.

The `file` format can be used in conjunction with `tsh -i` and
`tctl -i` to use those tools with a tbot-generated identity.

Fixes #10812

* Make identityfile formats first-class config templates

This promotes most of the important identityfile formats to proper
config templates. User-facing `kinds` are removed to reduce confusion
and several config templates are now required.

 * The `ssh_client` template is now required and will be added
   automatically in all cases if not specified.
 * A new required `tls_cas` template is added to always export
   the current Teleport server CAs in a usable format.
 * A new required `identity` template is added to always export an
   identity file usable with tsh/tctl.
 * New optional `cockroach`, `mongo`, and `tls` templates can export
   specifically-formatted TLS certs for various databases and apps.

Additionally some other changes were caught during testing:
 * `botfs` now allows users to specify if files should be opened for
   reading or for writing; previously, written files were never
   truncated when opened for writing leading to garbage at the end of
   files if the length changed. Truncation isn't sane for reading so
   the two use-cases are now split.

* Update lib/client/identityfile/identity.go

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

* Address first batch of review comments

Tweaked the `botfs.openStandard` and `botfs.openSecure` functions to
accept a plain file mode, and removed a ton of boilerplate in
`configtemplate.go`.

* Fix problematic nil interface check in configtemplate

* Clarify comment about `client.Key` DB certs

* Address review feedback

 - Use `DatabaseCA` for database specific templates; make the `tls`
   template's CA configurable; write the database CA alongside the
   others.
 - Simplify nil interface check

* Fix outdated var names

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
2022-05-06 01:03:05 +00:00
Joel 652536f4e5
Don't enforce standard k8s and ssh auth mechanisms when joining sessions (#11144) 2022-05-05 19:42:57 +00:00
Jeff Pihach cceac2db71
Add hint message when removing access requests. (#11963)
* Add hint message when removing access requests.

* Add hint message if removing an access request that has already been approved.

* fixed typo.

* do not delete access requests unless it hasn't been approved or a force flag has been provided.

* Tweaked hint messaging.
2022-05-04 22:11:39 +00:00
Noah Stride 9348ef172f
reduce verbosity of missing kernel support warning for secure symlink (#12396) 2022-05-04 09:07:55 +00:00