Commit Graph
761 Commits
Author SHA1 Message Date
Marco Dinis c90bf7e9a4 AWS OIDC App Access: add PublicAddr to App (#41543)
* AWS OIDC App Access: add PublicAddr to App

This PR adds a missing field to the App created to handle the AWS App
Access when using the AWS OIDC credentials
The PublicAddr is required and was not being set.

* fix identation
2024-05-15 07:11:50 +00:00
rosstimothyandEdoardo Spadolini 7a7f982ed9 Add tbot ssh-proxy-command (#41346)
The new subcommand is meant to be a replacement for tbot proxy ssh
which does the ssh proxying entirely within tbot to reduce resource
consumption. The old mechanism spawned a tsh process to perform the
proxying which leads to increased CPU and memory consumption - which
can be quite problematic when used as an OpenSSH ProxyCommand for
an ansible playbook.

The new command also deviates in behavior from tsh proxy ssh in that,
for the moment, it requires users to explicitly dictate whether
tls routing, alpn connection upgrades instead of guessing by making a
call to webapi/ping. This again turns out to be quite resource
intensive when tbot is used as an OpenSSH ProxyCommand for an ansible
playbook.

In the future tbot can look this information up out of band and store
it in the proper location so that tbot ssh-proxy-command can consume
it directly without users needing to provide it. The behavior as is
provides a path toward the future while also allowing users to gain
the performance improvements now.

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2024-05-10 21:05:47 +00:00
Gabriel Coradoandrosstimothy 55e2ea204f Implement debug service and its CLI commands (#39865)
* feat: debug service

* fix(service): lint and test assertion

* refactor: code review suggestions

* chore(service): update change log level log message

* fix(service): wrong error assertion

* fix(service): unable to set trace log level

* chore(utils): rename SupportedLogLevelsString

* refactor(teleport): change `seconds` default value

* fix(teleport): remove trailing line on profiles file

* chore(teleport): add profile examples

* refactor(service): use marshal/unmarshal log level functions

* fix(teleport): fix tarball file timestamps

* refactor: move debug service + constants to a separate package

* test(debug): move request to a helper

* chore(debug): remove leftover file

* chore(log): typo

* refactor: move package from lib/debug to lib/srv/debug

* refactor: code review suggestions

* fix(service): socket file consistency

* test(common): use one temporary directory per socket test

* chore(tool): update debug service connection error message

* refactor(debug): use enhanced serve mux

* chore(teleport): fix usage examples

* Apply suggestions from code review

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

* refactor: code review suggestions

* refactor(debug): move marshal/unmarshal text log level to debug

* refactor: code review suggestions

* refactor: move debug service client to lib/client/debug/

* refactor: code review changes

* feat(debug): progress on collect profiles

* refactor: code review suggestions

* chore(gomod): update

* fix(debug): set log level validations

* refactor(debug): move client interface

* feat(debug): add limit reader for collect profiles

* refactor(debug): remove progress bar

* Revert "chore(gomod): update"

This reverts commit 8dbebbf69f.

* refactor: remove debug service endpoints constants

* test(service): fix wrong constant

* refactor(debug): remove collect profiles limit reader

* chore(debug): make client struct public

* refactor(debug): change collect time to 0

* test(service): deflake test

* test(service): add missing auth config

* test(debug): fix missing assertion

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2024-05-07 19:41:55 +00:00
Jakub NyckowskiandTiago Silva bc53a8235c Add Crown Jewel resource (#40914)
* Update labels datatype in Teleport crownjewel proto

This commit modifies the labels from a map to repeated TeleportLabel in CrownJewel proto, and accordingly updates the getter function in proto generated code. The newly introduced TeleportLabel type contains a Key and repeated values for improved flexibility.

Clean up

Update and restructure CrownJewel service proto

The code modifications include renaming and restructuring several types and altering various functions in the CrownJewel service proto. Major changes involve renaming DeleteCrownJewel

Rename 'kind' to 'kinds' in crownjewel API

This commit changes the 'kind' field to 'kinds' in the crownjewel API to better reflect its purpose of holding multiple resource types. Changes are made across several files - 'crownjewel.go', 'crownjewel.pb.go' and 'crownjewel.proto'.

After rebase fixes

Remove CrownJewel type from several files

This commit represents the removal of the CrownJewel type from several files. CrownJewel type references are deleted in certain Go files, and imports of CrownJewel in multiple files are being adjusted. The specifics of why this type is removed is not evident from the diffs, but the deletions will affect the related functionalities.

Add CrownJewel update functionality

This update enables the 'UpdateCrownJewel' functionality. If a 'CrownJewel' resource already exists, it can now be updated instead of returning an error. This enhances flexibility when dealing with resource management. It also introduces the ARN field into the 'AWSMatcher' service.

Update CrownJewel service with pagination and improve matchers

This update adds pagination to the CrownJewel service for more efficient data handling. It also improves the matching capabilities with the inclusion of Teleport and AWS matchers and allows for selective querying with these matchers. Additionally, it includes various changes to structure and naming for better clarity and ease of use.

Refactor CrownJewel protos to use ResourceHeader

This refactoring replaces the previous structure of CrownJewel proto's fields Kind, Sub_kind, Version, and Metadata with a single object called Header (ResourceHeader). It simplifies the code structure and harmonizes it with other protos. Now, Header contains the essential attributes that were previously distributed across multiple separate fields.

Add GetCrownJewels method to cache and accessgraph

The function GetCrownJewels has been added to the cache and the accessgraph. It retrieves all CrownJewel instances from the cache. Additionally, CrownJewel retrieval functionality has been removed from auth server and existing usages have been refactored.

Implement Crown Jewel creation feature

Updated the method `createCrownJewel` in the resources command to handle Crown Jewel creation. Introduced a new gRPC service `crownjewelv1` to handle client-server interactions for Crown Jewel objects. Crown Jewel expiry configuration has now also been enabled.

Add missing files

I have no words...

Update authentication and event handling

Refactored the argument from 'auth.ClientI' to '*auth.Client' in 'createCrownJewel' function in 'resource_command.go'. Removed unused import 'durationpb' in 'auth_with_roles.go'. Added a new event code 'AccessGraphAccessPathChangedCode' in 'codes.go' and 'AccessGraphAccessPathChanged' in 'api.go' for better monitoring and logging of access path changes.

Add access path changed event and relevant changes.

 update api

add grpc

update api

add cache support

add protos

* Fixes after rebase

* Refactor Crown Jewel resource methods

Updated API methods related to the Crown Jewel resource to improve clarity and consistency. Renamed `GetCrownJewels` to `ListCrownJewels`, added pagination parameters, and ensured uniform handling of the Crown Jewel resource across different parts of the codebase. Updated relevant comments for better code understanding.

* Removed CrownJewel converter, updated CrownJewel references

This commit removes the CrownJewel converter and updates references from the old CrownJewel type to the new protobuf-defined CrownJewel type, streamlining the codebase. The commit also disables CrownJewel deletion since it is not supported yet. Some minor errors were fixed regarding CrownJewel resource names.

* Implement Crown Jewel deletion functionality

The crown jewel deletion feature has been enabled by uncommenting and simplifying the code block. Now, the delete action is directly performed on the specific 'crown jewel' mentioned based on its name. The previously unsupported action returns an informative success message after the deletion.

* Refactored function 'allCombinations' and added authorization checks

Moved 'allCombinations' function into 'utils' package, renamed it to 'Combinations', and updated its references in 'dbobjectimportrulev1' and 'dbobjectv1' tests. Additionally, introduced admin authorization checks to 'CreateCrownJewels', 'UpdateCrownJewels', and 'DeleteCrownJewels'. Created corresponding tests for these changes.

* Add CrownJewel service to cache tests

The CrownJewel service has been added to the cache test file. The service creation is implemented and assigned to new fields in multiple methods within the cache tests. A new test function `TestCrownJewel` has also been added to validate CRUD operations for the service.

* Add access path changed event and update Crown Jewel tests

Added a new event code for when an access path changes in the access graph, and introduced new API calls to handle these situations. Also, updated crown jewel related tests and fixed copyright year in several files.

* Update protobuf import path

The protobuf import path was updated from "github.com/golang/protobuf/proto" to "google.golang.org/protobuf/proto" to ensure correct use and to prevent potential issues, while maintaining functionality in crown_jewels.go.

* Refactor CrownJewel and AccessGraph services

This commit optimizes the ListCrownJewelsResponse in the CrownJewel service by directly assigning the response instead of using an extra loop. Additionally, the EventsStream in the AccessGraph service and related tests have been updated to EventsStreamV2, reflecting the implementation of new versions of these methods.

* Add CrownJewel resource in access controls and tests

In both the cache test and access control files, CrownJewel resource has been included. This provides the system's ability to manage and test CrownJewel resources. Additionally, it allows the handling of CrownJewel resources in client events.

* Simplify implementation

* Update copyright dates and add license headers

Updated the copyright dates in several files to reflect the new year. Additionally, license headers have been added to some files where they were previously missing, ensuring the proper copyrights and GPL notice are visible.

* Refactor CrownJewel codebase for better readability

Fixed various typographical errors in CrownJewel's related functions and removed a TODO comment. Improved function and function calls' names that were incorrectly referring to different modules, making the code easier to read and understand across different CrownJewel services.

* Add validation for Teleport and AWS matchers in service

The validation has been added for Teleport and AWS matchers in the service layer to ensure that essential details are not missed when setting matchers. This includes checks to ensure that kinds and labels for Teleport, and types and tags for AWS matchers are properly set.

* gci

* Add CrownJewel update functionality and refactor related services

This commit adds the ability to update a CrownJewel resource within the ResourceCommand. It also includes refactoring of related services, condensed code logic, and improved utilization of existing methods for marshaling/unmarshaling CrownJewel. Specific changes in service.go and crown_jewels.go files have reduced code redundancy and enhanced the code structure.

* Relocate and update crown_jewels_test file

This commit moves the crown_jewels_test from the local to the services library and adds test cases for unmarshalling Crown Jewels data. Also, import statements for labelv1 and utils were introduced to support these changes.

* Update crown jewels test with AWS matchers

Revised the crown jewels test file by including AWS matchers section in the CrownJewel object. The change ensures to specifically match AWS infrastructure following certain parameters, thus enhancing the specificity and flexibility of our matchers. Apart from this, minor reordering of objects has also been done for better code organization.

* Added upsertCrownJewel function and related proto message

The commit adds the UpsertCrownJewel function in the service.go file, which enables upsert operations on crown jewel resources. Alongside, the UpsertCrownJewelRequest proto message is added to the crownjewel_service.pb.go file to handle such requests.

* Refactor CrownJewelsClient to use upsert

This change refactors the CrownJewelsClient to use the upsert method when the force flag is on. The code has been streamlined by eliminating the need for 'already exist' error checking and separate create and update methods.

* Add GetCrownJewel functionality and refactor validation

A GetCrownJewel function has been added to the Service, which retrieves a specific CrownJewel resource. Also, the CrownJewel validation process has been refactored, moving the validateCrownJewel function from service.go into the crownjewel library and renaming it to ValidateCrownJewel. These changes improve modularity and code organization.

* Add VerbCreate check and test for CrownJewel validation

The checkAccessToKind function now also checks for the VerbCreate permission. Additionally, a new test file, object_test.go, was added to validate the functionality of the CrownJewel object. This includes various validation checks such as "NilCrownJewel", "ValidCrownJewel", "MissingMatchers", among others.

* Refactor CrownJewel resource handling and validation

The codebase was updated to improve CrownJewel resources handling. This includes modifications to list, get, create, update, upsert, and delete functions in several files. Additionally, a validation function has been implemented for CrownJewel objects, ensuring required fields are present. Depreciated logger service has also been removed.

* Add cache implementation to CrownJewel service

The CrownJewel service has been enhanced by integrating it with cache. The main changes include adding "Cache" as part of ServiceConfig and using cache to fetch crown jewels instead of directly using the backend services. The cache interface with the methods "ListCrownJewels" and "GetCrownJewel" has been added to handle these operations.

* Add Cache to service configuration in crownjewelv1 tests

In this commit, we added the Cache field to the service configuration used in the tests for the crownjewelv1 service. This ensures that the service configuration used in the tests matches the expected real-world configuration.

* Update CrownJewelsService to use ConditionalUpdateResource

This commit changes the CrownJewelsService's `UpdateCrownJewel` method to use the `ConditionalUpdateResource` method instead of the `UpdateResource` method. This change will provide a more appropriate update strategy for the specific needs of the CrownJewelsService.

* Replace 'Cache' with 'Reader' in crownjewel service & remove DeleteAllCrownJewelsRequest

The 'Cache' in crownjewel service has been replaced with 'Reader' to improve code readability and to match with its functionality. Also, the DeleteAllCrownJewelsRequest functionality was removed as it posed a high risk potential for data loss and it wasn

* Update tests for Crown Jewel service

This commit updates the test suite of the Crown Jewel service. An object is fetched from the backend before updating its expiry time, ensuring the revision is populated. In addition, a new test is introduced to handle the scenario where the revision is missing when updating a Crown Jewel.

* Refactor protobuf marshaling with utils

This commit replaces the usage of the `protojson` method for marshaling and unmarshaling protobuf objects in `crown_jewel.go` with the `FastMarshal` and `FastUnmarshal` methods from `utils`.
protojson is failing to unmarshal resources.

* Update CrownJewel test and serialization methods

Updated the test condition in crown_jewels_test.go to use Proto.Equal for object comparisons. Also, swapped out the FastMarshal and FastUnmarshal methods with protojson's Marshal and Unmarshal in the CrownJewels service.

* Add missing license

---------

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
2024-05-07 15:48:24 +00:00
Brian Joerger 8c328a880b MFA for App Access - tsh proxy app and Teleport Connect (#40857)
* Add key.DBTLSCert and key.AppTLSCert helper methods.

* Add TSH_APP_LOCAL_PROXY user certs requester option.

* Break up app login into multiple methods.

* Generalize cert checker local proxy middleware and add an app cert implementation.

* Use AppCertChecker for tsh proxy app.

* Add test check for proxy mfa certs being kept off disk.

* Apply changes to Teleport Connect.

* Addressed bl-nero's comments.

* Address comments from ravicious.

* Add proxy app cert ttl test.

* Restore v15 fallback for tsh proxy app session creation; Minor naming refactors.

* Add cluster flag to app logout.

* Refactor teleterm test to cleanup session MFA requirement.

* Address comments.
2024-05-06 19:29:53 +00:00
Nic Klaassen 1464e753b8 [vnet][0] setup virtual netstack (#40889)
* [vnet] setup virtual netstack

* remove unused context

* better goroutine and error handling

* remove CGNAT constant

* remove promiscuous mode and unused param

* make sure to complete TCP request

* don't stash context

* fix err handling in test

* rename error

* expand comment on test network stack
2024-04-30 01:09:09 +00:00
Forrest 14605bafab filter expired requests from cache reads (#40858) 2024-04-26 18:24:38 +00:00
Marco André DinisandRafał Cieślak 774b54ae5c Add AWS AccountID to IAM Roles in AWS App Access (#40657)
* Add AWS AccountID to IAM Roles in AWS App Access

* add story

* Use named export

---------

Co-authored-by: Rafał Cieślak <rafal.cieslak@goteleport.com>
2024-04-25 07:33:59 +00:00
Zac Bergquist 8cd1c429f5 Fix up some poor wording (#40832)
Closes #40294
Closes #39172
2024-04-23 22:01:41 +00:00
Marco André Dinis db726c0025 Allow dynamic AWS Session provider (#40553)
* Allow dynamic AWS Session provider

Up until now, all the AWS Sessions were generated using the ambient
credentials.

This PRs changes this and allows for custom AWS Session Providers.
This will allow the Session to be created from an Integration.

Another PR will be created where this is used to allow AWS OIDC to be
used as an AWS Session Provider.

* typo
2024-04-22 09:36:02 +00:00
Gavin Frazar 6e9bc6a44c increase app access max http request size to 70MiB (#40242)
* increase app access max http request size to 70MB

* move request body limiting into handlers

* shim original behavior with custom reader wrappers

* speed up aws handler tests
2024-04-19 22:30:26 +00:00
rosstimothy 5b016b97f3 Enrich slog records with tracing identifiers (#40533)
* Enrich slog records with tracing identifiers

* fix: remove IsRecording check
2024-04-19 14:06:27 +00:00
rosstimothy 9390ca6f96 Add a deferred slog.Handler for use in package global variables (#40658)
The new packageHandler allows global slog.Loggers to be created
with attributes and groups that are not expanded until runtime.
This allows the data to be formatted with a custom slog.Handler
which is set via slog.SetDefault instead of the default logger
provided by log/slog.

Closes #40629
2024-04-19 13:14:39 +00:00
Nic Klaassenandrosstimothy 680ac535ce fix: return OpaqueAccessDenied for NotFound remote cluster errors (#40571)
* fix: return OpaqueAccessDenied for NotFound errors

This commit modifies OpaqueAccessDenied to return an identical generic
NotFound error whether the input error is NotFound or AccessDenied.
The commit also updates all call sites of OpaqueAccessDenied to use it in
the paths where there is any error fetching the resource as well as when
access is denied.

It doesn't do much good to return AccessDenied errors as NotFound, if
they don't match the NotFound error you would get if the resource really
didn't exist.
It's trivial to tell the errors apart and discover the existence of a
resource you shouldn't be allowed to access.
The commit attempts to mitigate that issue and properly hide the
existence of resources the user should not be allowed to list.

* remove changes unrelated to remote clusters

* improve doc comment

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

* make sure gRPC errors match

* fix integration test

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2024-04-18 19:01:01 +00:00
Forrest e0850043fe deflake genmap test (#40437) 2024-04-11 16:25:58 +00:00
Forrest 776cf202c9 add genmap helper (#39916) 2024-04-08 22:28:33 +00:00
rosstimothy a0b67f8d8b Update slog json handler to prefer fmt.Stringer over json marshaling (#40019)
Builds on https://github.com/gravitational/teleport/pull/39974 to
prefer writing a single string instead of a json object to logs. This
more closely follows the behavior of the text formatter which
will output strings. The primary motivation is to ensure that no
secrets or unwanted items of a struct make it into json logs because
it is converting an object differently than the text handler.

There are two other options to avoid this, but both rely on doing
the right thing when adding an attribute, which may be overlooked or
forgotten and ultimately not noticed because only text ouput was
tested with.

1) Call .String() directly on the attribute, but this goes against
 the performance guidance in the slog docs.

2) Wrap the attribute in a logutils.StringerAttr which follows the
 recomendations in the slog docs:

> If you want to avoid eagerly paying the cost of the String call
> without causing the handler to potentially inspect the structure
> of the value, wrap the value in a fmt.Stringer implementation
> that hides its Marshal methods.
2024-04-01 13:50:43 +00:00
Mike Jensen d0a722d93b Replace UnixShellQuote with shsprintf.EscapeDefaultContext from github.com/google/safetext (#40046)
This change is a change in how we are handling the untrusted input.  Instead of adopting a strategy of quoting (which was incomplete), this instead escapes any special characters.

Although github.com/google/safetext is new, and without any current tags for us to reference, I believe it would be better to reference their implementation than to update the UnixShellQuote to handle the newly identified cases.
2024-03-29 21:49:07 +00:00
rosstimothy 6522669824 Update slog json handler to output error text (#39974)
The default slog json handler attempts to format attributes with
json.Marshal instead of a string representation, which resulted in
errors being output as json objects instead of just the message.

```
"error":{"error":{"message":"Unable to communicate with the Teleport Auth Service"}}
```

In order to restore json output to contain only the error message
instead of the entire object special handling is done in our slog
handler wrapper that replaces the error object with the message.
2024-03-28 21:57:49 +00:00
rosstimothy 197a7d8863 Improve performance of resource parsing via predicate expressions (#39929)
The existing resource parser was converted to use typical under
the hood. Aside from the type safety improvements the making the
switch allows a single predicate expression to be parsed once and
evaluated per resource. The previous parser worked backwards, it
created a parser per resource with the same expression which lead
to elevated memory consumption and poor performance.

An additional bug was fixed that prevented predicate filtering from
working properly with the unified resource API due to applying
predicates prior to filtering by kind. This resulted in queriers
for server specific things (resource.spec.hostname) to fail even
when only the server resource was specified in the resource kinds.

Benchamrk results for the changes in this commit compared to master
show a 75% reduction in the test time and a 96% reduction in allocations
during the tests.

```bash

$ benchstat e77e5e080b1848da830a9030d43c38be55a5b8d5.txt 8eff752a93dfe96225a71431af829015e83400fa.txt
goos: darwin
goarch: arm64
pkg: github.com/gravitational/teleport/lib/auth
                                              │ e77e5e080b1848da830a9030d43c38be55a5b8d5.txt │ 8eff752a93dfe96225a71431af829015e83400fa.txt │
                                              │                    sec/op                    │        sec/op         vs base                │
ListUnifiedResourcesFilter/labels-12                                            73.88m ±  1%            64.74m ± 6%  -12.37% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_path-12                                   294.06m ± 20%            74.83m ± 5%  -74.55% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_index-12                                  307.63m ±  4%            76.32m ± 4%  -75.19% (p=0.000 n=10)
ListUnifiedResourcesFilter/search_lower-12                                      130.7m ±  5%            130.5m ± 4%        ~ (p=0.971 n=10)
ListUnifiedResourcesFilter/search_upper-12                                      147.4m ±  5%            138.7m ± 2%   -5.87% (p=0.003 n=10)
ListUnifiedResources/simple_labels-12                                            1.748 ±  2%             1.744 ± 2%        ~ (p=0.631 n=10)
geomean                                                                         246.6m                  150.6m       -38.93%

                                              │ e77e5e080b1848da830a9030d43c38be55a5b8d5.txt │ 8eff752a93dfe96225a71431af829015e83400fa.txt │
                                              │                     B/op                     │         B/op          vs base                │
ListUnifiedResourcesFilter/labels-12                                            735.2Ki ± 0%           724.6Ki ± 1%   -1.44% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_path-12                                  238.873Mi ± 0%           7.585Mi ± 0%  -96.82% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_index-12                                 238.869Mi ± 0%           7.587Mi ± 0%  -96.82% (p=0.000 n=10)
ListUnifiedResourcesFilter/search_lower-12                                      16.77Mi ± 0%           16.77Mi ± 0%        ~ (p=0.436 n=10)
ListUnifiedResourcesFilter/search_upper-12                                      16.78Mi ± 0%           16.76Mi ± 0%        ~ (p=0.052 n=10)
ListUnifiedResources/simple_labels-12                                           1.272Gi ± 0%           1.273Gi ± 0%        ~ (p=0.739 n=10)
geomean                                                                         49.67Mi                15.69Mi       -68.41%

                                              │ e77e5e080b1848da830a9030d43c38be55a5b8d5.txt │ 8eff752a93dfe96225a71431af829015e83400fa.txt │
                                              │                  allocs/op                   │      allocs/op        vs base                │
ListUnifiedResourcesFilter/labels-12                                             11.45k ± 0%            11.41k ± 0%   -0.37% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_path-12                                    4962.0k ± 0%            161.5k ± 0%  -96.75% (p=0.000 n=10)
ListUnifiedResourcesFilter/predicate_index-12                                   4812.0k ± 0%            161.5k ± 0%  -96.64% (p=0.000 n=10)
ListUnifiedResourcesFilter/search_lower-12                                       161.6k ± 0%            161.6k ± 0%        ~ (p=0.419 n=10)
ListUnifiedResourcesFilter/search_upper-12                                       161.7k ± 0%            161.6k ± 0%        ~ (p=0.116 n=10)
ListUnifiedResources/simple_labels-12                                            23.70M ± 0%            23.70M ± 0%   +0.01% (p=0.019 n=10)
geomean                                                                          743.7k                 238.5k       -67.93%
```
2024-03-28 17:28:52 +00:00
Yassine Bounekhla 4b4fa81d01 implement notification sortcaches (#39616) 2024-03-27 13:40:05 +00:00
rosstimothy bf270a124d Allow typical parsers to optionally support dynamic values (#39765)
Provides an opt-in mechanism to allow parsers to support dynamically
resolving variables at runtime. While this defeats some of the
static compile type benefits that typical guarantees, it is required
to allow existing parsers to be converted to use typical.

The existing resource parsers allow searching for variabls by their
fully qualified path. For example, the hostname of a server may
be quiered via `resource.spec.hostname`. In order to support this
typical could use some reflection to automatically add variables
to every nested field but that would be complicated and expensive.

Instead the ParserSpec can now be configured with
`GetUnknownIdentifier`, which allows creators of the parsers to
have full control over how a dynamic variable is resolved. The
parser prevents any dynamic resolution if the value is not configured
to limit the unsafe behvior to only parsers that explicitly opt in.
2024-03-27 13:07:47 +00:00
Marco André Dinis 455632e28a EC2 Auto-Discovery: EICE support (#35504)
* AutoDiscover: add support for EICE nodes

* ignore openssh nodes when updating labels from serverinfo

* downcase imports

* improve comment on why we need account/instance and subkind

* add applyovertime method

* skip nodes that wont expire in the near future

* create helper functions
2024-03-26 16:16:20 +00:00
Mike Jensen b0992936b8 Quote user supplied inputs provided to scripts to avoid RCE (#39644)
* Quote user supplied inputs provided to scripts to avoid RCE

This change introduces the func `utils.UnixShellQuote` which will quote any inputs which could potentially allow execution or script escape.
This is utilized to ensure that scripts produced from a potential Phishing link could not contain code execution which may expose a user.

* awsAccessGraphOIDCSync: Ensure role parameter is quoted correctly

* join_tokens: Move shell quote to `getJoinScript` rather than where parameters are extracted

This will increase safety moving forward, but it requires a more conservative quoting strategy.
2024-03-26 14:47:19 +00:00
rosstimothy 8e692a1d4a Make slog attributes output the same content regardless of format (#39428)
* Make slog attributes output the same content regardless of format

There were a few instances of fmt.Stringers being passed to slog
as attributes to delay their evaluation as per the performance
considerations of slog: https://pkg.go.dev/log/slog#hdr-Performance_considerations.
However, this resulted in the json handler emitting different
content since they check to see if attributes are json.Marshalers
and not fmt.Stringers. To rectify the situation, a new slog.LogValuer
implementation was added that wraps a fmt.Stringer so that attributes
can be lazily constructed while producing the same output no matter
the log output format.

* fix: wrap identity and correct typo
2024-03-18 18:32:52 +00:00
Andrew Burke 491130b20c Add remote port forwarding for Teleport nodes (#38828)
* Add remote port forwarding for Teleport nodes

This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.

* Fix windows build
2024-03-15 22:58:36 +00:00
Marco André Dinis 64ad6ba632 AWS OIDC IdP Configuration: support S3 buckets as provider (#39026)
This PR adds support for setting the AWS OIDC Integration with an S3
bucket as issuer.
2024-03-15 22:11:25 +00:00
rosstimothy df76ec95cd Bump github.com/gravitational/trace from 1.3.1 to 1.4.0 (#39292)
* Bump github.com/gravitational/trace from 1.3.1 to 1.4.0

## Changelog
- Bump google.golang.org/grpc from 1.43.0 to 1.53.0 by @dependabot in #94
- Bump golang.org/x/net from 0.8.0 to 0.17.0 by @dependabot in #100
- Bump google.golang.org/grpc from 1.53.0 to 1.56.3 by @dependabot in #101
- Bump golang.org/x/crypto from 0.14.0 to 0.17.0 by @dependabot in #105

## Breaking Changes
- Remove logrus dependency by @rosstimothy in #107
- Remove references to UDP logrus hook from README by @rosstimothy in #108

Full Changelog: https://github.com/gravitational/trace/compare/v1.3.1...v1.4.0

* remove final references to removed trace functionality

* fix: formatter error handling
2024-03-15 19:51:53 +00:00
Reed Loden 23c67d4c16 Re-enable AWS IMDSv1 fallback (#39363)
It was discovered that some customers' EKS clusters did not have their IMDSv2 hop limits
set correctly, causing requests for key functionality to attempt IMDSv1 fallback and failing.

For now, re-enable IMDSv1 fallback by way of removing the explicit disabling of
`EC2MetadataEnableFallback` until better documentation, error handling, and other work
can be done to inform customers that they need to correctly set their IMDSv2 hop limits.
2024-03-14 18:12:50 +00:00
rosstimothy 1aec5414f1 Replace constants from trace with equivalents defined in teleport (#39307)
* Remove logging from circuit breaker

The logging is never output, and if it was would be very verbose.
Instead of dropping the level down to trace the logger is removed
entirely.

* Add constants from trace library

The logging functionality in trace is being removed in an upcoming
release. To prepare the logging component keys are copied from trace
into teleport.

* Convert trace.ComponentFields to teleport.ComponentFields

* Replace trace.Component with teleport.ComponentKey

* Replace trace logging constants
2024-03-14 13:04:29 +00:00
Trent Clarke 360af371c6 Extends SyncMap with new utility methods (#39108)
* Extends SyncMap

Adds some useful utility methods to the the SyncMap class. The
motivating example for these additional methods is the Okta reconciler,
which is currently using several map+mutex pairs.

* Update sync_map.go
2024-03-12 00:22:10 +00:00
980da79a84 kube: Return errors when users aren't allowed to list resources (#38029)
* kube: Return errors when users aren't allowed to list resources

Previously to this commit, if the user was denied to list resources from
a certain namespace, Teleport would return an empty list instead of
returning an error if it's impossible for the request to match any
resource in that namespace.

This commit returns an error for cases where the role's
`kubernetes_resources` denies any resource to be returned. This is a
small nit to incorporate some customer expectations.

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

* Update lib/utils/replace.go

Co-authored-by: Hugo Shaka <hugo.hervieux@goteleport.com>

* handle code review suggestions

* Update lib/utils/replace.go

Co-authored-by: Anton Miniailo <anton@goteleport.com>

* fix test names

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Co-authored-by: Hugo Shaka <hugo.hervieux@goteleport.com>
Co-authored-by: Anton Miniailo <anton@goteleport.com>
2024-02-27 00:38:32 +00:00
Forrest 44ef26673a add sortcache helper (#38391) 2024-02-23 19:20:30 +00:00
Zac Bergquistandrosstimothy 41fbc7ba2d Fix TestReadEnvironmentFile on macOS (#38022)
* Fix TestReadEnvironmentFile on macOS

This test writes sample data to a temporary file and then tries to
parse it. In #34177 we disallowed reading the environment file from
a symlink, but the Go utilities we use to create temp files end up
using symlinks on macOS.

Fix this by breaking out the core functionality such that it only
requires an io.Reader instead of an os.File.

* Use consistent language in log output

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

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2024-02-14 00:48:11 +00:00
Andrew Burke b352c13405 Add LoadAndDelete and Range to utils.SyncMap (#38046)
This change adds the LoadAndDelete and Range methods to utils.SyncMap,
which function the same as their sync.Map counterparts.
2024-02-12 19:58:10 +00:00
Alan Parra 22b371f869 chore: Bump golangci-lint to v1.56.0 (#37854)
* chore: Bump golangci-lint to v1.56.0

* Use only enable linters for testifylint

* Fix various testifylint offenders

* Fix testifylint offenders in api/
2024-02-07 19:54:00 +00:00
rosstimothy b7318b5c7e Enable errorlint via golangci-lint (#37669)
Adds the new linter and configures it to prevent direct error
comparisions and type assertions in favor of errors.Is and errors.As.
All current violations caught by the linter have been updated
accordingly.
2024-02-02 15:59:24 +00:00
Rafał Cieślak c9297fab0f Add fqdn to apps returned from tsh daemon (#37173)
* Move AssembleAppFQDN to lib/utils

* Update comment for endpoint_uri

* Fix comment for TotalCount, move AppServerOrSAMLIdPServiceProvider

* Remove unnecessary libclient import

* Add fqdn to apps returned from tsh daemon

* Drop "Server" from AppServerOrSAMLIdPServiceProvider, add Go doc

* Rerun make grpc
2024-01-26 09:12:28 +00:00
Nic Klaassen 38ccec52fe fix (#37241) 2024-01-25 22:01:14 +00:00
Zac Bergquist a9b30020df Improve error message when reading certs (#37263)
If you mistakenly point `cert_file` at a private key
instead of a cert, you would say a "no PEM data found"
error. This is misleading, as there is PEM data, it is
just not the correct type.
2024-01-25 21:35:25 +00:00
Zac Bergquist 4329c28960 Remove some dead code (#37269) 2024-01-25 19:42:43 +00:00
rosstimothy 1a2c712054 Extend expiry functionality of FnCache (#36620)
The FnCacheConfig now provides an optional OnExpires callback which
will be called when any item in the cache is removed due to expiry.
Eviction of expired entries used to only happen on retrieval
attempts, but this can now be triggered on demand using
(FnCache) RemoveExpired. A new Shutdown method was also added to
allow all items in the cache to be removed. If OnExpires is set
then it will be called for every item in the cache during Shutdown.
2024-01-13 14:43:07 +00:00
rosstimothy 7511eafd6c Stop populating the http reverse proxy ErrorLog (#36653)
When creating a reverse proxy the ErrorLog was being created
with the writer returned from logrus.WriterLevel. This writer
uses an io.Pipe and a goroutine to get any log messages written
from a standard log.Logger to our custom formated logrus.Entry.
The ErrorLog only ever omits output in a few very rare (hopefully)
error cases, which means we were creating an extra goroutine per
reverse proxy which in most cases would never be used to produce
any added output. Additionally, now that we are starting to support
log/slog, any output from a log.Logger will now be formatted via
our registered default slog handler. Meaning that we can still
get the benefits of producing output from the ErrorLog in the
desired format without the penalty incurred by using logrus.WriterLevel.

Partially addresses #36541.
2024-01-13 14:42:53 +00:00
Brian Joerger e7ac968247 Address deprecation TODOs for or before v15. (#36473) 2024-01-11 01:03:22 +00:00
Andrew Burke d29a6ed6c8 Add callback flag to tsh login (#35457)
This change adds the --callback flag to tsh login, which overrides
the base URL printed when doing an SSO login.
2024-01-09 19:32:58 +00:00
rosstimothy 08b8f335b0 Update slog handlers to support configured extra_fields (#36372) (#36376)
In addition to configuring output format users can configure the
fields which are included in log messages. Prior to this our slog
handlers didn't support this feature and always output the default
fields. Now, both the slog and logrus output is identical no matter
the extra_fields configuration as verified by TestExtraFields. It
was also found that due to the way the logurs json formatter was
configuring itself in CheckAndSetDefaults the timestamp was always
included in the final output even if it was not included in the
configured extra_fields.
2024-01-08 17:04:44 +00:00
rosstimothy b4df3778a1 Update slog handlers to support configured extra_fields (#36372)
* Update slog handlers to support configured extra_fields

In addition to configuring output format users can configure the
fields which are included in log messages. Prior to this our slog
handlers didn't support this feature and always output the default
fields. Now, both the slog and logrus output is identical no matter
the extra_fields configuration as verified by TestExtraFields. It
was also found that due to the way the logurs json formatter was
configuring itself in CheckAndSetDefaults the timestamp was always
included in the final output even if it was not included in the
configured extra_fields.

* fix: update component comment
2024-01-08 16:00:10 +00:00
Mike Jensen fcc97de9f9 Better control on user injected environment values (#36132)
* Better control on user injected environment values

This commit includes two changes:
  * In `environment` we expanded the list of MacOS environment values which should be filtered.  It was demonstrated that these can be used to get code execution in MacOS.
  * In `reexec` we no longer provide the cmdmsg.Environment for the `teleport exec`.  As part of the development of a9055bccd9 it was attempted to fully clear out the environment, but testing showed that to be potentially problematic.  It was believed the safest option was to use the cmd environment, however this introduces a new source of environment variables.  Because this exec happens under `root` this is particularly dangerous (even more so when combined with the missed OSX values mentioned above).  As such we now are only providing the filtered exec environment, which is a closer (but safer) option to the functionality prior to a9055bccd9.

* Update filter to exclude all DYLD_ and LD_ prefixed variables
2023-12-29 19:25:53 +00:00
Zac Bergquist 5753264917 Go 1.21 cleanup (#36044)
- Use min/max builtins over custom funcs
- Leverage sync.OnceValue instead of hand-rolled impl
2023-12-27 16:13:14 +00:00
Zac Bergquistandhorus ff9a747001 fix: typo in comment (#36032)
Signed-off-by: Zac Bergquist <zac.bergquist@goteleport.com>
Co-authored-by: horus <horus.li@gmail.com>
2023-12-27 15:04:06 +00:00