Commit graph

228 commits

Author SHA1 Message Date
Andrew Lytvynov ae6e57d346 Add missing error checks under tool/... 2020-05-15 16:56:44 +00:00
Andrew Lytvynov f3d9298674 gosimple: remove redundant select wrappers for single-channel receive
Select is unnecessary, unless there are multiple channels to
send/receive from.
2020-05-15 16:32:45 +00:00
Andrew Lytvynov 0add471f16 gosimple: remove comparisons to boolean constants
`if x == true` or `if x == false` should be just `if x` or `if !x`.
2020-05-15 16:32:45 +00:00
Andrew Lytvynov 91ba4ba122 Fetch advertised proxy addresses when using an identity file
Proxy advertises its preferred web/ssh/kube addresses via the `Ping`
endpoint. `tsh` hits this endpoint on login and caches addresses on disk
(in profile, along with credentials).
For all subsequent commands, `tsh` loads the cached information from
disk.

When using an identity file, `tsh` skips loading the profile (and it can
be missing entirely). In this case, we need to `Ping` the proxy
explicitly to fetch the correct public addresses for a proxy.

Fixes #3513
2020-05-07 01:37:33 +00:00
Andrew Lytvynov b1eae4ac4c Remove unused functions and methods throughout lib/...
This code is not caught by linters because it's exported and they assume
there's some external users.
Since teleport is relatively self-contained, we can tell for sure
whether something is called or not.
2020-05-06 00:02:53 +00:00
Andrew Lytvynov 2c1bf076e6 Add support for kubernetes identity file format
There are two new ways you can generate a kubeconfig:
- `tctl auth sign --user=foo --format=kubernetes --out=kubeconfig` for
  admins
- `tsh login --format=kubernetes -o kubeconfig` for users

This allows admins to generate long-lived kubeconfigs for e.g. CI
systems.

A tricky part is getting the kubernetes endpoint for a proxy in `tctl`.
It does its best to guess the address, but falls back to asking user to
pass `--proxy` flag.
It looks like right now, the proxy info available via the auth server's
API doesn't have kubernetes public_addr for proxies.

