Commit Graph
793 Commits
Author SHA1 Message Date
Andrew Lytvynov 3d02ae6279 mfa: per-session MFA certs for SSH and Kubernetes (#5564)
* mfa: per-session MFA certs for SSH and Kubernetes

This is client-side support for requesting single-use certs with an MFA
check.

The client doesn't know whether they need MFA check when accessing a
resource, this is decided during an RBAC check on the server. So a
client will always try to get a single-use cert, and the server will
respond with NotNeeded if MFA is not required. This is an extra
round-trip for every session which causes ~20% slowdown in SSH logins:

```
$ hyperfine '/tmp/tsh-old ssh talos date' '/tmp/tsh-new ssh talos date'
Benchmark #1: /tmp/tsh-old ssh talos date
  Time (mean ± σ):      49.9 ms ±   1.0 ms    [User: 15.1 ms, System: 7.4 ms]
  Range (min … max):    48.4 ms …  54.1 ms    59 runs

Benchmark #2: /tmp/tsh-new ssh talos date
  Time (mean ± σ):      60.2 ms ±   1.6 ms    [User: 19.1 ms, System: 8.3 ms]
  Range (min … max):    59.0 ms …  69.7 ms    50 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary
  '/tmp/tsh-old ssh talos date' ran
    1.21 ± 0.04 times faster than '/tmp/tsh-new ssh talos date'
```

Another few other internal changes:

- client.LocalKeyAgent will now always have a non-nil LocalKeyStore.
  Previously, it would be nil (e.g. in a web UI handler or when using an
  identity file) which easily causes panics. I added a noLocalKeyStore
  type instead that returns errors from all methods.

- requesting a user cert with a TTL < 1min will now succeed and return a
  1min cert instead of failing

* Capture access approvals on MFA-issued certs

* Address review feedback

* Address review feedback

* mfa: accept unknown nodes during short-term MFA cert creation

An unknown node could be an OpenSSH node set up via
https://goteleport.com/teleport/docs/openssh-teleport/

In this case, we shouldn't prevent the user from connecting.

There's a small risk of authz bypass - an attacker might know a
different name/IP for a registered node which Teleport doesn't know
about. But a Teleport node will still check RBAC and reject the
connection.

* Validate username against unmapped user identity

IssueUserCertsWithMFA is called on the leaf auth server in case of
trusted clusters. Username in the request object will be that of the
original unmapped caller.

* mfa: add IsMFARequired RPC

This RPC is ran before every connection to check whether MFA is
required. If a connection is against the leaf cluster, this request is
forwarded from root to leaf for evaluation.

* Fix integration tests

* Correctly treat "Username" as login name in IsMFARequired

Also, move the logic into auth.Server out of ServerWithRoles.

* Fix TestHA

* Address review feedback
2021-03-10 15:42:16 -08:00
Andrew Lytvynov eee051c4a6 grpc: use the regular buildbox and bump gogoproto version (#5879)
An extra dockerfile for gRPC generation is extra maintenance burden. It
was also using a really old base image that has a ton of known vulns.

Also, update GOGO_PROTO_TAG to match the version we have vendored via
go.mod.
2021-03-10 11:16:08 -08:00
Andrew Lytvynovanda-palchikov 5c71da92b9 mfa: reuse the same challenge for all U2F devices (#5837)
* mfa: reuse the same challenge for all U2F devices

Challenge is a random string that U2F devices must sign. The JS API
requires you to use the same challenge for all registered devices,
instead of one challenge per device that we had previously. See
https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-javascript-api.html#dictionary-u2fsignrequest-members

Reuse the same challenge for U2F devices to match the JS API. Also,
propagate the version string to follow the spec exactly.

* Update lib/auth/auth.go

Co-authored-by: a-palchikov <deemok@gmail.com>

Co-authored-by: a-palchikov <deemok@gmail.com>
2021-03-10 10:28:36 -08:00
Andrew Lytvynov 6d8f778157 mfa: add WithMFA to session-related audit events (#5833)
* mfa: put device UUID in MFAVerified cert extensions

Instead of just a bool, add the device UUID. This will be used in audit
events when a session is started using MFA-issued certs.

* Add WithMFA to session-related audit events

Also extract a common function for parsing SSH certs.
2021-03-04 14:18:30 -08:00
Andrew Lytvynov f9f62ff902 mfa: audit events for adding/removing devices (#5665)
* mfa: audit events for adding/removing devices

Also add `With2FA` field to `UserLogin` when an MFA device is used
during login.

* Address review feedback

* mfa: reorganize audit event structure to be flat
2021-03-04 11:02:35 -08:00
Roman Tkachenko 5e0178d3f6 Fix db server test data race (#5832) 2021-03-03 13:02:42 -08:00
Alexey Kontsevoy 472df28f2a Add "billing_information" RBAC resource (#5676)
* Expose GRPC client connection to plugins
* Replaces global plugin state with the PluginRegistry
2021-03-01 22:47:03 -05:00
Andrew Lytvynov efc99a068c Update Go dependencies
Several dependencies can't be updated due to breakages (etcd and grpc
for example).

Also updated ttlmap usage since their API changed.
2021-02-23 18:04:55 -08:00
Brian Joerger 488cf7b66c API credential loaders (#5455) 2021-02-22 16:43:00 -08:00
Brian Joerger 427bafe7b2 API Go module (#5449) 2021-02-22 16:20:43 -08:00
Roman Tkachenko 21b90a64cf Add app and db access flags to license (#5627) 2021-02-22 08:35:08 -08:00
Jane Quintero f3f87489ce remove pointer from GetUploadMetadata in MultipartUploader interface + PR feedback
pass uploadmetadata by value

update test

use DiscardAuditLog in tests

update e and use uploadHandler as UploadMetadataGetter
2021-02-19 17:29:11 -08:00
Jane Quintero 9b26bfe821 emit session upload event 2021-02-19 17:29:11 -08:00
Sasha Klizhentas 013f9680c9 OSS RBAC
Implements RFD #7

https://github.com/gravitational/teleport/blob/master/rfd/0007-rbac-oss.md

OSS users can use roles. Some FedRamp related role options
are limited to enterprise.

All users are migrated to a new role "ossuser".

This role is a limited access role downgrading all users
from OSS role "admin".

All trusted clusters are mapped to "ossuser" as well.

Github connector maps teams to generated roles.

For transition period, format `tctl users add alice` works
alongside with `tctl users add alice --roles=admin`, but prints
a warning.
2021-02-17 17:04:03 -08:00
Andrew Lytvynov eed77ade1b auth: add RequireSessionMFA to roles and enforce it (#5539)
* auth: add RequireSessionMFA to roles and enforce it

Enforcement kicks in when at least one role that grants access requires
it. Right now, clients don't request MFA-verified certs yet, so if a
role sets the field, it won't be usable. Next PR will add client logic
to request the special certs.

* Address review feedback
2021-02-17 15:22:24 -08:00
5739b63e51 mfa: add new second_factor options "on" and "optional" (#5508)
* mfa: add new second_factor options "on" and "optional"

"on" means that 2FA is required for all users, either TOTP or U2F.

"optional" means that 2FA is supported for all users, but not required.
Only users with MFA devices registered will be prompted for 2FA on
login.

The login with both supported methods is using the same API as the U2F
login. It just now supports TOTP in addition. The API endpoints are
still named after "u2f", I'll rename those in a future PR (in a
backwards-compatible way).

* Apply suggestions from code review

Co-authored-by: Gus Luxton <gus@gravitational.com>
Co-authored-by: a-palchikov <deemok@gmail.com>

* Address reivew feedback

Co-authored-by: Gus Luxton <gus@gravitational.com>
Co-authored-by: a-palchikov <deemok@gmail.com>
2021-02-16 16:24:23 -08:00
Roman Tkachenko 8dcfbfc5f0 Add mysql functional/integration tests (#5472) 2021-02-12 15:09:26 -08:00
Andrew Lytvynovanda-palchikov 0f49d601a7 auth: API for requesting per-connection certificates (#5527)
* auth: API for requesting per-connection certificates

See https://github.com/gravitational/teleport/blob/master/rfd/0014-session-2FA.md#api

This API is a wrapper around GenerateUserCerts with a few differences:
- performs an MFA check before generating a cert
- enforces a single usage (ssh/k8s/db for now)
- embeds client IP in the cert
- marks a cert to distinguish from regular user certs
- enforces a 1min TTL

* Apply suggestions from code review

Co-authored-by: a-palchikov <deemok@gmail.com>

Co-authored-by: a-palchikov <deemok@gmail.com>
2021-02-10 20:29:00 -08:00
Roman Tkachenko 81e1102250 Add MySQL support for database access (#5453) 2021-02-10 11:08:13 -08:00
a-palchikov 86908cc2f3 Web UI disconnects (#5276)
* Use fake clock consistently in units tests.
* Split web session management into two interfaces and implement them separately for clear separation
* Split session management into New/Validate to make it aparent where the sessions are created and where existing sessions are managed. Remove ttlmap in favor of a simple map and handle expirations
explicitly.
Add web session management to gRPC server for the cache.

* Reintroduce web sessions APIs under a getter interface.
* Add SubKind to WatchKind for gRPC and add conversions from/to protobuf. Fix web sessions unit tests.
* lib/web: create/insert session context in ValidateSession if the session has not yet been added to session cache.
lib/cache: add event filter for web session in auth cache.
lib/auth: propagate web session subkind in gRPC event.

* Add implicit migrations for legacy web session key path for queries.
* Integrate web token in lib/web
* Add a bearer token when upserting a web session
* Fix tests. Use fake clock wherever possible.

* Converge session cache handling in lib/web

* Clean up and add doc comments where necessary

* Use correct form of sessions/tokens controller for ServerWithRoles. Use fake time in web tests

* Converge the web sessions/tokens handling in lib/auth to match the old behavior w.r.t access checking (e.g. implicit handling of the local user identity).

* Use cached reads and waiters only when necessary. Query sessions/tokens using best-effort - first looking in the cache and falling back to a proxy client

* Properly propagate events about deletes for values with subkind.

* Update to retrofit changes after recent teleport API refactorings

* Update comment on removing legacy code to move the deadline to 7.x

* Do not close the resources on the session when it expires - this beats the purpose of this PR.
Also avoid a race between closing the cached clients and an existing reference to the session by letting the session linger for longer before removing it.

* Move web session/token request structs to the api client proto package

* Only set HTTP fs on the web handler if the UI is enabled

* Properly tear down web session test by releasing resources at the end. Fix the web UI assets configuration by removing DisableUI and instead use the presence of assets (HTTP file system) as an indicator that the web UI has been enabled.

* Decrease the expired session cache clean up threshold to 2m. Only log the expiration error message for errors other than not found

* Add test for terminal disconnect when using two proxies in HA mode
2021-02-04 16:50:18 +01:00
Andrew Lytvynov 5ce5e1c525 mfa: implement management commands in tsh (#5473)
* mfa: implement management commands in tsh

New commands are:
- tsh mfa ls
- tsh mfa add
- tsh mfa rm

There are 2 problems intentionally left in this PR to keep it small:

1. TOTP registration requires user to manually enter the secret in the
app. When there's free time, I'll add platform-specific QR code display
to make this easier.

2. U2F authentication only checks one of the registered devices. This is
a limitation of the u2f-host binary, which can't check multiple devices
at once (even if spawning multiple u2f-host commands in parallel). In
the next PR, I'll replace u2f-host with a Go library that supports this.

* Address review feedback
2021-02-03 16:06:42 -08:00
Andrew Lytvynov 81927a7f95 mfa: device management API (#5456)
Add 3 new RPCs for the auth server:
- AddMFADevice
- DeleteMFADevice
- GetMFADevices

All RPCs act on the user calling them, rather than specifying the user
in parameters. It's one less thing to validate and also prevents authz
bugs with one user messing with other user's MFA devices.

Add and Delete RPCs are streaming both ways, to allow MFA using an
existing device (prevents MFA bypass) and a challenge/response
registration used in U2F and TOTP. This approach makes the challenge
bound to the RPC connection and doesn't require backend storage.
2021-02-03 10:12:25 -08:00
Andrew Lytvynov 4b5bb54bf4 u2f: restructure MFA backend to support multiple devices (#5404)
Each user can now have multiple devices. This commit only changes the
backend structure to support it, the client and API haven't been updated
yet.

Also added a migration for existing MFA data on auth server startup.
2021-02-01 17:30:39 -08:00
Brian Joerger ce6e08c438 api dependency reduction - uuid (#5386)
Move uuid generation for access requests to /lib/services.
2021-02-01 11:12:49 -08:00
Brian Joerger eedcd78981 api dependency reduction - authentication (#5385)
Move methods involving authentication logic into /lib/services.
2021-02-01 10:59:51 -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
Brian Joerger efe91c4def api dependency reduction - ssh (#5379)
Move Cert Authority methods out of api to remove dependency on crypto/ssh.
2021-01-29 10:28:24 -08:00
Brian Joerger 74f7c801da api dependency reduction - oidc and predicate (#5366) 2021-01-29 10:00:59 -08:00
Brian Joerger 626ad243eb api dependency reduction - utils constants (#5363)
Moved constants and utils used in /api into /api/constants and /api/utils respectively.
2021-01-29 09:37:01 -08:00
Brian Joerger c3e86f1696 Refactor API Dependencies - tlsca and gosaml2 (#5242) 2021-01-20 17:30:03 -08:00
Brian Joerger a555844116 Refactor API Dependencies - clockwork (#5253)
Deprecate SetTTL method in favor of SetExpiry and remove other dependencies on clockwork.
2021-01-20 15:55:32 -08:00
Brian Joerger 7f0c20d9a2 API Dependency Reduction - lib/jwt (#5295)
Refactor CertAuthority methods and GenerateAppToken to remove lib/jwt dependency.
2021-01-19 14:16:25 -08:00
Brian Joerger 76b6b6d84d Refactor lib/utils/parse dependency in api package. (#5261) 2021-01-19 11:32:07 -08:00
Roman Tkachenko 8e1865464b Database access (#5005) 2021-01-14 18:21:38 -08:00
Brian Joerger 64f80f1d1a Move proto files and other select files from lib/events package to api/types/events package. (#5251) 2021-01-14 16:13:17 -08:00
Brian Joerger eb97e172f1 Refactor TrustedCluster.CheckAndSetDefaults logic. (#5287) 2021-01-14 15:58:50 -08:00
Brian Joerger ab3d1a11da Move /lib/wrappers to /api/types/wrappers. (#5286) 2021-01-14 14:58:44 -08:00
Brian Joerger 165c78846f Refactor AuditStream endpoints to remove lib/session dependency. (#5252) 2021-01-12 12:45:14 -08:00
Brian Joerger 39eff6e625 Refactor OpType and constants from lib/backend into the types package. (#5241) 2021-01-12 10:47:30 -08:00
a-palchikov 6684c37103 Use fake clock consistently in units tests. (#5263)
Use fake clock consistently in units tests.
2021-01-12 12:10:00 +01:00
Brian Joerger 3c3ce160d9 Move API types and functionality from lib/services to api/types. (#5143) 2021-01-11 10:02:34 -08:00
Forrest Marshall f5c62fcc20 add dynamic access oracle 2020-12-31 09:57:05 -08:00
joerger f020f75078 Refactor API client into a separate package. 2020-12-29 10:06:37 -08:00