Commit graph

47 commits

Author SHA1 Message Date
Andrew Lytvynov cd2f4fceb7
Remove JSON schema validation (#6685)
* Remove JSON schema validation

Removing JSON schema validation from all resource unmarshalers.

--- what JSON schema gets us

Looking at the JSON schema spec and our usage, here are the supposed benefits:
- type validation - make sure incoming data uses the right types for the right fields
- required fields - make sure that mandatory fields are set
- defaulting - set defaults for fields
- documentation - schema definition for our API objects

Note that it does _not_ do:
- fail on unknown fields in data
- fail on a required field with an empty value

--- what replaces it

Based on the above, it may seem like JSON schema provides value.
But it's not the case, let's break it down one by one:
- type validation - unmarshaling JSON into a typed Go struct does this
- required fields - only checks that the field was provided, doesn't actually check that a value is set (e.g. `"name": ""` will pass the `required` check)
  - so it's pretty useless for any real validation
  - and we already have a separate place for proper validation - `CheckAndSetDefaults` methods
- defaulting - done in `CheckAndSetDefaults` methods
  - `Version` is the only annoying field, had to add it in a bunch of objects
- documentation - protobuf definitions are the source of truth for our API schema

--- the benefits

- performance - schema validation does a few rounds of `json.Marshal/Unmarshal` in addition to actual validation; now we simply skip all that
- maintenance - no need to keep protobuf and JSON schema definitions in sync anymore
- creating new API objects - one error-prone step removed
- (future) fewer dependencies - we can _almost_ remove the Go libraries for schema validation (one transient dependency keeping them around)

* Remove services.SkipValidation

No more JSON schema validation so this option is a noop.
2021-06-01 15:27:20 -07:00
Andrej Tokarčík ad00c6c789
Introduce ClusterNetworkingConfig extracting fields from ClusterConfig (#6638) 2021-05-07 13:54:08 +02:00
Brian Joerger 4398797f14
Pass context through new gRPC converted endpoints. (#6118) 2021-03-23 18:26:52 -07:00
Lisa Kim 84a4f00114
Define cloud billing event types and codes (#6037)
* Exported auth.clientImpersonator and auth.clientUsername for use in e
2021-03-23 17:23:01 -07:00
Alexander Klizhentas f17625c1a8
Adds controls for impersonation requests. (#6009) (#6073)
Fixes #5352

```yaml
allow:
  impersonate:
    users: ['alice', 'bob']
    roles: ['*']
    where: 'contains(user.spec.traits["groups"], impersonate_role.traits)'
```

Adds "impersonator" to all X.509 and SSH client certs
issued using impersonation and does best effort to track
requests by impersonators in audit events.

Limits certs TTL to the impersonator's max session TTL.

Prevents impersonating users to recursively impersonate
other users.

Allows impersonating users to renew their own certificate,
for example to set route to cluster.

Adds missing token permission for editor role.
2021-03-19 16:04:43 -07:00
Brian Joerger 494782fe12
Convert Role endpoints to gRPC. (#5458) 2021-03-10 17:54:08 -08:00
Brian Joerger ce87251ea0
api dependency reduction - marshalers (#5384)
Refactor Marshal logic on types, and move it into /lib/services to reduce dependencies in /api.
2021-02-01 10:26:50 -08:00
Sasha Klizhentas c623aa4dc5 Add cluster labels
Fixes #3604

This commit adds support for cluster_labels
role parameter limiting access to remote clusters by label.
New tctl update rc provides interface to set labels on remote clusters.

Consider two clusers, `one` - root and `remote` - leaf.

```bash
$ tsh clusters
Cluster Name Status
------------ ------
one          online
two          online
```

Create the trusted cluster join token with labels:

```bash
$ tctl tokens add --type=trusted_cluster --labels=env=prod
```

Every cluster joined using this token will inherit env:prod labels.

Alternatively, update remote cluster labels by modifying
`rc` command. Letting remote clusters to propagate their labels
creates a problem of rogue clusters updating their labels to bad values.

Instead, administrator of root cluster control the labels
using remote clusters API without fear of override:

```bash
$ tctl get rc

kind: remote_cluster
metadata:
  name: two
status:
  connection: online
  last_heartbeat: "2020-09-14T03:13:59.35518164Z"
version: v3
```

```bash
$ tctl update rc/two --set-labels=env=prod

cluster two has been updated
```

```bash
$ tctl get rc
kind: remote_cluster
metadata:
  labels:
    env: prod
  name: two
status:
  connection: online
  last_heartbeat: "2020-09-14T03:13:59.35518164Z"
```

Update the role to deny access to prod env:

```yaml
kind: role
metadata:
  name: dev
spec:
  allow:
    logins: [root]
    node_labels:
      '*': '*'

    # Cluster labels control what clusters user can connect to. The wildcard ('*') means
    # any cluster. If no role in the role set is using labels and cluster is not labeled,
    # the cluster labels check is not applied. Otherwise, cluster labels are always enforced.
    # This makes the feature backwards-compatible.
    cluster_labels:
      'env': 'staging'
  deny:
    # cluster labels control what clusters user can connect to. The wildcard ('*') means
    # any cluster. By default none is set in deny rules to preserve backwards compatibility
    cluster_labels:
      'env': 'prod'
```

```bash
$ tctl create -f dev.yaml
```

Cluster two is now invisible to user with `dev` role.

```bash
$ tsh clusters
Cluster Name Status
------------ ------
one          online
```
2020-11-03 16:10:15 -08:00
Andrew Lytvynov 61a69b3f02 Improve error logging for trusted cluster token validation
Auth server and proxy should internally log the full error message
without masking it.
2020-10-15 00:44:38 +00:00
Andrew Lytvynov 92ed2db38a Fixing golint warnings, batch 1
Mostly cosmetic changes:
- making receiver names consistent
- renaming `foo.FooBar` to `foo.Bar` (using package name as prefix)
- removing redundant `else` branches
- changing `a += 1` to `a++`
2020-10-13 00:22:49 +00:00
Sasha Klizhentas d160507430 Session streaming
This commit introduces GRPC API for streaming sessions.

It adds structured events and sync streaming
that avoids storing events on disk.

You can find design in rfd/0002-streaming.md RFD.
2020-09-28 23:08:56 -07:00
Andrew Lytvynov 6a14edcf1f Keep RemoteCluster resources up-to-date in the backend
Prior to this commit, RemoteCluster resource data was dynamically
generated from TunnelConnection resources.

Keep using TunnelConnections, but record any changes to RemoteCluster in
the backend too. This lets us preserve the LastHeartbeat field after
TunnelConnections get deleted (as they do when a reverse tunnel
disconnects).
2020-08-28 00:28:45 +00:00
Andrew Lytvynov 5bd66a396e Plumb caller username for CRUD events via contexts
Our auth middleware already attaches a TLS identity as context value.
Plumb contexts through and extract the username when recording events.
If the received context doesn't have an identity attached, use "system"
as username.

Lots of noise here due to missing context.Context plumbing :(
We should eventually plumb contexts to all those RPC interfaces.

Updates #3816
2020-06-18 19:01:35 +00:00
Andrew Lytvynov a9eae02374 errcheck: add missing error handling in lib/auth 2020-06-03 21:57:04 +00:00
Lisa Kim 7acf6b516e
Emit audit events when trusted clusters are upserted or deleted #3719 (#3727)
* Bug Fix: prevent user from deleting their own root CA
2020-05-19 14:47:47 -07:00
Andrew Lytvynov 732dfd5a64 Revert changes to truth tables
The team is split on style preferences here. Revert to the original
switch format and disable the relevant check.
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
Russell Jones 1bf2bbc5fd Configurable timeout for tunnel offline threshold.
Added support for a configurable offline threshold based off the keep
alive interval and max count for marking a connection from an agent as
offline.
2019-05-22 09:36:18 -07:00
Cove Schneider 8b299e9c28 spelling cleanup 2018-11-15 12:44:51 -08:00
Russell Jones 064038a6d3 Propagate cancelation context. 2018-10-12 17:42:37 -07:00
Sasha Klizhentas e84bf10889 Batch get for tunnel connection, remote cluster
Use batch fetch for tunnel connections
and remote cluster objects to speed up
teleport in scenarios with many trusted clusters.
2018-09-28 11:00:36 -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 fc9e349a62 use fast fetch for trusted cluster validation 2018-09-21 09:50:48 -07:00
Russell Jones 6439f7f973 Support configurable cipher suites. 2018-07-23 10:29:28 -07:00
Sasha Klizhentas 045490de25 External traits in node labels and regexp role map
This commit adds two extensions to template variables
in roles and adds support for regular expressions
and group captures in role mapping of trusted clusters.

1. Roles node_labels can expand variables from traits:

allow:
  node_labels:
    '{{external.key}}': '{{external.val}}'
deny:
  node_labels:
    '{{external.key}}': '{{external.val}}'

If traits variable is not found, label key pair in allow or
deny rule will be set to empty key or value, so if 'external.val'
trait is missing, the resulting role will not match
allow or deny rule:

allow:
  node_labels:
    '': 'val'
deny:
  node_labels:
    '': 'val'

Same thing will happen for missing value:

allow:
  node_labels:
    'key': ''
deny:
  node_labels:
    'key': ''

2. Trusted cluster role mapping can now
support advanced expressions:

a. Glob values will math any string, including
empty one

   role_map:
   - remote: 'cluster-*'
     local: [clusteradmin]

a. Regular expression syntax is supported:

Syntax: https://github.com/google/re2/wiki/Syntax

Brackets can be used as a capture group and referred
to with expand variable:

   role_map:
   - remote: '^clusteradmin-(.*)$'
     local: [unprivileged-$1]

Will map incoming role 'clusteradmin-account-1' to 'guest-account-1'.

3. Same regular expression syntax is supported for SAML and OIDC
mappings:

a. Glob matches of values instead of static matches:

  claims_to_roles:
      - {claim: "roles", value: "gravitational/*", roles: ["clusteradmin"]}

b. Regexp matches with subgroup expands:

  attributes_to_roles:
      - {name: "roles", value: "^gravitational/(.*)$", roles: ["cluster-$1"]}
2018-07-02 16:13:12 -07:00
Russell Jones 87010f5239 Revendor github.com/gravitational/roundtrip and enable sanitizer on it. 2018-06-02 00:38:46 +00:00
Russell Jones 5d5c3de588 Updated TLS ciphersuites and updated SSH ciphers, KEX, and MAC
algorithms in forwarding server.
2018-05-25 21:29:33 +00:00
Russell Jones cd0d0f49ee Consolidate token validation code. 2018-05-08 10:34:45 -07:00
Sasha Klizhentas ef20e45208 Enforce trusted cluster resource name, fixes #1543
This commit makes sure that trusted cluster resource
name is the same name as the cluster name it conects to.

If user supplies name of the trusted cluster resource
that is different from the cluster name, the warning
will be issued and trusted cluster will be renamed.

Upgrade procedure renames existing trusted clusters
in place.

If user supplies trusted cluster without role
mappings, or with role mappings referring to
non-existent roles that do not exist, the
error will be returned.
2018-01-11 14:13:30 -08:00
Sasha Klizhentas e114fbd46c Add support for remote_cluster, implements #1526
This commit adds remote cluster resource that specifies
connection and trust of the remote trusted cluster to the local
cluster. Deleting remote cluster resource deletes trust
established between clusters on the local cluster side
and terminates all reverse tunnel connections.

Migrations make sure that remote cluster resources exist
after upgrade of the auth server.
2017-12-28 17:48:30 -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 0354833211 Additional cleanup (added error messages). 2017-09-14 10:59:25 -07:00
Russell Jones 6bda631584 Refactored Trusted Cluster state change. 2017-09-14 10:53:03 -07:00
Russell Jones ff63e664de Refactored Trusted Cluster creation/update. 2017-09-12 18:44:49 -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 f34a0c4d6f Minor code changes: better error messages + comments 2017-09-09 20:04:39 -07: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 4719c4bdfa Allow enable or disable of a TrustedCluster without performing the
exchange again.
2017-08-18 20:14:42 +00:00
Russell Jones b4c805fe23 Re-factored cluster configuration. 2017-08-07 17:20:16 -07:00
Russell Jones 2286c6593d Remote clusters should only send their own CAs. 2017-06-27 11:55:59 -07:00
Russell Jones 2117306774 Added HTTP CONNECT tunneling support for Trusted Clusters. 2017-05-25 10:28: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
Sasha Klizhentas 17574fef54 fix trusted cluster key exchange 2017-03-21 18:15:05 -07:00
Russell Jones 084a9211c3 Call ConvertResponse to convert error to internal error type based on
HTTP response code and HTTP body contents.
2017-03-10 17:05:43 -08:00
Russell Jones 2f70866e5a Added TrustedCluster resource. 2017-03-09 13:49:44 -08:00