Commit graph

57 commits

Author SHA1 Message Date
Andrej Tokarčík f4e13ea8f3 Don't defer Close calls on writable files 2021-03-01 22:14:10 +01:00
Roman Tkachenko 8e1865464b
Database access (#5005) 2021-01-14 18:21:38 -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
Andrew Lytvynov 3c94003379 errcheck: fix findings in lib/backend, lib/client 2020-06-01 20:16:16 +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
Sasha Klizhentas 9d2a881f48 Break endless retry loop.
Previous Login code path was calling itself recursively.
In some cases that lead to endless loops with browser
opening up forever.

This commit factors out retry logic to RetryWithLogin
decorator handler that is used by CLI explicitly.

Client code became better as a result as there are no
hidden side effects.
2019-04-25 14:22:49 -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 cea10926a2 Convert "permission denied" errors into trace errors. 2019-02-04 10:10:37 -08:00
Russell Jones 1439408b34 If the server has a public address set, use that as the address instead
of the one passed in by the user.
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 35d4fbbae7 Added "tsh status" command. 2018-04-16 10:23:28 -07: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
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 5d31cc3dd8 Minor changes to tsh, closing two issues
* Closes #1212 (OpenSSH-compatible naming of user identity files stored
  in ~/.tsh/keys

* Closes #1128 (cache location collision when connecting two different
  proxies with similar cluster names)
2017-08-19 15:36:14 -07:00
Ev Kontsevoy 7c358f34cd Changed the default key file permissions
When `tsh login` saves the ephemeral credentials (private key + cert) to
`~/.tsh/keys` it now uses 0600 instead of 0640 for the files and 0700
for `~/.tsh` dir

Fixes #1171
2017-08-09 17:48:32 -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
Russell Jones f62efca23f Added more debug logging for "tsh agent". 2017-03-14 17:07:47 -07:00
Ev Kontsevoy e988630783 tsh logout + tctl create
This commit closes #667

- `tsh logout` will now log you out of everything
- `tctl upsert` has been renamed to `tctl create`
2017-01-29 19:26:27 -08:00
Ev Kontsevoy 4a07dd3e22 Improved CLI login procedure
This commit adds several improvements to how CLI SSH login works

- Validated keys are added to the SSH agent [1]
- tsh will does not verify host keys twice anymore
- error messages for "access denied" look clean now

[1] This is huge. This means that tsh login can "feed" the keys to the
    built-in SSH agents of the OS and OpenSSH can fetch them from there.

QUESTION: why do we even need `tsh agent` option then? ssh-agent is
installed on every Linux/OSX machine.
2017-01-24 19:54:41 -08:00
Ev Kontsevoy 7964bfc54e Client profiles for TSH 2016-10-22 12:54:16 -07:00
Ev Kontsevoy d0e6e42015 Bufix: certificate expiration issue
This commit closes #529

Teleport was using nanoseconds to set the certificate expiration,
instead of milliseconds.

Changes:

- Switched from nanoseconds to seconds
- Switched from UTC to native time (because that's what golang/x/ssh
  uses internally)
2016-09-12 17:55:31 -07:00
Ev Kontsevoy b4a6a4f972 Cleaned up Teleport logging
* Downgraded many messages from `Debug` to `Info`
* Edited messages so they're not verbose and not too short
* Added "context" to some
* Added logical teleport component as [COMPONENT] at the beginning of
  many, making logs **vastly** easier to read.
* Added one more logging level option when creating Teleport (only
  Teleconsole uses it for now)

The output with 'info' severity now look extremely clean.
This is startup, for example:

