Commit graph

162 commits

Author SHA1 Message Date
Trent Clarke 3149d0b953 Enforce valid UTF8 keys on all backends.
The use of non-UTF8 keys with the DynamoDB back-end causes a failure
deep within the AWS request deserialization code, presenting a
non-obvious failure to the user.

This change adds validation to all backends that requires all keys
are valid UTF8 strings. It also adds a warning to the Backend
interface declaration that the keys may be constrained to valid
UTF8.

Other changes include:
 * Updating the `Backend` conformance test suite to not present binary
   keys to the various backend implementations.
 * Adding a `region` value to the DynamoDB configuration test input
 * Adding missing imports to `_test` files.
 * Updating build instructions in README
2021-03-19 17:14:05 -07:00
Andrej Tokarčík f7a2eb4ed5 Include CA cert file path in the error message 2021-03-02 13:20:43 -08:00
Andrej Tokarčík 012b1235a6 Get rid of unnecessary var declarations 2021-03-02 13:20:43 -08:00
Andrej Tokarčík 539ba24550 Fix support for insecure etcd mode 2021-03-02 13:20:43 -08:00
Andrej Tokarčík 976d8517cb
Remove support for migrating from legacy etcd prefix (#5798)
This code should have been removed in 4.4.
2021-03-02 20:49:11 +01:00
Andrej Tokarčík f88665fe12 Add obfuscation to diagnostic metrics 2021-03-01 22:14:10 +01: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
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
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
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
Roman Tkachenko 8e1865464b
Database access (#5005) 2021-01-14 18:21:38 -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
joerger f020f75078 Refactor API client into a separate package. 2020-12-29 10:06:37 -08: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
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
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 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 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
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
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
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
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 97858672d1 etcd: add more info in migration error message 2020-09-18 20:58:42 +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
Andrew Lytvynov 396812cebf etcd: fix data race in migration tests 2020-09-14 21:26:36 +00:00
Andrew Lytvynov 2d902a7624 etcd: more tweaks with slashes for migration
When custom prefix is `/foo/`, the migration would move `/teleport/a` to
`/foo/a`, but the backend later tries to read `/foo//a`.

Also added tests to cover these edge cases.
2020-09-14 21:26:36 +00:00
Andrew Lytvynov d4f7be9d35 etcd: backup data before overwrite during migration
In case the migration kicks in by mistake, or ends up deleting more data
than expected, a backup will be very handy.
2020-09-14 21:26:36 +00:00
Andrew Lytvynov 03064cfa96 etcd: don't confuse prefixes during migration
The prefix fetching logic has a bug: it treats everything starting with
`/teleport` as the legacy prefix data, even if it's `/teleport-foo/bar`.
This is an issue if user specifies `/teleport-foo` as their custom
prefix. Each restart will copy the data from `/teleport-foo/...` to
`/teleport-foo-foo/...`.

Set the legacy prefix const to `/teleport/` instead. This avoids
excessive copying during startup.

Prefixes can still be confused later on, with `Watch` and `GetRange`,
but this is harder to migrate with backwards-compatibility.
2020-09-14 21:26:36 +00:00
Andrew Lytvynov 0f14636d4c Fix improper string conversions in backend tests
Go 1.15 catches these:
lib/backend/test/suite.go:402:12: conversion from OpType (int) to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?)

Since these are ints, they can be compared for equality without
stringifying.
2020-08-28 00:29:07 +00:00
Andrew Lytvynov b90452e772 firestore: marshal keys as []byte
Same as values, `backend.Item` passes keys as `[]byte` and has no
guarantees about the encoding. GetRange queries need extra care because
of this type mismatch too: `where` clauses are type-sensitive.
2020-08-11 18:40:34 +00:00
Andrew Lytvynov 37c3724d0d firestore: marshal values as []byte, not string
Firestore marshaler requires all string data to be valid UTF-8. Our
values are sometimes binary (like QR codes for OTP signup), which would
fail to marhal.

On reads, try using both new and old formats to support existing data.

Added tests for this fallback and for writing binary data into all
backends.
2020-08-11 18:40:34 +00:00
Andrew Lytvynov b4ed94e967 Fix a nil pointer dereference in firestore index creation
https://github.com/gravitational/teleport/pull/3766 removed a nil
pointer check when creating firestore indexes. This was a legitimate
check, for when indexes already exist.

Tested this manually. Unit testing is trickier because the firestore
emulator in gcloud doesn't support indexes.
2020-07-15 17:32:08 +00:00
Andrew Lytvynov 28dcee22e0 etcd: create a backend per-test instead of per-suite
This avoids data races between watchers and test setup.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov 8237adbb1b Revert etcd double-writing
Per discussion in https://github.com/gravitational/teleport/pull/3798
this is unnecessary complexity.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov c68b571080 Add a Migrate method to backend.Backend
Unify migrations and expose them to the calling code at startup.
All backends except for etcd implement a nop migration.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov c5d20b61c1 etcd: fix etcd double-writing and add tests
Using the wrong prefix in some double-write methods, oops.
Added tests to make sure it doesn't happen again.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov 61aafa3da6 etcd: copy data from the legacy prefix to config prefix at startup
This code is only intended for 4.3 and will be removed in 4.4.
The goal is to automatically move data to the correct etcd prefix that
the customer has specified in their config. Prior to 4.3, their data was
always written to `/teleport` prefix, ignoring the config.

The copy happens iff:
- /teleport is not empty
- config prefix is empty OR older than /teleport
2020-07-02 23:24:49 +00:00
Andrew Lytvynov 27bb30a905 etcd: double-write to legacy /teleport prefix
This double-writing will only exist in 4.3 and the config prefix is
still source-of-truth for reads.
Double-writes are necessary to allow users to downgrade to 4.2 and back
up again without losing data.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov a5e0720107 etcd: propagate the prefix from config
Prefix-handling code was using a hardcoded prefix (`/teleport`) instead
of the prefix specified in config. Use the correct config prefix and add
a test.
2020-07-02 23:24:49 +00:00
Andrew Lytvynov 3c94003379 errcheck: fix findings in lib/backend, lib/client 2020-06-01 20:16:16 +00:00
Andrew Lytvynov 617afc7e6f Fix remaining gosimple findings
List of fixed items:

```
integration/helpers.go:1279:2               gosimple  S1000: should use for range instead of for { select {} }
integration/integration_test.go:144:5       gosimple  S1009: should omit nil check; len() for nil slices is defined as zero
integration/integration_test.go:173:5       gosimple  S1009: should omit nil check; len() for nil slices is defined as zero
integration/integration_test.go:296:28      gosimple  S1019: should use make(chan error) instead
integration/integration_test.go:570:41      gosimple  S1019: should use make(chan interface{}) instead
integration/integration_test.go:685:40      gosimple  S1019: should use make(chan interface{}) instead
integration/integration_test.go:759:33      gosimple  S1019: should use make(chan string) instead
lib/auth/init_test.go:62:2                  gosimple  S1021: should merge variable declaration with assignment on next line
lib/auth/tls_test.go:1658:22                gosimple  S1024: should use time.Until instead of t.Sub(time.Now())
lib/backend/dynamo/dynamodbbk.go:420:5      gosimple  S1004: should use !bytes.Equal(expected.Key, replaceWith.Key) instead
lib/backend/dynamo/dynamodbbk.go:656:12     gosimple  S1039: unnecessary use of fmt.Sprintf
lib/backend/etcdbk/etcd.go:458:5            gosimple  S1004: should use !bytes.Equal(expected.Key, replaceWith.Key) instead
lib/backend/firestore/firestorebk.go:407:5  gosimple  S1004: should use !bytes.Equal(expected.Key, replaceWith.Key) instead
lib/backend/lite/lite.go:317:5              gosimple  S1004: should use !bytes.Equal(expected.Key, replaceWith.Key) instead
lib/backend/lite/lite.go:336:6              gosimple  S1004: should use !bytes.Equal(value, expected.Value) instead
lib/backend/memory/memory.go:365:5          gosimple  S1004: should use !bytes.Equal(expected.Key, replaceWith.Key) instead
lib/backend/memory/memory.go:376:5          gosimple  S1004: should use !bytes.Equal(existingItem.Value, expected.Value) instead
lib/backend/test/suite.go:327:10            gosimple  S1024: should use time.Until instead of t.Sub(time.Now())
lib/client/api.go:1410:9                    gosimple  S1003: should use strings.ContainsRune(name, ':') instead
lib/client/api.go:2355:32                   gosimple  S1019: should use make([]ForwardedPort, len(spec)) instead
lib/client/keyagent_test.go:85:2            gosimple  S1021: should merge variable declaration with assignment on next line
lib/client/player.go:54:33                  gosimple  S1019: should use make(chan int) instead
lib/config/configuration.go:1024:52         gosimple  S1019: should use make(services.CommandLabels) instead
lib/config/configuration.go:1025:44         gosimple  S1019: should use make(map[string]string) instead
lib/config/configuration.go:930:21          gosimple  S1003: should use strings.Contains(clf.Roles, defaults.RoleNode) instead
lib/config/configuration.go:931:22          gosimple  S1003: should use strings.Contains(clf.Roles, defaults.RoleAuthService) instead
lib/config/configuration.go:932:23          gosimple  S1003: should use strings.Contains(clf.Roles, defaults.RoleProxy) instead
lib/service/supervisor.go:387:2             gosimple  S1001: should use copy() instead of a loop
lib/tlsca/parsegen.go:140:9                 gosimple  S1034: assigning the result of this type assertion to a variable (switch generalKey := generalKey.(type)) could eliminate type assertions in switch cases
lib/utils/certs.go:140:9                    gosimple  S1034: assigning the result of this type assertion to a variable (switch generalKey := generalKey.(type)) could eliminate type assertions in switch cases
lib/utils/certs.go:167:40                   gosimple  S1010: should omit second index in slice, s[a:len(s)] is identical to s[a:]
lib/utils/certs.go:204:5                    gosimple  S1004: should use !bytes.Equal(certificateChain[0].SubjectKeyId, certificateChain[0].AuthorityKeyId) instead
lib/utils/parse/parse.go:116:45             gosimple  S1003: should use strings.Contains(variable, "}}") instead
lib/utils/parse/parse.go:116:6              gosimple  S1003: should use strings.Contains(variable, "{{") instead
lib/utils/socks/socks.go:192:10             gosimple  S1025: should use String() instead of fmt.Sprintf
lib/utils/socks/socks.go:199:10             gosimple  S1025: should use String() instead of fmt.Sprintf
lib/web/apiserver.go:1054:18                gosimple  S1024: should use time.Until instead of t.Sub(time.Now())
lib/web/apiserver.go:1954:9                 gosimple  S1039: unnecessary use of fmt.Sprintf
tool/tsh/tsh.go:1193:14                     gosimple  S1024: should use time.Until instead of t.Sub(time.Now())
```
2020-05-27 19:36:38 +00:00
Andrew Lytvynov 983b735e67 Fix tests for firestore backends
Reimplement cleanup code in the test itself, since the helper method is
gone.
2020-05-27 18:37:34 +00:00
Andrew Lytvynov 552d3e623c Cleanup of GCP backend implementation
- close all io.Closers where missing
- add error handling where missing
- improve error messages
2020-05-27 18:37:34 +00:00
Andrew Lytvynov 4b5cd7e68f gosimple: simplify or remote return statements 2020-05-15 16:32:45 +00:00
Andrew Lytvynov a48c40ad78 gosimple: replace time.Now().Sub(x) with time.Since(x) 2020-05-15 16:32:45 +00:00
Andrew Lytvynov 0add471f16 gosimple: remove comparisons to boolean constants
`if x == true` or `if x == false` should be just `if x` or `if !x`.
2020-05-15 16:32:45 +00:00