Commit Graph
594 Commits
Author SHA1 Message Date
Tiago Silva f078db61d7 Store host_uuid into Kubernetes Secret (#17475)
When recovering after a restart, `host_uuid` changes and Auth Server authentication fails. This happens because `host_uuid` is not stored in the Kubernetes Secret but it's stored in the certificate Common Name.
This PR forces the storage of the `host_uuid` into Kubernetes Secrets for later reuse.

Fixes #17474
2022-10-19 17:56:45 +00:00
Michael WilsonandZac Bergquist 08beb1b959 Ensure that TrackingReadConn and TrackingReader conform to io.Reader (#17377)
* Ensure that TrackingReadConn and TrackingReader conform to io.Reader

Implementations of io.Reader should return io.EOF directly when the end of
the stream is reached, because callers will compare the error using ==.

* Update lib/srv/monitor_test.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Use require.Equal for conn_test.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-10-14 15:01:38 +00:00
Edward Dowling d0a602deb6 Add initial OSS part of license expiry code. (#16753)
In “tsh login” show only alerts with on-login label.
    In “tsh status” show only alerts with “high” severity. Which license warning should match.
    In all “tctl” commands show only alerts with “high” severity.
2022-10-13 14:59:47 +00:00
Gavin Frazar ba7df65a0c support proxy db tunnel mfa access (#16958)
* Add local proxy middleware for db cert checking

* Use tls conversion util instead of inline

* Add middleware to local proxy config

* Add middleware configuration in tsh

* Use route to database check and set defaults func

* Dont trigger normal db login flow if using local proxy tunnel

* Split out adding client creds into helper func for testing

* Add integration test for local proxy tunnel db cert middleware

* Add unit test for local proxy middleware

* Update comment

* Make middleware on new conn block

* godoc

* Make any cert check error trigger cert renewal in local proxy middleware

* Move dbcertchecker into lib/client

* Remove unneeded mutex in local proxy and unused func in lib/utils

* Make local proxy middleware integration test more robust

* Print message before mfa prompt in proxy tunnel

* Add before prompt option to test

* Remove unneeded comment

* Change local proxy messages to be more clear

* Pass local proxy opts by reference

* Pass certs in opts instead of cert/key file path

This is so we can check if the error is recoverable while preparing
local proxy options. A tunneled local proxy can ignore the error because
it does not rely on cert files - it can just renew its certs if
necessary.

* Move db route checking back to tsh

* Fix lint err

* Fix typo and print the hint to same writer as the mfa prompt
2022-10-07 21:29:51 +00:00
Zac Bergquist 1a62376b78 Fix uses of require in goroutines (#16953)
The require checks from testify call (*testing.T).Fail, which should
only be called from the test goroutine.
2022-10-05 19:14:30 +00:00
Zac Bergquist e547957f93 Remove [direct] dependency on go.uber.org/atomic (#17035)
Reintroducing the change from #16884 now that Go 1.19.2 has been
released with the fix.

This reverts the revert from  09de0ba530.
2022-10-05 01:24:46 +00:00
Zac Bergquist 09de0ba530 Revert "Remove [direct] dependency on go.uber.org/atomic (#16884)" (#16918)
This reverts commit 4f3aa9a3f2.

We're unable to build for 32-bit Linux due to
https://github.com/golang/go/issues/55152,
which looks like it will be fixed with Go 1.19.2 next week.

We'll re-evaluate with the next Go release and reintroduce this change
as soon as we can.
2022-09-30 22:41:45 +00:00
Zac Bergquist 4f3aa9a3f2 Remove [direct] dependency on go.uber.org/atomic (#16884)
Go 1.19's sync/atomic package provides the same functionality
2022-09-30 20:39:05 +00:00
Andrew Burke ac257084a7 Automatically import Azure tags (#16218)
This change lets Teleport automatically import tags from the Azure instance it's running on.
2022-09-28 23:40:13 +00:00
Forrest Marshall ad4be5ae44 bucket etcd leases 2022-09-27 15:01:32 -07:00
Brian Joerger 4c0a6ff5b1 tsh PIV login integration (#15335)
* Add Yubikey PrivateKey implementation for use by Teleport clients.

  - Add yubikey login logic, reusing previously stored private keys.

  - Fix identity file decoding with PIV keys, which sign ecdsa certificates.

  - Add libpcsclite-dev pre-req for building on linux.

  - Remove unnecessary keys.Signer interface and move its functionality to keys.PrivateKey.

  - Move retry and jitter utils to new api/utils/retryutils package.
2022-09-23 19:44:10 +00:00
rosstimothy 7e036cdf42 Generic retrieval of FnCache values (#16485)
Coverts getting values in the `FnCache` from `FnCache.Get` to
`utils.FnCacheGet[T any]`. This allows us to have compile time
guarantees for the type being loaded, which allows us to remove
some of the manual type checking required of callers today.
2022-09-20 12:36:03 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Anton Miniailo 7695f23cb4 Fix known_hosts locking by refactoring our locks in utils/fs (#16364)
* Refactor our `utils/fs` locking to use `flock`
library and add support for windows.

Flock works differently on linx/mac vs windows. On windows it's impossible to
read/write file after locking, so we need to create separate lockfile.
2022-09-15 12:07:40 -04:00
Zac Bergquist 7f4297e50e Add missing tests for selector regexp matching (#16204)
This adds tests for the regex/glob style behavior that was added
in 045490de25 but not documented
until #10062.
2022-09-10 18:13:43 +00:00
Gavin FrazarandSTeve Huang 4a3f241e2a fixup untrusted cert errors (#16127)
* Add util helpers for untrusted cert errors

* Remove superfluous error checking

* Add helpful message on first time node join

* Cleanup cert error messages when connecting to auth service

* Add helpful certs message for tctl

* Fix flaky TestHandlerConnectionUpgrade

* Change long line back to the way it was before

Co-authored-by: STeve Huang <xin.huang@goteleport.com>
2022-09-07 22:49:20 +00:00
STeve (Xin) Huang 8394f4fb48 ALPN connection upgrade for MySQL behind ALB (#15669) 2022-09-01 16:05:03 +00:00
Forrest Marshall 7c9f26457a upgrade notifications 2022-08-31 12:09:30 -07:00
Andrew Burke 545e620839 Add validation for hostname read from EC2 (#15971)
This change adds validation for the hostname imported from an EC2 instance.
2022-08-31 17:56:31 +00:00
Nic Klaassen cf30661de6 Use regional STS endpoints for IAM join method (#15337) 2022-08-29 18:35:28 +00:00
Forrest Marshall 0ddaf37ebd fncache test improvements 2022-08-26 13:11:13 -07:00
Gabriel Corado a3a65e863b TLS routing ping for database protocols (#14887) 2022-08-26 16:42:23 +00:00
STeve (Xin) Huang fac43c5925 Fix an issue tsh aws s3 fails when using path with special characters (#15784) 2022-08-24 18:33:32 +00:00
rosstimothy 1973fcee24 Span improvements (#15388)
* Add spans to TeleportClient/ProxyClient/NodeSession

* Improve dialer tracing

* Alter default http client span name to include path

* propagate tracing options in NewClientConn
2022-08-18 21:29:03 +00:00
rosstimothy c469a34994 Move prometheus collectors from utils to metrics (#15288) 2022-08-09 17:35:19 +00:00
NajiObeid 7833dc63cb Naji/11867 manual resource joining (#13505)
* improve tsh configure messaging

* missing param

* improve cli output

* remove unnecessary change

* address pr comments

* address pr comments
2022-08-09 15:42:17 +00:00
Marco André Dinis a60d1c0f43 Download mTLS files from Web (#14526)
In the context of Teleport Discover we are trying to ease the usage of Teleport for the user's first interaction.

When adding a new database resource the user must, among other things, generate the mTLS files
Examples:
https://goteleport.com/docs/database-access/guides/postgres-self-hosted/#step-25-create-a-certificatekey-pair
https://goteleport.com/docs/database-access/guides/mysql-self-hosted/#step-24-create-a-certificatekey-pair

This PR aims to reduce this friction: the user should be able to setup the resource without prior setup of local tools (`tsh login`)
We're doing this by providing an endpoint that will return those exact files


Demo
```shell
marco@lenix ~/p/downloadmtls> curl --silent --insecure 'https://127.0.0.1.nip.io:3080/v1/webapi/sites/lenix/sign' --dat
a '{"hostname":"discover.example.com", "ttl":"9999h", "format": "db"}' --header 'Authorization: Bearer 308bf3dd3019ddc4
2cff44a48e028480' --header 'Content-Type: application/json' -OJ
marco@lenix ~/p/downloadmtls> tar -xvf teleport_mTLS_discover.example.com.tar.gz
server.key
server.crt
server.cas
marco@lenix ~/p/downloadmtls> head -1 server.*
==> server.cas <==
-----BEGIN CERTIFICATE-----

==> server.crt <==
-----BEGIN CERTIFICATE-----

==> server.key <==
-----BEGIN RSA PRIVATE KEY-----
```

Fixes https://github.com/gravitational/teleport/issues/14049
2022-08-01 10:14:18 +01:00
Noah Stride 3a853cdfd0 Self signed certificates tsh TTL fixes (#14985)
* start work on self signed tsh fixes

* fix go sum

* Adjust error formatting

* Complete less explicit error checks last

* Adjust PR feedback

* Further PR review

* Support darwin and linux certificate errors
2022-07-28 20:43:40 +00:00
Andrew BurkeandTim Ross 645afa051b Make EC2 availability check more robust (#14867)
This change improves the reliability of checking for the presence of an EC2 instance.

Co-authored-by: Tim Ross <tim.ross@goteleport.com>
2022-07-27 18:35:35 +00:00
Forrest Marshall 885c893f2a reduce sensitivity of fncache cancellation test 2022-07-27 09:26:08 -07:00
Krzysztof SkrzętnickiandMarek Smoliński 0e9d621b46 Alias support for tsh (#13305)
* aliases are read from global and user configs.
* we prevent Kingpin from terminating `tsh`; we handle parsing errors better.
* added support for `TELEPORT_DEBUG` env variable, changed how logging is initialized.
* debugging aliases is possible via `TELEPORT_DEBUG=1` env variable; `--debug` is ineffective as it comes into play too late.
* if alias definition calls `tsh`, we call the `Run()` function directly instead of spawning fresh `tsh`; this improves the UX.
* alias loops are detected and a proper error is shown.
* all flags are made repeatable; if only one value for a given flag is possible, the last instance of the flag will be effective. 

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-07-27 11:14:55 +00:00
Roman Tkachenko 38b8bb4307 Add support for proxying TCP apps (#13455)
Add support for proxying tcp apps
2022-07-26 19:01:39 +00:00
STeve (Xin) Huang 2da838fca1 Support AWS external id (#14086) 2022-07-26 14:47:12 +00:00
Nic Klaassen 98a1152984 Delete lib/utils/timeout_test.go (#14555) 2022-07-18 19:05:02 +00:00
Russell Jones 46653322af Refactor tests under util package.
Refactored all tests under "lib/util" to use testify instead
of gocheck.
2022-07-14 19:22:54 -07:00
Nic Klaassen dd12a7f60e Display helpful error when joining with invalid host ID for EC2 join method (#14404) 2022-07-14 22:34:51 +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
Forrest Marshall 6c02a4efd9 improve semaphore retries and tests 2022-07-13 11:19:18 -07:00
STeve (Xin) Huang cf88c0a283 Capture stderr from "tsh db connect" and reformat redis error (#13843) 2022-07-05 21:25:43 +00:00
David Boslee 0f7762c41b Fix agent mesh integration test (#13954)
By using a randomized load balancer we improve the chances of an agent
connecting to all proxy servers within the given time period.
2022-07-05 16:01:03 +00:00
Edoardo Spadolini c2c4e4a630 Use JSON logging in tests (#13977)
* Use JSON logging in tests

* log to logrus
2022-07-01 11:09:39 +00:00
Alex McGrath 38ba3adca6 Add utilities for detecting linux distro based on /etc/os-release (#13786)
Only AMZL/RHEL/Ubuntu/Debian are needed for now as those are the
target distros of EC2 discovery
2022-06-29 13:28:57 +00:00
Gavin Frazar 1858aafa15 Fix http proxy basic auth (#13140)
* Fix http proxy basic auth

* Update docs about HTTP CONNECT env var formats
2022-06-23 00:27:29 +00:00
Norbert SzeteiandZac Bergquist 0ab9716aac oss fuzz integration (#13473)
* Update api/types/fuzz_test.go
* do not fail if the file is missing
* missing go-118-fuzz-build fix

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-06-18 21:28:07 +00:00
Zac Bergquist 12e09b02f2 Deflake TestGRPCErrorWrapping (#13633)
This test would occaisonally fail with:

    === RUN   TestGRPCErrorWrapping
         grpc_test.go:125:
            	Error Trace:	grpc_test.go:125
            	Error:      	Received unexpected error:
            	            	EOF
            	Test:       	TestGRPCErrorWrapping

According to the GPRC docs
(https://pkg.go.dev/google.golang.org/grpc#section-readme)
io.EOF indicates that the server closed the stream and
that "the status of the stream may be discovered using ReadMsg."

Since the test is ultimately attempting to assert that the error
from Recv() is properly wrapped in an "already exists" error, we
tolerate the io.EOF on Send() and continue to check the error from
Recv().

I've run with this change for about 150K iterations and haven't seen
a failure. Prior to this change we would get a few failures per 10K
iterations.
2022-06-18 18:03:14 +00:00
rosstimothy 14ebab8b96 Manually instrument cache.Cache (#13318)
Adds a `trace.Tracer` to the `cache.Cache`so
that all operations can be traced. Also, updates
the `utils.FnCache` to link the `context.Context`
passed to the loadFn to any current spans. This
will allow any fetches made by the `FnCache` to
be associated with the call that lead to loading.

Note: There are a few methods in the `auth.Cache`
interface which do not take a `context.Context`.
For the time being all spans for these calls use
a `context.TODO` and will be updated in the future,
where the changes can be made on a per method basis.
2022-06-16 20:19:54 +00:00
Forrest Marshall 31f258fec9 inventory control stream & certs 2022-06-15 22:26:24 -07:00
Alan Parra 0ecf31de0e Restore terminal state on interrupt or exit (#13382)
Fixes an issue with ContextReader on `bash` where abandoned password reads cause
the terminal to remain "locked" even after `tsh` exits. This happens on
interrupts but also on regular exit if the user picks a security key in the dual
security key/OTP login prompt.

Doesn't seem to affect shells like `zsh` or `fish`.

Repro steps:

```shell
$ bash

# repro #1
$ ./tsh login --proxy=example.com
> Enter password for Teleport user llama: <CTRL-C>
# shell is now locked

# repro #2
# (Use an account with security key and OTP MFA.)
$ ./tsh login --proxy=example.com
> Enter password for Teleport user llama: <enters password>
> Tap any security key or enter a code from a OTP device <taps security key>
# shell is now locked
```

* Restore terminal state on interrupt or exit
* Notify prompt on tsh exit
* Review: context.WithTimeout and Notify on os.Exit
2022-06-10 14:44:18 -03:00
Nic Klaassen b1da3b3054 Make tsh ssh --request the default (#13326) 2022-06-10 17:14:29 +00:00
9bb07eabd2 Always use auth_servers when proxying an auth connection (#13310)
* Don't GetAuthServers in AuthProxyDialerService

* Don't GetAuthServers in localSite

* Fix lib/web tests

* Connect to a single auth in transport.start

* Review comments

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-06-10 16:03:14 +00:00