```
INFO[0000] [AUTH]  Auth service is starting on turing:32829  file=utils/cli.go:107
INFO[0000] [SSH:auth] listening socket: 127.0.0.1:32829  file=sshutils/server.go:119
INFO[0000] [SSH:auth] is listening on 127.0.0.1:32829    file=sshutils/server.go:144
INFO[0000] [Proxy] Successfully registered with the cluster  file=utils/cli.go:107
INFO[0000] [Node] Successfully registered with the cluster  file=utils/cli.go:107
INFO[0000] [AUTH] keyAuth: 127.0.0.1:56886->127.0.0.1:32829, user=turing  file=auth/tun.go:370
WARN[0000] unable to load the auth server cache: open /tmp/cluster-teleconsole-client781495771/authservers.json: no such file or directory  file=auth/tun.go:594
INFO[0000] [SSH:auth] new connection 127.0.0.1:56886 -> 127.0.0.1:32829 vesion: SSH-2.0-Go  file=sshutils/server.go:205
INFO[0000] [AUTH] keyAuth: 127.0.0.1:56888->127.0.0.1:32829, user=turing.teleconsole-client  file=auth/tun.go:370
INFO[0000] [AUTH] keyAuth: 127.0.0.1:56890->127.0.0.1:32829, user=turing.teleconsole-client  file=auth/tun.go:370
INFO[0000] [Node] turing connected to the cluster 'teleconsole-client'  file=service/service.go:158
INFO[0000] [AUTH] keyAuth: 127.0.0.1:56892->127.0.0.1:32829, user=turing  file=auth/tun.go:370
INFO[0000] [SSH:auth] new connection 127.0.0.1:56890 -> 127.0.0.1:32829 vesion: SSH-2.0-Go  file=sshutils/server.go:205
INFO[0000] [SSH:auth] new connection 127.0.0.1:56888 -> 127.0.0.1:32829 vesion: SSH-2.0-Go  file=sshutils/server.go:205
INFO[0000] [Node] turing.teleconsole-client connected to the cluster 'teleconsole-client'  file=service/service.go:158
INFO[0000] [Node] turing.teleconsole-client connected to the cluster 'teleconsole-client'  file=service/service.go:158
INFO[0000] [SSH] received event(SSHIdentity)             file=service/service.go:436
INFO[0000] [SSH] received event(ProxyIdentity)           file=service/service.go:563
```
You can easily tell that auth, ssh node and proxy have successfully started.
2016-09-02 17:28:18 -07:00
Ev Kontsevoy d38fc95d31 Support for non-Teleport servers 2016-06-16 18:58:29 -07:00
Ev Kontsevoy 639d1d0c7e Added support for regular 'known_hosts' 2016-06-16 18:30:02 -07:00
Ev Kontsevoy 86399296f9 No need to read local agent keys if SkipLocalAuth=true
Fixes #445
2016-06-08 11:48:31 -07:00
Ev Kontsevoy 029233b11f tsh logout implementation
Fixes #420
2016-06-01 17:02:39 -07:00
Ev Kontsevoy 8c2ffe940f De-duplication of known_hosts
This commit avoids adding dupes to known_hosts.
Fixes #412
2016-05-17 16:54:38 -07:00
Ev Kontsevoy bd9ad5782c Merge remote-tracking branch 'origin/master' into ev/log 2016-05-08 11:53:57 -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 fc317d781f Integration test for audit log 2016-05-04 16:49:59 -07:00
Ev Kontsevoy 43b224183d Intermediate commit: basic session bookkeeping in SessionLogger 2016-04-26 17:39:46 -07:00
Ev Kontsevoy b8788be4d4 Teleport was constantly asking for username+HOTP+password
The problem was in `time.Unix()` instead of `time.Unixnano()`
I'm not even sure how Unix() got in there...
2016-04-21 19:41:10 -07:00
Ev Kontsevoy e28f21922c Certificate TTL improvements
1. Server now always uses UTC timestamps for certificates it ussues
2. Client doesn't store cert validBefore time in separate files, it
   parses the cert itself.

Fixes #370
2016-04-19 16:09:22 -07:00
klizhentas ce33368e58 fix various 2FA and OIDC login hiccups 2016-04-19 14:56:01 -07:00
Ev Kontsevoy 069b2d2b4e Code review - brought back verbose logs 2016-04-19 10:51:43 -07:00
Ev Kontsevoy 2809433128 Merge branch 'ev/tsh-keystore' of github.com:gravitational/teleport into ev/tsh-keystore 2016-04-19 10:38:13 -07:00
Ev Kontsevoy 9e5ea47732 PR code review suggestions 2016-04-19 10:37:46 -07:00
Ev Kontsevoy 6b8b1b4e9b Renamed 'known_hosts' to 'known_cas' because it's not the same 2016-04-19 03:00:07 -07:00
Ev Kontsevoy 9869c5cd01 Fixed integration tests 2016-04-19 02:08:07 -07:00
Ev Kontsevoy 648db88f01 Got rid of boltDB-based "known hosts" storage for TSH
Now TSH uses the same file format as OpenSSH, stored in ~/.tsh/known_hosts
2016-04-19 00:10:48 -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
Ev Kontsevoy 8fe9b3eeb7 Teleport Client API refactoring
Goal: Easier manipulation of client keys

- configurable key store
- easier public API to sign & save keys (prior to this only tc.Login()
  could create a signed key) - this allows to implement custom Login
  logic in other clients.
2016-04-05 18:53:30 -07:00
klizhentas f398534515 moving code around and splitting interfaces 2016-04-04 17:09:00 -07:00
klizhentas ca7e3820d7 This commit adds ability to preconfigure the cluster without running
auth server. This is needed when you configure cluster from scratch and
all nodes including auth server spin up simultaneously.

* Add tctl tools to generate keys and certificates

  + Command "tctl authorities gen" generates public and private keypair.
  + Command "tctl authorities gencert" generates public and private keypair signed
    by existng private key
  + Command "tctl authorities export" was modified to be able to export exisitng private
    CA keys to local storage

   All of these commands are hidden by default.

section "static configuration"

* Add ability to configure teleport from environment variable

Environment variable TELEPORT_CONFIG can contain base64 encoded
YAML file config file of the standard file format, so teleport will use it on start

* Add special secrets section to the config file

Section "secrets" was updated to support pre-configured trusted CA keys and pre-generated keys

* Add special rts hidden section to add support for provisioning
2016-03-28 12:58:34 -07:00
Ev Kontsevoy e4ddcdea34 Minor code cleanup
- Killed a bunch of unused dead code in TSH
- Added clarifying comments to lib/client/keystore.go
2016-03-14 16:55:33 -07:00
Ev Kontsevoy 89505329af Streamlined the process of user login in TSH
Instead of asking to login inside of the callback, there is one clear
place where password is asked, it's inside of `TeleportClient.ConnectToProxy()`
2016-03-14 16:27:45 -07:00
klizhentas 0e503ca376 Add proper integration with OpenSSH on both sides 2016-03-09 19:39:15 -08:00
Ev Kontsevoy 02f9d38a50 Merge remote-tracking branch 'origin/master' into ev/tsh-ls
Conflicts:
	lib/hangout/hangout_test.go
2016-03-08 15:03:24 -08:00
Ev Kontsevoy 6d5b4a093b Changed global "key dir" constant from /tmp/.tsh to ~/.tsh
Fixes #212
Closes #212
2016-03-08 09:26:27 -08:00