Commit graph

2655 commits

Author SHA1 Message Date
Russell Jones 4f102552ee
Fixed build failure for non-Linux platforms. (#5800) 2021-03-01 18:17:02 -04:00
Joel Wejdenstål f3e07356c1
fix #5783 utmp regression on macos (#5784) 2021-03-01 17:40:59 -04:00
Andrej Tokarčík f4e13ea8f3 Don't defer Close calls on writable files 2021-03-01 22:14:10 +01:00
Andrej Tokarčík ee7693f41d Prevent AAP login CSRF with OAuth-style state tokens 2021-03-01 22:14:10 +01:00
Andrej Tokarčík ff18d38d7e Set cookies with '__Host-' prefix 2021-03-01 22:14:10 +01:00
Andrej Tokarčík c4faea980f Set stricter HTTP Content-Security-Policy directives 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 8720b1872a Assemble safe FQDN values for AAP redirects 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 89f0432ad5 Introduce utils.ReadAtMost to prevent resource exhaustion 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 85244157b0 Check CA expiration status when joining a cluster 2021-03-01 22:14:10 +01:00
Andrej Tokarčík f88665fe12 Add obfuscation to diagnostic metrics 2021-03-01 22:14:10 +01:00
Andrej Tokarčík a7f3a05e53 Fix AAP headers injection 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 46aa81b1ce Fix CLI content spoofing through access request reason 2021-03-01 22:14:10 +01:00
Andrej Tokarčík f958e03439 Require initialized TLS config in utils.TLSDial 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 80cf3ae749 Fix existence leak of label-restricted resources 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 899cc1c0ec
Propagate the mapped local user identity via auth.Context (#5794)
In `auth.Context`, the `Identity` field used to contain the original
caller identity and `User` field contained the mapped local user. These
are different, if the request comes from a remote trusted cluster.

Lots of code assumed that `auth.Context.Identity` contained the local
identity and used roles/traits from there.

To prevent this confusion, populate `auth.Context.Identity` with the
*mapped* identity, and add `auth.Context.UnmappedIdentity` for callers
that actually need it.

One caller that needs `UnmappedIdentity` is the k8s proxy. It uses that
identity to generate an ephemeral user cert. Using the local mapped
identity in that case would make the downstream server (e.g.
kubernetes_service) to treat it like a real local user, which doesn't
exist in the backend and causes trouble.

`ProcessKubeCSR` endpoint on the auth server was also updated to
understand the unmapped remote identities.

Co-authored-by: Andrew Lytvynov <andrew@goteleport.com>
2021-03-01 21:55:59 +01:00
Acrimon b9f7d2a53a fix last output timestamps on some systems 2021-02-26 22:59:51 +01:00
Gus Luxton 01fbe15b32
[tctl] Don't explicitly set value for config path and preserve backwards compatibility (#5731) 2021-02-25 22:00:48 -04:00
Roman Tkachenko ac7dea4345 Update old proxy version detection algorithm 2021-02-25 16:29:53 -08:00
Alexander Klizhentas 03161e8a6b
Sasha/newlines (#5738)
* Improves CLI error reporting

Escapes control characters, while allowing newlines.
Removes tabs in output.
2021-02-25 14:52:25 -08:00
Alexander Klizhentas 5e12308fa7
Adds public_addr when using ACME (#5734)
Fixes #5711

Adds required public_addr when using ACME mode.
2021-02-25 13:47:33 -08:00
Andrew Lytvynov af81a7892f
Make /lib/web tests more reliable (#5703)
Fix condition on the proxy registration check.

Use t.Cleanup to close all servers and clients reliably and avoid
running out of file descriptors.
2021-02-25 13:09:25 -08:00
Acrimon e9f90cb049 utmp fix for symlinked path 2021-02-25 20:50:30 +01:00
Alexander Klizhentas b5d8169fc0
Downgrades admin OSS role (#5710)
Fixes #5708

OSS users loose connection to leaf clusters after upgrade of the root cluster (but not leaf clusters).
Teleport 6.0 switches users to ossuser role, this breaks implicit cluster mapping of admin to admin users.

The fix downgrades admin role to be less privileged in OSS.
2021-02-25 11:28:41 -08:00
Andrew Lytvynov 5caa750088 Hide the k8s cluster defaulting error log on login
This specific error happens when there are no k8s clusters registered,
which is common. Don't include the original error in the log because it
includes the entire stack trace.
2021-02-24 18:27:00 -08:00
Andrew Lytvynov 485856fbb0 u2f: use gravitataional/ttlmap instead of mailgun/ttlmap 2021-02-23 18:04:55 -08:00
Andrew Lytvynov fc1c1dbd14 Move all utils.InitLoggerForTests calls to TestMain
This prevents data races between changing the standard logger and it
acutally being used.
2021-02-23 18:04:55 -08: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
Acrimon cb701c4743 Refactor lib/asciitable, lib/tlsca, lib/shell, lib/session and lib/config tests to not use gocheck 2021-02-23 18:30:06 +01: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
Lisa Kim 2669e7aef2
Open source UI users, roles, github cn, trusted cluster (#5540)
* Transferred user endpoints/handlers from e
* Transferred and refactored endpoints/handlers for roles, trusted clusters, and github cn from e
* Export ok() func so e can use
* Silence rbac auth connector access denials on first check failure
* Update e-ref
2021-02-22 08:54:36 -08:00
Roman Tkachenko 21b90a64cf
Add app and db access flags to license (#5627) 2021-02-22 08:35:08 -08:00
Sasha Klizhentas 71e6b1451d Improves teleport configure command.
Fixes #5559

Configure with -o file create file /etc/teleport.yaml.
This commit optimizes configure for getting users started instead of generating sample
files.

```bash
teleport configure -o file --cluster-name=example.com --acme --acme-email=alice@example.com
```
2021-02-19 20:27:21 -08:00
Jane Quintero c50133bfcf remove integration testing and use already implemented emitting exec events function 2021-02-19 20:15:20 -08:00
Jane Quintero cbf7f7bb7c emit exec event even if PTY is allocated 2021-02-19 20:15:20 -08:00
Travis Swientek deb3271b24 Utilize portForwardProxy logging to append connection context to logs. 2021-02-19 18:24:52 -08:00
Travis Swientek 3b640e9183 Quiet noisy logging of k8s port forwarding streams. 2021-02-19 18:24:52 -08:00
Jane Quintero 8da6c6c627 remove file 2021-02-19 17:29:11 -08:00
Jane Quintero 728a4c3ee4 lint 2021-02-19 17:29:11 -08:00
Jane Quintero 0d35e26968 feedback changes
lint
2021-02-19 17:29:11 -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 11f787f157 go formatting 2021-02-19 17:29:11 -08:00
Jane Quintero 1ca978bc43 make only protostreamer implement getuploadmetadata 2021-02-19 17:29:11 -08:00
Jane Quintero 9b26bfe821 emit session upload event 2021-02-19 17:29:11 -08:00
Lisa Kim 4db05acbef
Better error handling with auth connectors (#5599)
* Log all errors
* Create redirect handler wrapper
2021-02-19 12:57:47 -08:00
Andrew Lytvynov e1e80636cc
kube: add kube_public_addr config field to proxy_service (#5611)
With the introduction of `kube_listen_addr`, some users are confused on
how to set a public address for k8s access that's different from
`public_addr` of the proxy. `kube_public_addr` removes that confusion
and more closely resembles the other proxy endpoints.

This config:

```yaml
proxy_service:
  kube_listen_addr: 0.0.0.0:3026
  kube_public_addr: kube.example.com:3026
```

translates to the old format:

```yaml
proxy_service:
  kubernetes:
    enabled: yes
    listen_addr: 0.0.0.0:3026
    public_addr: kube.example.com:3026
```
2021-02-18 14:33:11 -08:00
Andrej Tokarčík e03ff32469
Prefer registering via proxy when the server's port is 443 (#5600)
Checking for port 3080 was already implemented as part of #5182.
2021-02-18 13:25:46 +01: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 6ae441a541
Verify access to a remote cluster on GenerateUserCerts (#5593)
Cluster labels were added in 5.0 to restrict access to trusted clusters.
Enforce this restriction on `tsh login leafName` (aka `GenerateUserCerts`).

Note: access check is already enforced on actual user connections
(ssh/k8s/etc) and listing of trusted clusters (`tsh clusters`). You
cannot bypass authz to actually connect to that cluster.
2021-02-17 16:13:32 -08:00
Roman Tkachenko e6e6728250
Apply traits to kube, app and database labels (#5597) 2021-02-17 15:59:20 -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
Roman Tkachenko 81670e6c2c
Relax app session cookie same-site policy (#5565) 2021-02-17 14:07:00 -08:00
Roman Tkachenko 524b13f8b5
Fix listener is closed log spam (#5581) 2021-02-16 18:12:44 -08:00
Andrew Lytvynov 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
Gus Luxton 94acec4c84
Add TELEPORT_CONFIG_FILE to disable reading Teleport config from disk (#5483) 2021-02-16 15:24:08 -04:00
Acrimon 324ccda21f Implemented utmp/wtmp support. 2021-02-15 20:58:30 +01:00
Isaiah Becker-Mayer 87bda80d62
gzip static assets (#5544)
* adding gzip middlewear for gzipping static assets
* Only setting Content-Type if it has not been set explicitly previously, simplifying isCompressedImageRequest with strings function
* upgrading to using a pool for our gzip writers in order to increase memory efficiency
2021-02-14 02:07:46 -05:00
Roman Tkachenko 8dcfbfc5f0
Add mysql functional/integration tests (#5472) 2021-02-12 15:09:26 -08:00
Andrew Lytvynov 9a6b5e31d2
Check MFA device name uniqueness (#5560)
Device uniqueness is checked on `GetUsers`, so if a duplicate name
appears, any operations touching users will fail.
Check device name uniqueness on `UpsertMFADevice` to avoid this.

Also, swap the OTP device creation order on user signup/reset: only
upsert the device after validating the token.
2021-02-12 13:16:01 -08:00
a-palchikov e65eac59b0
tsh scp to use target directory correctly (#5501)
* Fixes the scp logic to take target directory into account in sink mode.
Also expose channel error in scp client so the error is more visible to
the user. Old behavior will only output the 'exit code n' if anything
breaks.

Fixes https://github.com/gravitational/teleport/issues/5497.

* Silence 'wait: remote command exited without exit status or exit signal' error when interrupting the scp session. Leave a TODO to fix properly in a future PR

* Address review comments
2021-02-11 19:35:40 +01: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
Roman Tkachenko 81e1102250
Add MySQL support for database access (#5453) 2021-02-10 11:08:13 -08:00
Forrest Marshall db89206db6 improve tsh tests 2021-02-09 13:31:03 -08:00
Andrew Lytvynov 0415e422f1
mfa: support multiple U2F keys on CLI login (#5484)
After adding several U2F tokens with `tsh mfa add`, you can now `tsh
login` using any of those tokens.

Two caveats:

1. The MFA method you get prompted for on login depends on the
`second_factor` config field on the auth server. There isn't yet an
option to require _either_ TOTP or U2F yet, even if you have both kinds
registered.

2. Web logins still need updating.

Also a few small unrelated changes:
- remove u2f-host binary presence check and docs
- hide `tsh mfa` commands until the feature is complete
2021-02-09 10:02:43 -08:00
Brian Joerger 8ee8122b10
Remove deprecated marshalers (#5454) 2021-02-08 19:50:17 -08:00
Andrew Lytvynov 491a298b1a
mfa: replace u2f-host with github.com/flynn/u2f (#5477)
This change removes the need for users to manually install u2f-host.
It also enables us to do U2F authentication with multiple devices.
2021-02-04 11:10: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
a-palchikov c7f494b3eb
Test flakes: make tests reentrant (#5343)
* Make tests reentrant.
* Address review comments
* Bump e to release
2021-02-03 13:49:28 +01:00
a-palchikov aa5c5223a7
Guard server session with a mutex to prevent races when the session is (#5365)
used from multiple goroutines.
2021-02-03 13:47:49 +01:00
a-palchikov cc35ce0912
Use fake clock to avoid off by 1 errors with real time. 2021-02-03 13:34:12 +01:00
dmitri a74c90769c Fix reported data races in lib/backend unit tests.
Fixes https://github.com/gravitational/teleport/issues/5331.
2021-02-02 15:07:25 -08:00
dmitri 907bb4c90d Use fake clock to avoid time skews.
Fixes https://github.com/gravitational/teleport/issues/5344.
2021-02-02 14:32:23 -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
Andrew Lytvynov 5ca68f2351
Remove 'var _ = fmt.Printf' from *_test.go files (#5438)
These declarations serve no purpose, likely leftover from old debugging.
2021-01-29 17:01:10 -08:00
Andrew Lytvynov 79b0d54ee8
u2f: extract registration/authentication logic into lib/auth/u2f (#5387)
This is just a refactoring without functional changes. Pull all the u2f
handling spread across multiple client and server packages into one
place.

Also clean up an obsolete vendored dependency, unrelated to this PR.
2021-01-29 11:30:15 -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
Russell Jones 43fc9f6de6 Added support for a cancelable Accept.
Added support for a cancellation Accept to allow port forwarding listener to be
closed upon cancellation of the passed in context.
2021-01-28 16:56:07 -08:00
a-palchikov 43d142085e
Wait on scp process at the end of the test. Service the stderr pipe to (#5418)
avoid 'broken pipe' in scp side.

Fixes https://github.com/gravitational/teleport/issues/5417.
2021-01-28 12:55:54 +01:00
Roman Tkachenko f0a180be7a
Refactor db access audit logger for better reuse (#5421) 2021-01-27 13:43:09 -08:00
Pierre Beaucamp dd35562c94
Fix truncated audit-log when using DynamoDB (#5381)
* Fix truncated audit-log when using DynamoDB

This is a fix for #4977. Teleport will continue to query DynamoDB until
the response doesn't contain a `LastEvaluatedKey` anymore, which signals
the end of the result set.

Co-authored-by: Alexey Kontsevoy <biz.kovoy@gmail.com>
2021-01-27 13:19:06 -05:00
Andrew Lytvynov b092fa9143
When exporting a kubeconfig, overwrite the target file (#5297)
* When exporting a kubeconfig, optionally overwrite the target file

Running `tctl auth sign ---out=filepath` or `tsh login --out=filepath`
might overwrite the target `filepath` regardless of its existing
contents.

Make the tools prompt the user before overwriting (by default) and
provide a flag to always force the overwrite (for automation).

Without overwrites, writing kubeconfig could fail if parsing the
existing file as a kubeconfig fails.
2021-01-27 10:00:52 -08:00
Roman Tkachenko 127693c315
Refactor db proxy/engine for easier reuse (#5325) 2021-01-21 15:34:12 -08:00
Roman Tkachenko f7e6838ee5
Refactor postgres service file handling, add db config command (#5319) 2021-01-21 15:21:17 -08:00
Roman Tkachenko 92c03df14c
Rename database role to db (#5359) 2021-01-21 10:14:07 -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
Forrest Marshall d91410771e fix extraneous logins in tctl output 2021-01-20 11:33:26 -08:00
Andrew Lytvynov 61bcc22a26
kube: always enable proxy protocol support (#5299)
Proxy protocol is sometimes used by load balancers to communicate the
real client IP address. Re-use the detection/parsing code from
lib/multiplexer on all k8s listeners (proxy and kubernetes_service)
2021-01-19 23:48:30 +00: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
Russell Jones b8c0b96415 Fixed panic when NewServerContext returns error.
If "NewServerContext" returns an error, then the error is logged using
the returned context which is nil causing a panic.

This change always uses the logger attached to the server instead.
2021-01-15 17:11:01 -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
Sasha Klizhentas f88cbaf575 Makes SAML error messages friendly to users. 2021-01-14 15:12:04 -08:00
Brian Joerger ab3d1a11da
Move /lib/wrappers to /api/types/wrappers. (#5286) 2021-01-14 14:58:44 -08:00
a-palchikov 0ddde38df2
Suppress linter warning about unnecessary type conversion on darwin. (#5302) 2021-01-14 19:23:48 +01:00
a-palchikov 524c9483b3
Explicitly cast time values to int64 to enable 32-bit builds. (#5291)
Updates https://github.com/gravitational/teleport/pull/4764.
2021-01-14 11:10:47 +01: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
Ev Kontsevoy a9829381e8
Updated URLs inside the product (#5260) 2021-01-11 19:34:53 -04:00
Brian Joerger 3c3ce160d9
Move API types and functionality from lib/services to api/types. (#5143) 2021-01-11 10:02:34 -08:00
Andrej Tokarčík 7b723d3313
Determine node registration method based on server port (#5182)
The logic of `auth.Register` is adapted so that it attempts the proxy mode connection first in case the first of the auth servers to register with has port `defaults.HTTPListenPort` (= 3080).
2021-01-08 18:30:37 +01:00
Andrej Tokarčík f2e118c43c
Extend tsh clusters output with "Cluster Type" and "Selected" columns (#5051) 2021-01-07 15:03:58 +01:00
Andrej Tokarčík a178a278ef
Support viewing cluster auth preferences with tctl get cap (#5159) 2021-01-07 14:42:45 +01:00
a-palchikov 72630d1df5
Implement support for preserving file times for 'tsh scp' (#4764)
* Add -p flag to scp
* Add support for preserving access/modification times on files/directories when copying files between hosts.
* lib/sshutils/scp: add time statting for directories
* Add directory handling for scp
* Rewrite scp tests with testify
* Address review comments
2021-01-06 13:21:06 +01:00
Andrew Lytvynov ceb081d428
Tweaks for k8s support detection in tsh (#5172)
- detect whether k8s support is on based on proxy advertising a k8s port
- make sure proxy advertised k8s port is updated on re-login
- don't touch user's kubeconfig if k8s support is disabled in proxy
2021-01-04 10:49:43 -08:00
Lisa Kim e5604b274c
Add AccessRequest access to userACL (#4984)
* Add AccessRequest access to userACL
* Define requestable roles
* Update UI test plan to include access request
* Edit testplan and fix whitespace issue
* When renewing session, set expiry to the shortest time
2020-12-31 13:41:08 -05: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
Sasha Klizhentas c0bb732545 Adds ACME - auto cert management
This commit fixes #5177

Initial implementation uses dir backend as a cache and is OK
for small clusters, but will be a problem for many proxies.

This implementation uses Go autocert that is quite limited
compared to Caddy's certmagic or lego.

Autocert has no OCSP stapling and no locking for cache for example.
However, it is much simpler and has no dependencies.
It will be easier to extend to use Teleport backend as a cert cache.

```yaml
proxy_service:
  public_addr: ['example.com']
  # ACME - automatic certificate management environment.
  #
  # It provisions certificates for domains and
  # valid subdomains in public_addr section.
  #
  # The sudomains are valid if there is a registered application.
  # For example, app.example.com will get a cert if app is a regsitered
  # application access app. The sudomain cookie.example.com is not.
  #
  # Teleport acme is using TLS-ALPN-01 challenge:
  #
  # https://letsencrypt.org/docs/challenge-types/#tls-alpn-01
  #
  acme:
    # By default acme is disabled.
    enabled: true
    # Use a custom URI, for example staging is
    #
    # https://acme-staging-v02.api.letsencrypt.org/directory
    #
    # Default is letsencrypt.org production URL:
    #
    # https://acme-v02.api.letsencrypt.org/directory
    uri: ''
    # Set email to receive alerts and other correspondence
    # from your certificate authority.
    email: 'alice@example.com'
```
2020-12-22 17:33:20 -08:00
Andrew Lytvynov 96019ce0be
Make k8s errors responses decode-able by kubectl (#5166)
* Make k8s errors responses decode-able by kubectl

`kubectl` expects a k8s `Status` object in error responses.
Intercept generic handler errors and forwarder errors, and wrap them in
a `Status` object.
2020-12-18 15:27:45 -08:00
Andrew Lytvynov 225777cc53
Use strict teleport.yaml validation in warning mode (#5057)
* Use strict teleport.yaml validation in warning mode

Strict YAML validation catches the cases where a valid config key is
placed in the wrong location in the config. These errors were not
caught by the old validation.
The failure is always reported, but only fails startup when both old and
new validations fail. This will let the users fix their configs during
6.0 release and we will start enforcing it in 7.0.

Example:
```yaml
auth_service:
  data_dir: "/foo" # this field must live under "teleport:", not "auth_service:"
```

Output:
```
$ teleport start -c teleport-invalid.yaml
ERRO             "Teleport configuration is invalid: yaml: unmarshal errors:\n  line 6: field data_dir not found in type config.Auth." config/fileconf.go:303
ERRO             This error will be enforced in the next Teleport release. config/fileconf.go:304
[AUTH]         Auth service 5.0.0-dev:v4.4.0-alpha.1-262-g307040886-dirty is starting on 0.0.0.0:3025.
... continues startup ...
```

* Remove newlines from YAML error
2020-12-18 14:11:53 -08:00
Andrew Lytvynov 4fc106553f
Upload k8s session recordings regardless of request context (#5145)
The HTTP request context is canceled when the client disconnects. Using
this context in the session recorder prevents it from uploading the
session when it's finished.

Use the server context instead, to prevent lost recordings.
2020-12-16 11:46:59 -08:00
Andrej Tokarčík 1fe6226803
Improve error message reported when node is offline (#5036) 2020-12-15 16:36:39 +01:00
Andrew Lytvynov 05c73c9372
Upgrade gosaml2 library to v0.6.0 (#5118)
See https://github.com/russellhaering/gosaml2/security/advisories/GHSA-xhqq-x44f-9fgg
2020-12-14 11:34:20 -08:00
Andrej Tokarčík ee87fce040
Don't log error on tunnel node after its serving agent is stopped (#5042) 2020-12-11 17:39:19 +01:00
a-palchikov ca60c7eb35
Add SetLevel to utils.Logger interface (#5082) 2020-12-11 12:59:09 +01:00
a-palchikov 7809a47356
Fix a flaky test in lib/srv/app (#5079) 2020-12-11 12:36:02 +01:00
a-palchikov c94e5042c7
Server data race (#4790)
* Add logger attributes to be able to propagate logger from tests for identifying tests
* Add test case for Server's DeepCopy.
* Update test to using the testing package directly. Update dependency after upstream PR.
2020-12-09 16:46:33 +01:00
Andrew Lytvynov 3fa6904377
Multiple fixes for k8s forwarder (#5038)
* kube: emit audit events using process context

Using the request context can prevent audit events from getting emitted,
if client disconnected and request context got closed.
We shouldn't be losing audit events like that.

Also, log all response errors from exec handler.

* kube: cleanup forwarder code

Rename a few config fields to be more descriptive.
Avoid embedding unless necessary, to keep the package API clean.

* kube: cache only user certificates, not the entire session

The expensive part that we need to cache is the client certificate.
Making a new one requires a round-trip to the auth server, plus entropy
for crypto operations.

The rest of clusterSession contains request-specific state, and only
adds problems if cached.
For example: clusterSession stores a reference to a remote teleport
cluster (if needed); caching requires extra logic to invalidate the
session when that cluster disappears (or tunnels drop out). Same problem
happens with kubernetes_service tunnels.

Instead, the forwarder now picks a new target for each request from the
same user, providing a kind of "load-balancing".

* Init session uploader in kubernetes service

It's started in all other services that upload sessions (app/proxy/ssh),
but was missing here. Because of this, the session storage directory for
async uploads wasn't created on disk and caused interactive sessions to
fail.
2020-12-08 11:12:07 -08:00
a-palchikov 673c2907f2
Augment session events with cluster name (#4994)
Add cluster name to event metadata
2020-12-08 13:33:44 +01:00
a-palchikov 7c87576a8b
flaky tests: consistent logging (#4849)
* Update logrus package to fix data races
* Introduce a logger that uses the test context to log the messages so they are output if a test fails for improved trouble-shooting.
* Revert introduction of test logger - simply leave logger configuration at debug level outputting to stderr during tests.
* Run integration test for e as well
* Use make with a cap and append to only copy the relevant roles.
* Address review comments
* Update integration test suite to use test-local logger that would only output logs iff a specific test has failed - no logs from other test cases will be output.
* Revert changes to InitLoggerForTests API
* Create a new logger instance when applying defaults or merging with file service configuration
* Introduce a local logger interface to be able to test file configuration merge.
* Fix kube integration tests w.r.t log
* Move goroutine profile dump into a separate func to handle parameters consistently for all invocations
2020-12-07 15:35:15 +01:00
Andrew Lytvynov 11f5dc6c39
Set TTL on kube_service resources (#5008)
Without this, deleted kube_services linger in the backend and show up as
obsolete kubernetes clusters in tsh.

Ideally, this TTL logic should be enforced centrally, but I'd like to
fix the bug first, and do a larger refactoring later.
2020-12-03 15:51:32 -08:00
jane (quin) 9c26188d30
Fix coordinated omission bug (#4643)
* benchmark package

* use default config if path is not specified

* progressiveBench as a config method

* implement a main.go approach to run progressive tests

* make teleport client, run specified benchmark

* function and method descriptions

* make teleport client

* testing

* change interface method signatures

* dry up bench.go code, move producer goroutines to own function

* output formatting

* remove yaml

* fix linter errors

* remove print

* PR suggested changes, moved export latency profile functionality to the benchmark package

* PR fixes

* method description

* update testing

* linter

* docs and example

* PR suggestion changes

* fix coord omission bug

* remove benchmark struct

* remove threads, using open system

* recover in run

* close channel, check if open with each execution

* update testing, pr suggestions

* add more instructions to readme

* update example.go

* pass back context

* use SyncBuffer

* export response and service histograms

* update readme, exporting profiles section

* return from execute()

* export singular latency profile

* export response profile

* Revert "export response profile"

This reverts commit 5a21cb034c.

* export response profile

* update branch

* format example.go

* remove threads

* update example.go

* update branch

* goimports

* add signal handler & update docs

* PR suggestions

* exit out of interactive session

* revert execute

* PR suggestion

* run commmand on non-interactive instead of nil
2020-12-01 11:04:31 -08:00
Andrew Lytvynov c4583b7a1a
Fix response flushing on streaming k8s requests (#5009)
Streaming requests, like `kubectl logs -f` will slowly write response
data over time. The `http.ResponseWriter` wrapper we added for capturing
the response code didn't propagate `http.Flusher` interface and
prevented the forwarder library from periodically flushing response
contents.

This caused `kubectl logs -f` results to be delayed, delivered in
batches as some internal buffer filled up.
2020-11-30 17:41:50 -08:00
Vladimir Kochnev b911f4b551
Fix JWK kty from "rsa" to "RSA" (#4993)
JWKS libraries expect it to be "RSA", not "rsa", example:
6cfa98f8ac/src/JwksClient.js (L79-L81)

According to RFCs, "kty" field seems to be case-sensitive, though there
cannot be names matching in a case-insensitive manner:
https://tools.ietf.org/html/rfc7518#section-7.4.1

The list of key types available in RFC 7518:
https://tools.ietf.org/html/rfc7518#section-6.1

Co-authored-by: Gus Luxton <gus@gravitational.com>
2020-11-27 11:07:41 -04:00
a-palchikov 9b73af55ab
Fix local etcd backend tests (#4986)
* Fix etcd backend tests to properly skip if etcd is not requested/availalable
* Address review comments
2020-11-26 13:56:28 +01:00
jane (quin) 6eaaf3a27e
Linear benchmark generator (#4588)
* benchmark package

* use default config if path is not specified

* progressiveBench as a config method

* implement a main.go approach to run progressive tests

* make teleport client, run specified benchmark

* function and method descriptions

* make teleport client

* testing

* change interface method signatures

* dry up bench.go code, move producer goroutines to own function

* output formatting

* remove yaml

* fix linter errors

* remove print

* PR suggested changes, moved export latency profile functionality to the benchmark package

* PR fixes

* method description

* update testing

* linter

* docs and example

* PR suggestion changes

* PR changes

* wrap errors

* move bench to benchmark & testing updates

* PR changes

* PR suggestions
2020-11-25 15:47:39 -08:00
Andrew Lytvynov c6832ec606
Set server_addr in audit events from connection info (#4985)
This sets a useful server IP, when no advertise_ip is set. Previously,
the address was taken from the listener, and is usually "0.0.0.0:3022"
or "[::]:3022".

Also, add some test cases in utils for IPv6 handling.
2020-11-25 12:08:37 -08:00
Ben Arent 09928a7f2b
Cherry pick Gravitational -> GoTeleport (#4932) 2020-11-25 11:18:55 -08:00
Andrew Lytvynov cdf26c74e5
Change log about missing kube clusters on login to debug (#4935)
This is a totally OK situation in clusters without k8s integration, so
it shouldn't be a warning.
2020-11-23 18:02:35 +00:00
Russell Jones d0a202f1bc Added error checking to Application Access CLI.
Check if both application name and URI are provided when attempting to
join an application service process to a cluster.
2020-11-20 16:38:52 -08:00
Russell Jones b66ca14f61 Added HTTP method to app.session.request.
Added HTTP method field to "app.session.request" events.
2020-11-20 16:38:40 -08:00
Lisa Kim c56df637d1
Add AuthType field for web config (#4946) 2020-11-20 11:21:07 -08:00
Brian Joerger 1439f35902
[docs] Go API Docs CA (#4777) 2020-11-20 10:17:39 -08:00
a-palchikov 09064cbc6f
Configure etcd client's message size (#4800)
* lib/backend/etcdbk: add a configuration attribute to set the client's
send message size limit.
* Update etcd backend section w.r.t new client configuration attribute

Updates https://github.com/gravitational/teleport/issues/4786.
2020-11-19 14:03:51 +01:00
a-palchikov ab205963f5
Fix typos (#4903) 2020-11-19 13:39:16 +01:00
Forrest Marshall 5ad1a9025c fix early watcher closure 2020-11-18 15:40:56 -08:00
Forrest Marshall 68adee36a9 fix tsh login with trusted clusters 2020-11-18 15:40:56 -08:00
Andrew Lytvynov 645ac573c5
UX improvements for kube CLI interactions (#4893)
- 'tsh kube login' fetches the latest list of kube clusters instead of
  only using existing kubeconfig contexts.
  This makes 'tsh kube login' succeed when a kube cluster was added
  after last 'tsh login'.
- 'tsh kube ls' no longer wrongly marks selected clusters, if they
  weren't generated by tsh.
- 'tctl rm' now works with kube_service objects.
- 'tsh login' now updates kubeconfig entries when a login session is
  already active
- 'teleport.yaml' now uses 'labels' and 'commands' for RBAC labels on
  kubernetes_service; this is consistent with ssh and app services.
2020-11-18 22:31:04 +00:00
Russell Jones 48a37af5ad Updated default admin role.
Updated default admin role to support reading services.KindProxy. This
is needed by "tctl" when using credentials from ~/.tsh to generate the
join message.
2020-11-18 11:49:23 -08:00
Andrew Lytvynov 05f5f2d241
Prevent a panic in tsh kube login when logged out (#4885)
Turns out, client.Status can return a nil error *and* profile.
Handle nil profile separately and return a simple error.
2020-11-18 17:51:28 +00:00
AdamKorcz c0ecb0a081
Minor update to fuzzing README (#4889) 2020-11-18 11:56:01 -04:00
Russell Jones 986bf08ab3 Consolidated application checks.
Consolidated application validation checks. The previous implementation
had a bug in it where it would fail if no /etc/teleport.yaml existed.
2020-11-17 17:57:00 -08:00
Russell Jones 898088a282 Fixed application dialing in proxy recording mode.
Only use the forwarded agent when dialing in proxy recording mode when
the connection type is SSH.
2020-11-17 17:57:00 -08:00
Andrew Lytvynov aceffd9a35
Add more data to k8s session events (#4858)
Added fields:
- kube users/groups
- pod name/namespace
- container name/image
- node name

Container image and node name need to be fetched from the k8s API, they
are not known from just the client request. This fetch is optional, and
if it fails (like due to permission errors), those fields will be
missing.

Since kubernetes_service can talk to k8s API and proxy_service can't,
all session events are now emitted by kubernetes_service and skipped by
the proxy (used to be the other way around).
2020-11-17 23:46:51 +00:00
Andrew Lytvynov 679b3e6719
Fix a server parsing regression between 4.4 and 5.0 (#4865)
The `KubernetesClusters` field in `ServerSpecV2` used to be a
`[]string`:
https://github.com/gravitational/teleport/pull/4354/files#diff-50ec8b71306e75db3cb193b581cdd51139b03f90e23e7804cbef7edf712bbfac
Later, it was changed to `[]*services.KubernetesCluster`, which is
incompatible when parsing.

Unfortunately, the string version slipped into 4.4. When upgrading to
5.0, teleport fails to parse the old server object at startup and
crashes.

Rename the JSON tag from `kubernetes_clusters` to `kube_clusters` to
distinguish the different versions of this field when parsing. The old
`kubernetes_clusters` will just be ignored.
2020-11-17 21:50:12 +00:00
Andrew Lytvynov 43178f34d8
Add a depth limit to RBAC expression parser (#4848)
Our current parsing code runtime grows exponentially with nested
selectors (e.g. '{{a.b.c.d.e.f}}'), mostly due to memory churn from
slice allocations. With 100,000 levels of selectors, parsing takes ~80s
on my machine.
If an attacker can submit these expressions for parsing, they can DoS
the auth server with relatively small payloads (<1MB).

All real-world expressions are <10 AST nodes deep. Add a sanity check of
1000 levels to protect against malicious inputs.

We can optimize the code later on, but it's not very useful for real
world performance.
2020-11-17 18:53:38 +00:00
Andrew Lytvynov 4b2247f340
Rename tsh kube clusters to tsh kube ls (#4850) 2020-11-16 18:50:49 +00:00
Sasha Klizhentas e6681abe6a Fan out events in async mode for async recordings.
This commit fixes #4695.

Teleport in async recording mode sends all events to disk,
and uploads them to the server later.

It uploads some events synchronously to the audit log so
they show up in the global event log right away.

However if the auth server is slow, the fanout blocks the session.

This commit makes the fanout of some events to be fast,
but nonblocking and never fail so sessions will not hang
unless the disk writes hang.

It adds a backoff period and timeout after which some
events will be lost, but session will continue without locking.
2020-11-13 17:10:35 -08:00
Forrest Marshall 45cc314426 improve cache correctness
improves the reliability and correctness of the cache via
various small improvements, including preventing reads of
partially initialized/reset state, and delaying watcher
init events until unhealthy states recover.

fixes an issue where reads could result in missing or
inconsistent results.
2020-11-13 16:29:18 -08:00
Russell Jones 768b58351f Changed redirect endpoint when session is expired.
When the user does not have a session, if the user tries to access a
proxied application at it's FQDN, Teleport does best effort resolution.

This fix changes the behavior of what happens when the user has a
session but the session is expired. The user was being redirected to the
login page. This fix changes the behavior to by in sync with the
no-session behavior in doing best effort resolution.
2020-11-13 16:15:33 -08:00
Russell Jones 211116adaa Added username to "app.session.chunk" event. 2020-11-13 15:04:32 -08:00
Russell Jones cf635a7e60 Addressed code review comments. 2020-11-13 14:52:00 -08:00
Andrew Lytvynov dd3977957a Register a kubernetes cluster from proxy_service
A proxy running in pre-5.0 mode (e.g. with local kubeconfig) should
register an entry in `tsh kube clusters`.
After upgrading to 5.0, without migration to kubernetes_service, all the
new `tsh kube` commands will work as expected.
2020-11-13 14:52:00 -08:00
Russell Jones 8f8b94bcc9 Added application name validation.
Added validation check that ensures application names are valid DNS
subdomains. This is because and application name can potentially be used
in the DNS name of the application if either a public address is not
provided or the application is accessed via a trusted cluster.
2020-11-13 13:50:52 -08:00
Russell Jones 6a4436107c Updated "teleport start" help message. 2020-11-12 20:46:52 -08:00
Russell Jones f13040a433 Added integration tests for Application Access. 2020-11-12 18:01:45 -08:00
Andrew Lytvynov 271d7ea4e7
Migrate kube_service CRUD endpoints to gRPC (#4792)
The REST endpoints weren't used in any release yet, so we don't need to
worry about backwards-compatibility.
2020-11-12 18:35:34 +00:00
Andrew Lytvynov 450f3e7b81
Add kubernetes_cluster to all kube-related events (#4794)
Also, fix a regression in tsh, where it wouldn't update the kubeconfig
on older clusters without kubernetes_service.
2020-11-12 17:20:42 +00:00
Andrew Lytvynov 4bc8011722
RBAC for kubernetes clusters (#4782)
* Add labels to KubernetesCluster resources

Plumb from config to the registered object, keep dynamic labels updated.

* Check kubernetes RBAC

Checks are in some CRUD operations on the auth server and in the
kubernetes forwarder (both proxy or kubernetes_service).
The logic is essentially copy-paste of the TAA version.
2020-11-11 22:58:33 +00:00
Andrew Lytvynov 52c52c7e20
Add "tsh kube" commands (#4769)
1. `tsh kube clusters` - lists registered kubernetes clusters
   note: this only includes clusters connected via `kubernetes_service`

2. `tsh kube credentials` - returns TLS credentials for a specific kube
   cluster; this is a hidden command used as an exec plugin for kubectl

3. `tsh kube login` - switches the kubectl context to one of the
   registered clusters; roughly equivalent to `kubectl config
   use-context`

When updating kubeconfigs, tsh now uses the exec plugin mode:
https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins
This means that on each kubectl run, kubectl will execute tsh with
special arguments to get the TLS credentials.

Using tsh as exec plugin allows us to put a login prompt when certs
expire. It also lets us lazy-initialize TLS certs for kubernetes
clusters.
2020-11-11 22:22:01 +00:00
Alexey Kontsevoy 2b022b8f37
Add Cloud flag to Teleport license (#4776)
* Add Cloud flag to Teleport license
2020-11-10 21:50:23 -05:00
Russell Jones e13cc165c7 Updated storage configuration to apply to events.
Updated storage configuration to not only apply to DynamoDB in the
backend package, but also DynamoDB in the events package. This allows
configuring continuous backups and auto scaling for the events table.
2020-11-10 16:40:08 -08:00
Russell Jones 85703618fe Fixed migration version check logic.
Fixed migration version check logic to allow Application Access to work
on development builds.
2020-11-10 16:09:19 -08:00
Russell Jones 5a524de54a Fixed regression in application access dialing.
Pass the target address, in the case of application access
services.LocalNode, in the Dial request to the reverse tunnel subsystem
instead of filling it in within the reverse tunnel subsystem.
2020-11-10 16:09:19 -08:00
AdamKorcz 3c218e2290
Added 3 fuzzers (#4124)
* Added 3 fuzzers
2020-11-10 17:35:51 +00:00
Andrew Lytvynov 0711da03b7
Set start_time in k8s session.end event (#4770)
The field got lost somewhere during recent refactors. Set the start_time
to correctly show session duration on web UI.
2020-11-10 17:12:10 +00:00
Sasha Klizhentas ce8c83d722 Adds support for loading tctl creds from ~/.tsh profile
This commit fixes #4439
2020-11-09 20:24:09 -08:00
Andrew Lytvynov b16ad647b4
Kubernetes request routing and cluster registration (#4670)
This change has several parts: cluster registration, cache updates,
routing and a new tctl flag.

> cluster registration

Cluster registration means adding `KubernetesClusters` to `ServerSpec`
for servers with `KindKubeService`.

`kubernetes_service` instances will parse their kubeconfig or local
`kube_cluster_name` and add them to their `ServerSpec` sent to the auth
server. They are effectively declaring that "I can serve k8s requests
for k8s cluster X".

> cache updates

This is just cache plumbing for `kubernetes_service` presence, so that
other teleport processes can fetch all of kube services. It was missed
in the previous PR implementing CRUD for `kubernetes_service`.

> routing

Now the fun part - routing logic. This logic lives in
`/lib/kube/proxy/forwarder.go` and is shared by both `proxy_service`
(with kubernetes integration enabled) and `kubernetes_service`.

The target k8s cluster name is passed in the client cert, along with k8s
users/groups information.

`kubernetes_service` only serves requests for its direct k8s cluster
(from `Forwarder.creds`) and doesn't route requests to other teleport
instances.

`proxy_service` can serve requests:
- directly to a k8s cluster (the way it works pre-5.0)
- to a leaf teleport cluster (also same as pre-5.0, based on
  `RouteToCluster` field in the client cert)
- to a `kubernetes_service` (directly or over a tunnel)

The last two modes require the proxy to generate an ephemeral client TLS
cert to do an outbound mTLS connection.

> tctl flag

A flag `--kube-cluster-name` for `tctl auth sign --format=kubernetes`
which allows generating client certs for non-default k8s cluster name
(as long as it's registered in a cluster).
I used this for testing, but it could be used for automation too.
2020-11-09 19:40:02 +00:00
Russell Jones c04775000d Removed logic to export to text format. 2020-11-08 08:19:15 -08:00
Sasha Klizhentas 4649b45522 Add --format=json playback option
This commit fixes #4577, updates #1580

```bash
$ tsh play --format=json ~/play/0c0b81ed-91a9-4a2a-8d7c-7495891a6ca0.tar | jq '.event
"print"
"print"
"session.disk"
```
2020-11-08 08:19:15 -08:00
Lisa Kim 727c1fae9b
Get additional roles from approved access request when extending web session (#4619)
* Add strategyAccess field in user context
* Enable passing of requestID to renewSession handler and extendWebSession
2020-11-05 13:15:57 -08:00
Forrest Marshall af05ce3eeb extended dynamic access API
Various improvements related to extending the dynamic access
API, including:

- Support for users with no statically defined roles.

- Unify trait mapping logic (e.g. claims_to_roles) across
the connector types.

- Support for matcher syntax and claims_to_roles mappings when
configuring which roles a user is able to request.

- Allow tsh or the web UI to automatically generate wildcard
access requests when dictated by role configuration.

- Allow RBAC configuration to attach annotations to pending
access requests which can be consumed by plugins.

- Allow plugins to attach annotations to approvals/denials
which appear in the audit log, and may also be looked up
later to determine additional info about a resolution.

- Support prompts, request reasons, and approval/denial
reasons for access requests.
2020-11-05 12:18:26 -08:00
a-palchikov 679941fc17
lib/web: add package-level logger (#4645)
* lib/web: update logging to go through a package-level logger.
Updates https://github.com/gravitational/teleport/issues/4110.
* Unify uses of package-level logger. Update e
* Fix linter warning and tests
* Address review comments
2020-11-05 20:46:54 +01:00
Russell Jones bf0d76da84 Added support for admin user and token management.
Updated default admin rule in Enterprise to include KindUser: RW and
KindToken: RW permissions to allow admins to perform user and token
management.
2020-11-05 10:49:59 -08:00
Russell Jones 2bf6f0411c Added support for DynamoDB Auto Scaling. 2020-11-03 17:46:34 -08:00
Russell Jones bf200c1f74 Added support for DynamoDB Continuous Backups. 2020-11-03 17:46:34 -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
Russell Jones 904b0d0488 Added Application Access.
Added support for an identity aware, RBAC enforcing, mutually
authenticated, web application proxy to Teleport.

* Updated services.Server to support an application servers.
* Updated services.WebSession to support application sessions.
* Added CRUD RPCs for "AppServers".
* Added CRUD RPCs for "AppSessions".
* Added RBAC support using labels for applications.
* Added JWT signer as a services.CertAuthority type.
* Added support for signing and verifying JWT tokens.
* Refactored dynamic label and heartbeat code into standalone packages.
* Added application support to web proxies and new "app_service" to
  proxy mutually authenticated connections from proxy to an internal
  application.
2020-11-03 14:32:13 -08:00
Brian Joerger 9379b676f1
Add new helper function for parsing multiple addresses at once. (#4675) 2020-11-03 13:50:22 -08:00
Andrew Lytvynov 5ec194cd0d
Implement kubernetes_service registration and startup (#4611)
* Implement kubernetes_service registration and sratup

The new service now starts, registers (locally or via a join token) and
heartbeats its presence to the auth server.

This service can handle k8s requests (like a proxy) but not to remote
teleport clusters. Proxies will be responsible for routing those.
The client (tsh) will not yet go to this service, until proxy routing is
implemented. I manually tweaked server addres in kubeconfig to test it.

You can also run `tctl get kube_service` to list all registered
instances. The self-reported info is currently limited - only listening
address is set.

* Address review feedback
2020-10-30 17:19:53 +00:00
Andrew Lytvynov fd2959260e
Add kube_listen_addr to proxy_service (#4616)
This is a shorthand for the larger kubernetes section:
```
proxy_service:
  kube_listen_addr: "0.0.0.0:3026"
```
if equivalent to:
```
proxy_service:
  kubernetes:
    enabled: yes
    listen_addr: "0.0.0.0:3026"
```

This shorthand is meant to be used with the new `kubernetes_service`:
https://github.com/gravitational/teleport/pull/4455
It reduces confusion when both `proxy_service` and `kubernetes_service`
are configured in the same process.
2020-10-28 21:52:08 +00:00
Brian Joerger a0bbabc16b
Read token from storage when it's not found in the cache. (#4648) 2020-10-28 09:51:33 -07:00
Andrew Lytvynov f56014f95f
Make k8s permissions test optional (#4618)
* Make k8s permissions test optional

There are several legitimate cases where it can fail:
- root proxy running inside k8s but without access to local k8s cluster
- root proxy running with a dummy kubeconfig that we recommended in the
  past

Leave a ForwarderConfig flag to enforce this check, it will be useful in
kubernetes_service later that should always have the right permissions.
2020-10-23 18:30:48 +00:00
Andrew Lytvynov bd974ef09a
golint: final batch of fixes (#4589)
And enable `golint` during `make lint`.
2020-10-22 00:13:09 +00:00
Sasha Klizhentas ac2fb2f9b4 Fixes configuration with multiple event backends
This commit fixes #4598

Config with multiple event backends was crashing on 4.4:

```yaml
  storage:
    audit_events_uri: ['dynamodb://streaming', 'stdout://', 'dynamodb://streaming2']
```
2020-10-21 15:23:56 -07:00
Sasha Klizhentas 7b8bfe4f60 Backoff on network errors and mark corrupted records.
Uploader retries slower on network errors and picks the pace
after any upload has succeeded.

Records that were corrupted, will never get uploaded.

The uploader will create streams indefinitely, clogging the auth server
with streams. Now uploader writes marker for bad session uploads
and does not attempt to reupload.
2020-10-21 14:33:04 -07:00
Andrew Lytvynov 5cd212fecd
Add kubernetes_service to teleport.yaml (#4497)
* Fix local etcd test failures when etcd is not running

* Add kubernetes_service to teleport.yaml

This plumbs config fields only, they have no effect yet.

Also, remove `cluster_name` from `proxy_config.kubernetes`. This field
will only exist under `kubernetes_service` per
https://github.com/gravitational/teleport/pull/4455

* Handle IPv6 in kubernetes_service and rename label fields

* Disable k8s cluster name defaulting in user TLS certs

Need to implement service registration first.
2020-10-19 17:28:10 +00:00
Russell Jones d9c6119a14 Fixed PAM integration tests. 2020-10-16 17:36:19 -07:00
Andrew Lytvynov 483ea8b23d Add config option to gate pam_authenticate calls
Most users won't need this, so the behavior is optional. Default system
configs will usually trigger a password prompt, which is why this
feature is disabled by default.
2020-10-16 17:36:19 -07:00
Andrew Lytvynov 566b7cc457 RFD 1: user testify/require instead of testify/assert
`require` is a sister package to `assert` that terminates the test on
failure. `assert` records the failure but lets the test proceed, which
is un-intuitive.

Also update all existing tests to match.
2020-10-16 00:15:25 +00:00
Andrew Lytvynov 01516c5744 Partial revert of negative regexps in RBAC labels
This change was not backwards compatible - variable interpolation should
work in node_labels.

This commit partially reverts
https://github.com/gravitational/teleport/pull/4253 and
https://github.com/gravitational/teleport/pull/4430
2020-10-15 21:46:06 +00:00
Sasha Klizhentas 2592c4a440 Fix context leak in events fanout.
This commit fixes #4511.

Fanout watcher.Close method was cancelling
the context, but did was not removing the watcher
from the fanout list.

GRPC server was not releasing memory buffers associated
with the streams after clients disconnects.

Goroutines associated with the GRPC server were closed,
but buffers remained in memory:

https://github.com/gravitational/teleport/issues/4511
https://github.com/grpc/grpc-go/issues/3728#issuecomment-695883580

In Go, child context created with context.WithValue(parent)
references parent context and parent context references
child context back.

When the parent context is closed, it removes the child references,
but the child keeps referencing the parent context.

If the child context is leaked, objects associated
with the parent context are not garbage collected.

GRPC UnaryInterceptor created context.WithValue(ctx, User)
to add a user and passed this context to methods.

WatchEvents GRPC server created services.Fanout.Watcher
and referenced the child context.

Fanout watcher Close method did not remove the watcher
from the fanout buffer list causing the leak.
2020-10-14 21:33:44 -07:00
Sasha Klizhentas f0c6d94248 Fixes cert authority rollback for IOT nodes.
IOT nodes could not reconnect in rollback state because
cert authority was missing the new SSH public key.

IOT nodes were authenticating using new certificate
and were rejected.
2020-10-14 21:33:44 -07:00
Sasha Klizhentas 8f98767aac Fix firestore events interface and init stage.
This comit fixes #4508

Gogoproto is not compatible with APIv2 protoc-gen-go.
Track the issue here: https://github.com/gogo/protobuf/issues/678
Meanwhile, this commit switches to google protobuf to unmarshal firebase struct.

Add a missing method EmitAuditEvent causing teleport to crash
with firestore events backend.
2020-10-14 19:52:03 -07:00
Alexey Kontsevoy 1ab776a73b
Allow managing local users and adding a server via web ui (#4498)
* Add token access to userACL (#4357)
* Add node access to userACL (#4445)

Co-authored-by: Lisa Kim <lisa@gravitational.com>
2020-10-14 21:22:50 -04: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
Gus Luxton 9df2ee3474
Fix broken build on master (#4553) 2020-10-14 18:01:10 -03:00
Andrew Lytvynov a986ab0b51 kube: allow startup with a dummy kubeconfig_file
Prior to https://github.com/gravitational/teleport/pull/3811, if users
wanted to run a root proxy without k8s clusters but leaf proxies with
k8s, they had to put a dummy `kubeconfig_file` on the root proxy.

The permissions self-test added in
https://github.com/gravitational/teleport/pull/3812 didn't take that
into account.

So, users who keep the old workaround and upgrade to 4.4 will see their
proxies fail to start. To recover, they have to realize that
`kubeconfig_file` can be removed.
2020-10-14 17:29:34 +00:00
Andrew Lytvynov fda813ee45 tsh: print kubernetes info in profile status
Print when k8s support is detected, and if so what users/groups are
used.
2020-10-14 16:59:14 +00:00
Andrew Lytvynov 3122e152d3 Emit audit events for most k8s requests
In the "catch all" handler of k8s proxy, emit a new event KubeRequest
containing relevant request info.
Do best-effort parsing of the URL path to extract API fields like
namespace, resource name and kind.

Events related to discovery are suppressed due to their spamminess.
2020-10-14 16:58:44 +00:00
Lisa Kim f7360b72ea
Fix incorrect github login success event code (#4509) 2020-10-13 09:14:46 -07: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
Brian Joerger 248a17a874
Add check and error when starting teleport with an outdated etcd node. (#4481) 2020-10-08 18:02:50 -03:00
Andrew Lytvynov c0335d4f6f Reduce the necessary k8s permissions for integration tests
Previously, we needed:
- create on namespaces
- impersonate on all users/groups/service accounts
- list pods in kube-system namespace (via teleport-ci-test-group)
- exec/portforward on kube-dns pod in kube-system namespace (via teleport-ci-test-group)

Now, we need:
- create on namespaces
- create on pods in namespace teletest
- impersonate on all users/groups
- get/exec/portforward on pod test-pod in namespace teletest (via teleport-ci-test-group)

Unfortunately, `resourceNames` in RBAC doesn't work with `create` verbs,
so we can't scope down impersonation to just the right users/groups.
2020-10-08 20:59:00 +00:00
jane (quin) 888d6f5d9a
updated HDR histogram vendor (#4461) 2020-10-07 17:13:18 -07:00
Andrew Lytvynov e095e30342 Add kubernetes cluster name to TLS certs
K8s cluster name is specified during login (for now) and gets plumbed to
a new extensions on the TLS cert. The name is validated against all
known k8s clusters reported via proxy heartbeats. If no name is
provided, the extension remains empty.

The name in the cert will get used by proxies for routing, once we fully
support multiple k8s clusters per teleport cluster.

This was tested with direct and github login flows.
2020-10-07 16:26:54 +00:00
Sasha Klizhentas c1b1c6a154 Improves logging and error handling in filesessions.
Adds chaos tests for async file upload.

Fixes playback for legacy sessions stored unpacked on disk
2020-10-06 13:41:17 -07:00
Forrest Marshall 7c70ca61ed include namespace in session.rejected event 2020-10-06 10:00:21 -07:00
Forrest Marshall 44dac2e7a4 permit empty namespace 2020-10-06 10:00:21 -07:00
Andrew Lytvynov 46a1321051 Use the correct k8s port in tctl auth sign --format=kubernetes
Previously, it used the public_addr of the proxy directly.
Now it parses it and replaces the port with k8s port.
2020-10-05 18:01:06 +00:00
Andrew Lytvynov 63da43245e Validate node_labels syntax at role creation time
Also improve error output and user validation.
Based on missed feedback in https://github.com/gravitational/teleport/pull/4253#pullrequestreview-499061448
2020-10-05 18:00:55 +00:00
Andrew Lytvynov 9b59832382 tsh: don't fall back to login when using identity file
First, this is unexpected behavior. If `tsh` fails using the identity
file, it should tell the user why and exit, instead of masking it.

Second, this can lead to a segfault, since the `TeleportClient` isn't
fully initialized for logins (e.g. uses a half-initialized Agent).
2020-10-05 16:25:09 +00:00
Andrew Lytvynov 39895db54c Override role session TTL for k8s principals in tctl auth sign
When running 'tctl auth sign' as an admin, we override the TTL on
roles/logins to allow making long-lived creds.
We didn't do that for k8s users/groups and silently filtered them out.
This change makes them consistent.
2020-10-05 16:07:47 +00:00
Andrew Lytvynov 5d357db004 Improve error logging for identity file parsing
Addresses feedback from https://github.com/gravitational/teleport/pull/4318#pullrequestreview-499067377

- improve error logging to be more actionable
- add missing license headers to files
- use utils.SyncBuffer in testlog.FailuresOnly
2020-10-02 17:05:19 +00:00
Gus Luxton fda711a1ff Rename auth.proto -> authservice.proto to fix naming conflict 2020-10-01 16:21:56 -07:00
Andrew Lytvynov 83060829a3 Apply suggestions from code review
Co-authored-by: Gus Luxton <gus@gravitational.com>
2020-09-30 15:56:31 +00:00
Andrew Lytvynov 3c2e4e2ec1 Add cluster_name to proxy kubernetes config
Cluster name from this field plug all clusters from kubeconfig are
stored on the auth server via heartbeats.
This info will later be used to route k8s requests back to proxies.

Updates https://github.com/gravitational/teleport/issues/3952
2020-09-30 15:56:31 +00:00
Andrew Lytvynov 75d7fbb508 Migrate services.MatchLabels to parse.Matcher
This should be backwards-compatible plus add the {{regexp.match(...)}}
and {{regexp.not_match(...)}} functions.
2020-09-29 21:25:50 +00:00
Andrew Lytvynov 1330415d33 utils/parse: implement Matcher
Matchers use a similar syntax to Expressions, but behave differently:
- Expressions get evaluated - they interpolate some values and return a
  final string.
- Matchers check whether some string matches a value

Matchers implement the same logic as utils.SliceMatchesRegex and add 2
new functions:
- {{regexp.match("foo")}} - match input against a raw regex
- {{regexp.not_match("foo")}} - same as match, but inverts the result
2020-09-29 21:25:50 +00:00
Andrew Lytvynov bb69574e02 utils/parse: support string literal expressions
No need to handle literal expressions (e.g. without "{{foo.bar}}"
substitutions) at the higher level. Something like "foo" is a valid
expression which always returns "foo" regardless of traits.
2020-09-29 21:25:50 +00:00
Andrew Lytvynov e9b7a25d6a utils/parse: rewrite tests in the new RFD style 2020-09-29 21:25:50 +00:00
Andrew Lytvynov a3d3f2aa1d k8s: enable SPDY pings on in/outbound connections
This helps with ELB and similar L5 load balancers that don't respect
TCP-level keep-alives. ELB for example kills connections after 60s of no
application traffic.

With this PR, you can leave a `kubectl exec` session open indefinitely
without any activity.
2020-09-29 21:04:02 +00:00
Andrew Lytvynov cfb7839c08 Update vendored k8s dependencies 2020-09-29 21:04:02 +00:00
Andrew Lytvynov 2eeab9bf80 Document client.Key.HostKeyCallback behavior without CAs 2020-09-29 21:03:42 +00:00
Andrew Lytvynov d91716e150 Unit tests for user reverse tunnels 2020-09-29 21:03:42 +00:00
Andrew Lytvynov 19132c4f9e Support tctl through a proxy
Use the reverse tunnel endpoint, similar to IoT nodes, to connect to the
auth server. Also add an `--insecure` flag, similar to tsh, for testing
with self-signed certs on the proxy.
2020-09-29 21:03:42 +00:00
Andrew Lytvynov 8aacdc1b0f Update github.com/russellhaering/goxmldsig to v1.1.0
See https://github.com/russellhaering/goxmldsig/security/advisories/GHSA-q547-gmf8-8jr7
2020-09-29 17:51:50 +00:00
Forrest Marshall b2faac1d0d track current profile via regular file instead of symlink 2020-09-29 10:15:17 -07: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 97858672d1 etcd: add more info in migration error message 2020-09-18 20:58:42 +00:00
Andrew Lytvynov 3004b65019 proxy: add proxy_ssh_sessions_total metric
This is similar to server_interactive_sessions_total, but tracks all
SSH sessions through a proxy.
2020-09-18 20:57:34 +00:00
Pierre Beaucamp 52c11b5117
Fix error message formating for s3sessions/s3handler.go (#4339) 2020-09-18 11:10:50 -03:00
Forrest Marshall 1d20053807 fix race in TestWeb 2020-09-17 11:02:35 -07:00
Forrest Marshall ae2336dfd0 concurrent session control
Adds support for Concurrent Session Control and a new
semaphore API.  Roles now support two new configuration
options, `max_ssh_connections` and `max_ssh_sessions`
which correspond to the total number of authenticated
ssh connections per cluster, and the number of ssh sessions
within a connection respectively.  Attempting to exceed
these limits generate variants of the `session.rejected`
audit event and cause the connection/session to be
rejected.
2020-09-17 11:02:35 -07:00
Sasha Klizhentas 0f4e82548f Initial work on semaphores 2020-09-17 11:02:35 -07:00
Forrest Marshall c3210b7a12 fix racy logging & session channel rejection 2020-09-17 11:02:35 -07:00
Andrew Lytvynov 74cbd1379c
Split remote cluster watching from reversetunnel.AgentPool (#4290)
* Split remote cluster watching from reversetunnel.AgentPool

Separating the responsibilities:
- AgentPool takes a proxy (or LB) endpoint and manages a pool of agents
  for it (each agent is a tunnel to a unique proxy process behind the
  endpoint)
- RemoteClusterTunnelManager polls the auth server for a list of trusted
  clusters and manages a set of AgentPools, one for each trusted cluster

Previously, AgentPool did both of the above.

Also, bundling some cleanup in the area:
- better error when dialing through tunnel and directly both fail
- rename RemoteKubeProxy to LocalKubernetes to better reflect the
  meaning
- remove some dead code and simplify config structs

* reversetunnel: factor out track.Key

ClusterName is the same for all Agents in an AgentPool. track.Tracker
needs to only track proxy addresses.
2020-09-17 15:07:44 +00:00
Andrew Lytvynov 3587cca784
Always collect metrics about top backend requests (#4282)
* Always collect metrics about top backend requests

Previously, it was only done in debug mode. This makes some tabs in
`tctl top` empty, when auth server is not in debug mode.

* backend: use an LRU cache for top requests in Reporter

This LRU cache tracks the most frequent recent backend keys. All keys in
this cache map to existing labels in the requests metric. Any evicted
keys are also deleted from the metric.

This will keep an upper limit on our memory usage while still always
reporting the most active keys.
2020-09-16 20:33:19 +00:00
Kris G cdcb24f178
DynamoDB respect HTTP Connect proxies (#4271)
* DynamoDB: Build http transport from defaults before manipulating parameters, this allows the transport to be pre-populated with proxy information if set by HTTPS_PROXY/NO_PROXY environment variables.
2020-09-15 18:57:59 +00:00