Commit Graph
79 Commits
Author SHA1 Message Date
Brian JoergerandJakub Nyckowski d73949cdf5 Fix identity file relogin issue (#20452)
* Set SkipLocalAuth on identity file use; Simplify logic for SkipLocalAuth.

* Fix TrustedCertsFromCACerts to work with known hosts without proxy host set in host name; Fix HostKeyCallback for keys.

* Add regression test where known hosts are not written with proxy host.

* Fix client key default host key callback.

* Return empty list, not not found error, when there are no trusted certs.

* Restore option to filter trusted host keys in host key callback.

* Update lib/client/identityfile/identity_test.go

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

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
2023-01-30 18:07:35 +00:00
Brian Joerger 2922ad009a Allow non-standard agent keys. (#18449) 2023-01-13 17:59:51 +00:00
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00
Brian Joerger 3633b54723 cluster specific ssh-agent keys (#14677) 2022-11-18 00:52:56 +00:00
Brian Joerger 66e71e4a7b Update LocalKeyAgent.Signers to return all available signers (#17610) 2022-11-16 19:46:03 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +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
Andrew Burke db7fdff809 Add option for tsh to load all CAs (#15178)
This change adds an option to let tsh load CAs for all clusters when logging in, instead of just the current cluster.
2022-10-05 18:29:09 +00:00
Brian Joerger 4c0a6ff5b1 tsh PIV login integration (#15335)
* Add Yubikey PrivateKey implementation for use by Teleport clients.

  - Add yubikey login logic, reusing previously stored private keys.

  - Fix identity file decoding with PIV keys, which sign ecdsa certificates.

  - Add libpcsclite-dev pre-req for building on linux.

  - Remove unnecessary keys.Signer interface and move its functionality to keys.PrivateKey.

  - Move retry and jitter utils to new api/utils/retryutils package.
2022-09-23 19:44:10 +00:00
Alan Parra 65e0116512 Remove HOTP support (#16579)
While looking up github.com/gokyle/hotp I found some old deprecation warnings
and decided to address them.

* Remove HOTP support
* Update comment on checkOTP
* Remove OTPType
* Remove a few more HOTP references
2022-09-21 17:50:33 +00:00
Brian Joerger 3a5a285883 Generalize private keys in tsh (PIV integration) (#15334)
Primary Changes:
 - Remove reliance on Private Key PEM:
 - Update native and keygen packages to return PrivateKey instead of PEM key
 - Add new PrivateKey interface which implements crypto.Signer
 - Replace PEM encoded private key usage where possible
 - Replace calls to tls.(Load)X509KeyPair with keys.(Load)X509KeyPair in
client packages

Minor Changes:
 - Remove unused agent.AddedKey return from LoadKey
 - Simplify sshutils and removed unused code paths
 - Add ecdsa and ed25519 key support
2022-08-25 23:26:44 +00:00
Roman Tkachenko ec512bafa4 Implement proxy templates (#12848) 2022-06-07 00:06:52 +00:00
Alexey Kontsevoy 4d0c0b2c84 teleterm (alpha) 2022-04-01 13:02:56 +02:00
Marek Smoliński fbd5a2aafd Fix tsh tctl do not load all CAS (#9357) 2022-01-31 13:35:15 +01: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
Marek Smoliński c335534e02 Fix tsh ssh proxy (#8826) 2021-11-05 13:30:10 +01:00
Roman Tkachenko e1c3f80aa0 Fixes for cert checker and Postgres config builder (#8251) 2021-09-17 13:28:40 -07:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Tim BuckleyandRoman Tkachenko 9a9562ba35 Add tsh config helper to generate OpenSSH client configuration (#7437)
* Add `tsh config ssh` helper to generate OpenSSH client configuration

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

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

* Fix broken link to Trusted Clusters documentation

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

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

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

* Fix known_hosts_migrate_test after rebase

* First pass at review feedback

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

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

* Ensure top-level hostnames never match wildcard patterns

* Add additional host count check to `canPruneOldHostsEntry`.

* Replace excess call to `isOldStyleHostsEntry` with documented invariant

* Trim trailing dots on absolute hostnames in `matchesWildcard`

Co-authored-by: Roman Tkachenko <roman@gravitational.com>
2021-07-22 13:40:02 -07:00
Trent Clarke 2f51af0e04 Delete user k8s, etc. certificates on re-issue (#6492)
Delete user k8s, etc. certificates on re-issue

Prior to this change, user certificates for services like kubernetes were
preserved across a certificate re-issue. This led to issues where elevated
privileges granted by an access request were not applied to the service
certificates as they were not updated during the reissue process.

This patch changes the certificate re-issue process such that:
 * certificates for services (like Kuberenetes) are not preserved
   over a certificate re-issue. It is expected that they will be recreated
   on the first access to the service in question, and
 * the local keystore files for these certificates services are explicitly
   deleted so that the now-invalid cached certificates are not returned
   on keystore queries.

See-Also: #5047
2021-05-05 19:20:12 -07:00
Andrew Lytvynov b8fbb2d1e9 mfa: cancel TOTP prompt if U2F was used (#6542)
Implement context-based cancellation in `/lib/utils/prompt`, for MFA
prompts.

This fixes the following scenario:
```sh
User has both OTP and U2F devices registered.
$ tsh mfa ls
Name  Type Added at                      Last used
----- ---- ----------------------------- -----------------------------
otp   TOTP Wed, 21 Apr 2021 19:41:44 UTC Wed, 21 Apr 2021 19:44:32 UTC
usb-a U2F  Wed, 21 Apr 2021 19:44:34 UTC Wed, 21 Apr 2021 19:44:34 UTC

Add a new OTP device, using existing U2F device:
$ tsh mfa add
Choose device type [TOTP, U2F]: totp
Enter device name: otp2
Tap any *registered* security key or enter a code from a *registered* OTP device: <tap> # <- First OTP prompt here
Open your TOTP app and create a new manual entry with these fields:
Name: awly@localhost:3080
Issuer: Teleport
Algorithm: SHA1
Number of digits: 6
Period: 30s
Secret: 3UD42X2NN7EEZ6LUPG6NFMNOLDY6AJTS

Once created, enter an OTP code generated by the app: 607738 # <- Second OTP prompt here
MFA device "otp2" added.
```

Before this PR, the first OTP prompt (for `*registered* device`) would
hang in the background. The OTP code from the newly-registered device is
prompted later, but any text written ends up going to the first prompt.

After this PR, the first prompt is canceled and the code from a new
device goes to the second prompt as intended.

Note: this is implemented using pure Go code (background goroutine
consuming `os.Stdin`) rather than syscalls (e.g. `poll` or `select`)
for portability.
2021-04-29 11:22:11 -07:00
Andrew Lytvynov 1e7a369b26 web: fix AccessRequest loading on user cert reissue (#6264)
Load access requests from SSH cert instead of the profile. The profile
only exists on CLI clients, but not in the proxy.

Note: theoretically, SSH cert may be missing in some cases for CLI
clients. We should eventually encode access requests in TLS certs too,
which are always present.
2021-04-06 16:20:04 -07:00
Andrej Tokarčík e525c94e1c Delete obsolete stored keys in LocalKeyAgent.AddKey (#6251)
* Delete obsolete stored keys in LocalKeyAgent.AddKey

* Don't panic when no stored key found
2021-04-01 09:53:15 -07: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
Brian Joerger 2beb991598 API client connection overhaul (#5625)
* Added support for connecting API client through tunnel proxy and web proxy addresses (with identity file).

* Added concurrent dialing logic to dial several possible dialing combinations and seamlessly return the first client to connect.
2021-03-23 14:39:20 -07:00
xacrimon d162b02060 implement rfd 18 2021-03-17 19:04:06 +01:00
Andrew Lytvynov b092fa9143 When exporting a kubeconfig, overwrite the target file (#5297)
* When exporting a kubeconfig, optionally overwrite the target file

Running `tctl auth sign ---out=filepath` or `tsh login --out=filepath`
might overwrite the target `filepath` regardless of its existing
contents.

Make the tools prompt the user before overwriting (by default) and
provide a flag to always force the overwrite (for automation).

Without overwrites, writing kubeconfig could fail if parsing the
existing file as a kubeconfig fails.
2021-01-27 10:00:52 -08:00
Andrew Lytvynov 52c52c7e20 Add "tsh kube" commands (#4769)
1. `tsh kube clusters` - lists registered kubernetes clusters
   note: this only includes clusters connected via `kubernetes_service`

2. `tsh kube credentials` - returns TLS credentials for a specific kube
   cluster; this is a hidden command used as an exec plugin for kubectl

3. `tsh kube login` - switches the kubectl context to one of the
   registered clusters; roughly equivalent to `kubectl config
   use-context`

When updating kubeconfigs, tsh now uses the exec plugin mode:
https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins
This means that on each kubectl run, kubectl will execute tsh with
special arguments to get the TLS credentials.

Using tsh as exec plugin allows us to put a login prompt when certs
expire. It also lets us lazy-initialize TLS certs for kubernetes
clusters.
2020-11-11 22:22:01 +00:00
Sasha Klizhentas ce8c83d722 Adds support for loading tctl creds from ~/.tsh profile
This commit fixes #4439
2020-11-09 20:24:09 -08:00
Andrew Lytvynov 4f2528b568 tsh: create an in-memory agent when using identity file
The agent might be needed for forwarding, when cluster is in proxy
recording mode. In proxy recording mode agent forwarding is mandatory.
2020-08-12 15:51:31 +00:00
Andrew Lytvynov d3260103ff Keep using the default (ssh-rsa) signing algo for SSH handshakes
x/crypto/ssh does not support SHA2 signatures for handshakes yet. We'll
keep using SHA2 for cert signing, but handshakes have to wait.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov a32ed8b118 Support RSA certificates in sshutuils.AlgSigner
Previously we matched the public key type for only plain public key
authn.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 133d3ea047 Add options to skip connecting to ssh-agent from tsh
In particular, gpg-agent doesn't support SSH certificates, so writing to
it is potentially disruptive for the user: https://dev.gnupg.org/T1756

User has two options:
- pass `--no-use-local-ssh-agent` for individual calls to tsh
- set `TELEPORT_USE_LOCAL_SSH_AGENT=false` to make it permanent

Fixes #3169
2020-05-19 20:04:59 +00:00
Andrew Lytvynov 4b5cd7e68f gosimple: simplify or remote return statements 2020-05-15 16:32:45 +00:00
Andrew Lytvynov 2a93910fa2 gosimple: remove unnecessary blank identifiers in for loops 2020-05-15 16:32:45 +00:00
Andrew Lytvynov 64edb20ea1 Load trusted TLS CA with keys in local keystore
Local keystore records trusted TLS CA certs in `<host>/certs.pem`.
When loading client.Key, also load the TLS CA cert for
`key.TrustedCertificates` field.

Without this field, `kubeconfig.Update` called by tsh can't populate the
CA cert in kubeconfig, which causes x509 validation errors with kubectl.
2020-04-24 18:07:20 +00:00
Russell Jones 630d2bf266 Only check certificate algorithms in FIPS mode.
Update utils.CertChecker to only check key and certificate algorithms
when in FIPS mode. Otherwise accept keys and certificates generated with
any algorithm.
2019-07-26 13:25:18 -07:00
Russell Jones ae074ede36 Always validate certificate (or key) algorithm.
Added utils.CertChecker that wraps a ssh.CertChecker. The new
certificate checker first checks if the certificate is a valid
certificate for Teleport. At the moment that is 2048-bit RSA then calls
the underlying certificate checker to perform the requested validation.
2019-03-19 17:47:53 -07:00
Russell Jones 7a62b25921 Validate host certificates in both tsh as well as the recording proxy.
Add IP addresses to host certificate.
2018-12-12 16:33:03 -08: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 cece4be212 Initial implementation of Kubernetes support
This issue updates #1986.

This is intial, experimental implementation that will
be updated with tests and edge cases prior to production 2.7.0 release.

Teleport proxy adds support for Kubernetes API protocol.
Auth server uses Kubernetes API to receive certificates
issued by Kubernetes CA.

Proxy intercepts and forwards API requests to the Kubernetes
API server and captures live session traffic, making
recordings available in the audit log.

Tsh login now updates kubeconfig configuration to use
Teleport as a proxy server.
2018-06-03 12:55:13 -07:00
Russell Jones 5eddc324ee Unload keys from agent upon logout. 2018-03-09 22:41:52 +00:00
Russell Jones 07e90d0ad6 LocalKeyAgent only loads keys for a user logged into a proxy. 2018-01-20 00:40:38 +00:00
Sasha Klizhentas 0130c6aa41 Mutual TLS Auth server and clients.
This commit introduced mutual TLS authentication
for auth server API server.

Auth server multiplexes HTTP over SSH - existing
protocol and HTTP over TLS - new protocol
on the same listening socket.

Nodes and users authenticate with 2.5.0 Teleport
using TLS mutual TLS except backwards-compatibility
cases.
2017-12-27 11:37:19 -08:00
mricher b58cb051e8 Correct various typos
This was fixed running the `misspell` linter in fix mode using
`gometalinter`. The exact command I ran was :
```
gometalinter --vendor --disable-all -E misspell --linter='misspell:misspell -w {path}:^(?P<path>.*?\.go):(?P<line>\d+):(?P<col>\d+):\s*(?P<message>.*)$' ./...
```

Some typo were fixed by hand on top of it.
2017-10-20 10:20:26 +02:00
Sasha Klizhentas 8b81a0c384 Migrate to golang/dep for dependency management
Update following packages:

* Replace Sirupsen/log with sirupsen/log everywhere
* Update etcd client to 3.2.4
* Update docker/term to moby/term
* Update kr/pty to v1.0.0 release
* Update K8s client to 2.0
2017-08-22 15:30:30 -07:00
Ev Kontsevoy 84bb78ad2c Finished implementation of --out flag for tsh login
* Hooked up `MakeIdentityFile()` with `tsh.onLogin()`
* Made sure that `--out` flag prevents from writing into `~/.tsh`

Closes #1127
2017-07-10 22:27:37 -07:00
Ev Kontsevoy 63cef003d6 Code review edits
key-agent changes:

tsh now ignores public keys loaded from the SSH key agent unless they
are certificates. this fixes the problem of 'host auth' callback being
called for 3rd party public keys in the SSH-agent (and tsh had no choice
but to prompt user if he wanted to add thoses hosts to known_hosts file)

tctl auth changes:

`tctl auth` now outputs to stdout by default. If you set -o to a file,
it will use that file instead. Getting rid of -o was not possible
because it's still useful if --format is set to `dir` (OpenSSH
compatible output).

other changes:

- added more detailed comments in a few places
- restored error handling logic
2017-06-12 13:12:17 -07:00
Ev Kontsevoy 3ff5820b67 Covered host authentication with tests 2017-06-11 19:22:23 -07:00