Fixes #2825
2020-04-30 00:19:51 +00:00
Andrew Lytvynov 28a7624244 Fix staticcheck findings in integration/ and tool/
Original finding list:
```
tool/tctl/common/node_command.go:163:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
		fmt.Printf(string(out))
		^
tool/tctl/common/status_command.go:110:2: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
	fmt.Printf(view())
	^
tool/tctl/common/status_command.go:126:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
		fmt.Printf(view())
		^
tool/tctl/common/token_command.go:201:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
		fmt.Printf(tokensView())
		^
tool/tctl/common/token_command.go:207:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
		fmt.Printf(string(data))
		^
tool/tctl/common/user_command.go:248:2: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
	fmt.Printf(string(out))
	^
tool/tctl/common/user_command.go:294:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
		fmt.Printf(string(out))
		^
integration/helpers.go:200:2: SA4006: this value of `err` is never used (staticcheck)
	cryptoPubKey, err := sshutils.CryptoPublicKey(cfg.Pub)
	^
integration/helpers.go:399:3: SA4006: this value of `roles` is never used (staticcheck)
		roles = append(roles, role)
		^
integration/helpers.go:597:4: SA4006: this value of `roles` is never used (staticcheck)
			roles = append(roles, role)
			^
integration/helpers.go:599:4: SA4006: this value of `roles` is never used (staticcheck)
			roles = user.Roles
			^
integration/integration_test.go:1625:2: SA4006: this value of `err` is never used (staticcheck)
	adminsRole, err := services.NewRole(mainAdmins, services.RoleSpecV3{
	^
integration/integration_test.go:2185:2: SA4006: this value of `output` is never used (staticcheck)
	output, err = runCommand(main, []string{"echo", "hello world"}, cfg, 1)
	^
integration/integration_test.go:2340:2: SA4006: this value of `output` is never used (staticcheck)
	output, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 1)
	^
integration/kube_integration_test.go:154:2: SA4006: this value of `err` is never used (staticcheck)
	role, err := services.NewRole("kubemaster", services.RoleSpecV3{
	^
integration/kube_integration_test.go:321:2: SA4006: this value of `err` is never used (staticcheck)
	role, err := services.NewRole("kubemaster", services.RoleSpecV3{
	^
integration/kube_integration_test.go:366:2: SA4006: this value of `err` is never used (staticcheck)
	role, err := services.NewRole("kubemaster", services.RoleSpecV3{
	^
integration/kube_integration_test.go:386:2: SA4006: this value of `err` is never used (staticcheck)
	pods, err := s.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
	^
integration/kube_integration_test.go:465:2: SA4006: this value of `err` is never used (staticcheck)
	mainRole, err := services.NewRole("main-kube", services.RoleSpecV3{
	^
integration/kube_integration_test.go:579:2: SA4006: this value of `err` is never used (staticcheck)
	pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
	^
integration/kube_integration_test.go:727:2: SA4006: this value of `err` is never used (staticcheck)
	mainRole, err := services.NewRole("main-kube", services.RoleSpecV3{
	^
integration/kube_integration_test.go:840:2: SA4006: this value of `err` is never used (staticcheck)
	pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
	^
integration/kube_integration_test.go:1008:2: SA4006: this value of `err` is never used (staticcheck)
	role, err := services.NewRole("kubemaster", services.RoleSpecV3{
	^
tool/teleport/common/teleport_test.go:83:2: SA4006: this value of `cmd` is never used (staticcheck)
	cmd, conf := Run(Options{
	^
tool/teleport/common/teleport_test.go:91:2: SA4006: this value of `cmd` is never used (staticcheck)
	cmd, conf = Run(Options{
	^
tool/tsh/tsh.go:170:2: SA4006: this value of `cmdLine` is never used (staticcheck)
	cmdLine := []string{}
	^
integration/helpers.go:399:11: SA4010: this result of append is never used, except maybe in other appends (staticcheck)
		roles = append(roles, role)
		       ^
integration/helpers.go:597:12: SA4010: this result of append is never used, except maybe in other appends (staticcheck)
			roles = append(roles, role)
			       ^
integration/integration_test.go:1092:7: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
		for len(b.Tunnel.GetSites()) < 2 && len(b.Tunnel.GetSites()) < 2 {
		   ^
integration/integration_test.go:1426:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
	for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
	   ^
integration/integration_test.go:1691:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
	for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
	   ^
integration/integration_test.go:1895:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
	for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
	   ^
integration/kube_integration_test.go:548:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
	for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
	   ^
integration/kube_integration_test.go:814:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck)
	for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
	   ^
```
2020-04-29 22:40:15 +00:00
Andrew Lytvynov 84af6958fc Extract identity file formatting/parsing into a package
Identity file formatting (former `client.MakeIdentityFile`) will soon
support writing a `kubeconfig` file.

`lib/kube/kubeconfig` depends on `lib/client`, if calls to
`kubeconfig.Update` were added to `client.MakeIdentityFile`, we'd have
an import cycle:
tool/tctl -> lib/client -> lib/kube/kubeconfig -> lib/client

To break the cycle, I extract the identity file formatting (and parsing)
code into a standalone package. It's logically isolated functionality
anyway.

Now the imports will be:
tool/tctl┬─> lib/client
         ├─> lib/kube/kubeconfig ─> lib/client
         ╰─> lib/client/identity ┬─> lib/client
                                 ╰─> lib/kube/kubeconfig -> lib/client
