Commit Graph
50 Commits
Author SHA1 Message Date
Edoardo Spadolini ccffd6b5be Allow unknown fields when unmarshaling protojson resources (#53469)
* Prohibit implicitly strict protojson unmarshaling

* Avoid jsonpb.Unmarshal

* Define marshal option to disallow unknown fields

* Avoid protojson.Unmarshal

* Disallow unknown fields in tctl create

* Disallow unknown fields in the web UI
2025-03-27 14:35:37 +00:00
rosstimothy 2cced62805 Fix violations of non-constant format strings linter (#51812)
Depends on https://github.com/gravitational/teleport.e/pull/6006.
Now that we are compliant, the ignore rule was removed from the
golangci-lint config to prevent future regressions.
2025-02-04 16:43:35 +00:00
Nic Klaassen 47502620e2 feat: PuTTY PPK support for non-RSA keys (#48650)
The commit adds support for Ed25519 and ECDSA keys to PuTTY PPK files
generated by tsh. It also adds support for Ed25519 and ECDSA trusted
host CAs.
2024-11-12 20:03:19 +00:00
Brian Joerger b7c0e79fed Remove delayed closing of yubikey connection to prevent the connection from leaking after program execution. (#48414) 2024-11-06 20:11:02 +00:00
Grzegorz Zdunek 47494db923 Sign a hashed message in hardware key warmup call (#48206)
Otherwise, signing may fail with "input must be a hashed message" error.
2024-10-31 22:09:39 +00:00
Grzegorz Zdunek 22b50149df Support hardware keys prompts in Connect (#47652)
* Add new protos for hardware key prompts

* Implement hardware key prompts on the daemon side

* Show prompts in the UI

* `PromptHardwareKeyPINAsk` -> `PromptHardwareKeyPIN`

* Improve proto docs

* `PromptHardwareKeySlotOverwrite` -> `ConfirmHardwareKeySlotOverwrite`

* Fix typo

* Remove unnecessary `form`

* Pass an enum to `AskPIN` instead of the entire message

* Remove an invalid restriction of PIN/PUK to numbers only

* Improve the copy
2024-10-23 07:12:33 +00:00
Nic Klaassen 0a0d4137db eliminate rsa.GenerateKey and lib/auth/native (#47768) 2024-10-21 20:55:22 +00:00
Grzegorz Zdunek 95af4c1808 Support custom hardware key prompt (#47273)
* Allow passing custom prompt to YubiKey

* Handle `prompt.Touch` cancellation

* Pass `HardwareKeyPrompt` through all the layers

* Add an empty `HardwareKeyPromptConstructor` to Connect

* Remove `ParsePrivateKeyWithCustomPrompt`

* Add missing godoc

* Fix teleterm tests

* Include `cliprompt.go` only for `go:build piv && !pivtest`

* Lint and test fixes
2024-10-16 10:00:03 +00:00
Grzegorz Zdunekandjoerger bd6fdbf2c1 Cache PIV connections to share across the program execution (#47091)
* Cache yubikey objects.

* Cache PIV connections to share across the program execution.

* Do not release the connection until `sign` returns

* Do not ignore errors

* Perform a "warm up" call to YubiKey

* Fix tests

* Use a specific interface to check if the key can be "warmed up"

* Allow abandoning `signer.Sign` call when context is canceled

* Make sure that the cached key is valid for the given private key policy

The reason for adding this check was failing `invalid key policies` test.

* Make `hardwareKeyWarmer` private

* Force callers to release connection

* Improve comments

* Fix lint

* Improve `connect` comment

* Fix race condition

* Simplify `release` logic

* Trigger license/cla

---------

Co-authored-by: joerger <bjoerger@goteleport.com>
2024-10-16 08:02:17 +00:00
rosstimothy 185988f449 Clean up code marked for deletion in v17 (#47364)
* Clean up code marked for deletion in v17

Removes legacy PIVSlot and App SessionID marked for deletion in v17

* fix: remove missed todo delete comment

* fix: restore comment about caching routeToApp

* fix: validate scope and restore username retrieval

* fix: setting scopes in requests

* fix: update TF docs
2024-10-10 15:36:53 +00:00
Krzysztof SkrzętnickiandNic Klaassen cb2f54c2a7 Fix creation of JKS wallet for Oracle. (#47212)
* Fix creation of JKS wallet for Oracle.

Unwrap *keys.PrivateKey to fetch inner signer that satisfies `x509.MarshalPKCS8PrivateKey` expectations. This change allows passing keys.PrivateKey to createJKSWallet. The updated function will correctly marshal the private key for Oracle's JKS wallet creation.

* Add and use `MarshalSoftwarePrivateKeyPKCS8DER`.

* Update lib/client/db/oracle/oracle_test.go

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

---------

Co-authored-by: Nic Klaassen <nic@goteleport.com>
2024-10-08 08:15:13 +00:00
Nic KlaassenandEdoardo Spadolini 1efa0ae77c fix: tolerate mismatched key PEM headers (#46725)
* fix: tolerate mismatched key PEM headers

Issue #43381 introduced a regression where we now fail to parse PKCS8
encoded RSA private keys within an "RSA PRIVATE KEY" PEM block in
some cases.
This format is somewhat non-standard, usually PKCS8 data should be in a
"PRIVATE KEY" PEM block. However, certain versions of OpenSSL and
possibly even Teleport in specific cases have generated private keys in
this format.

This commit updates ParsePrivateKey and ParsePublicKey to be more
tolerant of PKCS8, PKCS1, or PKIX key data no matter which PEM header is
used.

Fixes #46710

changelog: fixed regression in private key parser to handle mismatched PEM headers

* fix typo in comment

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2024-09-18 19:20:43 +00:00
Nic KlaassenandBernard Kim eff0a707d7 split SSH and TLS keys in tsh login (#45995)
* key split wip

* fix piv tests

* fix terraform tests

* spelling fixes

* fix kube benchmark

* fix identity files in integrations tests

* self review

* fix typo in comment

Co-authored-by: Bernard Kim <bernard@goteleport.com>

* speed up device login tests

* use EC keys in TestProxyAppWithIdentity

* faster tsh tests

* fix race on error value

* fix lint

* write out EC SSH keys in OpenSSH format

* fix lint

* fix keyring comparisons

* PrecomputeTestKeys in lib/client

* parallelize TestNoRelogin subtests

* use ecdsa for self-signed TLS certs

* remove redundant GetTrustedCerts

* improve latency of precomputeTestKeys

Instead of waiting for all 25 test keys before returning a single one,
tests can now make use of the first precomputed test key as soon as it's
ready.
In local testing with this change, the first key is ready after ~75ms vs
>350ms on master.

* fix test and lint

---------

Co-authored-by: Bernard Kim <bernard@goteleport.com>
2024-09-12 19:36:32 +00:00
Nic Klaassen 6eb6b981b3 Split user keys for k8s access (#44779)
* split user keys for k8s access

* remove unnecessary loop

* prevent race when reading/writing key/cert pairs

* reuse RSA keys

* single file for kube key and cert

* update comment with file layout
2024-08-13 17:41:33 +00:00
Nic Klaassen cbb19fece2 Split user keys for app access (#44609)
* rfd edits

* split keys for app access

* update paths visualization

* godocs

* speed up TestAppCommands

* fix possible panic in test

* fix piv test
2024-08-06 22:40:57 +00:00
Hugo Shaka 26f9b77948 Support detecting a credential expiry (#43886)
* Support detecting a credential expiry

* Fix Expiry() and add tests

* protect identityFile cred with a lock

* add godoc

* Fix tests
2024-07-11 02:57:14 +00:00
Nic Klaassen fb8ef40e01 remove RSA-specific methods on keys.PrivateKey (#43982) 2024-07-10 18:50:39 +00:00
Nic Klaassen a48c4f7765 configurable key algorithms for proxy to database agent certs (#43329)
* configurable algorithms for proxy to database agent certs

* rfd edit

* use v1 suite in test

* fix typo

* fix bad merge
2024-06-26 23:06:22 +00:00
Nic Klaassen bcb169912d consolidate (un)marshalling of keys to/from PEM format (#43260)
* consolidate (un)marshalling of key PEMs

This commit consolidates various functions we have for marshalling
private and public keys to and from the PEM format, mostly by replacing
functions from lib/utils and lib/tlsca with equivalents in api/utils/keys.

The new functions also support ECDSA and Ed25519 keys, which is
necessary for the implementation of RFD136.

* speed up TestMTLSClientCAs

* fix new use in local proxy middleware
2024-06-21 19:32:11 +00:00
Alan Parra 72780dce68 fix: Forbid SSO users from logging in using passwordless (#41062)
* Save the WebAuthn UserHandle in the mock Key

* Simplify passwordless tests

* fix: Forbid SSO users from logging in using passwordless

* Rename tests to TestPasswordlessProhibitedForSSO
2024-04-30 19:07:57 +00:00
Zac Bergquist 8cd1c429f5 Fix up some poor wording (#40832)
Closes #40294
Closes #39172
2024-04-23 22:01:41 +00:00
Brian Joerger f57021d956 Don't count mfa-verifeid Private Key Policy as MFA for Admin Actions (#39257)
* Don't count hardware key support as MFA verification for admin actions.

* Add clarifying comments to IsMFAVerified methods to prevent future misuse.

* Update test.
2024-03-13 17:57:26 +00:00
Brian Joerger 5577bdad45 Add e2e tests for Hardware Key support (#38994)
* Add fake yubikey private key implementation for tests.

* Add TestHardwareKeyLogin.

* Simplify Hardware Key support test plan.

* Enable piv test package in tests.

* Add TestMarshalAndParsePrivateKey.

* Address simple comments.

* Remove *testing.T from mockSSOLogin in; Add and use better helper methods for mocking sso login.

* Refactor test to dynamically set mock attestation data; revert related changes.
2024-03-07 21:37:21 +00:00
Brian Joerger 328986789e Hardware key serial number attestation (#37728)
* Add support for hardware key serial number attestation through user
trait.

* Modify AttestHardwareKey interface to return full attestation data

* Add serial number to attestation data and verify it

* Add unit test.

* Address comments.

* Don't accept partial matches.

* Fix build and test errors.
2024-02-10 01:07:58 +00:00
Brian Joerger bca9688bb2 Fix hardware key sign err shadow bug. (#37285) 2024-01-25 21:48:33 +00:00
Brian Joerger e7ac968247 Address deprecation TODOs for or before v15. (#36473) 2024-01-11 01:03:22 +00:00
Brian Joerger 01db597c04 Add fix for PIV PIN policy bug in YubiKeys with firmware version 5.3.1. (#36427) 2024-01-09 23:23:33 +00:00
Brian Joerger 9c70432929 Fix default key slot comments and docs. (#34350) 2023-11-09 18:15:46 +00:00
Brian JoergerandMike Jensen 129df08ba4 Enable hardware key support in the WebUI (#32781)
* Add web_session private key policy.

* Add attestation logic for web session.

* Prevent users from retrieving their own web session secrets.

* Update RFD.

* Attest extended web sessions if the original web session was attested.

* Update rfd/0080-hardware-key-support.md

Co-authored-by: Mike Jensen <jentfoo@users.noreply.github.com>

* Fix policy set unit test.

---------

Co-authored-by: Mike Jensen <jentfoo@users.noreply.github.com>
2023-10-13 19:59:11 +00:00
Brian Joerger c0b3299de7 Add support for Hardware Key PIN (#31743)
* Update RFD with hardware key pin policies.

* Consolidate policy logic and update tests.

* Add pin private key policies; Make PIV PIN/Touch prompts work together.

* Prompt user to set pin/puk from default.

* Handle unexpected PIN auth errors.

* Resolve RFD password prompt comment.

* Handle incompatible private key policy in role sets (future-proof).

* Resolve comment on require mfa type string godocs and tests.

* A satisfying change.

* Address PIN/PUK prompt comments and other code suggestions.

* Resolve comments.

* Fix test that prompts for pin twice.

* Fix test.
2023-10-13 19:07:43 +00:00
Brian Joerger 4d094a7743 Remove deprecate function; update e ref. (#32275) 2023-10-12 00:31:46 +00:00
Brian Joerger a36d4d1e34 Configure custom PIV slot for hardware key support (#31732)
* Update RFD.

* Add custom PIV slot logic.

* Add custom piv slot to cluster auth preference.

* Fix error handling of parsing private key policy errors.

* Add new PIVSlot string type.
2023-10-11 01:36:22 +00:00
Michael Wilsonandrosstimothy ed488aabcc Add the Access List review backend. (#32924)
* Add the Access List review backend.

The Access List review backend has been added to Teleport.

* Update tests to remove frequency_changed.

* Update lib/services/access_list.go

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Update lib/services/access_list.go

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Tweak errors, add gRPC client to go along with new interfaces.

* Update comments, fix errant bugs with api client, remove reviews getter.

* Fix comments in proto, tweaks to tests and backend.

* Remove call to SetName.

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-10-05 20:32:25 +00:00
Brian Joerger 2c53f04310 Client check for YubiKey private key touch/pin policies (#32264)
* Preemptively check yubikey private key touch/pin policies on the client side.

* Replace hardware key signer functions with private key methods.

* Refactor overwrite/generate key logic.
2023-09-29 00:10:05 +00:00
Brian Joerger f87c46ad73 Make Hardware Key unit test interactive (#32235)
* Make yubikey unit test interactive and add to test plan.

* Move yubikey hardware signer method tests to interactive yubikey test.

* Remove hardware key interactive unit test from testplan
2023-09-27 18:55:47 +00:00
Brian Joerger 64d94666b7 Refactor PIV metadata certificate logic (#32250)
* Change PIV metadata cert to be self signed by an ephemeral key so it can be signed without touch/pin.

* Refactor touch prompt logic.

* Prompt user before overwriting non-teleport certificates instead of just returning an error.

* Update RFD and Docs.

* Address CR.

* Export some methods and variables for use in tests.

* Address comments.
2023-09-26 18:04:40 +00:00
Brian Joerger adb4194e3b Fix tsh logout with broken key dir (#32351)
* Check for compare failed error when checking user's keys.

* Add test.

* Return not found error when tls certificate is missing.
2023-09-22 17:47:28 +00:00
Brian Joerger 7a9a987847 Have hardware_key_touch count towards MFA verification instead of replacing the normal MFA verification flow. (#31663) 2023-09-18 16:47:34 +00:00
Tiago SilvaandBrian Joerger f8ab3aa037 Improve tsh kube credentials read operations (#22388)
While loading a key from storage, Teleport client transverses the
storage directory to read the secrets and reads each file one by one.
This has huge impacts on `tsh kube credentials` because when calling
`kubectl` in parallel, the disk operations become overloaded and the
operation time increases exponentially.

This PR removes the transverse when reading credentials for Kubernetes
clusters and adds a quick read operation that reads the following files:
- `$TSH_HOME/current_profile`
- `$TSH_HOME/$profile.yaml`
- `$TSH_HOME/keys/$PROXY/$USER-kube/$TELEPORT_CLUSTER/$KUBE_CLUSTER-x509.pem`
- `$TSH_HOME/keys/$PROXY/$USER`

| - | P=1 | P=10 | P=40 | P=80 | P=120 |
| --- | --- | --- | --- | --- | --- |
| old direct | 9.90s user 3.14s system 64% cpu 20.284 total | 11.08s user 3.60s system 496% cpu 2.955 total | 12.46s user 4.36s system 820% cpu 2.050 total | 12.81s user 4.76s system 811% cpu 2.164 total | 13.02s user 5.07s system 861% cpu 2.100 total|
| old teleport | 18.45s user 7.80s system 51% cpu 51.085 total | 21.58s user 10.03s system 434% cpu 7.270 total | 22.33s user 10.52s system 178% cpu 18.402 total | 22.04s user 10.83s system 96% cpu 33.977 total | 22.57s user 11.45s system 55% cpu 1:01.34 total|
| new direct | 9.51s user 2.90s system 146% cpu 8.460 total | 13.75s user 4.95s system 718% cpu 2.603 total | 12.21s user 4.43s system 832% cpu 1.999 total | 11.72s user 4.50s system 839% cpu 1.933 total | 12.06s user 4.62s system 830% cpu 2.009 total |
| new teleport | 16.10s user 5.97s system 42% cpu 52.104 total | 21.62s user 9.01s system 381% cpu 8.023 total | 23.22s user 10.11s system 540% cpu 6.162 total | 21.64s user 9.81s system 603% cpu 5.208 total | 20.70s user 9.13s system 602% cpu 4.948 total |

---

| - | P=1 | P=10 | P=40 | P=80 | P=120 |
| --- | --- | --- | --- | --- | --- |
| old no tsh kube credential | 8.61s user 2.99s system 31% cpu 36.336 total | 9.57s user 3.39s system 283% cpu 4.565 total | 10.22s user 4.03s system 553% cpu 2.574 total | 9.32s user 3.82s system 559% cpu 2.351 total | 11.49s user 4.85s system 624% cpu 2.617 total
| new no tsh kube credential | 8.27s user 2.94s system 24% cpu 45.041 total | 10.85s user 4.31s system 195% cpu 7.767 total | 11.32s user 4.64s system 469% cpu 3.401 total | 10.83s user 4.51s system 553% cpu 2.773 total | 10.90s user 4.84s system 537% cpu 2.930 total |

---

| instances | old total | old avg | **new total** | **total avg** |
| --- | --- | --- | --- | --- |
| 1 | 0.145 | 0.145 | 0.074 | 0.074 |
| 10 | 0.430 | 0.043 | 0.146 | 0.0146 |
| 20 | 0.740 | 0.037 | 0.284 | 0.0142 |
| 30 | 1.108 | 0.037 | 0.417 | 0.0139 |
| 40 | 1.483 | 0.037 | 0.580 | 0.0145 |
| 60 | 13.604 | 0.228 | 0.825 | 0.0137 |
| 80 | 30.236 | 0.378 | 1.143 | 0.0142 |
| 106 | 46.681 | 0.440 | 1.413 | 0.0133 |

Fixes #19313

Co-authored-by: Brian Joerger <bjoerger@goteleport.com>
2023-03-01 19:54:36 +00:00
Brian Joerger 731acf9cb7 Hardware Key UX fixes (#20849)
* Save private key policy in profile.

* Fix tsh status/logout with yubikey unplugged; fix cluster alert on tsh status with hardware_key_touch.

* Set private key policy from ping response.

* Skip cluster alerts on tsh status.
2023-01-30 19:17:53 +00:00
Brian Joerger 3633b54723 cluster specific ssh-agent keys (#14677) 2022-11-18 00:52:56 +00:00
Lisa Kim ef92182ef4 [reopen] Handle private key policy errors for the web UI (#17928)
- When user registers or resets, when running into
policy errors, we don't send back an error, but instead
a 200 (to indicate user has successfully registered/resetted)
and a flag to determine if policy was enabled
- Send back policy configurations for cluster config,
this will allow the web UI login page to just display
redirection messages without login attempts
- For role configured policy, login attempts will be
required and a specific error will be returned so that
the UI can then better redirect the user
2022-10-31 23:18:54 +00:00
Brian Joerger 9725c405a5 Make PIV builds opt-in for Mac and Windows (#17767) 2022-10-25 16:35:34 +00:00
Brian Joerger 5024e63975 tctl hardware key fixes (#17607) 2022-10-21 19:34:45 +00:00
Brian Joerger c2f412dece Verify attestation statement on the client side first. (#17550) 2022-10-18 18:39:29 +00:00
Alan Parra 2b44e5f23e Bump golangci-lint to 1.50.0 (#16966)
Update golangci-lint to v1.50.0 and fix a few linter issues.
2022-10-04 17:28:23 +00:00
Brian Joerger 92c7432197 PIV touch prompt (#16781) 2022-10-01 01:19:49 +00:00
Brian Joerger ce20b20753 PIV login enforcement (#15874)
Add private key policy enforcement.

  - Add private key policy cert extensions and enforcement.

  - Add private key policy settings and attestation logic.

  - Wire attestation request through login endpoints.

  - Store attestation data for reissue requests.

  - Add private key policy discovery and logic.

  - Relogin on hardware key policy errors.

  - Include integration with Teleport Connect.
2022-09-30 23:27:48 +00: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
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