Commit Graph
97 Commits
Author SHA1 Message Date
rosstimothy c2fc9a9375 Add idle connection timeouts to http clients and servers (#22885)
Sets `http.Server.IdleTimeout` and `http.Client.IdleConnTimeout`
on clients and servers which didn't have them set. A default of
360s was chosen to be on par with the default of an NLB without
being identical.

This was added as another safety measure to prevent leaking any
idle connections indefinitely as seen in #22757.

`apidefaults.DefaultDialTimeout` was also renamed to
`apidefaults.DefaultIOTimeout` to better reflect its usage.
2023-03-10 16:47:06 +00:00
rosstimothy 6e9a3cfcc9 Reduce etcd requests performed by a KeepAlive (#21892)
When performing a KeepAlive the key was first retrieved from
etcd to verify that it existed before updating the item. However,
a Put operation with the `ignore_value` set will return a not
found error if the key does not exist
(https://etcd.io/docs/v3.4/learning/api/#put). So we can safely
remove the get and rely on etcd to prevent updating a key that
does not exist.

Also converts `concurrentqueue.Queue` to be generic over the given
Input and Output of the worker function.
2023-02-16 15:27:39 +00:00
rosstimothy c6d8fca73f Cache etcd lease ttl (#21481)
Since #16636 etcd leases have been bucketed, yet when watching events
we still determine the ttl for each particular item in `fromEvent`
by retrieving the ttl from etcd. To reduce the number of ttl requests
sent to etcd we now cache the ttl per lease id.

Closes #21380
2023-02-08 20:35:04 +00:00
Steven Martin e1ebc332f8 spell fixes (#19419) 2022-12-16 19:01:28 +00:00
Vitor Enes 0403a4eebb Improve error message if dialing etcd nodes times out (#18789)
If all etcd nodes are unreachable, Teleport exits with the following
message:
```
ERROR: initialization failed
context deadline exceeded
```

With this commit we get instead:
```
ERROR: timed out dialing etcd endpoints: [https://127.0.0.1:2381 https://127.0.0.1:12381]
initialization failed
context deadline exceeded
```

Note that if only some of the etcd nodes are unreachable, the etcd
client already provides a useful error message:
```
ERROR: initialization failed
failed to dial endpoint https://127.0.0.1:12381 with maintenance client: context deadline exceeded
```
2022-11-28 18:40:24 +00:00
Roman TkachenkoandVictor Sokolov 3fd1cca5b2 Github Actions workflow (#18617)
Signed-off-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Victor Sokolov <gzigzigzeo@gmail.com>
2022-11-22 16:55:26 -05:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
rosstimothy 1750b79951 Stop using etcd serializable mode (#16941)
From the etcd docs:

> To obtain lower latencies and higher throughput for read requests
> clients can configure a request’s consistency mode to serializable,
> which may access stale data with respect to quorum, but removes the
> performance penalty of linearized accesses' reliance on live consensus.

By leveraging serializable mode it is entirely possible to retrieve
stale data. This means that a Create followed by a Get could result
in a NotFound error, which results in issues like #13276. While this
improves latency it breaks the consistency guarantees required by
Teleport.

To ensure that our consistency requirements are met all etcd operations
are converted to use the default linearized mode by removing the
`WithSerializable` option.

Closes #13276.
2022-10-05 02:09:29 +00:00
Forrest Marshall ad4be5ae44 bucket etcd leases 2022-09-27 15:01:32 -07:00
Roman Tkachenko 9d04ee27c2 Fix CA pool loading for etcd backend (#16484) 2022-09-20 22:03:07 +00:00
rosstimothy c469a34994 Move prometheus collectors from utils to metrics (#15288) 2022-08-09 17:35:19 +00:00
Noah Stride 02b4f8575f Configure linter to catch British 🇬🇧 spellings 🇺🇸 🦅 📖 (#14363)
* configure golangci-lint misspell to check for anglicized spellings

* Americanize spellings

* fix aws constant value with british spelling 🇬🇧

* update api types with americanized spellings

* use american spellings .cloudbuild/scripts
2022-07-14 10:51:23 +00:00
Zac Bergquist 3f507dfd06 Remove uses of deprecated ioutil package 2022-03-16 15:05:42 -06:00
Jim Bishopp fe958969dc Remove migration from backend API (#10835)
The Migrate method on the Backend interface was not implemented by any
backends.

Migration should be implemented in the New method of backends so they
can be sure migration happens before any background processes are
started.
2022-03-08 03:08:09 +00:00
Edoardo Spadolini 5acab226a0 Upgrade from go.etcd.io/etcd v3.4.14 to go.etcd.io/etcd/{api,client}/v3 v3.5.1 (#9607)
* Prepare `etcdbk` to use the newer `go.etcd.io/etcd/v3` lib

* `go get go.etcd.io/etcd/api/v3 go.etcd.io/etcd/client/v3`

* Fix direct/indirect split in go.mod
2022-01-10 13:44:25 -05:00
Forrest Marshall 92f724cfd0 fix double-init and buffer overflows 2021-09-17 15:05:23 -07:00
Trent ClarkeandZac Bergquist 4c1bd5fc96 Skip etcd prefix test if disabled (#8202)
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
2021-09-13 12:19:09 -07:00
Trent Clarke e91860631e Port backend tests to testify / fix racy tests (#8170)
In order to get better visibility into the backend database tests using
the standard Go tooling, this changeset ports the backend tests away
from `Check`, and into subtests & `testify` for assertions.

This change means that individual sub-tests
 1. can be more easily identified in the json test logs, and
 2. can be more easily run individually from the command line

During this port I also discovered that some tests are using the fake
clocks incorrectly, which may be a cause of some of our flaky etcd
tests.
2021-09-10 04:14:04 -07:00
Forrest Marshall 13ad93e11a fix race in etcd test 2021-08-13 16:02:41 -07:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Forrest Marshall 50a7680d9a fix init event emission 2021-07-22 15:21:07 -07:00
Forrest Marshall 530430e232 improve etcd event processing 2021-07-21 14:35:04 -07:00
Andrej Tokarčík 7c630ec960 Introduce Lock resource (#7430) 2021-07-07 18:20:53 +02:00
Brian Joerger 4d36870ff0 Remove remaining API aliases (#7137) 2021-06-08 12:08:55 -07:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Andrew Lytvynov 11c62e8897 etcd: use a separate connection to check peer versions (#6905)
There is a data race in etcd that breaks the internal state in etcd client
implementation for some server setups (user/pass authentication with
JWTs).
2021-05-19 10:07:08 -07:00
NajiObeid 86a6abcfcb lazy init of prometheus collectors (#6561)
* lazy init of prometheus collectors

* incorporate metrics intorduced in #6271

* linting

* tests

* pr changes

* tests

* pr changes
2021-05-19 11:53:36 -04:00
a-palchikovandAndrew Lytvynov 3d459db6d3 Test flakes: use ordering tests for keep alives (#5358)
* Evaluate watcher events to decide whether keep-alives are effective
instead of relying on arbitrary TTLs (implemented as absolute time which
adds to trouble).

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

* Replace the approximate expire timestamps comparisons with the ordering tests

* Address review comments. Move ordered keep-alive tests back to backend/test/suite

* Use an alternative implementation of FakeClock.Advance for etcd to use real time.Sleep as etcd server cannot use fakeclock

* Address review comments

* Use fake clock in firestore tests

* Add missing import

Co-authored-by: Andrew Lytvynov <andrew@goteleport.com>
2021-04-14 14:47:14 -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
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
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
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
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
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 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 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