2020-04-21 23:12:38 +00:00
Andrew Lytvynov df535f50a0 Refactor lib/kube/client
- rename package from `client` to `kubeconfig` and remove "kubeconfig"
  from function names
  (https://github.com/golang/go/wiki/CodeReviewComments#package-names)
- export `Update` and `UpdateWithClient` to allow updates without
  building a full `TeleportClient`
- accept an optional user-specified path to kubeconfig, to bind to CLI
  flags
2020-04-21 19:51:52 +00:00
Andrew Lytvynov b994920aa8
Add make rules for linting (#3563)
Top-level `make lint` rule that scans everything and a CI-specific rule
for Jenkins.
Currently only enable "unused", since it's reliable. The list will
expand.

Also clean up stragglers that somehow slipped through in #3552.

Updates #3551
2020-04-10 11:37:09 -07:00
Dmitry Sharshakov cf3760159b Ask for auth in 'tsh clusters' if certificate has expired
Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
2020-03-30 17:44:09 -07:00
Forrest Marshall 56eea87d13 implement transparent UUID based routing 2020-03-05 10:30:20 -08:00
Forrest Marshall 9caef15f6b fix tsh identity output & trusted CA init on login 2020-02-18 13:57:26 -08:00
Forrest Marshall 568e185996 Add support for access request resource to cache (#3213)
Cache was missing support for access requests, causing
watchers to hang indefinitely without receiving events
when cache was in use.
2019-12-19 14:14:22 -08:00
Lars Lehtonen a5a909ef86 tool/tsh: fix dropped error in authFromIdentity() 2019-12-07 12:41:28 -08:00
Forrest Marshall 088be329af implement delayed access-request cleanup 2019-12-06 15:56:04 -08:00
Lars Lehtonen 5af4f04734 tool/tsh: fix dropped error in TestMakeClient() 2019-12-04 18:14:41 -08:00
Forrest Marshall ec327b6e03 Implment access-request system (workflow API) 2019-12-02 14:05:51 -08:00
Roman Tkachenko 07b25088ec Remote tctl execution. (#2991)
* Teach tctl to use remote auth servers and identity.

* Tests and cleanups.
2019-09-24 14:01:30 -07:00
Russell Jones 9135a5ade7 Use roles and traits in certificate for RBAC.
If an attacker can force a username change at an IdP, upon second login,
the services.User object of the original user can be updated with new
roles and traits. If these new roles and traits differ, the original
user can have their privileges raised (or lowered).

To mitigate this, encode roles and traits within the certificate and use
these when fetching roles to make RBAC decisions. If roles and traits are
not encoded within an certificate (for example for old style SSH
certificates then fallback to using the services.User object and log a
warning.
2019-09-03 13:44:20 -07:00
Forrest Marshall 04cea89e58 Expand TELEPORT_SITE environment to tsh login, fixes #2668 (#2675) (#2942)
The following now works:

```
TELEPORT_SITE=two.example.com tsh login
```
2019-08-29 14:02:13 -07:00
Russell Jones e117e857ab Allow port forwarding without command execution. (#2900)
Added ability to port forwarding without remote command execution.
Equivalent of -N for OpenSSH.
2019-08-17 10:33:55 -07:00
Sasha Klizhentas 838e75468c Add support for ProxyJump.
This commit implements #2543

In SSH terms ProxyJump is a shortcut for SSH client
connecting the proxy/jumphost and requesting .port forwarding to the
target node.

This commit adds support for direct-tcpip request support
in teleport proxy service that is an alias to the existing proxy
subsystem and reuses most of the code.

This commit also adds support to "route to cluster" metadata
encoded in SSH certificate making it possible to have client
SSH certificates to include the metadata that will cause the proxy
to route the client requests to a specific cluster.

`tsh ssh -J proxy:port ` is supported in a limited way:

Only one jump host is supported (-J supports chaining
that teleport does not utilise) and tsh will return with error
in case of two jumphosts: -J a,b will not work.

In case if `tsh ssh -J user@proxy` is used, it overrides
the SSH proxy coming from the tsh profile and port-forwarding
is used instead of the existing teleport proxy subsystem
2019-07-26 10:58:11 -07:00
Alexander Klizhentas 96b259348f
Use client cert metadata to route requests. (#2859)
This commit fixes issue #2766.

The prior logic in Kubernetes module used
SNI to route requests to the target kubernetes cluster.

This approach created problems with long cluster names
exceeding 61 character DNS label limit and
required setting up DNS wildcard records.

This commit changes the routing to use the metadata
encoded in client's x509 certificate to route the
request to the target cluster.

SNI approach will be supported for several versions
to preserve backwards compatibility.
2019-07-15 17:40:43 -07:00
Roman Tkachenko f39250443b Update tsh help string. (#2847) 2019-07-10 10:26:53 -07:00
Forrest Marshall cda5a39d28 Add TLS certs to user identity files
- Updates the identity files exported by `tctl auth sign` to include the
user's TLS certificate, as well as the set of available TLS root CA
certs.

- Adds a new GRPC-based auth server method, `GenerateUserCerts`, which
exports both SSH and TLS based certs.
2019-07-03 12:54:03 -07:00
Russell Jones ecda810e46 Connect to tunnel nodes through recording proxy.
Pass connection to target node, even if it's a node connected over a
reverse tunnel, to the forwarding server.
2019-06-12 16:26:06 -07:00
Russell Jones 089de07e5c Remove IP from nodes connected over tunnel.
Don't heartbeat address for nodes connected to clusters over a reverse
tunnel. Print warning to users if listen_addr or public_addr are set as
these are not used.
2019-06-12 16:26:06 -07: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
Alexander Klizhentas e832a0aea2 Expand TELEPORT_SITE environment to tsh login, fixes #2668 (#2675)
The following now works:

```
TELEPORT_SITE=two.example.com tsh login
```
2019-04-24 16:02:23 -07:00
Alexander Klizhentas 269706691c Use relevant SSHProxyAddr after Login (#2657)
Login could change the SSH proxy address based
on the information from "ping" endpoint

The function ConnectToProxy was saving
old version of the variable and kept using
it during login procedure.

This commit fixes that so the relevant
variable is always referenced.
2019-04-24 16:02:23 -07:00
Sasha Klizhentas 7e636b0b2b Add --bind-addr, fixes #2620
This commit adds `--bind-addr` flag to tsh login
and TELEPORT_LOGIN_BIND_ADDR environment variable
to set up login bind address for SSO redirect flows.

Usage examples:

```
tsh login  --bind-addr=localhost:3333
tsh login --bind-addr=:3333
tsh login --bind-addr=[::1]:3333
TELEPORT_LOGIN_BIND_ADDR=localhost:7777 tsh login
```

Refactor redirect flow and fix URLs for --bind-addr
2019-04-15 15:19:45 -07:00
Russell Jones 0019528676 Don't unlink profile on logout. 2019-02-11 14:58:21 -08:00
Russell Jones bd2732737e User experience enhancements for OpenSSH options.
Support key=value syntax for OpenSSH options and show help if the -o
flag is in the wrong place.
2019-02-05 10:31:24 -08:00
Russell Jones 9daa9a781b Sort nodes by "Node Name" in tsh ls. 2019-02-04 10:10:51 -08:00
Sasha Klizhentas 5a36b35ad1 Fetch certificate authorities during every login.
This commit fixes the problem when login
is initiated during another command, for example
'tsh ls' and misses code path that updated cert
authorities in the main module.

By moving code in the Login the change makes sure
that additional cert authorities are always fetched.
2019-01-28 14:47:12 -08:00
Alexander Klizhentas 7fc238e5e5
Fetch trusted CA from the main cluster. (#2487)
This PR fixes an issue with tsh login.

Here is a flaw in logic described using the following
scenario:

Assume there are two clusters, 'main' and 'east'.

1. User logs into the first cluster 'main'
2. Selects the cluster 'east' in the profile
3. Next day, logs in again
4. Client pulls the trusted CA from the cluster 'main'
as a part of SSH login procedure and adds to the keystore
5. Client connects to cluster 'east' because it is
set as a current cluster in the profile
6. Client attempts to connect to the auth server of the cluster
'east' and fails because it does not trust the certificate
of the 'east' yet, only 'main.

This PR fixes the issue by making sure the client
always connects to the cluster 'main' in the step 5 instead.
2019-01-16 15:38:55 -08:00
Jeremy Hiatt 9387f8f94f tsh: Fix typos in Teleport Enterprise URL 2018-12-26 16:16:31 -08:00
Russell Jones b64555a8d0 Remove Teleport related entries from kubeconfig upon "tsh logout". 2018-11-29 13:48:24 -08:00
Russell Jones ccab010062 Advertise a minimum version for clients. 2018-11-16 16:34:19 -08:00
Russell Jones 8ce36a92fe Only update kubeconfig if the proxy supports Kubernetes. 2018-11-13 18:13:52 -08:00
Russell Jones a4d996296d Extract principal from certificate and add it to the host login in the
Teleport client.
2018-11-07 13:18:20 -08:00
Russell Jones 043b9d5283 UX improvements to "tsh ls". 2018-11-05 16:52:10 -08:00
Russell Jones a2a7d15576 Add support for OpenSSH options. 2018-11-05 16:40:46 -08: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
Sasha Klizhentas a1116b7783 Set some defaults from identity file.
This commit reduces the amount of typing some users have
to do when using identity file:

* Teleport user is set from the certificate
* Auth preference is set to local

In addition it fixes several UX problems:

* Commands `tctl auth sign` and `tsh login -o`  now include
trusted CA keys in the identity file.

* Command `tsh ssh -i` is now noninteractive and only
uses identity file for authentication, in case
if identity file can not authenticate, no other interactive
or non-interactive authentication methods will be used.
Before this commit, tsh tried to fallback to interactive
login mode or read the keys from agent socket.
2018-09-13 16:47:14 -07:00
Russell Jones 4cc4262371 Update certs.pem file along with known hosts when fetching known CA. 2018-09-06 16:24:34 -07:00
Russell Jones 97074076cb Split public_addr into web_proxy_addr and ssh_proxy_addr. 2018-08-31 16:33:54 -07: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