Commit Graph
19 Commits
Author SHA1 Message Date
Yassine Bounekhla f2c8833cea implement listing notifications for a user with matching (#39942) 2024-05-15 19:26:58 +00:00
rosstimothy 67f499a457 Refactor auth client code into lib/auth/authclient (#41460)
This starts separating the lib/auth client and server code into
distinct packages to reduce the dependency tree of client tools.
For the time being aliases were left to all things moved into
lib/auth/authclient to reduce the changeset and ensure code still
compiles. Future changes will be built off this to convert code
to use lib/auth/authclient where applicable, this was intentionally
left to a minimum amount of changes to facilitate backports.
2024-05-14 13:28:06 +00:00
STeve (Xin) Huang e192ad386e Propagate user-agent from GRPC for cert.create events (#37726)
* Add user-agent to cert.create event

* fix tctl and minor stuff

* fix integration test
2024-02-08 20:39:43 +00:00
rosstimothy 327c877cbd Reuse tunnel resolvers instead of creating one per connection attempt (#37566)
The `CachingResolver` is backed by a `FnCache` but does not expose
a way to close the underlying cache. This leads to memory leaks
as captured in #37025. Instead of modifying the resolver to allow
explicit cleanup to occur, the resolvers were refactored to be
created once per process instead of per connenction attempt to the
cluster. Since the cluster address is read from the config file, it
won't be changed for the duration of the process which allows us to
safely use a single resolver. The one potential downside to this
approach is the cache may return possibly stale errors during an
outage until the entry is TTLed.

Fixes #37025
2024-02-02 17:08:48 +00:00
Brian Joerger e99b342a1f Fix OTP prompt (#35537)
* Fix otp prompt; remove related dead code.

* Implement basic read waiting for fake readers in tests.

* Add regression test.
2023-12-12 20:43:43 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <fred.heinecke@goteleport.com>
2023-12-01 17:48:14 +00:00
Noah Stride 22584cbdf0 Machine ID: Add experimental ClientCredentialOutput for Operator's use (#34442)
* Start writing out rough plan

* More progress

* Refactor tbot/identity.Identity

* Fix TBot main test

* Add real Insecure rather than using tls.InsecureSkipVerify

* Fix Imports

* Restore integrations/operator

* Remove unused field

* Unnecessary sprintf

* Use facade in integration/operator

* Don't forget License!

* Another license file

* Correctly set Insecure for authclient.Connect

* Fix Insecure status with `tsh` profile

* Add GoDocs for DestinationNop

* GoDoc UnstableClientCredentialOutput
2023-11-22 19:20:44 +00:00
Brian Joerger 621c7b3a5b Make MFA prompt client agnostic (#34087)
* Make MFA prompt client agnostic for universal use, e.g. in Teleport Connect.

* Refactor to address CR.

* Resolve comments.

* Add tc.PromptMFA.

* Fix lint.

* Extract common high level interfaces and structs into api/mfa for better flexibility in API MFA prompts.

* Resolve comments.

* Remove unused field.

* Fix miss-set quiet field.
2023-11-09 18:14:12 +00:00
Brian Joerger 9b29150ca0 Add MFA prompt to Clients for Admin Actions. (#30203)
* Add MFA PerRPCredentials.

* Add RetryWithMFA unary interceptor.

* Add MFA prompt retry mechanism for Admin API requests.
2023-08-25 19:14:13 +00:00
Zac Bergquist 29e5a0c473 Make tctl build for Windows (#25447)
* Add a no-op syslog impl for Windows

* Break tctl's dependency on lib/srv

tctl's auth client depends on the lib/reversetunnel package in order
to dial the auth server via reverse tunnel. This package in turn
depends on lib/srv/forward and lib/srv, which is a bunch of
Linux-specific code for Teleport services (re-exec, etc).

By extracting the client side code for dialing via reverse tunnels
into its own package, we can now build tctl for Windows with the
following incantation:

    CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -o tctl.exe ./tool/tctl
2023-05-24 20:44:18 +00:00
Noah Stride 2e78fbb544 Fix GoRoutine leak in authclient.Connect (#26119)
* Fix goroutine leak in auth client connection

* Explicitly ignore .Close error

* Break each connection method into its own function for clarity
2023-05-12 12:45:27 +00:00
STeve (Xin) Huang b1941aaa85 TLS routing behind LB support for Auth, SSH, Reverse tunnel (#23866)
* ALPN connect test improvements

* fix typos

* remove extra period

* simplify error check

* moving things over

* tsh dials

* reverse tunnel

* fix auth connect

* move ping

* add ssh support

* add HTTP client support

* Move ALPN dialer, ALPN conn upgrade, Ping conn to api

* beatify

* add test

* beautify round 2

* fix timeout

* Implement alpn-ping upgrade for reversetunnel and ssh

* clean up

* fix proxy test

* minor refactor

* remove WebProxyAddr

* require IsALPNConnUpgradeRequiredFunc

* add tlsRoutingWithConnUpgradeConnect

* fix lint

* simplify

* remove debug log and change unknown upgrade type to 404

* Force new proxy client to use web proxy when TLS routing is enabled
2023-04-14 19:22:23 +00:00
rosstimothy 7da7fd12d7 Make TestTeleportProcess_reconnectToAuth less flaky (#24170)
1) Sets the process `ClientTimeout` and propogate to the appropriate
clients so that connection attempts don't last 30s
2) Lowers the `MaxRetryPeriod` and uses a real clock instead of using
the default value and a fake clock to advance time
3) Sets the process `Log` so that the test outputs more than just
a single failure statement
2023-04-06 12:37:40 +00:00
Gavin FrazarandSTeve Huang cac726f75a fix tctl insecure flag with remote proxy (#16125)
* Propagate tctl --insecure flag

* Move ExitCodeError into common package

* Add TryRun helper func to tctl for testing

* Return error instead of exiting directly

* Add test for tctl insecure with profile

* Remove debug println

* Update want err message

* Remove unnecessary errors.Is implementation for ExitCodeError

* Update error message for cert error in test

* Fix flaky TestHandlerConnectionUpgrade

* Test that TryRun error is assignable to ExitCodeError

* gofmt

* Fix import order

Co-authored-by: STeve Huang <xin.huang@goteleport.com>
2022-09-18 23:02:37 +00:00
Andrew Burke 22c0fccba7 Restore HTTP_PROXY for multi-port mode (#13048)
This change undoes the changes in #11990 and #12335 for Teleport going forward.
2022-06-07 11:57:16 -07:00
rosstimothy 25ec2c8a39 Add client side circuit breaker to auth clients (#10282)
* Add client side circuit breaker to auth clients

In order to apply back pressure we can utilize a circuit breaker that
monitors error responses from auth server. When tripped it will prevent
all outbound requests to auth for a period of time. This can also help
prevent a potential thundering heard when auth is in an unhealthy state.
By default the circuit breaker will only be tripped if 90% of the
requests made in the monitoring interval fail.
2022-06-03 11:55:56 -04:00
rosstimothy e8bfe2c931 FnCache context improvements (#12719)
* FnCache context improvements

Modifies the FnCache to be constructed with a context.Context
which is passed to all loadfn provided to Get. This removes
the burden placed on callers to ensure loadfn are not request
context scoped.
2022-05-31 18:50:18 +00:00
Andrew Burke e1e6437879 Ignore HTTP_PROXY in reverse tunnels, part 2 (#12335)
This change disables HTTP_PROXY in a few places that were missed in #11990.
2022-05-11 23:00:58 +00:00
bb121d7b1e Certificate renewal bot (#10099)
* Add certificate renewal bot

This adds a new `tbot` tool to continuously renew a set of
certificates after registering with a Teleport cluster using a
similar process to standard node joining.

This makes some modifications to user certificate generation to allow
for certificates that can be renewed beyond their original TTL, and
exposes new gRPC endpoints:
 * `CreateBotJoinToken` creates a join token for a bot user
 * `GenerateInitialRenewableUserCerts` exchanges a token for a set of
   certificates with a new `renewable` flag set

A new `tctl` command, `tctl bots add`, creates a bot user and calls
`CreateBotJoinToken` to issue a token. A bot instance can then be
started using a provided command.

* Cert bot refactoring pass

* Use role requests to split renewable certs from end-user certs
* Add bot configuration file
* Use `teleport.dev/bot` label
* Remove `impersonator` flag on initial bot certs
* Remove unnecessary `renew` package
* Misc other cleanup

* Do not pass through `renewable` flag when role requests are set

This adds additional restrictions on when a certificate's `renewable`
flag is carried over to a new certificate. In particular, it now also
denies the flag when either role requests are present, or the
`disallowReissue` flag has been previously set.

In practice `disallow-reissue` would have prevented any undesired
behavior but this improves consistency and resolves a TODO.

* Various tbot UX improvements; render SSH config

* Fully flesh out config template rendering
* Fix rendering for SSH configuration templates
* Added `String()` impls for destination types
* Improve certificate renewal logging; show more detail
* Properly fall back to default (all) roles
* Add mode hints for files
* Add/update copyright headers

* Add stubs for tbot init and watch commands

* Add gRPC endpoints for managing bots

* Add `CreateBot`, `DeleteBot`, and `GetBotUsers` gRPC endpoints
* Replace `tctl bot (add|rm|ls)` implementations with gRPC calls
* Define a few new constants, `DefaultBotJoinTTL`, `BotLabel`,
  `BotGenerationLabel`

* Fix outdated destination flag in example tbot command

* Bugfix pass for demo

* Fixed a few nil pointer derefs when using config from CLI args
* Properly create destination if `--destination-dir` flag is used
* Remove improper default on CLI flag
* `DestinationConfig` is now a list of pointers

* Address first wave of review feedback

Fixes the majority of smaller issues caught by reviewers, thanks all!

* Add doc comments for bot.go functions

* Return the token TTL from CreateBot

* Split initial user cert issuance from `generateUserCerts()`

Issuing initial renewable certificate ended up requiring a lot of
hacks to skip checks that prevented anonymous bots from getting
certs even though we'd verified their identity elsewhere (via token).

This reverts all those hacks and splits initial bot cert logic into a
dedicated `generateInitialRenewableUserCerts()` function which should
make the whole process much easier to follow.

* Set bot traits to silence log messages

* tbot log message consistency pass

* Resolve lints

* Add config tests

* Remove CreateBotJoinToken endpoint

Users should instead use the CreateBot/DeleteBot endpoints.

* Create a fresh private key for every impersonated identity renewal

* Hide `config` subcommand

* Rename bot label prefix to `teleport.internal/`

* Use types.NewRole() to create bot roles

* Clean up error handling in custom YAML unmarshallers

Also, add notes about the supported YAML shapes.

* Fetch proxy host via gRPC Ping() instead of GetProxies()

* Update lib/auth/bot.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Fix some review comments

* Add renewable certificate generation checks (#10098)

* Add renewable certificate generation checks

This adds a new validation check for renewable certificates that
maintains a renewal counter as both a certificate extension and a
user label. This counter is used to ensure only a single certificate
lineage can exist: for example, if a renewable certificate is stolen,
only one copy of the certificate can be renewed as the generation
counter will not match

When renewing a certificate, first the generation counter presented
by the user (via their TLS identity) is compared to a value stored
with the associated user (in a new `teleport.dev/bot-generation`
label field). If they aren't equal, the renewal attempt fails.
Otherwise, the generation counter is incremented by 1, stored to the
database using a `CompareAndSwap()` to ensure atomicity, and set on
the generated certificate for use in future renewals.

* Add unit tests for the generation counter

This adds new unit tests to exercise the generation counter checks.

Additionally, it fixes two other renewable cert tests that were
failing.

* Remove certRequestGeneration() function

* Emit audit event when cert generations don't match

* Fully implement `tctl bots lock`

* Show bot name in `tctl bots ls`

* Lock bots when a cert generation mismatch is found

* Make CompareFailed respones from validateGenerationLabel() more actionable

* Update lib/services/local/users.go

Co-authored-by: Nic Klaassen <nic@goteleport.com>

* Backend changes for tbot IoT and AWS joining (#10360)

* backend changes

* add token permission check

* pass ctx from caller

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* fix comment typo

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* use UserMetadata instead of Identity in RenewableCertificateGenerationMismatch event

* Client changes for tbot IoT joining (#10397)

* client changes

* delete replaced APIs

* delete unused tbot/auth.go

* add license header

* don't unecessarily fetch host CA

* log fixes

* s/tunnelling/tunneling/

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* auth server addresses may be proxies

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* comment typo fix

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* move *Server methods out of auth_with_roles.go (#10416)

Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address another batch of review feedback

* Addres another batch of review feedback

Add `Role.SetMetadata()`, simplify more `trace.WrapWithMessage()`
calls, clear some TODOs and lints, and address other misc feedback
items.

* Fix lint

* Add missing doc comments to SaveIdentity / LoadIdentity

* Remove pam tag from tbot build

* Update note about bot lock deletion

* Another pass of review feedback

Ensure all requestable roles exist when creating a bot, adjust the
default renewable cert TTL down to 1 hour, and check types during
`CompareAndSwapUser()`

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-02-19 02:41:45 +00:00