Commit Graph
1322 Commits
Author SHA1 Message Date
rosstimothy b0dc78610e Migrate upserting CAs to gRPC (#23140)
Adds `UpsertCertAuthority` to the `teleport.v1.trust.TrustService`
and deprecates the HTTP api. The `services.Trust` interface was
also updated to include a `context.Context` in both
`CreateCertAuthority` and `UpsertCertAuthority.

To ensure backwards compatibility the `auth.Client` will first
attempt to use the gRPC client and if that fails with a not
implemented error it will fallback to using HTTP.

Part of #6394
2023-03-16 14:46:43 +00:00
Brian Joerger 475388280d Headless Login: tsh implementation (#22751)
* * Implement tsh --headless

 * Implement tsh headless approve

* Add better headless authn state handling.

* Add godoc for new tsh field.
2023-03-15 18:05:02 +00:00
Tiago Silva ea5edcab67 Add app_server support to tctl get/rm commands (#23119)
This PR adds support for `app_server` get and remove commands through
`tctl`.
2023-03-15 17:26:17 +00:00
rosstimothy 1c3188a38a Add a dedicated client to communicate with the Proxy SSH server (#22629)
A new `api/client/proxy/Client` has been added to interact with
the SSH and gRPC servers that the Proxy serves on its SSH port.
The client will first try connecting to the gRPC server and if
that fails it will fall back to the SSH server.

Much of the SSH functionality mimics the existing behavior of the
`ProxyClient` in `lib/client`. This is the first part of phasing
out that client in favor of the new client. There will be a follow
up PR that migrates `lib/client` to make use of the new client instead.

Part of #19812
2023-03-15 13:41:56 +00:00
rosstimothy f02468e9fb Migrate the delete ca api to gRPC (#23070)
Adds `DeleteCertAuthority` to the trust grpc service and deprecates
the legacy HTTP api. Additionally the `DeleteCertAuthority` method
in the `services.Trust` interface now takes a `context.Context` as
the first parameter. In order to plumb the context through from all
the call sites `DeleteRemoteCluster` from `services.Presence` was
also modified to take a `context.Context` as the first parameter.
2023-03-15 13:11:37 +00:00
Brian Joerger 5a3a374203 Decouple SkipLocalAuth, UseKeyPrincipal, and static auth methods. (#21182)
* Fix TestDiagnoseSSHConnection to be less strict on the exact unknown user error message, which may vary between OS's.

* Decouple/refactor SkipLocalAuth, UseKeyPrincipal, and static auth methods.

* Resolve comments.

* * Add tests for new methods

* Update proxy ssh principal test to catch regression

* Bump predicate error in switch case priority
2023-03-14 23:22:08 +00:00
rosstimothy 9d066364a8 Migrate GetCertAuthorities to gRPC (#22985)
Adds a new `GetCertAuthorities` unary RPC to
`teleport.v1.trust.TrustService` and deprecates the equivalent
HTTP endpoint. All associated interfaces have been updated to remove
the marshal options as well.
2023-03-14 14:45:01 +00:00
STeve (Xin) Huang 3a0ab15f4a Support App access behind load balancer (#22565)
* Support App access behind load balancer

* revert unecessary change

* fix lint

* Fix UT

* minor refactor
2023-03-14 13:47:41 +00:00
Jeff Pihach 1513294b7b Add CreatedBy and CreatedOn fields to locks. (#22667)
* Add CreatedBy and CreatedOn fields to locks.

* Move the setting of the CreatedBy and CreatedOn for locks to the server instead of the client.

* Add tests for the tctl resource lock import and for the tctl lock create command.

* Use clockwork for time in lock creation tests.

* Make fake clock optional and use the golang 0 date.

* Change CreatedOn to CreatedAt.

* Allow a custom time to be passed through as a fake clock.

* Actually accept a fake clock with useFakeClock.

* Pass Clock through as a configuration value when initializing Teleport for the tests.

* Test cleanup

* Set CreatedBy and CreatedAt values in test mocks.

* Fix failing test from enabling clock passthrough to auth.
2023-03-13 16:14:24 +00:00
Tiago Silva 674a3a1ec1 Removes deprecated KindKubeService objects (#22663)
This PR removes the `types.KindKubeService` objects that were
deprecated in Teleport 11.

Teleport 12 removed the double heartbeat and for Teleport 13 we can
safely drop the support of the old hearbeat based on `types.Server`
objects.

Clients older than Teleport 12 connecting to a Teleport 13 server will
fail since they cannot heartbeat using the old mechanism.
2023-03-13 10:55:39 +00:00
rosstimothy fa3bb9ac59 Ensure that the webclient closes connections (#22832)
The `http.Client.Transport` created in `newWebClient` wraps a
chain of `http.RoundTripper` over an underlying `http.Transport`.
Since we cannot guarantee that each `http.RoundTipper` has a
`CloseIdleConnections` method the usage of
`defer clt.CloseIdleConnections()` does not guarantee that the http
connections created during Find/Ping/etc are closed.

To prevent leaking connections implementations of `http.RoundTripper`
have added a `CloseIdleConnections` method added that forwards the
request on to the wrapped interface. The `otelhttp.Transport` does
not implement this method either so care has been taken to wrap it
in a `http.RoundTripper` which will call the root transport in
`enforceCloseIdleConnections`. An upstream issue has been filed
with otelhttp: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3543
to get the method added to their `Transport` implementation.

This wasn't noticed prior to upgrading to go1.20 becuase prior to
[this](https://github.com/golang/go/commit/4e7e7ae1406c70d9cc0809ec11105a55a60a0b70)
commit the `ReadHeaderTimeout` set on the Proxy web api http.Server
would cause the connection to appear idle and get terminated by the
server.

`TestWebClientClosesIdleConnections` was added to capture the leak
in connections as reported in #22757 and prevent any regressions.
2023-03-10 15:21:16 +00:00
rosstimothy 95d6d0fee1 Migrate GetCertAuthority to gRPC (#22624)
The HTTP client created by `auth.NewClient` has an idle timeout of
30s and each instance periodically gets cert authorities in
`TeleportProcess.syncRotationStateCycle`. If there has been no
activity when the ticker expires then the request will result in a
brand new connection to Auth to be established. This can cause a
spikes in open file descriptors on the Proxy when there are a large
number of instances connected via a tunnel.

To prevent periodic dialing when retrieving cert authorities the
endpoint has been migrated to the new Trust gRPC service. For now
only the get endpoint has been migrated but the rest of the CRUD
operations for cert authorities should be migrated from the HTTP
api to the gRPC service as well.
2023-03-10 14:32:34 +00:00
8e05bcbb1b Export CRL and Database CA in DER format (#22578)
* feat(tctl): auth export type db der

* feat(tctl): add "crl" command to export revocation lists

* Apply suggestions from code review

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

* chore(tctl): change command description

* Apply suggestions from code review

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* feat(auth): enable role admin to call generate crl

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
Co-authored-by: Marek Smoliński <marek@goteleport.com>
2023-03-10 14:30:07 +00:00
Andrew Burke 4b21199c7d Allow DialProxy to use TLS (#22439)
This change adds support for HTTPS proxies (i.e. `HTTPS_PROXY=https://...`).
2023-03-10 00:05:17 +00:00
Noah Stride 24b7275d87 Fix panics caused by expiryless tokens (#22829)
* Fix panic due to expiryless token in bot add

* Fix other unprotected dereferences of *ProvisionToken.Metadata.Expires
2023-03-09 17:52:34 +00:00
Zac Bergquist 2ae9d770fc Refactor tctl's dependencies (#22693)
* Move configuration from lib/service to lib/service/servicecfg

The new servicecfg package will hold only configuration for services.
This will allow other packages (like tctl and tsh) to depend on
servicecfg without pulling in all of lib/service (which has a number
of platform-specific details).

This is the first step towards being able to build tctl for Windows.

* Move PAM and BPF config into servicecfg

This breaks a compile-time dependency on BPF/PAM for tctl.
2023-03-09 17:48:36 +00:00
Justinas Stankevičius bb4994e214 Add configuration options for hosted plugin runtime (#22320)
* Add Plugins feature flag

* Add config for plugins runtime

* Allow reading OAuth secrets from files

* Rename Plugins to HostedPlugins

Make it clear that this is separate from the upcoming
self-hosted, standalone plugins that will be part of the Teleport
binary.

* Only allow to read client credentials from files
2023-03-09 11:59:38 +00:00
Michael Wilson 49c64aabcb Move the authorizer into its own package. (#22776)
* Move the authorizer into its own package.

The Authorizer and associated functions and constants have been moved into
their own package `authz`. This will allow us to more easily create separate
services for gRPC functionality so that we're not pushing as much into the
`lib/auth` package.

Though this PR is large, the only actual code change here is making
`ContextForLocalUser` exported and changing the `permissions_test.go` so that
it doesn't rely on the `lib/auth` package.

* Use context functions.

* Test and linting fixes.

* Add in a temporary alias file to ensure e still compiles.

* Use functions instead of var aliases for performance reasons.

* Adding in godocs, cleaning up tests.

* Fix tests.

* Add a few more aliases.
2023-03-09 02:21:10 +00:00
Noah Stride cfcc8076f6 Add correct link in place of placeholder for Telemetry docs (#22773) 2023-03-08 15:49:09 +00:00
86dbdafdcd Improve error messages for tsh login connectivity and ssh port (#19641)
* Improve error messages for tsh login connectivity and ssh port connection errors

* spell fix

* lint fix

* lint fix

* suggestion applied

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

* Moved message to helper function for ssh proxy connection error

* format function

* Include error message on non-specified port login

* Give error message on attempted proxy hosts

* style coding

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

* change to string construction

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

* bytes buffer update

* lint fix

* Update message

* Update lib/client/api.go

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

* Update lib/client/api.go

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

* Update tool/tsh/tsh.go

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

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-03-07 21:55:52 +00:00
Andrew LeFevre 6932a627c0 Make it easier to create registered openssh nodes with 'tctl' (#22615)
* make it easier to create registered openssh nodes with 'tctl'

Metadata.Name is set to a random UUID if it's unset, the requirement
to use '--force' when creating node resources is dropped, and more
checks for openssh node resources are added.

* added test coverage, renamed KindOpenSSHNode -> SubKindOpenSSHNode, added github.com/google/uuid to api/go.mod

* attempt to fix tests

* don't set node subkind if it's empty

* re-add test fix
2023-03-06 21:02:30 +00:00
Zac Bergquist bdc47fca62 Improve tctl auth export docs/help (#22589)
Ensure that valid export types are listed in both the --help
message and the CLI documentation.

Closes #22218
2023-03-06 19:24:33 +00:00
Noah StrideandEdoardo Spadolini 6eaea0300e Machine ID Agent Anonymous Analytics (#22174)
* Start fleshing out tbot anonymous analytics submission

* Support overriding telemetry endpoint

* Add debug message on success

* Refactor sendTelemetry to be compatible with unit testing

* Improve telemetry log message cppy

* Ensure exit occurs after telemetry submitted

* Improve mocking for tests

* Finish automated test

* Fix imports

* Switch to info level message when nto enabled

* Use preferred package import anme

* Use tbot specific telemetry endpoints

* Use start time instead of now in timestamp

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

* Add missing license headers

* Add brief comment

* Correct staging domain

* Ensure anonymous telemetry sends

* Exit telemetry wait early if context is already cancelled

* Correct linter errors

* Fail faster on telemetry submission

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-03-06 10:24:07 +00:00
Tiago SilvaandBrian Joerger f8ab3aa037 Improve tsh kube credentials read operations (#22388)
While loading a key from storage, Teleport client transverses the
storage directory to read the secrets and reads each file one by one.
This has huge impacts on `tsh kube credentials` because when calling
`kubectl` in parallel, the disk operations become overloaded and the
operation time increases exponentially.

This PR removes the transverse when reading credentials for Kubernetes
clusters and adds a quick read operation that reads the following files:
- `$TSH_HOME/current_profile`
- `$TSH_HOME/$profile.yaml`
- `$TSH_HOME/keys/$PROXY/$USER-kube/$TELEPORT_CLUSTER/$KUBE_CLUSTER-x509.pem`
- `$TSH_HOME/keys/$PROXY/$USER`

| - | P=1 | P=10 | P=40 | P=80 | P=120 |
| --- | --- | --- | --- | --- | --- |
| old direct | 9.90s user 3.14s system 64% cpu 20.284 total | 11.08s user 3.60s system 496% cpu 2.955 total | 12.46s user 4.36s system 820% cpu 2.050 total | 12.81s user 4.76s system 811% cpu 2.164 total | 13.02s user 5.07s system 861% cpu 2.100 total|
| old teleport | 18.45s user 7.80s system 51% cpu 51.085 total | 21.58s user 10.03s system 434% cpu 7.270 total | 22.33s user 10.52s system 178% cpu 18.402 total | 22.04s user 10.83s system 96% cpu 33.977 total | 22.57s user 11.45s system 55% cpu 1:01.34 total|
| new direct | 9.51s user 2.90s system 146% cpu 8.460 total | 13.75s user 4.95s system 718% cpu 2.603 total | 12.21s user 4.43s system 832% cpu 1.999 total | 11.72s user 4.50s system 839% cpu 1.933 total | 12.06s user 4.62s system 830% cpu 2.009 total |
| new teleport | 16.10s user 5.97s system 42% cpu 52.104 total | 21.62s user 9.01s system 381% cpu 8.023 total | 23.22s user 10.11s system 540% cpu 6.162 total | 21.64s user 9.81s system 603% cpu 5.208 total | 20.70s user 9.13s system 602% cpu 4.948 total |

---

| - | P=1 | P=10 | P=40 | P=80 | P=120 |
| --- | --- | --- | --- | --- | --- |
| old no tsh kube credential | 8.61s user 2.99s system 31% cpu 36.336 total | 9.57s user 3.39s system 283% cpu 4.565 total | 10.22s user 4.03s system 553% cpu 2.574 total | 9.32s user 3.82s system 559% cpu 2.351 total | 11.49s user 4.85s system 624% cpu 2.617 total
| new no tsh kube credential | 8.27s user 2.94s system 24% cpu 45.041 total | 10.85s user 4.31s system 195% cpu 7.767 total | 11.32s user 4.64s system 469% cpu 3.401 total | 10.83s user 4.51s system 553% cpu 2.773 total | 10.90s user 4.84s system 537% cpu 2.930 total |

---

| instances | old total | old avg | **new total** | **total avg** |
| --- | --- | --- | --- | --- |
| 1 | 0.145 | 0.145 | 0.074 | 0.074 |
| 10 | 0.430 | 0.043 | 0.146 | 0.0146 |
| 20 | 0.740 | 0.037 | 0.284 | 0.0142 |
| 30 | 1.108 | 0.037 | 0.417 | 0.0139 |
| 40 | 1.483 | 0.037 | 0.580 | 0.0145 |
| 60 | 13.604 | 0.228 | 0.825 | 0.0137 |
| 80 | 30.236 | 0.378 | 1.143 | 0.0142 |
| 106 | 46.681 | 0.440 | 1.413 | 0.0133 |

Fixes #19313

Co-authored-by: Brian Joerger <bjoerger@goteleport.com>
2023-03-01 19:54:36 +00:00
Alan Parra b2faf5f440 Set create_as_resource in device-related tctl RPCs (#22415)
* Allow devices writes with resource-like semantics

* Update generated protos

* Set `create_as_resource` in device-related `tctl` RPCs

* Do a few tweaks to `tctl` device resources
2023-03-01 15:43:43 +00:00
Andrew Burke be9fee43de Fix pickDefaultAddr not respecting HTTPS_PROXY (#22161)
This change fixes a bug where tsh would not respect HTTPS_PROXY when it
has to guess the Telport proxy's port.
2023-03-01 00:49:27 +00:00
MichaelandJeff Pihach d94fed7b0d Add static and dynamic web ui configuration options (#21945)
* Add UiConfig option to proxy service config

* Add uiConfig to GRV_CONFIG window object and use in terminal constructor

* Update configuration reference docs

* Remove extra structs and change property to scrollbackLines

* Update web/packages/teleport/src/config.ts

Co-authored-by: Jeff Pihach <hatched@users.noreply.github.com>

* Use a common struct and apply in applyProxyConfig

* Remove webclient dependency for fileconf

* Add missing doc comments

* Set individual properties of cfg.Proxy.UI

* Remove unneeded comment

* Add nolint rule

* Fix nolint

* Add test for UIConfig

* Cleanup tests

* Fix TestUIConfig context

* Allow dynamic config for web ui (#22097)

* Update protofiles

---------

Co-authored-by: Jeff Pihach <hatched@users.noreply.github.com>
2023-02-28 17:45:52 +00:00
Michael WilsonandAndrew Burke 437e93adbf Automatically parse entity ID from SAML SP during CLI creation. (#22101)
* Automatically parse entity ID from SAML SP during CLI creation.

When a SAML IdP service provider is created in the CLI, the entity ID will
be automatically parsed out of the entity descriptor and pushed into the
object before pushing the object to the backend.

Additionally, a small bug was found with the SAML IdP service provider get
logic and fixed.

* Update tool/tctl/common/collection.go

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

* Update tool/tctl/common/resource_command_test.go

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

* Bring back copy loop.

* Remove the SkipCheckAndSetDefault.

* Removing the check for the entity ID in the SP object.

* Restore missing comment.

* Parse entity ID as part of check and set defaults.

* Cleanup api go.mod/go.sum.

---------

Co-authored-by: Andrew Burke <31974658+atburke@users.noreply.github.com>
2023-02-27 20:58:22 +00:00
Michael Wilson ce9cccf844 Fix SAML IdP service provider CLI bug. (#22256)
The SAML IdP service provider collections object in the CLI was inadvertently
appending to the end of a preallocated array instead of using the array
directly.
2023-02-27 14:02:21 +00:00
rosstimothy c811979157 Export runtime traces from tsh (#22281)
Adds a `--trace-profile` flag to tsh that allows a user to specify
a file to file which a runtime trace profile should be saved to.
2023-02-27 13:57:05 +00:00
JoelandAlan Parra 073c784b3a Format collected data in the device tctl resource nicely (#22198)
* format collected data nicely

* remove name prefix

* update comment

* Update tool/tctl/common/device/resource.go

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

* fix test

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-02-23 19:10:03 +00:00
d89879c2f5 Add gRPC service definition for Plugin resources (#21750)
* Add plugin exchange service

* Add Plugin methods to auth

* Add gRPC-layer methods for Plugin

* Add RBAC presets for Plugin

* Test GetPlugin()/NoSecrets access

* Make error assertions more correct in role test

* Deny setting credentials if user can not read them

* gofmt

* Apply minor suggestions from code review

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* Move dependency into an existing block in go.mod

* Improve error messages for failed type assertions

* DRY WithSecrets access checks for Plugins

* Run new tests in parallel

* Improve error assertions in auth_with_roles_test

* TestGetPluginWithSecrets: split cases to subtests

* Clean up test servers and clients

* Add proto for plugin service

* Remove Plugin methods from auth service

Moved to a dedicated service

* Remove plugin-related auth methods

Moved to a dedicated service in Enterprise

* Remove CreatePlugin test from auth_with_roles_test

Moved to a dedicated service in Enterprise

* Pass "backend getter" to local plugins service

This pattern is used in Enterprise to set up secondary services
before auth (and backend) are created.

* Rename InitialCredentials to BootstrapCredentials

* Add plugins service to genproto.sh

* Reformat generated proto

* Remove obsolete PluginExchangeService

The equivalent of this is now in Enterprise

* Add kube service to genproto.sh; regenerate

* Add ListPlugins to plugin backend service

* Reimplement GetPlugins on top of ListPlugins

This is a "convenience" implementation for the backend service layer.

* Replace GetPlugins with ListPlugins in gRPC schema

* Fix ListKubernetesResources unit test

* Simplify plugin pagination key to just the name

* Use existing constant for page size

* Make dummy clients return errors instead of panic

* Remove obsolete field

* Ensure go.mod is valid for corresponding e changes

* Fix passing mutex ref

* Move teleport-plugins import to e_imports

* Revert oauth change in go.mod

* Use limit+1 to look-ahead when paginating plugins

* Test plugin pagination with pageSize > numPlugins

* Add descriptive messages to gRPC dummy clients

* Plugin: add RW for editor; remove secrets from gRPC

* Make message more descriptive for dummy gRPC conn

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
2023-02-23 14:32:41 +00:00
Gavin Frazar ade99b7520 update tsh local proxy tunnel logic (#21779)
* check if --cert-file, --key-file are given when tunnel is required
* require tunnel mode for SQL Server and Cassandra
* deprecate --cert-file and --key-file flags in favor of --tunnel
2023-02-22 23:54:14 +00:00
0fce40d294 Provide flag to only display tsh binary version (#20521)
* Add flag to only check tsh binary version and not server version

* Update language

* Update variable comment

* Removed unncessary default flag, changed to --client from --client-only, updated variables used

* Add showing proxy address to tsh version

* Verbiage change for client flag

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

* client only flag in docs

* Fix word for tsh —client

* Change flag description

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

* Updated tsh version comments, --client description

* copy edits

* Remove CLI docs, putting in a sep PR

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
Co-authored-by: alexfornuto <alex.fornuto@goteleport.com>
2023-02-22 22:52:42 +00:00
JoelandAlan Parra 9ae691feb5 Implement tctl resource commands for Device Trust (#21921)
* handle tctl create device.yaml

* delete + fix create

* delete by asset tag

* factor out finder

* tctl get device

* gci

* use unmarshaler

* device

* test + unmarshal version check

* improve error

* fix device asset search

* fix parse shortcut bug

* various fixes

* rename CheckAndSetDefaults to checkAndSetDefaults

* Update tool/tctl/common/device/resource.go

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

* Update tool/tctl/common/collection.go

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

* Update tool/tctl/common/resource_command.go

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

* fix import

* improve findDeviceByIDOrTag and allow multiple returns for fuzzy asset tag searching in tctl get devices/

* update create/delete messages

* print warn instead of error

* mark sanity check

* resource rework

* add comments

* fix typo

* Update tool/tctl/common/resource_command.go

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

* Update tool/tctl/common/resource_command.go

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

* Update tool/tctl/common/resource_command.go

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

* drop findmultiple

* Update tool/tctl/common/resource_command.go

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

* Update tool/tctl/common/device/resource.go

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

* various feedback updates

* user friendly enum for ostypes

* add comments

* Update tool/tctl/common/resource_command.go

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

* Update tool/tctl/common/device/resource.go

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

* Update tool/tctl/common/device/resource.go

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

* Update tool/tctl/common/device/resource.go

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

* Update tool/tctl/common/device/resource.go

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

* gci

* feedback

* typos

* Update tool/tctl/common/device/resource.go

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

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-02-22 21:11:13 +00:00
Nic Klaassen d77fb5bee4 fix: improve tsh logs when skipping auto Access Request (#22048)
Currently the `tsh` debug log is polluted with "errors" created by the
[automatic access request feature](https://goteleport.com/docs/access-controls/access-requests/resource-requests/?scope=enterprise#automatically-request-access-for-ssh)
even in completely expected scenarios, e.g. when the user has no
permission to create Resource Access Requests.

Before this change:
```
$ tsh ssh -d alice@one-auth
...<omitted>...
2023-02-17T15:30:16-08:00 DEBU [TSH]       unable to request access to node error:[
ERROR REPORT:
Original Error: *trace.BadParameterError user attempted a resource request but does not have any &#34;search_as_roles&#34;
Stack Trace:
        github.com/gravitational/teleport/api@v0.0.0/client/client.go:880 github.com/gravitational/teleport/api/client.(*Client).CreateAccessRequest
        github.com/gravitational/teleport/tool/tsh/tsh.go:2896 main.accessRequestForSSH.func1
        github.com/gravitational/teleport/lib/client/api.go:1351 github.com/gravitational/teleport/lib/client.(*TeleportClient).WithRootClusterClient
        github.com/gravitational/teleport/tool/tsh/tsh.go:2895 main.accessRequestForSSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:2916 main.retryWithAccessRequest
        github.com/gravitational/teleport/tool/tsh/tsh.go:2993 main.onSSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:1086 main.Run
        github.com/gravitational/teleport/tool/tsh/tsh.go:482 main.main
        runtime/proc.go:250 runtime.main
        runtime/asm_amd64.s:1598 runtime.goexit
User Message: user attempted a resource request but does not have any &#34;search_as_roles&#34;] tsh/tsh.go:2920

ERROR REPORT:
Original Error: *trace.AccessDeniedError access denied to alice connecting to one-auth:0@default@cluster-one
Stack Trace:
        github.com/gravitational/teleport/lib/client/client.go:1633 github.com/gravitational/teleport/lib/client.NewNodeClient
        github.com/gravitational/teleport/lib/client/client.go:1563 github.com/gravitational/teleport/lib/client.(*ProxyClient).ConnectToNode
        github.com/gravitational/teleport/lib/client/api.go:1451 github.com/gravitational/teleport/lib/client.(*TeleportClient).ConnectToNode
        github.com/gravitational/teleport/lib/client/api.go:1525 github.com/gravitational/teleport/lib/client.(*TeleportClient).runShellOrCommandOnSingleNode
        github.com/gravitational/teleport/lib/client/api.go:1408 github.com/gravitational/teleport/lib/client.(*TeleportClient).SSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:2995 main.onSSH.func1.1
        github.com/gravitational/teleport/lib/client/api.go:504 github.com/gravitational/teleport/lib/client.RetryWithRelogin
        github.com/gravitational/teleport/tool/tsh/tsh.go:2994 main.onSSH.func1
        github.com/gravitational/teleport/tool/tsh/tsh.go:2907 main.retryWithAccessRequest
        github.com/gravitational/teleport/tool/tsh/tsh.go:2993 main.onSSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:1086 main.Run
        github.com/gravitational/teleport/tool/tsh/tsh.go:482 main.main
        runtime/proc.go:250 runtime.main
        runtime/asm_amd64.s:1598 runtime.goexit
User Message: access denied to alice connecting to one-auth:0@default@cluster-one
```

After:
```
$ tsh ssh -d alice@one-auth
...<omitted>...
2023-02-17T16:42:29-08:00 DEBU [TSH]       Not attempting to automatically request access, reason: Resource Access Requests require usable "search_as_roles", none found for user "nklaassen" tsh/tsh.go:2922

ERROR REPORT:
Original Error: *trace.AccessDeniedError access denied to alice connecting to one-auth:0@default@cluster-one
Stack Trace:
        github.com/gravitational/teleport/lib/client/client.go:1633 github.com/gravitational/teleport/lib/client.NewNodeClient
        github.com/gravitational/teleport/lib/client/client.go:1563 github.com/gravitational/teleport/lib/client.(*ProxyClient).ConnectToNode
        github.com/gravitational/teleport/lib/client/api.go:1451 github.com/gravitational/teleport/lib/client.(*TeleportClient).ConnectToNode
        github.com/gravitational/teleport/lib/client/api.go:1525 github.com/gravitational/teleport/lib/client.(*TeleportClient).runShellOrCommandOnSingleNode
        github.com/gravitational/teleport/lib/client/api.go:1408 github.com/gravitational/teleport/lib/client.(*TeleportClient).SSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:2997 main.onSSH.func1.1
        github.com/gravitational/teleport/lib/client/api.go:504 github.com/gravitational/teleport/lib/client.RetryWithRelogin
        github.com/gravitational/teleport/tool/tsh/tsh.go:2996 main.onSSH.func1
        github.com/gravitational/teleport/tool/tsh/tsh.go:2907 main.retryWithAccessRequest
        github.com/gravitational/teleport/tool/tsh/tsh.go:2995 main.onSSH
        github.com/gravitational/teleport/tool/tsh/tsh.go:1086 main.Run
        github.com/gravitational/teleport/tool/tsh/tsh.go:482 main.main
        runtime/proc.go:250 runtime.main
        runtime/asm_amd64.s:1598 runtime.goexit
User Message: access denied to alice connecting to one-auth:0@default@cluster-one
```
2023-02-21 17:36:02 +00:00
Edward Dowling d29a9c62c6 Change init logger to include timestamp for debug level (#21732)
* Change init logger to include timestamp for debug level

* Disable timestamps for tsh in dev mode
2023-02-17 16:48:18 +00:00
STeve (Xin) Huang a8a069a93e Add athena-jdbc format to tsh proxy aws (#21811)
* AWS access: Athena JDBC support

* capture SplitHostPort error
2023-02-17 14:43:14 +00:00
Edward Dowling a82b267c87 Add check on apiserver upserUser to ensure all roles on user exist (#21659)
* Add check on apiserver upserUser to ensure all roles on user exist

* Move role check on upsert user to client side

* Move user role checks on upsert to tctl

* Add err to message about missing role
2023-02-16 16:25:14 +00:00
Noah StrideandAlan Parra f3ba5750a8 Make tctl nodes add / tctl tokens add use CreateToken RPC (#21189)
* Start removing generateToken

* Refactor `tokens add` to use `CreateToken` RPC

* Correct deprecation version

* Remove calls to GenerateToken

* Start tests for token crud

* Allow user role rules to be provided wth CreateUserAndRole helper

* Add TestCreateToken to tls_test

* Add TestUpsertToken

* Add GetTokens test

* Add TestGetToken

* Add test for DeleteToken RPC

* Dedupe error assertions

* Add support for emitting trusted cluster token creation events to Create/UpsertToken

* Fix imports

* Change parameter order to appease linter

* Fix broken token expiry test

* Fix token expiry time for TestAuth_RegisterUsingToken

* Remove unnecessary cleanup

* Apply suggestions from code review

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

* Change test comment from deprecation notice

* `make gprc` after code review changes

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Rename tests

* Update lib/auth/tls_test.go

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

* More test cases for GetTokens

* Improve message on duplicate token

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-02-16 09:36:55 +00:00
Jonathan Lassoff 2ebdd0c8bf tsh/tctl: Improve error message when using --identity without a proxy or auth server (#21124)
Fixes #19293
The error message "missing parameter hostname" wasn't very clear what hostname
was missing. Fail faster further up the stack and print a better error message
explaining what is happening.

This applies some checks aroung argument parsing while also adding some
belt-and-suspenders validation into `NewClientStoreFromIdentityFile`
2023-02-15 19:43:17 +00:00
e30ebcf023 Allow a tsh aws to proxy any command (#19941)
* Allow a tsh aws user to specify a command to run with the AWS environment variables set

* Update name of the argument per feedback

* Address nits

---------

Co-authored-by: Daniel Ballenger <daniel@otter.ai>
Co-authored-by: Marek Smoliński <marek@goteleport.com>
Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
2023-02-14 21:44:41 +00:00
Tiago Silva 263884dab0 Change error response formatting for "/version" endpoint (#21289)
* Change formatting for "/version" endpoint

This PR changes the formatting for "/version" endpoint since Kubernetes
clients do not expect a JSON response on that endpoint.
This PR returns the error message directly into the body without any
formatting so that `kubectl` is able to present the desired error.

```
kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.25.4
Kustomize Version: v4.5.7
Error from server (InternalError): an error on the server ("this user cannot request kubernetes access, has no assigned groups or users") has prevented the request from succeeding
```

Fixes #20900

* change message wording

* add validation when generating kube creds

* fix typo
2023-02-14 20:44:54 +00:00
Tiago Silva 956dfd24dc Remove required cluster name when using tsh kube login --all (#21746)
This PR removes the requirement of providing a cluster name to login
into if the user provides the `--all` flag.

If the user does not provide a cluster, Teleport does not select any
cluster by default.

Fixes #21713
2023-02-13 21:10:56 +00:00
Alan Parra 8c84d0a766 Add device lock support (#21667)
* Add Device to LocketTarget proto

* Refactor LockTarget.Match

* Test lib/srv.ComputeLockTargets

* Test lib/services.LockTargetsFromTLSIdentity

* Test device lock during cert issuance

* Add device lock targets where applicable

* Add --device to `tctl lock`

* Fix godocs (unrelated)

* Review: Drop redundant comments
2023-02-13 14:46:11 +00:00
Gavin Frazar 5c752c4df8 Fixup teleport db configure create (#20968)
* add missing flags
* fix config generation bugs
* always wrap generated strings value in quotes
* parse and check generated config
* update tests for db agent config gen
2023-02-11 00:54:07 +00:00
Zac Bergquist c924be5c6d Refer to tsh apps subcommand (#21431)
The `tsh appps` family of commands is aliased to `tsh apps`, so both
invocations work correctly. The command itself is defined as `tsh apps`,
so this is what appears in the help message.

Update references to `tsh app` to recommend `tsh apps` instead so that
there isn't confusion when browsing `tsh help` and looking for a missing
`app` subcommand.

Fixes #21367
2023-02-10 21:40:55 +00:00
Noah Stride 0181993047 Allow the creation and usage of expiryless ProvisionTokens (#21133)
* Allow the creation and usage of expiryless tokens

* Tidy up loose ends

* Fix imports

* Add tests for changes to expiryless behaviour

* Use new RPCs for new expiryless behaviour

* Add tests for new RPCs

* Remove unused import

* Recreate behaviour for tokens expiring in past

* Missing NoError check int ests

* Correctly americanize behavior
2023-02-10 13:45:36 +00:00
Gavin Frazar 44b3c5d60c disable MFA TTL limit for local proxy tunnel (#21200)
* require local proxy tunnel when mfa is required
* local proxy tunnel cert reissue with RequesterName
* add test for db mfa session TTL adjustment
2023-02-09 21:27:21 +00:00
Andrew Burke 732594f191 Add Azure join method (#20019) 2023-02-08 17:21:11 +00:00