Commit Graph
25 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
rosstimothy 9d066364a8 Migrate GetCertAuthorities to gRPC (#22985)
Adds a new `GetCertAuthorities` unary RPC to
`teleport.v1.trust.TrustService` and deprecates the equivalent
HTTP endpoint. All associated interfaces have been updated to remove
the marshal options as well.
2023-03-14 14:45:01 +00:00
rosstimothy 95d6d0fee1 Migrate GetCertAuthority to gRPC (#22624)
The HTTP client created by `auth.NewClient` has an idle timeout of
30s and each instance periodically gets cert authorities in
`TeleportProcess.syncRotationStateCycle`. If there has been no
activity when the ticker expires then the request will result in a
brand new connection to Auth to be established. This can cause a
spikes in open file descriptors on the Proxy when there are a large
number of instances connected via a tunnel.

To prevent periodic dialing when retrieving cert authorities the
endpoint has been migrated to the new Trust gRPC service. For now
only the get endpoint has been migrated but the rest of the CRUD
operations for cert authorities should be migrated from the HTTP
api to the gRPC service as well.
2023-03-10 14:32:34 +00:00
Krzysztof Skrzętnicki 1a184bfbe5 Pass parent context to prompt.Confirmation() in identityfile. (#20685) 2023-01-26 11:09:31 +00:00
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00
Jakub Nyckowski d68cb9377b Switch golang.org/x/crypto to gravitational fork (#19579)
* Switch golang.org/x/crypto to gravitational fork

* Update golden files

* Add comment to go.mod

* Update api module to use crypto fork.

* Move x/crypto to replaced section in dependabot.yml
2023-01-04 19:30:58 +00:00
Noah Stride f82470b08e Remove deprecated kinds field from tbot config (#18439) 2022-11-14 16:55:48 +00:00
Nic Klaassen 962e5a25bc plumb context to keystore methods (#18034)
* plumb context to keystore methods

Contexts are more relevant now with the GCP KMS keystore which makes
http requests, this commit makes sure they are passed everywhere they
are needed, with only a few `context.TODO`s sprinkled in.
2022-11-10 18:57:17 -08: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
Noah Stride a7ee3b3de4 Add file based locking to TBot (#17940)
* Add file based locking to tbot

* Add test for destination locking and clarify lock error

* Fix import weirdness

* Rename Lock -> TryLock

* Add warning on DestinationDirectory.TryLock re: ACLs
2022-11-01 11:30:41 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Tim Buckley 35352aa406 Export SSH User CAs in tbot's ssh_host_cert template (#17452)
* Export SSH User CAs in tbot's ssh_host_cert template

The ssh_host_cert template didn't previously export the user CA cert,
meaning users would've still had to export this by hand, and keep it
up-to-date if CAs are rotated.

This now generates a proper CA compatible with sshd's
`TrustedUserCAKeys` in `ssh_host-user-ca.pub`.

* Address review feedback
2022-10-18 00:31:15 +00:00
Jakub Nyckowski db5efe773e Remove tsh dependency on lib/config - build fix (#17193) 2022-10-07 21:06:56 +00:00
Jakub NyckowskiandRoman Tkachenko 0df39758a0 Refactor OpenSSH config generation (#17138)
Unify OpenSSH config generation between tsh and tbot.

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-10-07 18:11:57 +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
rosstimothy ebfbfd496e Use testauthority instead of native to generate keys in tests (#16486)
* use test authority

* use testauthority for InitConfig RSAKeyPairSource

* add named returns to test authority
2022-09-21 20:53:09 +00:00
Tim Buckley 81f42bbaed Add where predicate and Machine ID support to SSH host certificates (#16261)
* Add `where` predicate and Machine ID support to SSH host certificates

This adds `where` RBAC predicate support to `host_cert`
pseudo-resources, and adds support for requesting host certs to
Machine ID (with or without these RBAC predicates).

More specifically, this:
 * Makes 3 new set functions available during `where` predicate
   evaluation: `all_equal`, `all_end_with`, and `is_subset`. These
   make it possible to examine the `host_cert.principals` field.
 * Adds a new optional `host_cert` field to the standard `where`
   context. It's only ever set specifically in `GenerateHostCert()`.
 * Sets a custom context in `GenerateHostCert()` to pass along host
   cert parameters.
 * Makes current config available to tbot config templates
 * Adds a new `ssh_host_cert` config template to Machine ID
 * Refactors `tbot/config` tests to use shared mock bot / auth
   implementations.

Host certs can be requested in Machine ID by adding a new config
template:
```yaml
destinations:
  - directory: /opt/machine-id
    configs:
      - ssh_host_cert:
          principals: [foo.example.com]
```

Bots will need a role like the following:
```yaml
kind: role
metadata:
  name: hostcert-bot
version: v5
spec:
  allow:
    rules:
      - resources:
          - host_cert
        verbs:
          - create
        where: 'is_subset(host_cert.principals, "foo.example.com")'
```

See the RFD for more information:
https://github.com/gravitational/teleport/blob/master/rfd/0083-machine-id-host-certs.md

* Fix lint failure

* Improve doc comments on the new predicate functions.

* Address review feedback

* Address review feedback

- Remove `AuthenticatedUserClientFromIdentity`'s unnecessary
  AuthServer param
- Add missing doc comments
- Pull out `getTestIdent` from the Kubernetes template test
- Move various test helpers into their own file
- Unexport new predicate functions
2022-09-14 20:18:05 +00:00
Brian Joerger 3a5a285883 Generalize private keys in tsh (PIV integration) (#15334)
Primary Changes:
 - Remove reliance on Private Key PEM:
 - Update native and keygen packages to return PrivateKey instead of PEM key
 - Add new PrivateKey interface which implements crypto.Signer
 - Replace PEM encoded private key usage where possible
 - Replace calls to tls.(Load)X509KeyPair with keys.(Load)X509KeyPair in
client packages

Minor Changes:
 - Remove unused agent.AddedKey return from LoadKey
 - Simplify sshutils and removed unused code paths
 - Add ecdsa and ed25519 key support
2022-08-25 23:26:44 +00:00
Noah Stride f8a870be29 Adjust Machine ID generated ssh cert path to align with convention (#15199)
* tbot migrate to key-cert.pub from sshcert

* Update golden files

* Explain len(data) == 0

* Switch `WrapWithMessage` to `Wrap`
2022-08-08 08:46:26 +00:00
Steven Martin c59cc21e13 Improve error message if data dir on tbot and tctl not available for permissions (#14282)
* Added permissions messages that match to the Teleport start on issues loading /var/lib/teleport dir
2022-07-25 23:27:04 +00:00
Tim BuckleyandNoah Stride 348b290cc7 Add app access support to Machine ID (#14551)
* Add app access support to Machine ID

This adds support for app access to Machine ID. Users can specify a
new destination-level `app` field which will request certificates
with the given app. Users can then either open a proxied connection
to the app, or supply the credentials via `curl` and access the app
through the public-facing proxy.

This includes a small change to `tsh` to support identity files in
various app-related commands (`proxy app`, `app ls`, etc). The
existing `tsh` wrappers in `tbot` automatically support these app
commands.

* Add app request test

* Clean up test

* Update lib/tbot/config/config_destination.go

Co-authored-by: Noah Stride <noah.stride@goteleport.com>

* Address review feedback

* Simplify `getApp` call

* Simplify `getApp` further

Co-authored-by: Noah Stride <noah.stride@goteleport.com>
2022-07-20 21:03:58 +00:00
Tim Buckley ad12d71e20 Add Kubernetes Access support to Machine ID (#14269)
* Add Kubernetes Access support to Machine ID

This adds support for Kubernetes Access to Machine ID. Users can now
request access to a Kubernetes cluster with the new
`kubernetes_cluster` config field. When a request is configured, a
`kubeconfig.yaml` is generated which can be used to access the given
cluster.

As part of this, we also refactor a few parts of the bot code to help
cache various requests that config templates make frequently by
passing a new trivial `bot.B` interface to the `Render()` function.
For good measure, we also fix the `destination.Destination` stutter
by moving the interface to `bot.Destination`.

* Remove unused CLI param and fix docstring typo

* Cache cert authority requests

We now cache most cert authority requests from config templates and
purge the cache after each cert renewal.

* Move bot.B to config.Bot

* Add a matching marshaller for the KubernetesCluster type.
2022-07-14 22:03:34 +00:00
Noah StrideandTim Buckley c18d914745 Machine ID CA rotation (#13231)
* start hashing out machine id CA rotation

* filter out incoming ca events by type

* support multiple trusted certificate authorities in known_hosts

* remove redundant trace.Debug from `tbot` `main()`

* filter to only recieve relevant CA events

* add exponential backoff to renewal

* remove unnecessary `.Ping()` check with new client

* add unit test for filtering CA events

* debounce reloads

* add retry limit and backoff for CA watching

* add integration test for CA rotation

* modify CA rotation watcher loop to retry forever

Co-authored-by: Tim Buckley <tim@goteleport.com>
2022-07-13 16:52:44 +00:00
Ryan Clark 3e3b9b42b5 Change tbot to allow reading the token from a file (#14087)
This changes tbot's configuration to access the token via a
getter/setter instead of a direct property, to allow us to fetch the
token (possibly reading it from a file) when we need it instead of when
the configuration is created.

This also changes the identity fetching logic, to try and read the token
when there is an identity present but not error, allowing for the token
file to have been deleted between restarts. If it can read the token,
it'll check to see if it has changed and refetch the identity if so.
2022-07-13 15:48:08 +00:00
Noah Stride 8b346ef06b Refactor tbot (#12855)
* start refactoring tbot to have a core struct

* refactor tbot into lib/

* move `tbot` subpackages to `lib/tbot`

* remove mutex pointer

* move `tshwrap` to `lib/` from `/tool/tbot/`

* move new template ssh client render test to lib/

* address pr feedback

* add request changed
2022-06-01 17:15:26 +00:00