Commit graph

41 commits

Author SHA1 Message Date
Brian Joerger 5e3f2359a4
Add DialOpts and CallOpts to API client. (#6301)
* Add DialOpts to client.Config.

* Add callOpts to client and client.WithCallOptions.

* Refactor use of atomic closedFlag.
2021-04-07 14:23:34 -07:00
Andrew Lytvynov 6d200faecb
tsh: handle missing cluster name in profile (#6257)
Cluster name can be missing in profiles created by older tsh versions.
Trying to load the client.Key without a cluster name now causes a
failure when using WithAllCerts (because ssh/db/kube certs are
per-cluster).

Also added some output to `tsh status` when no profiles can be loaded.
2021-04-02 11:00:15 -07:00
Brian Joerger 826ed676fa Refactor ssh.ClientConfig used by tctl and API clients to use the first valid principal as User. 2021-03-30 17:53:29 -07:00
Gus Luxton 854da48990
Add lint-api target and fix lint errors (#6169) 2021-03-30 17:02:04 -07:00
Brian Joerger ee57e539b5
tsh Profile SSH certs fix (#6214) 2021-03-30 12:10:52 -07:00
Andrej Tokarčík 52dfeec63e
Cache per-cluster SSH certificates under ~/.tsh (#5938)
```diff
 ~/.tsh/
 └── keys
    ├── one.example.com            --> Proxy hostname
    │   ├── certs.pem              --> TLS CA certs for the Teleport CA
    │   ├── foo                    --> RSA Private Key for user "foo"
    │   ├── foo.pub                --> Public Key
-   │   ├── foo-cert.pub           --> SSH certificate for proxies and nodes
    │   ├── foo-x509.pem           --> TLS client certificate for Auth Server
+   │   ├── foo-ssh                --> SSH certs for user "foo"
+   │   │   ├── root-cert.pub      --> SSH cert for Teleport cluster "root"
+   │   │   └── leaf-cert.pub      --> SSH cert for Teleport cluster "leaf"
```

When `-J` is provided, this also loads/reissues the SSH cert for the cluster associated with the jumphost's certificate. Fixes #5637.
2021-03-29 14:14:31 -07:00
Brian Joerger f15ceee373
Convert Token CRUD endpoints to gRPC. (#6105) 2021-03-26 19:23:20 -07:00
Brian Joerger c7d84c45d7
Convert Trusted Cluster CRUD endpoints to gRPC. (#6103) 2021-03-26 18:29:39 -07:00
Brian Joerger b1bb78a9e0
gRPC conversions - GithubConnector (#6101) 2021-03-26 17:16:49 -07:00
Brian Joerger 0076893155
gRPC conversions - SAMLConnector (#6100) 2021-03-26 16:39:27 -07:00
Brian Joerger 06d252ffca
gRPC conversions - OIDCConnector (#6067) 2021-03-26 15:52:16 -07:00
Brian Joerger 3d6ecb05cd
Remove duplicate sshutils package from merge failure. (#6165) 2021-03-25 19:33:24 -07:00
Brian Joerger 0540755624
Profile credentials dialer fix (#6122) 2021-03-25 17:55:49 -07:00
Brian Joerger c891bae327
Combine common crud proto messages into generic messages in types.proto. (#6058) 2021-03-25 14:25:37 -07:00
Forrest Marshall 59d2379b94 custom approval conditions 2021-03-24 14:33:40 -07:00
Brian Joerger 32c4ae255f
Add Credential loader support for tsh profiles. (#5993) 2021-03-23 16:35:42 -07:00
Brian Joerger 2beb991598
API client connection overhaul (#5625)
* Added support for connecting API client through tunnel proxy and web proxy addresses (with identity file).

* Added concurrent dialing logic to dial several possible dialing combinations and seamlessly return the first client to connect.
2021-03-23 14:39:20 -07:00
Roman Tkachenko a3837f6720
App access cli flow (#5918) 2021-03-22 09:18:53 -07:00
Brian Joerger 5e9ea1c7e1
Add Features and PublicAddrs to PingResponse (#5742) 2021-03-10 18:15:40 -08:00
Brian Joerger 494782fe12
Convert Role endpoints to gRPC. (#5458) 2021-03-10 17:54:08 -08:00
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 Lytvynov 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
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
Brian Joerger 488cf7b66c
API credential loaders (#5455) 2021-02-22 16:43:00 -08:00
Andrew Lytvynov 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
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 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 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 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
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 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
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