Commit graph

1622 commits

Author SHA1 Message Date
Brian Joerger d5e2623c03
Fix flaky test TestWithRsync/with_headless_tsh (#33538)
* Improve error output for flaky test; Disable ssh agent to fix flaky test.

* Skip TestWithRsync in flaky test detector because the test is too long.
2023-10-17 00:52:42 +00:00
Marek Smoliński f3545eba3f
Security Reports (#30853) 2023-10-16 10:11:54 +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
rosstimothy f1fd668e55
Automatically forward some spans from tsh to Cloud (#33329)
Alters the tracing initialization logic such that 50% of all
tsh ssh commands run against Cloud are sampled. Additionally some
of the detectors have been dropped to eliminate any details about
a users machine being included in the attributes.
2023-10-13 18:55:59 +00:00
Michael Wilson dc42d07174
Notify CLI users when access lists need reviews. (#33304)
When logging in via `tsh` or doing a `tsh status`, a message expressing which
access lists need to be reviewed will be displayed along with the amount of
time left until the next review.
2023-10-13 17:04:59 +00:00
Forrest 5c818458ef
fix oidc test race (#33419) 2023-10-13 00:27:42 +00:00
Tobiasz Heller 8d99cd16e4
external_cloud_audit: add resource layer (#32833) 2023-10-12 10:26:58 +00:00
Michael Wilson 82522acfb0
Allow access requests to use user login state. (#33317)
Access requests are now able to use the user login state as opposed to just
the static user definition. This will allow access lists to influence who can
review access requests.
2023-10-11 22:02:49 +00:00
Marco André Dinis de3a0cc5fd
DiscoveryConfig: init service and add resource to tctl (#32399)
* DiscoveryConfig: init service and add it to `tctl`

This PR starts the DiscoveryConfig service in gRPC server and allows
`tctl` to interact with those records.

It also adds access to the `editor` role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can
act upon any changes.

* add revision

* add upsert method

* improve tctl -f command
2023-10-11 10:24:05 +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
Andrew Burke c4b2861f70
Show resources in Slack notification for access requests (#32887)
This change updates Slack notifications for resource-based access
requests to include the resources being requested.
2023-10-10 21:01:32 +00:00
Forrest 53be85e4ff
fix watcher setup in oidc test (#33250) 2023-10-10 19:35:00 +00:00
Andrew LeFevre bbd6701e22
Report exit code of rsync processes if they fail in TestWithRsync (#33175)
* report exit code of rsync processes if they fail

* use correct 't' when asserting

* Update tool/tsh/common/proxy_test.go

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

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-10-10 17:34:03 +00:00
rosstimothy b60ea81d54
Update users interface (#32987)
services.UsersService now takes a context and returns the user
from write operations as shown in the diff below. The bulk of the
changes are from modifying code to account for the additional
parameter and/or return value. Functional changes to better make
use of the new API will come in follow up PRs.

```diff
// UserGetter is responsible for getting users
type UserGetter interface {
	// GetUser returns a user by name
-	GetUser(user string, withSecrets bool) (types.User, error)
+	GetUser(ctx context.Context, user string, withSecrets bool) (types.User, error)
}

// UsersService is responsible for basic user management
type UsersService interface {
	UserGetter
	// CreateUser creates user, only if the user entry does not exist
-	CreateUser(user types.User) error
+	CreateUser(ctx context.Context, user types.User) (types.User, error)
	// UpdateUser updates an existing user.
-	UpdateUser(ctx context.Context, user types.User) error
+	UpdateUser(ctx context.Context, user types.User) (types.User, error)
	// UpdateAndSwapUser reads an existing user, runs `fn` against it and writes
	// the result to storage. Return `false` from `fn` to avoid storage changes.
	// Roughly equivalent to [GetUser] followed by [CompareAndSwapUser].
	// Returns the storage user.
	UpdateAndSwapUser(ctx context.Context, user string, withSecrets bool, fn func(types.User) (changed bool, err error)) (types.User, error)
	// UpsertUser updates parameters about user
-	UpsertUser(user types.User) error
+	UpsertUser(ctx context.Context, user types.User) (types.User, error)
	// CompareAndSwapUser updates an existing user, but fails if the user does
	// not match an expected backend value.
	CompareAndSwapUser(ctx context.Context, new, existing types.User) error
	// DeleteUser deletes a user with all the keys from the backend
	DeleteUser(ctx context.Context, user string) error
	// GetUsers returns a list of users registered with the local auth server
-	GetUsers(withSecrets bool) ([]types.User, error)
+	GetUsers(ctx context.Context, withSecrets bool) ([]types.User, error)
	// DeleteAllUsers deletes all users
-	DeleteAllUsers() error
+	DeleteAllUsers(ctx context.Context) error
}
```

Depends on gravitational/teleport.e#2346
Implements step 3 of #32949
2023-10-10 14:07:46 +00:00
Tiago Silva 27c90c7179
Fix tsh kube credentials when root cluster roles don't allow Kube access (#33014)
* Fix `tsh kube credentials` when root cluster roles don't allow Kube access

This PR fixes an edge case where an error message is printed to the
users without proper knowledge of the role mappings between root and
leaf clusters.

The user certificates include the `kubernetes_users` and
`kubernetes_groups` allowed in the root cluster but nothing prevents the
access to be sucessfull if the leaf cluster roles after the mapping
introduce the kubernetes principals.

This PR prevents tsh from failing when generating certificates for leaf
Kubernetes clusters.

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

* Update tool/tsh/common/kube.go

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

* add check to tsh proxy

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-10-10 13:30:45 +00:00
Tiago Silva 8f713013c0
Header Connection: close causes kubectl to fail exec (#33050)
* Header `Connection: close` causes `kubectl` to fail exec

The header `Connection: close` causes failure in kubetl when it upgrades
the connection to SPDY.

The `ReadTimeout` and `WriteTimeout` are known to cause problems to
Kubernetes watch streams.

Fixes #33020

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

* add unit tests

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2023-10-09 18:28:07 +00:00
Tiago Silva c210c39138
Add initial command to session trackers (#32947)
When user starts a session, we do not report the initial command used
which causes visibility problems to moderators when they need to figure
out if they join or not the session.

This PR exposes the intial command for SSH and Kubernetes so moderators
can decide if they want to join the session or not based on the initial
command.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2023-10-07 20:25:18 +00:00
Michael Wilson 049363b882
Add in audit review recurrence presets. (#32843)
Access Lists now have audit review recurrence presets. These allow users to
specify review frequencies of 1, 3, 6, or 12 months, and specify the 1st,
15th, or last days of the target month. Presets have been used for their
simplicity over other various recurrence definition mechanisms, as these
presets are much clearer than many of the other options.
2023-10-03 22:36:05 +00:00
Gavin Frazar ce42cd9e81
remove db name checkers for protocols (#32530)
* dont enforce RBAC on connection to oracle/snowflake db

* require --db-name for oracle in tsh

* fix snowflake test

* fix format database connect args
2023-10-03 17:20:15 +00:00
Gavin Frazar ed4c0073b0
update --db-user and --db-name docs (#32523) 2023-10-02 22:32:30 +00:00
Alan Parra b95e020949
Rewrite tsh mfa rm using DeleteMFADeviceSync (#32767) 2023-10-02 17:18:17 +00:00
Gus Luxton a4b3248a45
puttyconfig: Switch to string-based Validity format and deprecate MatchHosts (#32598)
* puttyconfig: Switch to string-based Validity format and deprecate MatchHosts

* Switch to more restrictive, reliable parsing

* Add validity string errors to docs

* Remove invalid test case

* Add test case

* Remove any spaces from user-provided input and use sanitized hostname

* Apply fixes from code review

* Tidy up errors, provide consistent detail about which field contains an error

* Disable docs lint for dots in heading

This is needed here, as there are 5 error messages which all start the same way but end differently.

* Catch a few more error cases

* Only delete old MatchHosts key after new Validity key has been written successfully

* Apply suggestions from code review

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

* Address Zac's comments from code review

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-10-02 16:09:12 +00:00
Andrew Burke 15d190b26c
Add support for Client ID to Azure VM auto-discovery (#32360)
This change adds the `client_id` optio nto the Discovery Service for
Azure VMs, which sets the client ID of the managed identity for discovered
nodes to use when joining the cluster. This allows the discovered nodes
to be discovered while having multiple managed identities assigned.
2023-09-29 16:22:08 +00:00
Alan Parra 32bcd71591
fix: Fix panic on tsh device enroll --current-device (#32694)
* Test RunAdmin enrollment failure

* Fix RunAdmin when enrollment fails, protect tsh from nil device
2023-09-28 13:56:46 +00:00
rosstimothy 5dc2841177
Start migrating tctl edit away from force creating resources (#32604)
`tctl edit` was always performing a forceful update in the same way
that `tctl create -f` was. This prevents optimistic from being
enforced during the update step of the edit command and thus nullifies
some of the usefulness of the feature(preventing concurrent updates
to a resource).

Since not all resources support Update operations, some only support
Upsert, and optimistic locking will slowly be added one resource at
at time the new behavior was only implemented for user resources.
The UpdateHandlers will be updated in follow up PRs when the resource
has support for optimistic locking added.
2023-09-27 13:53:49 +00:00
rosstimothy 06e49aaef1
Use Proxy gRPC API during log in (#32388) 2023-09-27 11:16:40 +00:00
rosstimothy e035f4dbf3
Propagate resource revision to/from the backend (#32040)
* Set revision on resources retrieved from the backend

Adds a new `MarshalOption` that ensures the resource revision is
set when unmarshalling a backend item. The new `WithRevision` option
was also applied everywhere that the legacy `WithResourceID` was
being used.

* Prevent storing resource revision in the backend item value

The revision follows the same semantics as the resource id for
marshalling. This prevents both items from showing up in the value
of the backend item, which can prevent compare and swap operations
from completing succesfully. Each backend is responsible for
persisting the revision in some manner.

The existing PreserveResourceID was reused to prevent having to
make multiple copies of a resource when clearing the id and revision.
The marshal option will be updated in a follow up when the resource
id is removed.

* Ignore revision in resource comparisons
2023-09-26 16:58:04 +00:00
Brian Joerger 1c88f9ed1b
Move lib/utils/prompt to api/utils/prompt (#32334)
* Move /lib/utils/prompt to /api/utils/prompt.

* Replace uses of lib/utils/prompt with api/utils/prompt and delete pacakge.

* go mod tidy.
2023-09-25 19:31:37 +00:00
Alan Parra 5427f7da44
Move MFA registration to sync RPCs (#32333) 2023-09-22 19:40:12 +00:00
Jakub Nyckowski f9c419674c
Generate access list allowed promotions on access request creation (#31768)
* Generate access list suggestions on access request creation

* Add test
Cleanup code

* Add comment

* Fix typo and refactor access suggestion in services library

Fixed a typo in a comment in `access_list.go`. Refactored `accessrequest/suggestion.go` for enhanced code structure. The old model had all methods related to access request in a single interface, `accessRequestAPIGetter`, which had been divided among multiple interfaces for better division of responsibilities. A new function `GetSuggestedAccessLists` was created to narrow down the single duty for each function. These changes ensure more convenient unit testing and better accountability.

* Improve access request suggestions logic

This commit improves the logic for generating access request suggestions. It includes the requester's roles and traits as well as those from the access list and provides suggestions only for resource-based requests. A new method was also introduced for initializing AccessRequestSuggestions to avoid nil error.

* Refactor access list suggestions to promotions

The concept of 'suggestions' was updated to 'promotions' in different files (auth.go, client.go, auth_service_test.go, auth_service.proto among others) to make it more intuitive and align with the business context. This implies changing the wording, the functions called and the variable names. The feature itself hasn't changed, just the way it is referred.

* This commit changes the method name "GenerateAccessListSuggestions" to "GenerateAccessRequestPromotions" in multiple files. The naming is changed to reflect the actual function of the method, which is generating promotions for given access requests, rather than generating list suggestions. All relevant mentions and usages of this method are updated to reflect the name change. Modification also includes adjustments to the comments and interfaces related to the updated function for better code clarity.

* Refactor "GenerateAccessListSuggestions" to "GenerateAccessRequestPromotions"

Renamed method "GenerateAccessListSuggestions" to "GenerateAccessRequestPromotions" across the codebase. This change reflects the actual functionality of the method, which is to generate promotions for access requests, not suggestions. This aligns the method name with its purpose, and offers better code readability. Comments related to this function were also updated to maintain consistency.

* Update method handling access requests promotions

Revised the method of handling failures when generating access requests promotions. Now, even if promotions fail to generate, the request will not fail entirely. Instead, the request can still be approved but without promotions. Also, changed the UpsertAccessRequestAllowedPromotions method to CreateAccessRequestAllowedPromotions to clearly indicate its purpose, while revising related test cases and comments.
2023-09-22 19:34:32 +00:00
Alan Parra d72c4cfa4b
Allow correct TOTP registrations via AddMFADeviceSync (#32359)
* Add a challenge identifier to TOTPRegisterChallenge

* Update generated protos

* Allow correct TOTP registrations via AddMFADeviceSync

* Use GetClock() instead of `.clock`
2023-09-22 18:53:48 +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
Steven Martin ea47b2b5f8
Update token parameter description to be consistent (#30987) 2023-09-21 17:46:45 +00:00
Rafał Cieślak 847a1b1167
Implement waiting for Connect My Computer node to join cluster (#30905)
* Add daemon.Service.ResolveClusterURI

* Accept agents dir through command line flag

tshd needs to know this out of band, so that when the Electron app tells
it to watch for host UUID file for a specific cluster, the Electron app
can send just the profile name of the cluster instead of an arbitrary path
on the computer.

* Implement WaitForConnectMyComputerNodeJoin in tsh daemon

* wait: Use addEventListener instead of onabort

* Make TshAbortController emit abort event only once

This aligns it with a regular AbortController, which also emits the event
only once.

* Refactor how types are imported in tshd fixtures

* Implement WaitForConnectMyComputerNodeJoin in Electron app

* createAbortController: Add signal.aborted, use emitter.once

* Improve wait function based on Deno implementation

72d6e6641e/async/delay.ts (L39)

* Add a comment about the events package
2023-09-21 11:43:10 +00:00
rosstimothy 73a3e68c66
Stop implicitly loading global tsh config on Windows (#32221)
To avoid security issues caused by a possible lack of file system
permissions on Windows tsh only loads global config if the path
to the file is explicitly provided in the TELEPORT_GLOBAL_TSH_CONFIG
environment variable.
2023-09-20 18:16:56 +00:00
Gavin Frazar 8f24c4ff69
remove prefix matching in tctl (#31916)
* remove prefix matching in tctl

* replace prefix matching with exact discovered name match as a fallback
  when no resource full name matches the name given by a user

* refactor test helpers

* avoid decoding yaml/json into already initialized var
2023-09-18 21:21:20 +00:00
Gavin Frazar 259d32f5b7
remove tsh kube prefix matching (#31852)
* remove tsh kube prefix matching

* fix retry with relogin for ambiguous clusters
* fix access request func to only request specified cluster
* consolidate test setup for login/proxy kube selection tests
* add more test cases for kube selection
* remove prefix testing

* fix testism

* add origin cloud label in tests

* refactor the check for multiple cluster login into a func
2023-09-18 17:26:40 +00:00
Marco André Dinis 4d9adbd75a
AWS OIDC: command to configure IAM for listing databases (#31656)
* AWS OIDC: command to configure IAM for listing databases

Previously we were guiding users in a series of screens and copy/paste
so that the user could configure the AWS OIDC Integration.
This guide also included adding the first feature: enroll an RDS
Database.

We created a new command that sets up the OIDC IdP, but decoupled from
the enroll rds feature.

After updating the guide to use the new command and remove the guide, we
must provide a way for users to set up the required policy for Enrolling
RDS Databases.
This PR adds that command

* review pt1

* rename to ConfigureIAMListDatabasesRequest

* removed wrapper

* fix command description

* move aws client setup to common

* use logrus instead of log
2023-09-15 18:17:48 +00:00
Mike Jensen 4cba417e80
Careful handling when loading files (#31721)
* Careful handling when loading files

This commit attempts to provide a common API so that the decision of when to follow symlinks is a conscious decision.
Because Teleport (particularly the agent) runs in a privilege context, there is risk that following symlinks may allow information disclosure.

After review of the cases covered in this commit (and some additional cases where this API was not a natural fit), this does not appear to be a broad problem.  This commit however does fix the one known flaw described in the issue https://github.com/gravitational/teleport-private/issues/1009

* Apply PR feedback to rename OpenFile

* fs.go: Fix symlink evaluation

* fs.go: Fix for rebuilding absolute paths in symlink check

* fs_test.go: Add symlink testing

* Apply suggestions from code review

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>

* fs_test.go: Fix build for err reference

* fs.go: Apply PR feedback and consider Hardlinks

After PR discussion it was highlighted that MacOS does not guard against hardlinks in the same way linux does.  For that reason this implementation has been updated with OS conditional logic to validate against hardlinks.

* fs.go: Switch loop to range over components instead of index

* Minor improvements from PR feedback

* fs_test.go: Test public OpenFile API's and include OS specific validation

* Fix windows build

Make hardlink count lookup code build conditional to avoid undefined syscall.Stat_t.

* utils.getHardLinkCount result order update from PR feedback

* fs_windows.go: Comment improvements from PR feedback

* fs: Fix build for OSX

* Disable lint error due to unecessary cast on linux

---------

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>
2023-09-15 14:44:31 +00:00
Steven Martin 7cd98b2606
correct tsh recording command description (#31940) 2023-09-15 13:13:52 +00:00
Gavin Frazar d433f96e81
rework tsh database selection logic (#31689)
* disallow prefix matching
* select by exact name match first,
* otherwise look for unambiguous discovered name label match.
* look for an active db to resolve discovered name match ambiguity.
* add more predicate builder helpers
* check for db name in not found error for stale cert hint
* no error status on tsh db logout with no logged in dbs
* remove dead code
* refactor helper funcs to simplify code and make it easier to test
* test complex database selection
* test findActiveDatabase
* test choosing one db by discovered name
* add more resource selectors tests
* test formatDatabaseLoginCommand
* add debug logging for db selection
2023-09-13 17:55:21 +00:00
Forrest 2d8e6d3776
always generate request IDs server-side (#31760)
* server-side request ids

* update e-ref
2023-09-13 16:08:11 +00:00
rosstimothy debbe6a708
Move login rule command to oss tctl (#31773)
A new TestLoginRule rpc was added to perform evaluation of login
rules server side, allowing us to move the command to oss.
2023-09-13 15:37:18 +00:00
Marco André Dinis 069cd24368
AWS OIDC: Set up integration with a single command (#31521)
* AWS OIDC: Set up integration with a single command

Creating an AWS OIDC Integration requires a lot of clicks, copy/paste,
navigation between tabs.

This PR adds a single teleport command that creates all the required
resources in AWS:
- AWS OIDC Identity Provider that uses Teleport as source
- AWS IAM Role that can be used by this Identity Provider

This role, will then have inline policies allowing multiple features in
Teleport.
Example: a policy must be added to this role that has
`rds:DescribeInstances` and `rds:DescribeClusters` so that the user can
use the integration to enroll RDS Databases.

* improve docs

* improve godoc
2023-09-13 07:21:00 +00:00
Gavin Frazar df5f18aeb8
check for discovered kube cluster name exact match (#31744) 2023-09-12 19:55:25 +00:00
Noah Stride c7cc451667
[Buddy 30860] Added --insecure flag to tbot (#31093)
* Added --insecure flag to tbot; Added test; Added test-setup

* Removed old file

* Review comments

* Updated tests; Rework CAPins & CAPath verification; Split functions

* Cleanup old debug lines

* Cleaned up tests; Remove unnecessary InsecureSkipVerify;

* Add back InsecureSkipVerify to fix Authentication

* renamed DefaultBotConfigOpts parameter; remove some stale debug code; restored wrongfully delted InsecureSkipVerify;

* remove stale newline

* Improved warnings

* Updated tbot usage example

* Fix failing test; Cleanup Makefile target

* Removed unused config option from OnboardingConfig; Fixed import order

* Rename test; Rework if statement; Fix newline

* Updated shell script to comply with shellcheck; added example yaml to gitignore

* Remove example file

* Tidier comments for reg code

* behavior

* Remove unused var from Makefile test-go-unit-tbot

* Further simplify makefile

---------

Co-authored-by: FireDrunk <thijs.cramer@gmail.com>
2023-09-11 08:16:18 +00:00
Trent Clarke 4524974499
Adds default Github API urls to SSO connector. (#31397)
`tctl sso configure github` was producing an untestable connector
spec, or at least a spec that would _always fail_ when tested with
`tctl ssl test`, due to missing GitHub endpoints in the generated
spec.

This change adds the default GitHub endpoint URLs as default values
for the endpoint flags in `tctl sso configure github` so that the
produces spec is valis and testable.

Note: Our WebUI appears to magically add these values when saving
      a connector, so this issue only really effects `tctl sso test`

Includes doc update to match new output.

Fixes: #31396
Changelog: `tctl sso configure github` now includes default Github endpoints
2023-09-05 23:25:52 +00:00
Tiago Silva 8e5ac12562
Fix tsh kube login when creds are expired or doesn't exist (#31418)
This PR chains `client.RetryWithRelogin` and `retryWithAccessRequest`
helpers to deal with cases where user's credentials don't exist or are
already expired.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2023-09-05 16:11:26 +00:00
Gavin Frazar 5e2eea2e8c
use active db cert principals when available (#31188)
* use active db cert principals when available

* update databaseinfo test to cover regression case
2023-08-30 19:01:15 +00:00
Gavin Frazar 5b932266b9
remove deprecated tsh proxy db flags (#31121)
* --cert-file removed
* --key-file removed
2023-08-30 18:04:27 +00:00