Commit Graph
53 Commits
Author SHA1 Message Date
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
Gavin Frazar 3df617d989 fix tsh db connect with hardware backed key (#20806)
* Check key policy in tsh db connect flow

* Load key policy from identity file into temp profile
2023-01-30 23:29:47 +00:00
Marek Smoliński 978fd03a22 Don't use the KubeSNIPrefix SNI TLS Routing Prefix (#20277)
* Don't use the KubeSNIPrefix SNI TLS Routing Prefix

* update ut

* update

* update

* Update

* update
2023-01-30 10:15:18 +00:00
Tiago Silva 40861809a6 Add RoleV6 resource type (#19324)
This PR includes a new Role resource version that is compatible with V5 spec.

The new resource introduces the `kubernetes_resources` definition that allows operators to limit the Kubernetes resources that each member can access. The `kubernetes_resources` entries must follow the following format: `{"kind":"<kind>", "namespace":"<namespace>","name":"<pod>"}`. Currently, it only supports objects of `kind` `pod`. Valid examples `<namespace>/<name>:
- `*/*`: matches all pods in all namespaces.
- `default/*`: matches all pods in the `default` namespace.
- `*/nginx-*`: matches every pod prefixed with `nginx-` in every namespace.

For older resource versions - V5, V4, V3 - `kubernetes_resources` is automatically populated with `{"kind":"pod","namespace":"*","name":"*"}` to keep compatibility. For the newest version, it's mandatory to define its value otherwise access to pods will be denied.

Part of #18434
2023-01-05 09:58:12 +00:00
Jakub NyckowskiandRoman Tkachenko 0df39758a0 Refactor OpenSSH config generation (#17138)
Unify OpenSSH config generation between tsh and tbot.

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-10-07 18:11:57 +00:00
rosstimothy dcf6b07d07 Enforce max connection limits for label based tsh (#16241)
Label based tsh, `tsh ssh root@foo=bar uptime`, may potentially match
a number of nodes that exceeds the users `max_connections` limit.
However, tsh would blindly connect to all matching nodes and execute
the provided command simultaneously. This results in a number of
commands to fail because the user has too many concurrent sessions
open.

Now that #15641 has introduced running multiple commands inside
an `errgroup.Group` we can adjust the limit such that tsh will
never exceed the users `max_connections` limit. In order to
prevent label based tsh from consuming all of a users connections,
the `errgroup.Group` limit is set to half of `max_connections`.

Closes #4626
2022-09-22 19:52:08 +00:00
Anton Miniailo 1e5826d16c Make tctl auth sign to write out kube TLS server name if TLS routing is enabled (#15536)
* Make tctl write out kube tls server name if tls routing is enabled

Fixes #14489

* Extract kube TLS name generation function to shareable location

We want tctl to be able to use this function as well, so we're locating it
in a place where both tctl and tsh can use it.
Also changing input parameter to k8s host, since it doesn't really care
 about port number.
2022-08-17 22:36:51 +00:00
Zac Bergquist d1c6b0618e Fix lint warnings (#15312)
Mostly duplicated imports and redundant types in struct literals.
2022-08-08 20:20:29 +00:00
Matheus bf5eafebee Improve tsh play UX (#14879)
* Return user-friendly error on session not found

* Check if session is desktop before playing it and return user-friendly error message
2022-07-28 12:37:23 +00:00
Russell Jones f87c2b11c2 Refactor tests under client package.
Refactored all tests under "lib/client" to use testify instead
of gocheck.
2022-07-15 08:09:08 -07:00
Noah Stride e8cfcc78fa Improve tsh login handshake error messaging (#13836)
* improve principal mismatch error on unmultiplexed tsh login when `public_addr` empty

* Address Pr feedback
2022-07-11 18:17:31 +00:00
rosstimothy e5c745f331 Add manual tracing instrumentation to tsh (#13204)
Create spans for all public facing TeleportClient,
ProxyClient, and NodeClient methods. This makes
correlating spans easier to reason about when
looking at `tsh` traces. As a result of creating
spans, some additional context propagation is
required as well to ensure that spans are linked
properly.

This also removes the unused `quiet` argument from
`ConnectToCluster`. It's usage was not consistent
by existing callers, and it was ignored, so in order
to avoid confusion in future calls, it was removed.

#12241
2022-06-11 15:34:40 +00:00
Tim BuckleyandKrzysztof Skrzętnicki 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
Lisa Kim ad1f826824 [forward port] Grammar fixes and updating a test (#11016) (#12115)
Addressing minor code reviews received on a backport
2022-04-20 22:06:41 +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
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 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Trent Clarke b4c3b16d03 More review additions 2021-05-14 16:09:48 -07:00
Trent Clarke eea8dde38e Addressing review feedback 2021-05-14 16:09:48 -07:00
Trent Clarke 7fb9cb15f0 Address review feedback 2021-05-14 16:09:48 -07:00
Trent Clarke 17ffe33821 Adds concurrent default-port selection to tsh
Addresses issue #4924

If a default Web Proxy port is not specified by the user, either via
config or on the command line, `tsh` defaults to `3080`. Unfortunately
`3080` is often blocked by firewalls, leading to an unacceptably long
timeout for the user.

This change adds an RFC8305-like default-port selection algorithm,
that will try multiple ports on the supplied host concurrently and
select the most reponsive address to use for Web Proxy traffic. I
have included the standard HTTPS port (443) in the defaulut set,
and this can be easily expanded if other good candidates come along.

If the port selection fails for any reason, `tsh` reverts to the
legacy behaviour of picking `3080` automatically.
2021-05-14 16:09:48 -07:00
Roman Tkachenko d67e11ff2d Adding postgres_public_addr and mysql_public_addr (#6426) 2021-04-21 19:52:52 -07:00
Andrew Lytvynov 205e811c4d Fix infinite recursion in client.Config.WebProxyHostPort
Also fix the very lax `utils.ParseAddr` logic for addresses without `://`.
Just noticed this during unrelated code review, it's not a known bug.
2021-04-14 23:30:35 +00:00
Andrej Tokarčík 52dfeec63e Cache per-cluster SSH certificates under ~/.tsh (#5938)
```diff
 ~/.tsh/
 └── keys
    ├── one.example.com            --> Proxy hostname
    │   ├── certs.pem              --> TLS CA certs for the Teleport CA
    │   ├── foo                    --> RSA Private Key for user "foo"
    │   ├── foo.pub                --> Public Key
-   │   ├── foo-cert.pub           --> SSH certificate for proxies and nodes
    │   ├── foo-x509.pem           --> TLS client certificate for Auth Server
+   │   ├── foo-ssh                --> SSH certs for user "foo"
+   │   │   ├── root-cert.pub      --> SSH cert for Teleport cluster "root"
+   │   │   └── leaf-cert.pub      --> SSH cert for Teleport cluster "leaf"
```

When `-J` is provided, this also loads/reissues the SSH cert for the cluster associated with the jumphost's certificate. Fixes #5637.
2021-03-29 14:14:31 -07:00
Andrew Lytvynov fc1c1dbd14 Move all utils.InitLoggerForTests calls to TestMain
This prevents data races between changing the standard logger and it
acutally being used.
2021-02-23 18:04:55 -08:00
Brian Joerger 3c3ce160d9 Move API types and functionality from lib/services to api/types. (#5143) 2021-01-11 10:02:34 -08:00
a-palchikov 7c87576a8b flaky tests: consistent logging (#4849)
* Update logrus package to fix data races
* Introduce a logger that uses the test context to log the messages so they are output if a test fails for improved trouble-shooting.
* Revert introduction of test logger - simply leave logger configuration at debug level outputting to stderr during tests.
* Run integration test for e as well
* Use make with a cap and append to only copy the relevant roles.
* Address review comments
* Update integration test suite to use test-local logger that would only output logs iff a specific test has failed - no logs from other test cases will be output.
* Revert changes to InitLoggerForTests API
* Create a new logger instance when applying defaults or merging with file service configuration
* Introduce a local logger interface to be able to test file configuration merge.
* Fix kube integration tests w.r.t log
* Move goroutine profile dump into a separate func to handle parameters consistently for all invocations
2020-12-07 15:35:15 +01:00
Andrew Lytvynov 6746213886 Preserve SSH signing alg for existing CAs
Store the signing algorithm along the CA private key. When reading old
CAs that don't have it set, default to UNKNOWN proto enum which
corresponds to the old SHA1-based signing alg.

The only time you get a SHA2 signature is when creating a fresh cluster
and generating a new CA. This can be disabled in the config.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 88326d4e98 Support port-only spec in dynamic port forwarding
Example command: "tsh ssh -D 8080 foo@bar".
OpenSSH supports this, but tsh would fail to parse it.

Also add a few other test cases for other specs.
2020-06-24 21:17:10 +00:00
Russell Jones 9c4e556502 Fixed regressions in "tsh login <clusterName>".
Fixed regressions in how the cluster name was set in the profile when
doing "tsh login <clusterName>". The following examples illustrate
expected behavior.

Suppose root cluster is example.com and the leaf cluster is
leaf.example.com.

* "tsh login" will update profile to example.com.
* "tsh login example.com" will update profile to example.com.
* "tsh login leaf.example.com" will update profile to
  leaf.example.com.
* "tsh login invalid.example.com" will return an error.

Note: The profile is only updated when a identity flag is NOT provided.
This means the following command will NOT update the profile:

tsh --proxy=example.com login --out=certs.pem leaf.example.com
2020-04-29 10:49:23 -07:00
Alexander Klizhentas 8e0e4c2eff Fix ParseLabelSpec to support unicode characters (#2673) 2019-04-23 18:02:37 -07:00
Russell Jones f603bd1c5a Refactoring of SOCKS5 server. 2018-10-15 11:52:02 -07:00
Steven Aerts e1d896621f FIX 1693: SOCKS5 dynamic port forwarding
Implements the -D flag of ssh, but only with a SOCKS5 proxy.
OpenSSH also supports a SOCKS4 proxy.

This commit also fixes a bug in the server which prevented it from
forwarding raw IPv6 sockets, as the addresses were incorrectly
escaped.
2018-10-15 11:52:02 -07:00
Russell Jones 97074076cb Split public_addr into web_proxy_addr and ssh_proxy_addr. 2018-08-31 16:33:54 -07:00
Sasha Klizhentas 1f3b4e2c96 Kubernetes configuration, fetch proxy settings.
This commit moves proxy kubernetes configuration
to a separate nested block to provide more fine
grained settings:

```yaml
auth:
  kubernetes_ca_cert_path: /tmp/custom-ca
proxy:
  enabled: yes
  kubernetes:
    enabled: yes
    public_addr: [custom.example.com:port]
    api_addr: kuberentes.example.com:443
    listen_addr: localhost:3026
```

1. Kubernetes config section is explicitly enabled
and disabled. It is disabled by default.

2. Public address in kubernetes section
is propagated to tsh profile

The other part of the commit updates Ping
endpoint to send proxy configuration back to
the client, including kubernetes public address
and ssh listen address.

Clients updates profile accordingly to configuration
received from the proxy.
2018-08-06 11:57:36 -07:00
Alexey Kontsevoy 57b2789a49 http file transfer 2018-07-12 14:58:37 -04:00
Sasha Klizhentas e570b24eeb Update tsh login to select clusters.
The following changes have been introduced
to tsh login behavior:

1. tsh login now accepts cluster name
as an optional positional argument:

$ tsh login clustername

2. If tsh login is called without arguments
and the current credentials are valid,
tsh login now prints status, previous behavior
always forced login:

$ tsh login
... print status if logged in...

2. If tsh login is called with the proxy
equal to current, tsh login selects cluster,
otherwise it will re-login to another proxy:

$ tsh login one
... selected cluster one

$ tsh login two
... selected cluster two

$ tsh login --proxy=example.com three
... selected cluster three because
proxy is the same

$ tsh login --proxy=acme.example.com four
...will switch to proxy acme.example.com
and cluster four
2018-06-25 18:28:46 -07:00
Ev Kontsevoy cdfb15fd82 scp compatibility improvements 2017-06-09 10:48:21 -07:00
Ev Kontsevoy 1755870f27 Logging fixes and more
- Fixed logging. Closes #875
- Removed dead code
- Fixed 'exec' tests on OSX
2017-03-29 17:12:50 -07:00
Ev Kontsevoy 7964bfc54e Client profiles for TSH 2016-10-22 12:54:16 -07:00
Ev Kontsevoy 79152b2d08 Minor code refactoring
Moved code which parses OpenSSH-style port forwarding spec (-L flag)
from tsh/main into lib/client
2016-08-25 22:12:08 -07:00
Ev Kontsevoy 3060cf2650 Adds the ability to specify non-standard HTTPS proxy port
This commit fixes #491

Now `tsh` accepts `--proxy=host:port,port` allowing to specify two
ports, one for SSH and another for HTTPS.
2016-08-05 15:46:12 -07:00
Ev Kontsevoy cca475924b tsh now respects --user flag
Fixes #392
Fixes #396

Teleport now respects `--user` flag and, if --user is specified,
forces the certificate to belong to the given user.

This changes the file structure in `~/.tsh` directory. If a user logs in
under two different accounts, say "ekontsevoy" and "vince", it looks
like this:

```
~/.tsh/
├── keys
│   └── localhost
│       ├── ekontsevoy.cert
│       ├── ekontsevoy.key
│       ├── ekontsevoy.pub
│       ├── vince.cert
│       ├── vince.key
│       └── vince.pub
└── known_hosts

```

Also, to make tests more believable, I have added 3 more pre-generated
keys to 'testauthority' fixture, so instead of returning the same key
over and over, it now returns a random 1 of 4
2016-05-06 21:57:39 -07:00
Ev Kontsevoy 5e80c2d662 Simple filesystem-based keystore for TSH
Started re-writing Teleport client keystore. From a buggy JSON-to-file
to a standard, directory/filebased API behind a standard interface to
allow for alternative implementations.

```
~/.tsh/
└── sessions
    └── localhost
        ├── cert
        ├── key
        └── pub
```
2016-04-18 22:56:21 -07:00
Alexander Klizhentas 89673725e3 Few changes:
- added getProxyLogin() method to TeleportClient. It now uses the
  default approved principal to login into proxy or defaults to "host
  login"

- covered a bit more of TeleportClient functionality with basic unit
  tests
2016-04-17 20:46:34 -07:00
Ev Kontsevoy c07fcc60e0 Bugfix: teleport client was ignoring proxy port setting
Teleport client API `Config` struct in lib/client/api.go has a setting
`ProxyHost` with a comment saying "with optional ":port"

That :port part was ignored, so a client could not connect to proxies
that listen on non-default ports.
2016-04-05 17:05:01 -07:00
Ev Kontsevoy 8e1cdd8f0c scp 'destination' parameter did not allow for username spec
Fixes #318
2016-04-01 15:57:24 -07:00
Ev Kontsevoy 377a8de0cb Added --labels flag to teleport start command 2016-03-14 17:25:00 -07:00
Ev Kontsevoy f19ccc13ad Edited & cleaned up comments 2016-03-14 15:49:27 -07:00