Commit Graph
147 Commits
Author SHA1 Message Date
Joshua Behrens 19d482dad3 Allow user with at sign in name (#4002)
* Allow @ in scp targets
* Allow @ in proxyjump usernames
* Allow @ in tsh usernames
2020-07-21 10:41:31 -03: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 d7dc41659d Use CA signing alg from config file on manual rotation
This allows users to manually switch to a different algorithm by:
- setting the config file field
- running "tctl auth rotate"

If config file field is not set, existing signing algorithm of the CA is
preserved.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 9bc8fb3ae0 Add ca_signing_algo to the config file
This allows users to override the SHA2 signing algorithms we default to
now for compatibility with the (very) old OpenSSH versions.

For host and user certs, use the CA signing algo for their own
handshakes. This allows us to propagate the signing algo from auth
server everywhere else.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 96f56f3f40 Enforce SHA-512 for RSA SSH signatures
Motivation:

    x/crypto/ssh defaults to using SHA-1 for signatures:
    https://github.com/golang/crypto/blob/master/ssh/keys.go#L963-L982
    Because Teleport uses RSA for user, host and CA keys, we end up with
    SHA-1 by default.

    SHA-1 is now considered weak and OpenSSH plans to deprecate it:
    https://www.openssh.com/txt/release-8.3

Fix:

    Wrap all RSA `ssh.Signer`s and override `SignWithAlgorithm` to
    provide `SigAlgoRSASHA2512` if not otherwise specified. This will
    only affect new certs, existing certs will use `SigAlgoRSA` until
    rotated. For CA certs (e.g. exported with `tctl auth export`) users
    might need to manually rotate.

Limited local testing with openssh 8.2 client and
`-oHostKeyAlgorithms=-ssh-rsa` confirms that this works with a new
cluster and fails with an old one.
2020-06-24 21:25:33 +00:00
Forrest Marshall dfd40d21f5 proxy X11 forwarding support
- Role options now include a `permit_x11_forwarding` bool
which is set to `false` by default.

- Recording proxies now forward X11 requests and channels
when when permitted by RBAC.

- User certs will now include the `permit-X11-forwarding`
extension when permitted by RBAC.

- If X11 forwarding is requested for a session a new `x11`
audit event is emitted by recording proxies.
2020-06-24 11:40:47 -07:00
Forrest Marshall acde213069 Make agent channel setup lazy.
Changes agent channel setup behavior to be consistent
openssh by having servers lazily request agent channels
when they are needed, rather than immediately starting a
single connection-wide channel as soon as forwarding is
requested.  Fixes an issue introduced in #3613 which
caused openssh clients to hang on exit due to persistent
agent channel.
2020-06-10 14:15:51 -07:00
Andrew Lytvynov e6aab1dcaa errcheck: add missing error logging in lib/srv 2020-06-01 17:00:07 +00:00
Andrew Lytvynov f20da0caca Fix data races when accessing internal listeners
These listeners are already protected elsewhere, just missing locking in
a couple methods.
2020-05-21 20:38:37 +00:00
Andrew Lytvynov e2d65a3156 Auto assign ports for lib/srv/regular tests 2020-05-21 20:38:37 +00:00
Andrew Lytvynov d52ca0617d Add missing error checks in lib/srv and lib/sshutils
There's many more left in lib/srv, but this change is already big.
Some errors are left unhandled, where it makes sense.
2020-05-15 16:56:44 +00:00
Andrew Lytvynov a48c40ad78 gosimple: replace time.Now().Sub(x) with time.Since(x) 2020-05-15 16:32:45 +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 dba7f8e563 Remove ineffectual assignments
Caught by `ineffassign` linter.

Note the change in lib/srv/regular/sshserver.go - looks like we
advertised the custom listening port (`aport`), if it differed from
regular listening port (`port`).
2020-05-11 16:44:27 +00:00
Andrew Lytvynov e5478c937d Remove unnecessary type conversions
Caught by `unconvert` linter. No behavior changes here.
2020-05-11 16:44:27 +00:00
Andrew Lytvynov d40013f33b Send SCP error messages to receiver when upload fails
This serves two purposes:
1. on upload, the receiver (node) will exit with error and generate an
   SCP error audit event.
2. on download, the receiver (tsh) will print a meaningful message from
   the sender (node)

Fixes #2861
2020-05-06 00:03:30 +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
Forrest Marshall c341d2bc15 fix agent forwarding for multi-session connections
Changes the lifetime of agent forwarding to be scoped
to the underlying ssh connection, instead of the
specific ssh channel which initially passed the agent
forwarding request.
2020-04-28 17:45:29 -07:00
Andrew Lytvynov bdd388e0d0 Fix remaining staticcheck findings in lib/...
Fixed findings:
```
lib/sshutils/server_test.go:163:2: SA4006: this value of `clt` is never used (staticcheck)
	clt, err := ssh.Dial("tcp", srv.Addr(), &cc)
	^
lib/sshutils/server_test.go:91:3: SA5001: should check returned error before deferring ch.Close() (staticcheck)
		defer ch.Close()
		^
lib/shell/shell_test.go:33:2: SA4006: this value of `shell` is never used (staticcheck)
	shell, err = GetLoginShell("non-existent-user")
	^
lib/cgroup/cgroup_test.go:111:2: SA9003: empty branch (staticcheck)
	if err != nil {
	^
lib/cgroup/cgroup_test.go:119:2: SA5001: should check returned error before deferring service.Close() (staticcheck)
	defer service.Close()
	^
lib/client/keystore_test.go:138:2: SA4006: this value of `keyCopy` is never used (staticcheck)
	keyCopy, err = s.store.GetKey("host.a", "bob")
	^
lib/client/api.go:1604:3: SA4004: the surrounding loop is unconditionally terminated (staticcheck)
		return makeProxyClient(sshClient, m), nil
		^
lib/backend/test/suite.go:156:2: SA4006: this value of `err` is never used (staticcheck)
	result, err = s.B.GetRange(ctx, prefix("/prefix/c/c1"), backend.RangeEnd(prefix("/prefix/c/cz")), backend.NoLimit)
	^
lib/utils/timeout_test.go:84:2: SA1019: t.Dial is deprecated: Use DialContext instead, which allows the transport to cancel dials as soon as they are no longer needed. If both are set, DialContext takes priority.  (staticcheck)
	t.Dial = func(network string, addr string) (net.Conn, error) {
	^
lib/utils/websocketwriter.go:83:3: SA4006: this value of `err` is never used (staticcheck)
		utf8, err = w.encoder.String(string(data))
		^
lib/utils/loadbalancer_test.go:134:2: SA4006: this value of `out` is never used (staticcheck)
	out, err = Roundtrip(frontend.String())
	^
lib/utils/loadbalancer_test.go:209:2: SA4006: this value of `out` is never used (staticcheck)
	out, err = RoundtripWithConn(conn)
	^
lib/srv/forward/sshserver.go:582:3: SA4004: the surrounding loop is unconditionally terminated (staticcheck)
		return
		^
lib/service/service.go:347:4: SA4006: this value of `err` is never used (staticcheck)
			i, err = auth.GenerateIdentity(process.localAuth, id, principals, dnsNames)
			^
lib/service/signals.go:60:3: SA1016: syscall.SIGKILL cannot be trapped (did you mean syscall.SIGTERM?) (staticcheck)
		syscall.SIGKILL, // fast shutdown
		^
lib/config/configuration_test.go:184:2: SA4006: this value of `conf` is never used (staticcheck)
	conf, err = ReadFromFile(s.configFileBadContent)
	^
lib/config/configuration.go:129:2: SA5001: should check returned error before deferring reader.Close() (staticcheck)
	defer reader.Close()
	^
lib/kube/kubeconfig/kubeconfig_test.go:227:2: SA4006: this value of `err` is never used (staticcheck)
	tlsCert, err := ca.GenerateCertificate(tlsca.CertificateRequest{
	^
lib/srv/sess.go:720:3: SA4006: this value of `err` is never used (staticcheck)
		result, err := s.term.Wait()
		^
lib/multiplexer/multiplexer_test.go:169:11: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
	_, err = fmt.Fprintf(conn, proxyLine.String())
	        ^
lib/multiplexer/multiplexer_test.go:221:11: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
	_, err = fmt.Fprintf(conn, proxyLine.String())
	        ^
```
2020-04-28 15:17:44 +00:00
Andrew Lytvynov d1ea40d074 Enable linters: deadcode,goimports,govet,typecheck
And fix the relevant findings for these linters.

Also, set extra flags for `golangci-lint run` to make sure no findings
are suppressed.
2020-04-17 17:46:51 +00:00
Andrew Lytvynov f8661edea3 Clean up dead code across the codebase
Spring cleaning!
A very mechanical cleanup using several linters (unused, deadcode,
structcheck). Build and tests still pass so no behavior should be
affected.
2020-04-09 21:10:12 +00:00
Russell Jones 9a237b7328 Print scp status without quotes.
Don't escape the final \n in the scp status message. This way the status
message will get printed without double quotes.
2019-12-06 18:14:26 -08:00
Russell Jones 1479dfc258 Always emit exec command and exit code.
Due to the scp being inherently vulnerable to command injection, always
make sure the full command and exit code is recorded in the Audit Log
for accountability purposes.

For more details about scp, see the following.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=327019
https://bugzilla.mindrot.org/show_bug.cgi?id=1998
2019-09-03 13:44:20 -07: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
Sasha Klizhentas ba1fcf5d77 Fix teleport parsing to support IPV6
This commit fixes #2124
2019-07-23 20:36:34 -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 639a67503e Fix EOF error polluting logs 2019-05-14 17:10:32 -07:00
Russell Jones 6d1c16f745 Added support for nodes dialing back to cluster.
Updated services.ReverseTunnel to support type (proxy or node). For
proxy types, which represent trusted cluster connections, when a
services.ReverseTunnel is created, it's created on the remote side with
name /reverseTunnels/example.com. For node types, services.ReverseTunnel
is created on the main side as /reverseTunnels/{nodeUUID}.clusterName.

Updated services.TunnelConn to support type (proxy or node). For proxy
types, which represent trusted cluster connections, tunnel connections
are created on the main side under
/tunnelConnections/remote.example.com/{proxyUUID}-remote.example.com.
For nodes, tunnel connections are created on the main side under
/tunnelConnections/example.com/{proxyUUID}-example.com. This allows
searching for tunnel connections by cluster then allows easily creating
a set of proxies that are missing matching services.TunnelConn.

The reverse tunnel server has been updated to handle heartbeats from
proxies as well as nodes. Proxy heartbeat behavior has not changed.
Heartbeats from nodes now add remote connections to the matching local
site. In addition, the reverse tunnel server now proxies connection to
the Auth Server for requests that are already authenticated (a second
authentication to the Auth Server is required).

For registration, nodes try and connect to the Auth Server to fetch host
credentials. Upon failure, nodes now try and fallback to fetching host
credentials from the web proxy.

To establish a connection to an Auth Server, nodes first try and connect
directly, and if the connection fails, fallback to obtaining a
connection to the Auth Server through the reverse tunnel. If a
connection is established directly, node startup behavior has not
changed. If a node establishes a connection through the reverse tunnel,
it creates an AgentPool that attempts to dial back to the cluster and
establish a reverse tunnel.

When nodes heartbeat, they also heartbeat if they are connected directly
to the cluster or through a reverse tunnel. For nodes that are connected
through a reverse tunnel, the proxy subsystem now directs the reverse
tunnel server to establish a connection through the reverse tunnel
instead of directly.

When sending discovery requests, the domain field has been replaced with
tunnelID. The tunnelID field is either the cluster name (same as before)
for proxies, or {nodeUUID}.example.com for nodes.
2019-04-26 15:41:45 -07:00
Sasha Klizhentas 8356ae6a74 Use in-memory cache for the auth server API.
This commit expands the usage of the caching layer
for auth server API:

* Introduces in-memory cache that is used to serve all
Auth server API requests. This is done to achieve scalability
on 10K+ node clusters, where each node fetches certificate authorities,
roles, users and join tokens. It is not possible to scale
DynamoDB backend or other backends on 10K reads per seconds
on a single shard or partition. The solution is to introduce
an in-memory cache of the backend state that is always used
for reads.

* In-memory cache has been expanded to support all resources
required by the auth server.

* Experimental `tctl top` command has been introduced to display
common single node metrics.

Replace SQLite Memory Backend with BTree

SQLite in memory backend was suffering from
high tail latencies under load (up to 8 seconds
in 99.9%-ile on load configurations).

This commit replaces the SQLite memory caching
backend with in-memory BTree backend that
brought down tail latencies to 2 seconds (99.9%-ile)
and brought overall performance improvement.
2019-04-12 14:23:09 -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 ac9af87dfb Emit data transfer events.
Created *utils.TrackingConn that wraps the server side net.Conn and is
used to track how much data is transmitted and received over the
net.Conn. At the close of a connection (close of a *srv.ServerContext)
the total data transmitted and received is emitted to the Audit Log.
2019-03-08 19:22:20 +00:00
Russell Jones 27f5ef8f88 Added support for directory mode to scp.
On the client side, make sure directory mode is requested when sending
multiple files. On the server side, when in directory mode, validate
that the target is a directory.
2019-02-11 16:05:41 -08:00
Russell Jones 599b8b73c9 Fix scp client vulnerabilities.
Fixed scp client vulnerabilities to a malicious server found by Harry
Sintonen. For more information, see the following:

https://sintonen.fi/advisories/scp-client-multiple-vulnerabilities.txt
2019-02-11 14:57:57 -08:00
Russell Jones cea10926a2 Convert "permission denied" errors into trace errors. 2019-02-04 10:10:37 -08:00
Russell Jones 6c37b4a98e Added support for "keep_alive_interval" and "keep_alive_count_max" to
control how often the server sends keep-alive messages to clients and
after how many missed keep-alive replies the server tears down the
connection to the client.
2018-11-29 13:36:43 -08:00
Cove Schneider 8b299e9c28 spelling cleanup 2018-11-15 12:44:51 -08: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 9dbbefe316 Emit secure copy specific events instead of generic exec events when
using scp. Fix exec events to strip /bin/bash -c prefix when using
regular Teleport nodes.
2018-08-20 16:00:40 -07:00
Alexey Kontsevoy 7553f13256 fix handling of exitCodes during SCP 2018-07-25 16:07:16 -04:00
Alexey Kontsevoy ee98d7335d http files/separate remote location from file name in SCP requests 2018-07-18 19:05:00 -04:00
Alexey Kontsevoy 57b2789a49 http file transfer 2018-07-12 14:58:37 -04:00
Sasha Klizhentas 73c3ba38d9 Switch to 1.10.3 2018-06-12 17:26:43 -07:00
Russell Jones f476c49262 Don't send Teleport version in handshake. 2018-06-06 17:13:35 -07:00
Russell Jones 6be8af16c5 Removed depreciated code and re-factored tests to use
golang.org/x/crypto.
2018-04-05 23:14:20 +00:00
Sasha Klizhentas e809a7eb2c Better signal handling and pools for gzip.
Fixes #1698.

* Added sync.Pool to take care of many gzip.Writer
allocating a lot of large objects on the heap.

* Reshuffled signal handling, SIGQUIT is now
graceful shutdown, just like in Nginx.

* Signal USR1 prints hepful diagnostic info to stderr.

* Removed gops endpoint and flags.

* Fixed logs in some places.

* Debug flag now adds extra pprof handlers to diagnostic
endpoint.
2018-02-19 10:57:26 -08:00
Sasha Klizhentas 68b65f5b24 Teleport signal handling and live reload.
This commit introduces signal handling.
Parent teleport process is now capable of forking
the child process and passing listeners file descriptors
to the child.

Parent process then can gracefully shutdown
by tracking the amount of current connections and
closing listeners once the amount goes to 0.

Here are the signals handled:

* USR2 signal will cause the parent to fork
a child process and pass listener file descriptors to it.
Child process will close unused file descriptors
and will bind to the used ones.

At this moment two processes - the parent
and the forked child process will be serving requests.
After looking at the traffic and the log files,
administrator can either shut down the parent process
or the child process if the child process is not functioning
as expected.

* TERM, INT signals will trigger graceful process shutdown.
Auth, node and proxy processes will wait until the amount
of active connections goes down to 0 and will exit after that.

* KILL, QUIT signals will cause immediate non-graceful
shutdown.

* HUP signal combines USR2 and TERM signals in a convenient
way: parent process will fork a child process and
self-initate graceful shutdown. This is a more convenient
than USR2/TERM sequence, but less agile and robust
as if the connection to the parent process drops, but
the new process exits with error, administrators
can lock themselves out of the environment.

Additionally, boltdb backend has to be phased out,
as it does not support read/writes by two concurrent
processes. This had required refactoring of the dir
backend to use file locking to allow inter-process
collaboration on read/write operations.
2018-02-13 15:18:47 -08:00
Sasha Klizhentas f0da64fb63 UX and performance changes
* Do not log EOF errors, avoid polluting logs
* Trim space from tokens when reading from file
* Do not use dir based caching

The caching problem deserves a separate explanation.

Directory backend is not concurrent friendly - it has a
fundamental design flaw - multiple gorotuines writing to the
same file corrupt cache data.

This requires either redesign of the backend or switching
to boltdb backend for caching.

Boltdb backend uses transactions and is safe for concurrent
access. This PR changes local cache to use boltdb instead
of the dir backend that is now used only in tests.
2018-01-22 12:25:11 -08: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