Commit Graph
82 Commits
Author SHA1 Message Date
Noah Stride acb255cd88 GitLab Delegated Joining (#22705)
* Add type for GitLab ProvisionToken

* Add default behaviour for domain

* Add IDTokenClaims for GitLab

* Add gitlab token source and token validator

* Thread GitLab support through auth and tbot packages

* Adjust cluster name fetching in token validator

* Initialize GitLab token validator in auth

* Improve comment on `sub`

* Working GitLab CI delegated joining

* Add additional token rule fields

* Add checking for new configuration fields

* add additional test cases for validation of gitlab config struct

* Add TestAuth_RegisterUsingToken_GitLab

* Add tests for IDTokenSource

* Fix imports

* Add tests for GitLab Token Validator

* Fix some comments that were incomplete

* Add license headers
2023-03-16 16:19:11 +00:00
Andrew Burke 732594f191 Add Azure join method (#20019) 2023-02-08 17:21:11 +00:00
Noah Stride 476a4a7e82 context.TODO() tidying (#21288)
* Use `ctx` rather than `context.TODO()` where available

* Further propagation of context

* Use `context.Background()` instead of `context.TODO()` where appropriate in tests

* Further remove `context.TODO` from tests

* Appease linter on parameter order
2023-02-07 09:01:35 +00:00
Tiago Silva dfb353a49c This PR introduces a new ALPN protocol extension forwards proxy connections to a gRPC server with mTLS authentication. (#20808)
Proxy already has a `gRPC` server when using the `teleport-proxy-grpc` ALPN protocol. Still, that server does not impose mTLS auth since it's used by nodes when joining the cluster with dynamic joining methods.

Since we require that the user identity is available in the handler, this PR introduces a new gRPC server that imposes mTLS under the ALPN protocol `teleport-proxy-gprc-mtls`.

Part of #20324
Related to #19573
2023-01-30 15:04:46 +00:00
Noah Stride df658c4920 Fix Machine ID Certificate TTL on IAM join (#19999) 2023-01-09 16:41:13 +00:00
Hugo Shaka f0dd7d7d85 Kubernetes joinMethod (#18659)
This commit adds a new joinMethod as described in https://github.com/gravitational/teleport/pull/17905

This method allow pods running in the same Kubernetes cluster than the auth servers to join the Teleport cluster. It relies on Kubernetes tokens to establish trust. The goal is to be able to deploy proxies and auths separately and join them in a single cluser.

Pre Kubernetes 1.20, the tokens are static, long-lived, not bound to pods. We support them for compatibility reasons. Starting with Kubernetes 1.20, tokens are bound to pods (and starting with 1.21 they can be mounted through projected volumes). Starting with 1.21 we should only accept bound tokens. The chart will ensure tokens are properly mounted with projected volumes so we can benefit from the 1h to 10min token lifetime.
2022-12-02 20:30:52 +00:00
Noah StrideandZac Bergquist 291d6d53a6 CircleCI Secure Joining (#17626)
* Add API types for CircleCI joining

* Add validation for CircleCI configuration

* Add JoinMethodCircleCI across codebase

* Add token validator and token source for circleci

* Update join methods RFD

* Add CircleCI token source to register.go

* Add serverside support for circleci joining

* Add test for TokenSource

* Add success case for token validation test

* Add expired test case

* Add test case for token from another org

* Test RegisterWithToken for CircleCI

* Refactor GitHub RegisterUsingToken tests

* Refactor CircleCI RegisterUsingToken tests

* Add tests for ProvisionTokenSpecV2

* Appease linters

* Go Imports files

* Fix failing test for msising IDtoken

* Update lib/auth/join_circleci.go

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

* Move test server cleanup closer to initialisation

* Fix weird import reordering

* Include unexpected type in error message

* Simplify boolean algebra :)

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-11-01 12:15:10 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Nic Klaassen 08513dbb9a fix: make sure gRPC conns for IAM join method are closed (#17565)
clients close the stream and any connection when they are done with it
servers close the stream after a 1 minute timeout
proxy JoinService gRPC server closes idle connections with no RPC calls after 10 seconds
2022-10-24 19:20:44 +00:00
Forrest Marshall fe1dac1a90 fix rotation handling in GenerateHostCerts 2022-10-19 16:35:51 -07:00
Noah Stride 4ac629aab1 Support certificate expiry on bot join (#17206)
* Support certificate expiry on bot join

* Test bot register expiry

* Fix trailing slash in comment.

* goimports l/a/join_test.go
2022-10-13 08:16:12 +00:00
Noah Stride a54de3bb64 GitHub Actions joining (#16938)
* Introduce Github Actions join support

* Go mod tidy

* run goimports on source files

* Address PR comments

* More PR review comments

* Changes to tests based on PR feedback

* Improve error message in github rule validation

* Add support for SHA

* Add short message describing which fields shouldb be included
2022-10-05 10:05:48 +00:00
Ryan Clark 806a568ada Introduce config v3, add auth_server and proxy_server, remove auth_addresses (#15761) 2022-09-28 15:30:15 +00:00
Nic Klaassen 2d141b339a Auth enforces FIPS STS endpoints for IAM join method when in FIPS mode (#16124)
* only enforce fips endpoints in v12
2022-09-19 17:03:32 +00:00
Nic Klaassen c6fe8e0a22 Nodes use FIPS STS endpoints for IAM join method when in FIPS mode (#16123) 2022-09-12 23:24:01 +00:00
Nic Klaassen cf30661de6 Use regional STS endpoints for IAM join method (#15337) 2022-08-29 18:35:28 +00: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
Forrest Marshall 31f258fec9 inventory control stream & certs 2022-06-15 22:26:24 -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
Noah Stride 7e73d1a501 Convert GetDomainName and GetClusterCACert to gRPC (#12937)
* convert GetDomainNAme endpoint to gRPC

* migrate GetClusterCACert from http to grpc

* fix tests failing due to switch to gRPC transport

* Correct mispelt json tag

* remove `GetLocalClusterName` and `UpsertLocalClusterName` which are unused

* remove unused prefix constant from presence
2022-06-01 22:53:42 +00:00
Gavin FrazarandAlan Parra df4991ea8c Optionally provide ca_pin as a file path (#12796)
* Optionally provide ca_pin as a file path

* Fix lint errors

* Test CA pin reads from file and from string

* Simplify ApplyCAPins

* Update lib/service/cfg.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Update lib/utils/utils_test.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Move length check into ApplyCAPins

* Rename token.go to config.go

* Add test for statictoken parsing

* Refactor token parsing test

* Error on empty ca_pin file

* Warn if config value is a path to an empty file

* Update lib/config/fileconf_test.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Log empty file warning instead of printing

* Allow multiple entries in files referenced by config values

* Update static token parsing test

* Test reading multiple tokens/pins from a file referenced by a config

* Update lib/config/fileconf.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-05-31 22:14:50 +00:00
Joel 99116409d4 Remove needlessly complex key generation scheme (#12113) 2022-04-25 09:26:10 +00:00
Zac Bergquist 8521b388f2 Remove legacy JSON API for host certs (#11330)
This is a follow up to e256170d60.
Now that Teleport 9 is out, we can remove the last traces of
this API for Teleport 10.
2022-03-23 17:57:22 +01:00
Nic Klaassen 6e16ad6627 IAM join method support for tbot (#10535) 2022-03-01 00:35:34 +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
Zac Bergquist e256170d60 Remove the legacy JSON API for requesting host certs
In Teleport 8 we migrated all uses of this API to GRPC, but left
the JSON API in place so that Teleport 7 nodes could still join
the cluster.

In Teleport 9, the oldest nodes we support are v8, which use the
GRPC API, so we can safely remove the old API.
2022-02-15 18:40:48 -07:00
Nic Klaassen bc441ef2cf IAM Join Method (gRPC service) (#10087) 2022-02-10 00:41:34 +00:00
Nic Klaassen e00ff42cb8 IAM Join Method (backend implementation) (#10085) 2022-02-08 18:48:13 +00:00
Nic Klaassen f884cdd7e3 Make RegisterUsingTokenRequest a Protobuf type (#8690) 2021-10-27 10:59:44 -07:00
Nic Klaassen 2d10515f19 Implement Simplified Node Joining (#8250) 2021-10-08 10:41:28 -07:00
Brian Joerger 549b72c5a5 Fix GenerateHostCerts http fallback with LegacyCerts. (#8469)
* Fix GenerateHostKeys http fallback with LegacyCerts (PackedKeys).

* Replace registerUsingTokenResponseJSON.

* Remove redundant fallback logic for pre v8 clusters.
2021-10-06 11:42:02 -07:00
Zac Bergquist 839cdcfa97 Convert GenerateServerKeys to GRPC (#8193)
This commit contains 2 changes:

1. Rename GenerateServerKeys to GenerateHostCerts.
   This is a more accurate name and consistent with the existing
   GenerateUserCerts endpoint.
2. Change the request type to include a single role, rather than a
   list of roles. We only ever allowed a single role in the list
   anyway, so this change will prevent future mis-use of the API.

Note: a side effect of this change is we now have two similar endpoints:
- GenerateHostCert: old API that generates SSH cert only
- GenerateHostCerts: a newer API that generates SSH and TLS certs

To avoid making this change too big, we'll aim to deprecate
GenerateHostCert in the future.
2021-09-13 14:37:28 -07:00
Zac Bergquist 8a15c9a3a6 Require that public TLS and SSH keys are provided to register via token (#8135)
* Require that public TLS and SSH keys are provided to register via token

The original behavior attempted to make providing public keys optional,
and would generate keys if they were not provided. This had several
problems:

- The auth server is generating private keys for nodes and is
  potentially able to share them over the network.
- The return value for keys.Key would sometimes be set and sometimes
  be empty (the key is only set if the auth server generated it and
  knows what the key is)
- We only ever relied on this behavior as a shortcut in test code.
  In the production code this behavior was never used (and actually
  never worked due to a bug that would overwrite and discard the
  generated private key)

This commit requires that public keys are always provided, ensuring
that the private key is generated locally and never known by the
auth server.

It also results in a cleaner error message when either or both of the
public keys are missing from the request.

* Address review comments

* Fix tests that relied on certs being generated
2021-09-08 10:17:37 -07:00
Zac Bergquist 9a8bbc5b4d auth: remove DataDir from RegisterParams (#8110)
We stopped using this field years ago when support for CA pinning
was added in e69e67e372.
2021-09-01 08:29:44 -07:00
Nic Klaassen c9fda499de Add support for multiple CA pins (#7905) 2021-08-18 20:13:20 -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
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Andrej Tokarčík 85244157b0 Check CA expiration status when joining a cluster 2021-03-01 22:14:10 +01:00
Brian Joerger 488cf7b66c API credential loaders (#5455) 2021-02-22 16:43:00 -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
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
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
joerger f020f75078 Refactor API client into a separate package. 2020-12-29 10:06:37 -08: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
Andrew Lytvynov 703708ac79 Improve error message for revoked node join token
The node first tries using the token with auth server. If that fails, it
tries the same address as a proxy server.
If both fail, user only sees the error from the latter attempt. If using
CA pin, this error will be "x509: certificate signed by unknown
authority", which is confusing.

Log both errors, and mention that a fallback is happening. The output
looks like:

    ERRO [AUTH]      Failed to register through auth server: "my-hostname" [3e53a982-afd1-4d2f-8864-54c25fbe5865] can not join the cluster with role Node, the token is not valid; falling back to trying the proxy server auth/register.go:123
    ERRO [PROC:1]    Node failed to establish connection to cluster: failed to register through proxy server: x509: certificate signed by unknown authority. time/sleep.go:149
2020-04-23 20:09:35 +00:00
Alexander Klizhentas 32b84e6765 Read join tokens from file, fixes #2515. (#2864) 2019-07-17 12:51:18 -07:00
Russell Jones 77cf2c276c Clearer logging when node fails to join cluster. 2019-06-13 23:12:30 +00:00
Russell Jones 4e773e9b38 Remove CredentialsClient.
Removed CredentialsClient, instead pass client.HostCredentials to
auth.Register to break circular import.
2019-05-21 09:59:10 -07:00
Sasha Klizhentas d5243dbe8d Add keep alive support to GRPC clients.
This commit turns on KeepAlive support
for GRPC clients to make sure that dropped
connections are detected properly.
2019-05-02 15:09:33 -07:00