Commit Graph
238 Commits
Author SHA1 Message Date
Rafał Cieślak dfd21d4280 Fix validation in PIV PIN and PUK form in Connect, increase new PIN timeout (#55401)
* Properly validate new PUK confirmation

* Align PIN & PUK length with tsh

* Increase timeout for the prompt for setting new PIN and PUK
2025-06-05 22:37:49 +00:00
Nic Klaassen 2bedd3f8df [vnet] feat: write OpenSSH-compatible config file for VNet SSH (#55239) 2025-06-01 07:07:02 +00:00
Nic Klaassen 3a3099e2ec [vnet] feat: write VNet SSH keys to TELEPORT_HOME (#55228) 2025-06-01 05:50:10 +00:00
Erik Tate 479e99b866 adding support for encryption/decryption keys to keystore manager for (#54428)
gcp, pkcs11, and software backends
2025-05-29 19:40:43 +00:00
Marco Dinis c5c94aee18 WebAPI: endpoint that returns the oneoff command for AWS Roles Anywhere set up (#54853)
* WebAPI: oneoff script for AWS Roles Anywhere set up

* use w.Write instead of fmt.Fprint
2025-05-28 08:30:03 +00:00
Brian Joerger 9892cf65aa Warmup hardware key touch before login. (#55017) 2025-05-24 00:19:31 +00:00
Brian Joerger 7c975ce27c fix: release PIV connection during PIN prompts - avoid "the smart card has been reset" error (#54700)
* Refactor connection sharing logic to allow reconnection logic.

* Refactor signature method into organized parts; Move signPromptMu further down the callstack to allow better concurrent access; Add attestMu to prevent certificate corruption.

* Handle PIV reconnection within doWithSharedConn.

* Add test; Fix issues.

* Add debug log.

* Clean up locks.

* Only prompt PIN on retry; Clean up prompt logic.

* Add todo for upstream PR.

* Prevent PIV operations that don't support concurrency from being run concurrently; add test.

* - Revert connection sharing refactors.

- Add exclusiveOperationMu mutex and test.

* Address comments; Move touch prompt into abandonableSign for clearer synchronous logic.

* Restore cancel cause behavior.

* Address signature concurrency comments.

* Fix signature channel.
2025-05-23 18:42:41 +00:00
Brian Joerger a2e7c20feb feat: Hardware Key Agent validates known keys (#54691)
* * Have hardware key agent validate known keys instead of always validating by the PIV slot cert.

* Refactor cert check logic with a custom error.

* Add test.

* Update rfd.

* Fix lint.

* Address comments.

* Require knownKeyFn to be provided.

* Require fallbackService to be provided to agent service.

* Address comments.
2025-05-16 18:38:44 +00:00
Brian Joerger 8b0a848abf fix: don't cache an incorrect PIV PIN (#54614)
* Verify PIV PIN before we cache it; Fix lint for pincache.go with build tag.

* Add local test for PIN caching in the YubiKey service.

* Minor fixes.
2025-05-09 23:56:22 +00:00
Grzegorz Zdunek 2d4afb6e5a Support Windows desktop certs in tsh (#54317)
* Support Windows desktop certs in tsh

* Add missing `WindowsDesktopTLSCredentials` initialization
2025-05-09 07:13:36 +00:00
rosstimothy 52816e8427 Bump golangci-lint to v2 (#54410)
* Bump golangci-lint to v2

* fix lints

* update e

* fix: delete removed cli option
2025-05-07 22:14:51 +00:00
Brian Joerger a795626b27 Move stderr message to cliprompt. (#54207) 2025-04-29 17:39:06 +00:00
Brian Joerger 4db4cb3b79 feat: Hardware Key Agent - initialize hardware key service at start of tsh daemon (#54226)
* * Initialize shared hardware key service and client store for tshd

* Replace CustomHardwareKeyPrompt with SetPrompt

* Add lazy loaded tshd event service client and use it to initialize hardware key prompt early.

* Address comments; Set TshdEventsClient in daemon service.

* Fix test.

* Fix potential race condition on global yubikey service prompt.

* Add test.
2025-04-24 23:46:31 +00:00
STeve (Xin) Huang 238ff22b91 DB multi-session MFA Part 1: implement basic "tsh db exec" (#53296)
* Implement basic "tsh db exec"

* adding ut

* minor refactor, fix race, rename iter func

* add help

* always use service name

* overwrite max connections with env var

* single get databases call

* remove prefix output

* fix some flags

* iterutils

* ensure each database

* add summery

* refactor, tests

* revert auto rename change by editor

* revert migrate

* remove unused var

* review comments

* renaming --max-connections to --parallel

* make exec return result instead of error

* hint TELEPORT_PARALLEL_JOBS

* fix golint

* address PR comments
2025-04-24 20:28:43 +00:00
Brian Joerger 2be659da9a feat: Hardware Key Agent w/ PIN caching - fix cross-cluster support (#54144)
* Add hardware key PINCache.

* Remove PINCachingPrompt.

* Set PINCacheTTL in key ref.

* Add PINCache to cli and teleterm hardware key prompts.

* Resore signMu.

* Pass pin cache TTL in hardware key agent sign requests.

* Move pinCache to YubiKey struct to maintain support for multiple YubiKeys.

* Enforce max PIV PIN cache TTL of 1 hour.

* Remove unused fields.

* Ensure a new goroutine is not started when pin expiration is already set.

* Update error message.

* Remove goroutine.

* Move pin cache to piv package.

* Hold lock for PromptOrGetPIN.

* Add prompt timeout.
2025-04-23 22:46:13 +00:00
Brian Joerger a2dc8e1da7 feat: Hardware Key Agent - command hint (#54090)
* Supply command for context on hardware key prompt.

* * Include command in Teleport Connect hardware key prompts, excluding tshd commands

* Fix proxy host context passed to Teleport connect hardware key prompts

* Only use direct service for `tsh login` to avoid jumping between clients

* Add new line before command.

* Fix story.

* Address comments.

* Trim forward slash for windows.

* Change proxy_host to proxy_hostname; Update comment.
2025-04-18 22:44:16 +00:00
Brian Joerger 6b615b6280 Remove MaxUint32 call to fix builds on 32-bit systems. (#54125) 2025-04-18 18:15:38 +00:00
Gabriel CoradoandSTeve Huang f041ef25f7 Generate AWS regions list from AWS SDK V2 partitions file (#53104)
* feat: generate aws regions from SDK v2

* refactor(aws): only sort regions once

* chore(aws): add license header to generated file

* refactor: move global regions to another variable

* refactor: code review suggestions

* refactor(make): update go-generate target

* chore(ci): add target to lint go-generate up-to-date

* refactor(aws): drop global regions

* refactor(workflows): update target and remove git command

* refactor(aws): wrap regions value in sync.OnceValue

* refactor: move aws regions into a sub package of utils aws

* chore(api): remove global regions matching

* fix(makefile): target name

* chore(gomod): go mod tidy

* fix(tctl): add missing awsutils package

* chore(gomod): move indirect aws-sdk-go into indirect deps block

* add a temporary alias to avoid break e

---------

Co-authored-by: STeve (Xin) Huang <huangin52@gmail.com>
2025-04-18 14:19:08 +00:00
2af583d24d feat: Hardware Key Agent - require users to configure certificate (#54118)
* * Hardware key agent checks whether a key is configured for Teleport clients before performing a signature.

* Add detailed error message and docs for configuring PIV slot certificate.

* Add additional checks for mismatched public key on PIV slot, which can occur when generating a new key on a PIV slot with an active login session.

* Update api/utils/keys/piv/yubikey.go

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

* Apply suggestions from code review

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2025-04-18 01:03:39 +00:00
Brian Joerger 18cc4a1fe4 feat: Hardware Key Agent (#54026)
* Add HardwareKeyAgent proto service.

* Add hardware key agent client and server implementation.

* Add tsh piv agent command.

* Use hardware key agent service when available.

* * Add config option to Teleport connect to start the hardware key agent server

* Add flag to tsh daemon command to start the hardware key agent server

* Fix hardware key agent client connection for Windows.

* Add hardware key agent service; Add tests.

* Minor cleanup.

* Move hardware key agent proto to /api.

* * Restructure packages based on dependencies.

* Add hardware key agent test coverage for RSA, ECDSA, and ED25519 keys.

* Add PIV test coverage for RSA keys.

* Fix lint.

* Fix lint; Fix test.

* Address comments.

* Address comments.

* Fix merge conflict.
2025-04-17 01:14:32 +00:00
Brian Joerger 634376105c feat: Hardware Key PIN caching (#53976)
* Add PinCachingPrompt.

* Add PINCacheTimeout to auth preference proto message.

* Report PIVPINCacheTimeout through ping; Store PIVPINCacheTimeout in profile.

* Set PIV pin cache timeout for tsh and teleterm.

* Add SetPrompt and GetPrompt to hardware key service interface.

* Cleanup; Add test.

* Address comments.

* Rename to PINCacheTTL.

* Apply suggestions.

* Fix lint.

* Simplify randPIN for test.

* Use math/rand/v2.

* Update terraform docs.
2025-04-16 20:31:47 +00:00
Brian Joerger c8f7d978f4 feat: Hardware Key Agent - consolidate globally shared PIV service variables (#53974)
* Consolidate process-wide shared prompt mutex and yubikey connections into a shared YubiKeyService, which will also share the prompt.

* Fix interactive piv service tests.

* Fix wording on comment.
2025-04-15 23:25:47 +00:00
Brian Joerger d4dba3df40 Remove unused parameter in keys.NewPrivateKey (#53678)
* Remove unused parameter in keys.NewPrivateKey.

* Update e ref.
2025-04-15 20:43:09 +00:00
Nic Klaassen f65c6daed5 fix: correct ppk format of ed25519 keys (#53968) 2025-04-11 22:10:44 +00:00
Brian Joerger fe3193a4b1 feat: Hardware Key Agent - Propagate contextual key info from key store to hardware key prompts (#53703)
* Propagate contextual key info from key store through to hardware key prompts.

* Remove HardwareKeyPromptConstructor.

* Cleanup; add tests.
2025-04-11 16:55:04 +00:00
Brian Joerger 256bced874 feat: Hardware Key Agent - set hardware key service in client store (#53563)
* Replace prompt in keystore with hardware key service in client store.

* Add client StoreConfig and StoreConfigOpt.

* Add client store and key store tests.

* Provide nil service for ProfileStatus's AppsForCluster and DatabasesForCluster methods.

* Address comments.

* Fix test.

* Fix test with cmp.Diff.
2025-04-11 01:16:25 +00:00
Brian JoergerandSTeve Huang eedf8b6786 feat: Hardware Key Agent - Enrich the PEM encoded hardware private key file (#53675)
* Enrich hardware key PEM file.

* Add test.

* Validate PrivateKeyRef before/after encode/decode.

* Update api/utils/keys/hardwarekey/hardwarekey.go

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>

* Validate key ref in hardware key service implementations; Fix merge conflict.

---------

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
2025-04-10 22:02:57 +00:00
Brian Joerger 7e5d71801e feat: Hardware Key Agent - Add api/harwdarekey/piv package (#53677)
* Remove YubiKeyPrivateKey

* Remove keys package dependencies from PIV implementation.

* Move PIV implementation into new piv package.

* Move newPrivateKey into YubiKeyService.NewPrivateKey.

* * Clean up separation of concerns between YubiKey and YubiKeyService

* Replace hardwarekey.PrivateKey cache with YubiKey cache for proper support for multiple clusters or yubikeys

* Add YubiKey version field for use in version specific signature edge cases

* Change sharedPIVConnection connection from an embedded field.

* Address comments.

* Add getKeyRef helper method.
2025-04-10 17:31:27 +00:00
Brian Joerger 8020679513 Rename NewSoftwarePrivateKey to NewPrivateKey (#53598) 2025-04-09 23:34:15 +00:00
Brian Joerger 78c19bd65c feat: Hardware Key Agent - Add hardwarekey.Service interface with adapted PIV implementation (#53674)
* Add hardware key service interface; Add mock service for tests.

* Add piv implementation of hardware key service.

* Remove old yubikey parsing logic in favor of hardwarekey.PrivateKeyRef.

* Remove HardwareSigner in favor of hardwarekey.PrivateKey.

* Add test; Cleanup comment; Don't require pin/touch prompts in tests with MockHarwdareKeyService by default.

* Fix tests.

* Add TODOs.

* Use unhashed digest for WarmupHardwareKey.

* Address comments.

* Fix race condition in test service.

* Address comments.
2025-04-09 22:14:19 +00:00
Nic Klaassen 26906bb085 fix flaky TestMarshalAndParseKey (#53882) 2025-04-09 21:44:38 +00:00
Brian Joerger 58f71101d8 feat: Hardware Key Agent - Add api/utils/keys/hardwarekey package (#53671)
* Move hardware key files into new hardwarekey package.

* Tidy up PIVSlot logic and remove its piv-go dependency.

* Add godoc comments to cliPrompt methods; Update cliprompt.go license year.

* Add godocs.
2025-04-07 19:31:11 +00:00
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
Zac Bergquist b0049ecc2a Remove the custom current user lookup function (#52144)
We added this function to mitigate slow user.Current() calls in
Windows Active Directory environments. Go 1.24 ships with an optimized
verison of user.Current, rendering this utility unnecessary.

Closes #41922
2025-03-04 23:43:54 +00:00
Zac Bergquist cc3122e2fa Remove unnecessary keysIn helper (#52671)
* Remove unnecessary keysIn helper

* Remove slices.Any

It's a carbon copy of the standard library's slices.ContainsFunc.
2025-03-03 14:31:30 +00:00
STeve (Xin) Huang a344745017 GitHub proxy: git to prompt for password when tsh session expires (#51305)
* GitHub proxy: git to prompt for password when tsh session expires

* replace reference

* set ctx
2025-02-25 16:14:15 +00:00
STeve (Xin) Huang 84b66bd247 Do not delete integration CAs on auth init (#51938)
* Do not delete integration CAs on auth init

* change to an iterator

* fix lint
2025-02-13 21:02:57 +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
Tiago SilvaandGavin Frazar b61e70ea19 netiq: add plugin install prompt (#51502)
* netiq: add plugin install prompt

This PR adds the plugin prompt code to read the required parameters to
create the netiq plugin.

Part of https://github.com/gravitational/access-graph/issues/634

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* add license

* Update netiq.go

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

* Update netiq.go

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

* Update netiq.go

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

* handle review comments

* Apply suggestions from code review

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>

* consolidate prompt methods

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Co-authored-by: Gavin Frazar <gavin.frazar@goteleport.com>
2025-01-29 17:57:26 +00:00
rosstimothy ef859498bc Vendor gravitational/trace/trail in api (#51032)
* Vendor gravitational/trace/trail in api

Pulling in the trail package directly in api will allow the trace
module to shed the grpc-go dependency. This needs to land prior
to https://github.com/gravitational/trace/pull/112 being included
in a new version of trace.

There should be no noticable change in the api depdency tree since
it already depends on grpc-go. Some additional items from the
trace/internal package were also vendored within trail as needed.
Additionally, some of the public api of trail that was not being
consumed has been made private.

* fix: appease linters
2025-01-14 21:04:01 +00:00
rosstimothy 17edb10e43 Permit routing to agentless nodes with non-UUID metadata.name (#50915)
We suggest that a UUID is used for agentless nodes metadata.name
field, but we do not enforce it. This causes several edge cases
and slightly weird UX in places that expect the name to be a UUID.
Most notably, this presents dialing problems for the web ui as
described in https://github.com/gravitational/teleport/issues/50914.
To allowing dialing to function in all cases for these servers,
routing has been updated to permit matches on metadata.name, however,
the match is given a lower score then a match on a UUID. This should
permit dialing, though, it may still result in ambiguity.

Closes #50914.
2025-01-09 20:35:14 +00:00
Rafał Cieślak 0ade3a8f58 Add TargetPort to RouteToApp & use it to route connections to multi-port TCP apps (#49047)
* Add TargetPort to RouteToApp and AppMetadata proto messages

* Pass TargetPort during cert generation

* Refactor Pack.makeTLSConfig to accept struct

This will make it easier to add targetPort to it.

* Add labels to UUIDs used by appaccess test pack app servers

This makes them easier to distinguish when routing doesn't work as expected.

* Refactor Pack.CreateAppSession to accept a struct

* TestTCP: Create app session within test

If we kept the old code, we'd need to manually create a session for each
target port, which would create a lot of duplication.

* Prepare integration test fixtures for multi-port tests

* Add api/utils/net.IsPortInRange

* Use TargetPort when routing TCP connections

* Inline dialMultiPortTCPApp, centralize logic

* Check target port when connecting to single-port app

* Reorder check in IsPortInRange

* Use int instead of uint16

* Extract picking dialTarget to separate function

* addr → uriAddr

* Improve err msg for single-port apps when targetPort != uriPort

* Fix unnecessary conversion to int
2024-12-03 13:55:00 +00:00
Rafał Cieślak 87320df204 Add Ports field to app spec (#47706)
* Add Ports to AppSpecV3

* Validate ports of api/types.AppV3

* Add Ports to lib/config and lib/service/servicecfg

* lib/config TestApps: Improve error messages

* lib/service: Convert servicecfg.PortRange to types.PortRange

* Add multi-port TCP apps to config and tctl tests

* Rename Ports to TCPPorts

* Change port fields to uint16 where possible

* Update comments for Port and EndPort

* Extract port range validation to api/utils/net

* Replace custom check type with require.ErrorAssertionFunc

* Simplify validation of end port

* Fix expected message in api/types test

I forgot to update that one.
2024-12-03 12:41:12 +00:00
Nic Klaassen 75c2cef688 improve error message when v17 tctl reads v16 tsh profile (#49305) 2024-11-21 21:52:05 +00:00
Edoardo Spadolini bcbfa8192e Get rid of math/rand in favor of math/rand/v2 (#49294)
* Get rid of math/rand in favor of math/rand/v2

* Update retryutils to use rand.N

* Update e ref
2024-11-21 12:57:32 +00:00
Edoardo Spadolini a92e49fc74 Use thread-local RNGs for jitters (#48860)
* Use math/rand/v2's thread-local RNG for jitters

* Replace NewJitter() with DefaultJitter

* Replace NewFullJitter() with FullJitter

* Replace NewHalfJitter() with HalfJitter

* Replace NewSeventhJitter() with SeventhJitter

* Inline jitters in lib/utils/diagnostics/latency

* Replace var jitters in lib/utils with proxy functions

* Replace utils.HalfJitter with retryutils.HalfJitter

* Replace utils.FullJitter with retryutils.FullJitter

* Replace utils.SeventhJitter with retryutils.SeventhJitter

* Replace sharded jitters with thread-local ones

* Remove NewSeventhJitter reference in integrations
2024-11-13 16:35:09 +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
Tiago SilvaandMarco Dinis 768a0bd684 [entraid] add setup script for offline clusters. (#47863)
* [entraid] add setup script for offline clusters.

This PR adds a cli configuration for Entra ID where it's possible to default to system credentials instead of relying on OIDC for authentication in EntraID. OIDC is not always a possibility specially when the cluster is private and not internet acessible.

The UX is the following:

```text

Step 1: Run the Setup Script

1. Open **Azure Cloud Shell** (Bash) using **Google Chrome** or **Safari** for the best compatibility.
2. Upload the setup script using the **Upload** button in the Cloud Shell toolbar.
3. Once uploaded, execute the script by running the following command:
   $ bash entraid.sh

**Important Considerations**:
- You must have **Azure privileged administrator permissions** to complete the integration.
- Ensure you're using the **Bash** environment in Cloud Shell.
- During the script execution, you'll be prompted to run 'az login' to authenticate with Azure. **Teleport** does not store or persist your credentials.
- **Mozilla Firefox** users may experience connectivity issues in Azure Cloud Shell; using Chrome or Safari is recommended.

Once the script completes, type 'continue' to proceed, 'exit' to quit: continue

Step 2: Input Tenant ID and Client ID

With the output of Step 1, please copy and paste the following information:
Enter the Tenant ID: 1056b571-0390-4b08-86c8-2edba8d9ae79
Enter the Client ID: 1056b571-0390-4b08-86c8-2edba8d9ae79

Successfully created EntraID plugin "name".
```

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* move function to api

* handle code review comments

* Apply suggestions from code review

Co-authored-by: Marco Dinis <marco.dinis@goteleport.com>

* fix url

* enable group claims

* add godoc

* handle code review comments

* fix gomod

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Co-authored-by: Marco Dinis <marco.dinis@goteleport.com>
2024-10-29 17:51:58 +00:00