Commit graph

462 commits

Author SHA1 Message Date
Alexey Kontsevoy 3c670d5d58
Merge Teleport V4.3 UI branch to master (#3583)
* Add monorepo

* Add reset/passwd capability for local users (#3287)

* Add UserTokens to allow password resets

* Pass context down through ChangePasswordWithToken

* Rename UserToken to ResetPasswordToken

* Add auto formatting for proto files

* Add common Marshaller interfaces to reset password token

* Allow enterprise "tctl" reuse OSS user methods (#3344)

* Pass localAuthEnabled flag to UI (#3412)

* Added LocalAuthEnabled prop to WebConfigAuthSetting struct in webconfig.go
* Added LocalAuthEnabled state as part of webCfg in  apiserver.go

* update e-refs

* Fix a regression bug after merge

* Update tctl CLI output msgs (#3442)

* Use local user client when resolving user roles

* Update webapps ref

* Add and retrieve fields from Cluster struct (#3476)

* Set Teleport versions for node, auth, proxy init heartbeat
* Add and retrieve fields NodeCount, PublicURL, AuthVersion from Clusters
* Remove debug logging to avoid log pollution when getting public_addr of proxy
* Create helper func GuessProxyHost to get the public_addr of a proxy host
* Refactor newResetPasswordToken to use GuessProxyHost and remove publicUrl func

* Remove webapps submodule

* Add webassets submodule

* Replace webapps sub-module reference with webassets

* Update webassets path in Makefile

* Update webassets

1b11b26 Simplify and clean up Makefile (#62) https://github.com/gravitational/webapps/commit/1b11b26

* Retrieve cluster details for user context (#3515)

* Let GuessProxyHost also return proxy's version
* Unit test GuessProxyHostAndVersion & GetClusterDetails

* Update webassets

4dfef4e Fix build pipeline (#66) https://github.com/gravitational/webapps/commit/4dfef4e

* Update e-ref

* Update webassets

0647568 Fix OSS redirects https://github.com/gravitational/webapps/commit/0647568

* update e-ref

* Update webassets

e0f4189 Address security audit warnings Updates  "minimist" package which is used by 7y old "optimist". https://github.com/gravitational/webapps/commit/e0f4189

* Add new attr to Session struct (#3574)

* Add fields ServerHostname and ServerAddr
* Set these fields on newSession

* Ensure webassets submodule during build

* Update e-ref

* Ensure webassets before running unit-tests

* Update E-ref

Co-authored-by: Lisa Kim <lisa@gravitational.com>
Co-authored-by: Pierre Beaucamp <pierre@gravitational.com>
Co-authored-by: Jenkins <jenkins@gravitational.io>
2020-04-15 15:35:26 -04: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
Forrest Marshall 24e6d73224 fix cert reissue compatibility 2020-03-17 11:30:16 -07:00
Forrest Marshall ea45118850 detect old cert format on startup 2020-03-05 10:30:20 -08:00
Forrest Marshall 56eea87d13 implement transparent UUID based routing 2020-03-05 10:30:20 -08:00
Benjamin Alpert 6061d9ebb7 changed to conventions 2020-02-20 17:50:22 -08:00
Benjamin Alpert 17e92c0321 small fix 2020-02-20 17:50:22 -08:00
Benjamin Alpert 1d0c1b0c3d Fixes integration of dynamodb compatible endpoints (#3329) 2020-02-20 17:50:22 -08:00
Russell Jones de25684689 Added testing.Verbose to allow silencing of tests. 2020-02-06 11:15:44 -08:00
Sasha Klizhentas a22f7be365 Adds in-memory cache option, improves scalability for IOT mode.
This commit resolves #3227

In IOT mode, 10K nodes are connecting back to the proxies, putting
a lot of pressure on the proxy cache.

Before this commit, Proxy's only cache option were persistent
sqlite-backed caches. The advantage of those caches that Proxies
could continue working after reboots with Auth servers unavailable.

The disadvantage is that sqlite backend breaks down on many concurrent
reads due to performance issues.

This commit introduces the new cache configuration option, 'in-memory':

```yaml
teleport:
  cache:
    # default value sqlite,
    # the only supported values are sqlite or in-memory
    type: in-memory
```

This cache mode allows two m4.4xlarge proxies to handle 10K IOT mode connected
nodes with no issues.

The second part of the commit disables the cache reload on timer that caused
inconsistent view results for 10K displayed nodes with servers disappearing
from the view.

The third part of the commit increases the channels buffering discovery
requests 10x. The channels were overfilling in 10K nodes and nodes
were disconnected. The logic now does not treat the channel overflow
as a reason to close the connection. This is possible due to the changes
in the discovery protocol that allow target nodes to handle missing
entries, duplicate entries or conflicting values.
2020-02-06 09:16:48 -08:00
Benjamin Alpert 219cada7cc Added S3 third party support (#3054) 2020-01-02 17:56:53 -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
Russell Jones a5af2d72ff More enhanced session recording error imporvements
Move BPF checks to node startup and group them togeather.
2019-12-06 18:14:26 -08:00
Russell Jones 8aaed66c26 Improve enhanced session recording error messages.
If the user enabled enhanced session recording in file configuration but
the binary was built without BPF support (like macOS) then exit right
away with a message explaining that their operating system does not
support enhanced session recording.
2019-12-06 18:14:26 -08:00
Josh D 69d78b63c4 Make Teleport log its version upon service start #3145 (#3168)
* Make Teleport log its version upon service start #3145

This change implements a resolution to issue #3145. Version and Gitref string are output when components start information is logged.

https://github.com/gravitational/teleport/issues/3145

* fix merge artifact
2019-12-04 15:22:00 -08:00
Russell Jones 77e8b63470 Enhanced Session Recording.
Added package cgroup to orchestrate cgroups. Only support for cgroup2
was added to utilize because cgroup2 cgroups have unique IDs that can be
used correlated with BPF events.

Added bpf package that contains three BPF programs: execsnoop,
opensnoop, and tcpconnect. The bpf package starts and stops these
programs as well  correlating their output with Teleport sessions
and emitting them to the audit log.

Added support for Teleport to re-exec itself before launching a shell.
This allows Teleport to start a child process, capture it's PID, place
the PID in a cgroup, and then continue to process. Once the process is
continued it can be tracked by it's cgroup ID.

Reduced the total number of connections to a host so Teleport does not
quickly exhaust all file descriptors. Exhausting all file descriptors
happens very quickly when disk events are emitted to the audit log which
are emitted at a very high rate.

Added tarballs for exec sessions. Updated session.start and session.end
events with additional metadata. Updated the format of session tarballs
to include enhanced events.

Added file configuration for enhanced session recording. Added code to
startup enhanced session recording and pass package to SSH nodes.
2019-12-02 15:10:39 -08:00
Heather Young 69f0698636 Architecture revision (#3093)
Architecture revisions from @one000mph and &Yet.
2019-10-22 11:10:28 -07:00
Sasha Klizhentas 779b50c083 Merge branch 'gcp_ha_support' of https://github.com/bigcommerce/teleport into bigcommerce-gcp_ha_support 2019-09-24 11:00:53 -07:00
Alexander Klizhentas 7f494f7c10
Updating dependencies for etcd v3.3.15 (#2965)
Fixes #2762

This commit updates go etcd client that fixes
issue of the first etcd peer going down briging down
the whole cluster.
2019-09-08 10:50:56 -07:00
Joshua Durbin d346f2b124 adds support for GCP HA environments with gcs recording storage, firestore-backed events, and firestore backend storage 2019-09-05 13:09:55 -07:00
Forrest Marshall 05f3eeaf00 Support resource-based bootstrapping for backend. (#2871)
* Support resource-based bootstrapping for backend.

Outside of static configuration, most of the persistent state of an
auth server exists as a collection of resources, stored in its
backend.  The resource API also forms the basis of Teleport's more
advanced dynamic configuration options.

This commit extends the usefulness of the resource API by adding
the ability to bootstrap backend state with a set of previously
exported resources.  This allows the resource API to serve as a
rudimentary backup/migration tool.

Notes: This features is a work in progress, and very easy to misuse;
while it will prevent you from overwriting the state of an existing
auth server, it won't stop you from bootstrapping into a wildly
misconfigured state.  In general, resource-based bootstrapping is
not a complete solution for backup or migration.

* update e-ref
2019-08-29 16:16:03 -07:00
Gus Luxton 4b022fcacb
Handle HTTP connections to TLS socket in a more graceful way (#2886) 2019-08-13 14:03:22 -03: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 aa2335151a Add ability to output audit logs to stdout.
This commit implements #2872.

Similarly to file://, the scheme `stdout://` could be used complimentary
to the existing external scheme to logs audit logs:
to stdout:

```yaml
audit_events_uri: ['dynamodb://events', 'stdout://',]
```

Just like `file://` scheme it is only possible to use 'stdout://'
scheme when external events and session uploader are defined,
so all audit upload and search features of teleport could work.
2019-07-25 16:10:23 -07:00
Sasha Klizhentas ba1fcf5d77 Fix teleport parsing to support IPV6
This commit fixes #2124
2019-07-23 20:36:34 -07:00
Alexander Klizhentas 32b84e6765
Read join tokens from file, fixes #2515. (#2864) 2019-07-17 12:51:18 -07:00
Russell Jones 9c2cfa1cd8 Cleanup of dead code.
* Removed legacy backends no longer supported.
* Removed code marked for deletion.
* Updated Makefile to use $ instead of ` to match Enterprise.
2019-07-02 18:01:44 -07:00
Russell Jones c19765a9a4 Rotate certificate upon valid principals change.
Ignore 0.0.0.0 when checking if certificate needs to be rotated.
2019-06-28 16:08:12 -07:00
Russell Jones 15478ec065 Don't include port in host certificate principals.
When attempting to guess the IP address of a remote host to add to the
host certificate, always remove the port.

Improve logging, so it's clear when a nodes host certificate changes due
to the principals list being updated.
2019-06-24 11:34:52 -07:00
Russell Jones 3a0a8548d4 Improve logging when failing to connect to cluster. 2019-06-13 10:44:32 -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
Russell Jones 4e773e9b38 Remove CredentialsClient.
Removed CredentialsClient, instead pass client.HostCredentials to
auth.Register to break circular import.
2019-05-21 09:59:10 -07:00
Russell Jones a795aec624 Update preference order for tunnel address.
Return the tunnel address in the following preference order:

1. Reverse Tunnel Public Address.
2. SSH Proxy Public Address.
3. HTTP Proxy Public Address.
4. Tunnel Listen Address.
2019-05-07 13:17:13 -07:00
Russell Jones 09241c635e Added support for FedRAMP/FIPS 140-2.
Added "--fips" flag to "teleport start" command which can start
Enterprise in FedRAMP/FIPS 140-2 mode.

In FIPS mode, Teleport configures the TLS and SSH servers with FIPS
compliant cryptographic algorithms. In FIPS mode, if non-compliant
algorithms are chosen, Teleport will fail to start. In addition,
Teleport checks if the binary was compiled against an approved
cryptographic module (BoringCrypto) and fails to start if it was not.
If a client, like tsh, tries to use non-FIPS encryption, like NaCl,
those requests are also rejected.
2019-05-07 12:51:02 -07:00
Sasha Klizhentas d308e3a68e Fix several goroutine/connection leaks
This commit fixes several gorotuine and connection leaks
by setting header read timeout on http servers and
cleaning up failed connections.
2019-05-07 12:21:01 -07:00
Sasha Klizhentas e3ca4df5fc Simplify IOT reverse tunnel logic.
In case of IOT (whenever teleport nodes are
connecting to the proxy), there is no need
to create ReverseTunnel objects in the backend,
as there is always one reverse tunnel per node.

This commit removes the logic that created
reverse tunnel object in the backed in IOT cases
and refactors some other parts of the code.
2019-05-03 10:51:06 -07:00
Russell Jones e534183a46 Support dial back nodes with Trusted Clusters.
Instantiate agent pool (and agent) with a reference to the reverse
tunnel server.

Pass list of principals to agents when initiating a transport dial
request.

The above two changes allow the agent to look up principals in local
site when attempting to connect to a node within a trusted cluster.
2019-05-02 17:28:39 -07:00
Sasha Klizhentas d5243dbe8d Add keep alive support to GRPC clients.
This commit turns on KeepAlive support
for GRPC clients to make sure that dropped
connections are detected properly.
2019-05-02 15:09:33 -07:00
Sasha Klizhentas 7467e47718 Cache auth servers and new find endpoint
Whenever many IOT style nodes are connecting
back to the web proxy server, they all
call /find endpoint to discover the configuration.

This new endpoint is designed to be fast and not
hit the database.

In addition to that every proxy reverse tunnel
connection handler was fetching auth servers and
this commit adds caching for the auth servers
on the proxy side.
2019-04-30 17:43:01 -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
Alexander Klizhentas 6b5935fb71
Use RADIX trees for prefix matching. (#2666)
Buffer fan out used simple prefix match
in a loop, what resulted in high CPU load
on many connected watchers.

This commit switches to RADIX trees for
prefix matching what reduces CPU load
substantially for 5K+ connected watchers.
2019-04-22 15:28:04 -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
Sasha Klizhentas dd5f343e8b Kubernetes SNI proxy improvements, implements #2614
This commit hex encodes trusted cluster names
in target addresses for kubernetes SNI proxy.

For example, assuming public address of Teleport
Kubernetes proxy is main.example.com, and trusted
cluster is remote.example.com, resulting target
address added to kubeconfig will look like

k72656d6f74652e6578616d706c652e636f6d0a.main.example.com

And Teleport Proxy's DNS Name will include wildcard:

'*.main.example.com' in addition to 'main.example.com'

Note that no dots are in the SNI address thanks to hex encoding.

This will allow administrators to avoid manually updating
list of public_addr sections every time the trusted cluster and use
the wildcard DNS name.

The following addr:

remote.example.com.main.example.com would not have matched
*.main.example.com per DNS wildcard spec.
2019-03-21 14:05:33 -07:00
Sasha Klizhentas aefe8860c1 Kubernetes proxy to use impersonation API
This commit switches Teleport proxy to use impersonation
API instead of the CSR API.

This allows Teleport to work on EKS clusters, GKE and all
other CNCF compabitble clusters.

This commit updates helm chart RBAC as well.

It introduces extra configuration flag to proxy_service
configuration parameter:

```yaml
proxy_service:
   # kubeconfig_file is used for scenarios
   # when Teleport Proxy is deployed outside
   # of the kubernetes cluster
   kubeconfig_file: /path/to/kube/config
```

It deprecates similar flag in auth_service:

```yaml
auth_service:
   # DEPRECATED. THIS FLAG IS IGNORED
   kubeconfig_file: /path/to/kube/config
```
2019-03-18 15:46:49 -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
Sasha Klizhentas f4635de5c2 Allow S3 buckets in different regions, implements #2007
This commit allows additional configuration
for the `audit_sessions_uri` parameter:

`audit_sessions_uri: s3://example.com/path?region=us-east-1`

Additional query parameter `region` will override
default `audit` section `region` if set.
2019-02-09 21:39:40 -08:00
Russell Jones cea10926a2 Convert "permission denied" errors into trace errors. 2019-02-04 10:10:37 -08: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
Sasha Klizhentas f40df845db Events and GRPC API
This commit introduces several key changes to
Teleport backend and API infrastructure
in order to achieve scalability improvements
on 10K+ node deployments.

Events and plain keyspace
--------------------------

New backend interface supports events,
pagination and range queries
and moves away from buckets to
plain keyspace, what better aligns
with DynamoDB and Etcd featuring similar
interfaces.

All backend implementations are
exposing Events API, allowing
multiple subscribers to consume the same
event stream and avoid polling database.

Replacing BoltDB, Dir with SQLite
-------------------------------

BoltDB backend does not support
having two processes access the database at the
same time. This prevented Teleport
using BoltDB backend to be live reloaded.

SQLite supports reads/writes by multiple
processes and makes Dir backend obsolete
as SQLite is more efficient on larger collections,
supports transactions and can detect data
corruption.

Teleport automatically migrates data from
Bolt and Dir backends into SQLite.

GRPC API and protobuf resources
-------------------------------

GRPC API has been introduced for
the auth server. The auth server now serves both GRPC
and JSON-HTTP API on the same TLS socket and uses
the same client certificate authentication.

All future API methods should use GRPC and HTTP-JSON
API is considered obsolete.

In addition to that some resources like
Server and CertificateAuthority are now
generated from protobuf service specifications in
a way that is fully backward compatible with
original JSON spec and schema, so the same resource
can be encoded and decoded from JSON, YAML
and protobuf.

All models should be refactored
into new proto specification over time.

Streaming presence service
--------------------------

In order to cut bandwidth, nodes
are sending full updates only when changes
to labels or spec have occured, otherwise
new light-weight GRPC keep alive updates are sent
over to the presence service, reducing
bandwidth usage on multi-node deployments.

In addition to that nodes are no longer polling
auth server for certificate authority rotation
updates, instead they subscribe to event updates
to detect updates as soon as they happen.

This is a new API, so the errors are inevitable,
that's why polling is still done, but
on a way slower rate.
2018-12-10 17:20:24 -08:00
Cove Schneider 8b299e9c28 spelling cleanup 2018-11-15 12:44:51 -08:00
Russell Jones c18e33b71f Support different ready states. 2018-11-05 15:00:32 -08:00
Sasha Klizhentas 193a465e0d Reduce the polling period for rotation.
This commit reduces traffic consumed
by the teleport cluster by polling for CA
status less frequently.

It also addresses a bug in cert regeneration
that checked for the wrong principals
2018-10-26 17:00:37 -07:00
Russell Jones e69e67e372 Add support for CA pinning when joining a cluster. 2018-10-15 16:44:27 -07:00
Sasha Klizhentas 02a33675ed Detect remote cluster by SNI name
This commit improves performance of teleport with
hundreds of connected trusted clusters.

TLS handshake protocol expects server to send a
list of trusted certificate authorities to the client
and client must present certificate signed by those.

With Teleport current implementation, every remote cluster
client is signed by local certificate and is not cross
signed.

Auth server now expects clients to announce the
remote cluster they are connecting from using SNI.

Auth server will send only certificate authorities
of the cluster announced via SNI.

Alternative idea is to cross sign the certificate
of the client of the remote cluster. We will explore
this idea in the next releases.

This commit also removes unnecessary reads
from the database to check the remote server status
that slows down user interface and other clients.

This is done at the expense of proxies showing
servers as offline in case if this individual
proxy does not have the connection, although
it's a small UI price to pay for not reading
the database, as proxy will eventually
get the connection thanks to the discovery
protocol.
2018-09-28 11:00:36 -07:00
Sasha Klizhentas cd068733ab Read kubernetes config from kubeconfig
Fixes #1986

When deployed outside of the kubernetes cluster,
teleport now reads all configuration from kubernetes
config file, supplied via parameter.

Auth server then passes information about
target api server back to the proxy.
2018-09-25 17:32:28 -07:00
Sasha Klizhentas f17be1d9b9 Do not reveal error to the client, do not log token 2018-09-14 18:36:48 -07:00
Sasha Klizhentas 5c4a80a14b Shut down process on critical services errors
Whenever critical services in teleport exit
with errors, system should shut down immediatelly
and exit with error. This was not the case
since 2.7 release.
2018-09-07 18:09:18 -07:00
Sasha Klizhentas dca65a5234 Move keypair generation from auth server.
When many nodes join the cluster or rotate certificates,
auth server was forced to generate may private/public
key pairs simultaneosly creating bottleneck
on the auth server side.

This commit pushes the private public key generation
logic back to clients releiving the pressure from
auth server.
2018-09-05 17:48:45 -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
Russell Jones 3d9c34f1f0 Don't pass and clone client *tls.Config, instead pass cipher suites and
create new *tls.Config. Add test coverage for this.
2018-08-21 17:09:57 -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
Sasha Klizhentas fbb5aa2986 Initiate self-shutdown of a failed forked process.
This commit fixes #1970.

Original process is started but has failed to join the cluster
and repeatedly connects to it. This process is not
ready yet, but can process HUP (reload events).

1. HUP event is sent to a parent process.
2. The parent process forks a child process and
awaits a message from the child on the signal pipe.
3. If the child process fails to connect to the cluster
as well, it does not emit Ready event and a message
is never sent to the parent.
4. Parent process fails to receive a message and
assumes that parent process has failed to start.

As a result of this, there are two processes
both trying to connect to the cluster.

This commit changes behavior by adding extra step -
if the child process fails to enter ready stat and it is aware that
it was forked by the parent process, it initates self-shutdown.
2018-07-23 13:24:18 -07:00
Russell Jones 6439f7f973 Support configurable cipher suites. 2018-07-23 10:29:28 -07:00
Sasha Klizhentas 031168bbd4 Add readyz endpoint and clusters metrics.
This commit fixes #1610.

New readyz endpoint is added to existing
/metrics and /healthz endpoints activated by
diag addr-flag:

`teleport start --diag-addr=127.0.0.1:1234`

Readyz endpoint will report 503 if node or
proxy failed to connect to the cluster and 200 OK
otherwise.

Additional prometheus gagues report connection
count for trusted and remote clusters:

```
remote_clusters{cluster="one"} 1
remote_clusters{cluster="two"} 1

trusted_clusters{cluster="one",state="connected"} 0
trusted_clusters{cluster="one",state="connecting"} 0
trusted_clusters{cluster="one",state="disconnected"} 0
trusted_clusters{cluster="one",state="discovered"} 1
trusted_clusters{cluster="one",state="discovering"} 0
```
2018-07-20 19:01:15 -07:00
Sasha Klizhentas f699bd1a76 Fix error handling in audit sessions and events.
This commit fixes #2084
2018-07-18 15:54:51 -07:00
Sasha Klizhentas e595c3793d Log events to multiple destinations
This commit implements #2070

```yaml
teleport:
  storage:
    type: dir
    audit_events_uri:  [file:///var/lib/teleport/events, dynamodb://test_grv8_events]
    audit_sessions_uri: s3://testgrv8records
```
2018-07-16 18:34:13 -07:00
Sasha Klizhentas 66fa34bcde Add framework for trusted cluster K8s access 2018-06-22 12:56:58 -07:00
Russell Jones a62102c3e8 Add ability to detect when a proxy has been removed forever to discovery
protocol.
2018-06-21 23:14:52 +00:00
Sasha Klizhentas 03069a2aad Kubernetes proxy integration tests.
This PR contains Kubernetes proxy
integration tests and associated internal changes.
2018-06-14 16:47:52 -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 19b2936514 Update default cryptographic primitives. 2018-05-08 14:47:07 -07:00
Sasha Klizhentas ddd5150dd3 Introduce additional phase to CA rotation.
Flaky tests in teleport integration suite uncovered a problem.
It is possible that main cluster rotates certificate authority,
and will try to dial to the remote cluster with new credentials
before the remote cluster could fetch the new CA to trust.

To fix this, phase "update_clients" was split in two phases:

* Init and Update clients

Init phase does nothing on the main cluster except generating
new certificate authorities, that are trusted but not used in the
cluster.

This phase exists to give remote clusters opporunity
to update the list of trusted certificate authorities
of the main cluster, before main cluster reconnects with new clients
in "Update clients" phase.
2018-05-07 15:23:28 -07:00
Sasha Klizhentas 074961892a Precompute keys only for auth and proxies.
This commit fixes #1886

Previously the code was precomputing keys
even for SSH nodes, that do not need precomputed
private keys pool.
2018-05-04 13:41:13 -07:00
Russell Jones 876e04af07 * Push window size changes to clients instead of polling.
* Cache services.ClusterConfig within srv.ServerContext for the duration
  of a connection.
* Create a single websocket between the browser and the proxy for all
* terminal bytes and events.
2018-05-04 18:28:36 +00:00
Sasha Klizhentas 350ccc3ecd Delete code deprecated in 2.6.0
This commit fixes #1805
2018-05-03 16:44:39 -07:00
Sasha Klizhentas daff8de6ef Switch to default dir backend.
This commit fixes #1741

* If bolt backend was used as a default,
new teleport continues using it as a default to prevent
regressions on start.

* Otherwise, dir backend is used as a default.
2018-05-03 11:06:08 -07:00
Sasha Klizhentas a4c86e0603 Add public_addr support for auth and ssh services.
This commit fixes #1803, fixes #1889

* Adds support for public_addr for Proxy and Auth
* Parameter advertise_ip now supports host:port format
* Fixes incorrect output for tctl get proxies
* Fixes duplicate output of some error messages.
2018-05-02 18:04:05 -07:00
Sasha Klizhentas 3e144cb900 Teleport certificate authority rotation.
This commit implements #1860

During the the rotation procedure issuing TLS and SSH
certificate authorities are re-generated and all internal
components of the cluster re-register to get new
credentials.

The rotation procedure is based on a distributed
state machine algorithm - certificate authorities have
explicit rotation state and all parts of the cluster sync
local state machines by following transitions between phases.

Operator can launch CA rotation in auto or manual modes.

In manual mode operator moves cluster bewtween rotation states
and watches the states of the components to sync.

In auto mode state transitions are happening automatically
on a specified schedule.

The design documentation is embedded in the code:

lib/auth/rotate.go
2018-04-30 12:58:57 -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 2b1175fea5 Write PID file before signal the parent process.
This fixes the race with systemd reload.

P - parent, C - child

During live reload scenario,
the following happens:

P -> forks C
P -> blocks  on pipe read
C -> writes to  pipe
C -> writes pid file
P < - reads message from pipe
P <- shuts down

However, there is a race:

P -> forks C
P -> blocks  on pipe read
C -> writes to pipe
P < - reads message from pipe
P <- shuts down
C -> writes pid file

In this case parent process exited
before child process writes new pid file
what makes systemd think that main process
is down and stop both processes.

This fix changes the sequence to:

P -> forks C
P -> blocks on pipe read
C -> writes pid file
C -> writes to pipe
P < - reads message from pipe
P <- shuts down

to make sure the race can't happen any more.
2018-04-04 16:21:23 -07:00
Sasha Klizhentas 533b45bdff Use signal pipe to make live reload better.
This commit allows teleport parent process to track
the status of the forked child process using os.Pipe.

Child process signals success to parent process by writing
to Pipe.

This allows HUP and USR2 to be more intelligent as they
can now detect the failure or success of the process.
2018-04-03 17:25:43 -07:00
Sasha Klizhentas 9af093e6f6 Introduce new upload API.
This PR improves session recording:

* Nodes and proxies always buffer recorded sessions
to disk during the session what improves performance
and makes the recording more resilient to network failures.

* Async uploader running on proxy or node always uploads the
session tarball to the audit log server.

* Audit log server is the only component uploading
to the S3 or any other API.
2018-03-29 15:15:05 -07:00
Sasha Klizhentas 8898f4235d Add support for paths in S3 URI uploader. 2018-03-26 09:18:36 -07:00
Sasha Klizhentas 0f43c4935d Turn off proxy support when no-tls is used.
Fixes #1800
2018-03-20 17:55:39 -07:00
Russell Jones 785967e37f Added PAM support to Teleport. 2018-03-20 14:20:43 -07:00
Sasha Klizhentas 7d05c05b5b Fix logging, collect status of forked processes
fixes #1785, fixes #1776

This commit fixes several issues with output:

First teleport start now prints output
matching quickstart guide and sets default
console logging to ERROR.

SIGCHLD handler now only collects
processes PID forked during live restart
to avoid confusing other wait calls that
have no process status to collect any more.
2018-03-19 16:46:10 -07:00
Russell Jones 8de02770ef Include nodename in the host certificate. 2018-03-16 22:01:44 +00:00
Ev Kontsevoy 78139cc512 Updated log message 2018-03-15 17:06:32 -07:00
Sasha Klizhentas bad1b0498d External events and sessions storage.
Updates #1755

Design
------

This commit adds support for pluggable events and
sessions recordings and adds several plugins.

In case if external sessions recording storage
is used, nodes or proxies depending on configuration
store the session recordings locally and
then upload the recordings in the background.

Non-print session events are always sent to the
remote auth server as usual.

In case if remote events storage is used, auth
servers download recordings from it during playbacks.

DynamoDB event backend
----------------------

Transient DynamoDB backend is added for events
storage. Events are stored with default TTL of 1 year.

External lambda functions should be used
to forward events from DynamoDB.

Parameter audit_table_name in storage section
turns on dynamodb backend.

The table will be auto created.

S3 sessions backend
-------------------

If audit_sessions_uri is specified to s3://bucket-name
node or proxy depending on recording mode
will start uploading the recorded sessions
to the bucket.

If the bucket does not exist, teleport will
attempt to create a bucket with versioning and encryption
turned on by default.

Teleport will turn on bucket-side encryption for the tarballs
using aws:kms key.

File sessions backend
---------------------

If audit_sessions_uri is specified to file:///folder
teleport will start writing tarballs to this folder instead
of sending records to the file server.

This is helpful for plugin writers who can use fuse or NFS
mounted storage to handle the data.

Working dynamic configuration.
2018-03-15 12:42:43 -07:00
Ev Kontsevoy 0c95f9f613 User-visible errors polish
Fixes #1779
2018-03-14 17:00:44 -07:00
Sasha Klizhentas 61de96f45c Add failsafe for bolt, fixes #1729 2018-03-02 12:35:49 -08: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
Russell Jones 1a343de853 Fixed incorrect access of logger. 2018-02-15 21:23:34 +00:00
Russell Jones b139f72cab Create single instance of keygen per process. Use cache of precomputed
certificates when using recording proxy.
2018-02-15 21:23:30 +00:00
Sasha Klizhentas 11672b8493 Terraform improvements.
Fixes #1671

* Add notes about TOS agreements for AMI
* Use specific UID for Teleport instances
* Use encrypted EFS for session storage
* Default scale up auto scaling groups to amount of AZs
* Move dashboard to local file
* Fix dynamo locking bug
* Move PID writing fixing enterprise pid-file
* Add reload method for teleport units
2018-02-14 15:09:56 -08:00
Sasha Klizhentas 7b1b29be80 Add go-client initial example. 2018-02-13 18:55:24 -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
Russell Jones f2b8bbd1c1 Added *Ready events that indicate a service has started. Wait on these
events in integration events before starting a test.
2018-02-06 16:52:46 -08:00
Sasha Klizhentas bb9b00e451 Cache recently accessed items.
Introduce cache for items that were accessed
by proxies and nodes within 2 second window to reduce
load on database under high load.
2018-01-31 16:35:18 -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
Alexey Kontsevoy 583858d2cb add ClusterConfiguration section to teleport cfg 2018-01-20 14:25:31 -05:00
Sasha Klizhentas c1153734b0 Add support for extra principals, fixes #1174
Add support for extra principals for proxy.
Proxy section already supports public_addr
property that is used during tctl users add
output.

Use the value from this property to update
host SSH certificate for proxy service.

proxy_service:
  public_addr: example.com:3024

With the configuration above, proxy host
certificate will contain example.com principal
in the SSH principals list.
2018-01-08 20:36:34 -08:00
Sasha Klizhentas ef473d809e Join address for web, reverse tunnel, fixes #1544
Support configuration for web and reverse tunnel
proxies to listen on the same port.

* Default config are not changed for backwards compatibility.
* If administrator configures web and reverse tunnel
addresses to be on the same port, multiplexing is turned on
* In trusted clusters configuration reverse_tunnel_addr
defaults to web_addr.
2018-01-05 16:20:56 -08:00
Sasha Klizhentas 71c15e5835 Add support for NFS-friendly log protocol.
* Session events are delivered in continuous
batches in a guaranteed order with every event
and print event ordered from session start.

* Each auth server writes to a separate folder
on disk to make sure that no two processes write
to the same file at a time.

* When retrieving sessions, auth servers fetch
and merge results recorded by each auth server.

* Migrations and compatibility modes are in place
for older clients not aware of the new format,
but compatibility mode is not NFS friendly.

* On disk migrations are launched automatically
during auth server upgrades.
2018-01-04 18:54:37 -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
Russell Jones 3bfe61dc0b Added integration tests and minor fixes. 2017-12-19 17:40:05 -08:00
Russell Jones 37ab1596c4 Updated reverse tunnel to allow use to forwarding server. 2017-12-09 19:29:20 +00:00
Russell Jones 7018852c5d Added forwarding SSH server. 2017-12-04 17:01:52 -08:00
Roman Tkachenko 143b834e57 Changes for the upcoming teleport pro:
* Allow external audit log plugins
* Add support for auth API server plugins
* Add license file path configuration parameter (not used in open-source)
* Extend audit log with user login events
2017-11-21 17:35:58 -08:00
Sasha Klizhentas f8c715ef41 make audit accessible by admin group members
If user running teleport is a member of adm group
create the directory and all subdirectories
accessible to admins.

Remove obsolete migrations required for pre 2.3 releases.
2017-11-17 17:58:34 -08:00
Sasha Klizhentas fed7d2f116 fix audit log file leak, fixes #1433
This is a fix for file leak in audit log server caused
by design issue:

Session file descriptors in audit log were opened on demand
when the session event or byte stream chunk  was reported.

AuditLog server relied on SessionEnd event to close the
file descriptors associated with the session.

However, when SessionEnd event does not arrive (e.g.
there is a timeout or disconnect), the file descriptors
were not closed. This commit adds periodic clean up
of inactive sessions.

SessionEnd is now used as an optimization measure
to close the files, but is not used as the only
trigger to close files.

Now, inactive idle sessions, will close file descriptors
after periods of inactivity and will reopen the file
descriptors when the session activity resumes.

SessionLogger was not designed to open/close files
multiple times as it was reseting offsets
every time the session files were opened. This
change fixes this condition as well.
2017-11-15 18:39:27 -08:00
Russell Jones 1eb6f6bd52 Refactored lib/srv to support multiple servers. 2017-11-09 16:58:58 -08:00
sokoow 56f778a19d Fixes for https://github.com/gravitational/teleport/pull/1426 2017-11-01 21:03:20 +00:00
sokoow a737326042 Adding disable-tls flag, fixing https://github.com/gravitational/teleport/issues/1304 2017-11-01 21:03:20 +00:00
Russell Jones 146220e3c9 Set default cluster configuration when not specified. 2017-10-31 11:03:29 -07:00
Maximilien Richer cbca7fe984
Merge branch 'master' into fix-typo 2017-10-27 17:29:13 +02:00
Russell Jones 432a7ad787 Added services.ClusterConfig resource which controls where (and if) a
session is recorded.
2017-10-25 21:09:21 +00: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 9543bf2208 Merge branch 'master' into sasha/curiosity 2017-10-12 16:57:41 -07:00
Russell Jones 23ecf797e7 Corrected static token handling. 2017-10-12 01:10:05 +00:00
Sasha Klizhentas 6e4d6b0cb2 more work, discovery works 2017-10-07 18:11:03 -07:00
Sasha Klizhentas e12ec7422c refactoring 2017-10-05 17:29:31 -07:00
Ev Kontsevoy 93f7dd3bf9 Better handling of "development mode"
Instead of quietly changing behavior because `DEBUG` envar was set to
true, Teleport now explicitly requires scary --insecure flag to enable
this behavior.
2017-09-10 13:45:14 -07:00
Ev Kontsevoy e9bc910f92 Removed the unused "dynamicConfig" flag
I noticed we have this setting in code, which is always set to false and
never evaluated.
2017-09-06 14:19:54 -07:00
Russell Jones 7bf2b5c28f Use node name (defaults to hostname) instead of host UUID. 2017-08-31 01:08:44 +00:00
Russell Jones c543067001 Removed namespaces and expires from user interface. 2017-08-30 18:11:13 +00: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
Russell Jones b4c805fe23 Re-factored cluster configuration. 2017-08-07 17:20:16 -07:00
Russell Jones 084c8274b4 Allow configuration of the ciphers, KEX algorithm, and MAC algorithms
for node and proxy.
2017-06-11 12:16:10 -07:00
Sasha Klizhentas 68ae676c0a Merge branch 'master' into sasha/exp2 2017-05-27 15:38:44 -07:00
Russell Jones 78ee5d09ee Added support for allowing the reading of a users environment when
creating a new child session from ~/.tsh/environment.
2017-05-26 17:06:49 -07:00
Sasha Klizhentas e766a3c902 work 2017-05-25 18:56:32 -07:00
Russell Jones 2bf011cb3d Fix ^C ignored issue on CentOS 6.8. 2017-05-24 10:31:05 -07:00
Sasha Klizhentas 8ecfe3acc1 fix and complete tests 2017-05-20 12:52:03 -07:00
Sasha Klizhentas bf211f5764 integration test 2017-05-19 19:03:28 -07:00
Sasha Klizhentas 3c2570fa35 Sasha High Availability. 2017-04-07 16:54:15 -07:00
Russell Jones 00567f6d0c Added public_address to proxy server configuration and heartbeat. 2017-03-17 11:38:40 -07:00
Russell Jones 2f70866e5a Added TrustedCluster resource. 2017-03-09 13:49:44 -08:00
Russell Jones 54c7f1cd32 Added dynamic_config and removed seed_config. 2017-03-01 16:44:34 -08:00
Russell Jones 2033d8093c Fix configuration file regressions. 2017-02-24 14:48:52 -08:00
Russell Jones 1dcd3e11e5 Refactored authentication configuration, created resources for dynamic configuration of authentication configuration, and updated documentation. 2017-02-22 11:48:06 -08:00
Russell Jones 6295213815 Host certificate now presents two principals: hostUUID.clusterName and nodeName.clusterName. 2017-02-08 18:34:29 -08:00
Ev Kontsevoy 2150cb31de The web UI is not using the CLI client
TODO:
- Configure the CLI client to NOT use a keystore
- Configure the CLI client to NOT use ssh-agent
- Fix tests
- Comments
2017-02-02 22:54:48 -08:00
Sasha Klizhentas 83d979d007 fixing tests 2017-01-30 20:18:15 -08:00
Ev Kontsevoy ac205ad530 Finished cleaning up storage back-ends
I hope this closes #688
2017-01-15 23:23:37 -08:00
Ev Kontsevoy 7040331660 Fixed all tests
Also replaced mailgun.FrozenTime with `clockwork` in a few places
(mailgun's frozen time still remains elsewhere)
2017-01-15 16:28:18 -08:00
Ev Kontsevoy 312af8f02d Converted DynamoDB and etcd to common backend API
TODO:
- fix etcd tests
- do some manual testing of all backends
2017-01-15 16:28:18 -08:00
Ev Kontsevoy 40caec6048 Converted boltbk to the new format
BoltDB backend is now compatible with how all backends should
initialize.

Also all BoltDB-specific code/constants have been consolidated inside of
`backend.boltbk` package.
2017-01-15 16:28:18 -08:00