Commit graph

24 commits

Author SHA1 Message Date
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 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
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
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
Zac Bergquist d1c6b0618e
Fix lint warnings (#15312)
Mostly duplicated imports and redundant types in struct literals.
2022-08-08 20:20:29 +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
Edoardo Spadolini fa65fd02b1
Refactor Supervisor.WaitForEvent (#14940) 2022-07-28 13:34:27 +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 Buckley 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
Noah Stride 4bbd2047eb
Correctly exit out of tbot when one shot mode is enabled (#14565) 2022-07-20 09:33:24 +00:00
Noah Stride 7ed0a7ff50
Reduce flakiness of Testbot_Run_CARotation (#14486) 2022-07-19 09:27:16 +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 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
Noah Stride 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
Tim Buckley 70a73355c9
Properly handle empty list of role requests (#13456)
* Properly handle empty list of role requests

Currently, an empty list of role requests results in an ambiguous
situation: we usually use the presence of role requests to determine
whether or not we'd return impersonated certs or not. An empty list
of role requests returns a fresh set of non-impersonated certs
(possibly renewed if allowed), while a non-empty list of role requests
returns certs with just those roles.  However, if a client _intends_
to request impersonated certs but provides an empty list of role
requests it will instead receive non-impersonated (possibly renewable)
certs with the full permissions of the original user.

This could theoretically result in privilege escalation if a Machine
ID bot: (a) had any worthwhile permissions of its own, which is not
the case unless the bot role was manually modified and (b)
accidentally handed certs off to an attacker.

In practice this bug is fairly difficult to hit: `tbot` always
auto-fills all requestable roles if they are otherwise unset, and
`tctl bots add` requires `--roles=` to be passed. An empty string
here can trigger the bug however it is unlikely a user would pass this
by accident. Moreover, a bot without requestable roles cannot
accomplish much of anything, so this is exceedingly unlikely to
be intended behavior.

Additionally, certificate generation checks help to mitigate the
issue: bots currently lock themselves by accident after the first
renewal when this bug is triggered as they don't explicitly handle
receiving renewable certs when impersonated certs are expected. If an
attacker were to attempt a renewal, the generation counter would
similarly limit access, and as noted previously, the bot role grants
only minimal read-only access anyway.

---

To resolve the issue, this adds a new `RoleRequestsOnly` flag to
`UserCertsRequest` that allows clients to unambiguously specify if
they wish to receive a non-impersonated, possibly renewable, cert with
all the original user's roles and permissions, or if they wish to
receive only role-impersonated certs (or an error if roles are empty).
Machine ID passes this flag in all situations where an impersonated
cert is desired.

Additionally, we also now ensure users add at least one role in
`CreateBot()` (called by `tctl bots add`) as this is almost certainly
an unintended situation.

Fixes #13411

* Address review feedback, rename flag to UseRoleRequests

* Return a local error if no roles are specified
2022-06-27 16:25:12 +00:00
Noah Stride 5e8cfb345c
Correct terminology from SSHAddr to ListenAddr for Auth server (#13725)
Rename auth SSHAddr to ListenAddr
2022-06-22 23:03:08 +00:00
Edoardo Spadolini 1e49830ff9 Comments 2022-06-10 11:12:01 +02:00
Edoardo Spadolini bafbef35ba Fix listener flakiness in tbot tests 2022-06-10 11:12:01 +02:00
Tim Buckley fd2b4a1458
Fix file descriptor leaks in tbot (#13227)
* Fix file descriptor leaks in `tbot`

This fixes two file descriptor leaks in `tbot`, caused by a failure to close
the previous socket connected to the auth server after renewing an identity.

* Remove unnecessary `defer` from socket close
2022-06-09 23:15:38 +00:00
Tim Buckley 6a9b770fb9
Make TestDefaultTemplateRendering less failure prone (#13002)
* Make `TestDefaultTemplateRendering` less failure prone

The test requires the Teleport server to report a sane public proxy
address, however occasionally it takes some time to initialize and
returns an invalid value until that point.

This adds a wait loop to the client initialization helper to wait up
to 10 seconds for the server to return a sane value, which should
improve reliability of the test.

* Use `require.Eventually()`, reduce tick interval
2022-06-06 22:25:26 +00: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
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