Commit Graph
165 Commits
Author SHA1 Message Date
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
Gavin Frazar ee119ea6d6 Remove remaining db and discovery AWS SDK imports (#51628)
This eliminates all remaining references to AWS SDK v1 in the
lib/srv/db/... and lib/srv/discovery/... packages.
Most of the changes are simply to remove dead code.
2025-01-30 23:06:09 +00:00
Gavin Frazar b69d49b2a2 Simplify lib/utils/aws (#51627)
This eliminates the SigningService in favor of a free function
SignRequest, which eliminates AWS credential loading and simplifies the
AWS utils package.
In the process of doing this refactor, the AWS app handler has been
changed to use AWS SDK v2 to load its credentials as well.
2025-01-30 20:14:45 +00:00
Gavin Frazar 5fb00a4aee Migrate AWS session to SDK v2 (#51626)
Only DynamoDB and AWS MongoDB Atlas depended on GetAWSSession, and the
migration for these packages was trivial.
Since this was the last AWS method in lib/cloud/clients, the vast majority
of the changes are to remove dead code.
2025-01-30 16:51:33 +00:00
Gavin Frazar a9be7dbfbb Migrate AWS STS client to AWS SDK v2 (#51573) 2025-01-29 21:16:56 +00:00
Gavin Frazar 46c5e1901c Migrate AWS SecretsManager clients to AWS SDK v2 (#51150) 2025-01-29 20:04:36 +00:00
Gavin Frazar e936ab4fb4 Migrate AWS OpenSearch clients to AWS SDK v2 (#51135) 2025-01-28 23:33:21 +00:00
Zac Bergquist d71293f964 Replace usages of x/exp/maps with stdlib maps package (#51448) 2025-01-28 14:54:40 +00:00
Marco Dinis d3042d5022 GCP Server AutoDiscover: only log when the script fails (#51117)
* GCP Server AutoDiscover: only log when the script fails

When running Auto Discover for GCP VMs, teleport always logs the output
in debug level.

Now, it only logs the stdout/stderr when the installation fails.
It also adds some context on which VMs it failed and the log level is
now Error.

* Log once per RunCommand invocation
2025-01-24 16:58:01 +00:00
Tiago Silva 32076b7668 [gke] skip hard error when client misses permissions for some projects (#51344)
This PR fixes a behavior problem that results in GKE discovery to
completely fail when the client misses permissions in some of the
discovered projects.

If the client misses list permissions for projectID 1 but has the
required permissions for projectID 2, the discovery service should
continue with the projectID 2 discovery and skip the failing one.

Fixes #48101

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2025-01-22 19:28:37 +00:00
Gavin Frazar 48834e2a31 Migrate S3 and KMS in lib/cloud/clients to SDK v2 (#51142) 2025-01-21 20:55:14 +00:00
Gavin Frazar 5f47d30cd4 Migrate AWS MemoryDB clients to AWS SDK v2 (#51052) 2025-01-21 18:10:26 +00:00
Gavin Frazar cf15fa349c Migrate IAM in lib/cloud/clients to SDK v2 (#51145) 2025-01-17 18:22:28 +00:00
Gavin Frazar a9e75b852a Migrate AWS ElastiCache clients to AWS SDK v2 (#51050)
* Migrate AWS ElastiCache clients to AWS SDK v2

* add getEngineFn for db tests

* add ElastiCache engine label
2025-01-17 01:36:38 +00:00
Gavin Frazar 5240a4d83b migrate AWS Redshift Serverless to AWS SDK v2 (#50964) 2025-01-16 22:36:56 +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
Matt BrockandTiago Silva 47f4498b76 Adding the Azure sync module functions along with new cloud client functionality (#50366)
* Protobuf and configuration for Access Graph Azure Discovery

* Adding the Azure sync module functions along with new cloud client functionality

* Forgot to decouple role definitions fetching function from the fetcher

* Moving reconciliation to the upstream azure sync PR

* Moving reconciliation test to the upstream azure sync PR

* Updating go.sum

* Fixing rebase after protobuf gen

* Nolinting until upstream PRs

* Updating to use existing msgraph client

* Adding protection around nil values

* PR feedback

* Updating principal fetching to incorporate metadata from principal subtypes

* Updating opts to not leak URL parameters

* Conformant package name

* Using variadic options

* PR feedback

* Removing memberOf expansion

* Expanding memberships by calling memberOf on each user

* Also returning expanded principals for improved readability

* Removing ptrToList

* PR feedback

* Rebase go.sum stuff

* Go mod tidy

* Linting

* Linting

* Collecting errors from fetching memberships and using a WithContext error group

* Fixing go.mod

* Update lib/msgraph/paginated.go

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* PR feedback

* e ref update

* e ref update

* Fixing method

* Fetching group members from groups rather than memberships of each principal

* Linting

---------

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
2025-01-13 19:27:58 +00:00
Gavin Frazar aa34c34dad migrate AWS RDS services to AWS SDK v2 (#50848) 2025-01-10 22:23:38 +00:00
Guillaume J. Charmes 84956a8c8f Migrate eks discovery to aws sdk v2 (#50603)
* Remove all references to EKS sdk v1.

* Address PR comments.
2025-01-10 18:48:39 +00:00
Marco Dinis 4b2a0da91d Fix AWS ListDeployedDatabaseServices when there's no ECS Cluster (#50843)
Calling the AWS API `ecs:ListServices` with a non-existent ECS Cluster
name will return a 400 w/ ClusterNotFoundException.

The existing code was not handling that error and a raw error was
returned.

This PR changes the logic to ensure that case is handled and that the
ListDeployedDatabaseServices returns an empty list.

An alternative would be to call the ListClusters beforehand, but that
would increase the number of API calls we do to external services.
2025-01-09 09:45:41 +00:00
Gavin Frazar 20828a217d Simplify awsconfig loading (#50809)
This replaces awsconfig.WithIntegrationCredentialProvider option with the
awsconfig.WithOIDCIntegrationClient option.
This solves a chicken/egg problem with AWS config loading - callers no
longer need to load AWS config (to create a credential provider) to load
AWS config.
The OIDCIntegrationClient interface is also much simpler to implement.

This also adds default option overrides when creating an awsconfig.Cache.
For now, this is used to add an OIDCIntegrationClient when creating the
cache so that dependent callers don't have to.
2025-01-08 18:19:09 +00:00
Gavin Frazar ffacd99b28 migrate AWS Redshift services to AWS SDK v2 (#50600) 2025-01-06 21:23:44 +00:00
Gavin Frazar 40e597e19b Update awsconfig (#50561)
* Add a Cache for caching credentials, similar to SDK v1 session cache.
* Add a Provider interface that provides aws.Config
* Simplified role chaining options

Unlike our SDK v1 session cache, the SDK v2 implementation in this PR
does not include region as a cache key.
There are regional AWS STS endpoints for lower latency calls, but the
lowest latency path is to just grab credentials from the cache if we
already have them - the region they were originally taken from doesn't
matter.
2025-01-06 19:26:14 +00:00
Tiago Silva 4d3e7d3ec9 fix: access graph fails to fetch s3 bucket details (#50758)
* fix: access graph fails to fetch s3 bucket details

With SDK V1, AWS get bucket details such as policies, acls, status...
didn't require the specification of the target s3 bucket location. With
the recent changes to support newer versions of the AWS SDK, the get
bucket details started to fail with the following error:

```
BucketRegionError: incorrect region, the bucket is not in 'ap-south-1' region at endpoint '', bucket is in 'eu-central-1' region
status code: 301, request id: QS5C24H12ZV3VNM4, host id: mzVDk4010MPTCFdxyE/XwERX9W35MSge85PG+h5Jvwyvi7MhxdXLaysb2PTZCMY9r1ngBi6Gv6g=, failed to fetch bucket "cyz" acls polic
```

This PR uses `HeadBucket` to retrieve the location of the s3 bucket and
then uses the bucket location client to retrieve the s3 bucket details.

Fixes #50757

* fix tests

* handle review comments
2025-01-06 12:20:52 +00:00
rosstimothy 22fe81619b Convert lib/cloud to use slog (#50334) 2024-12-17 21:45:29 +00:00
Gavin Frazar 228c1c9f6f Rename lib/cloud/aws/config to lib/cloud/awsconfig (#50254) 2024-12-16 18:26:46 +00:00
Tiago Silva 5ab4b69336 Fixes Kubernetes Service using expired credentials (#50074)
The Kubernetes service occasionally fails to forward requests to EKS clusters or retrieve the cluster schema due to AWS rejecting the request with an "expired token" error.

EKS access tokens are generated using STS presigned URLs, which include details such as the cluster, backend credentials, and assumed roles. By default, these tokens are valid for 15 minutes, and the Kubernetes service refreshes them every $(15 - 1) / 2 = 7\text{ }minutes$.
However, our cloud SDK caches the underlying `aws.Session`, particularly those with assumed roles, for 15 minutes.

This leads to a scenario where the token is refreshed a second time at approximately 14 minutes, close to the token's 15-minute validity. If the underlying credentials expire before the next token refresh, given that they were reused from the previous query and cached since then, it  results in the Kubernetes Service considering the token valid (since it is a Base64-encoded presigned URL without knowledge about the credentials), but AWS EKS cluster rejects the request, treating the credentials as expired.

This PR adds an option to disable cache for EKS STS token signing which results in creating a session per EKS cluster sign process.

Bellow one can find the error message EKS returns.
```
2024-12-09T17:00:15Z ERRO [KUBERNETE] Failed to update cluster schema error:[
ERROR REPORT:
Original Error: *errors.StatusError the server has asked for the client to provide credentials
Stack Trace:
	github.com/gravitational/teleport/lib/kube/proxy/scheme.go:140 github.com/gravitational/teleport/lib/kube/proxy.newClusterSchemaBuilder
	github.com/gravitational/teleport/lib/kube/proxy/cluster_details.go:193 github.com/gravitational/teleport/lib/kube/proxy.newClusterDetails.func1
	runtime/asm_amd64.s:1695 runtime.goexit
User Message: the server has asked for the client to provide credentials] pid:7.1 start_time:2024-12-09T17:00:15Z proxy/cluster_details.go:210
2024-12-09T17:00:24Z ERRO [KUBERNETE] Failed to update cluster schema  error:[
ERROR REPORT:
Original Error: *errors.StatusError the server has asked for the client to provide credentials
Stack Trace:
	github.com/gravitational/teleport/lib/kube/proxy/scheme.go:140 github.com/gravitational/teleport/lib/kube/proxy.newClusterSchemaBuilder
	github.com/gravitational/teleport/lib/kube/proxy/cluster_details.go:193 github.com/gravitational/teleport/lib/kube/proxy.newClusterDetails.func1
	runtime/asm_amd64.s:1695 runtime.goexit
User Message: the server has asked for the client to provide credentials] pid:7.1 start_time:2024-12-09T17:00:24Z proxy/cluster_details.go:210
```

Changelog: Fixes an intermittent EKS authentication failure when dealing with EKS auto-discovery.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2024-12-12 22:34:03 +00:00
rosstimothy f8bfc867c6 Bump azure dependencies to latest versions (#49970)
# Updates

- github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v3 -> v6
- github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/redis/armredis/v2 -> v3
- github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 -> v6
2024-12-10 14:05:29 +00:00
rosstimothy 6c51c4e1b2 Filter while paging in GetByVMID (#49968)
This updates GetByVMID, used by azure joining, to filter by id for
each page of vms instead of filtering after accumulating _all_ vms
in memory first. While this does reduce memory consumption, the listing
process is still suboptimal in that _all_ instances in a subscription
are retrieved in response to _every_ join request.
2024-12-10 00:52:16 +00:00
rosstimothy 460ac5ea3b Use builtin tracing machinery of aws-sdk-go-v2 (#49826)
Replaces the use of go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws
with the tracing support now provided directly by the aws sdk.
See https://github.com/aws/aws-sdk-go-v2/discussions/2810 for more
details.

Some additional aws clients were also updated to include tracing
support.
2024-12-06 14:41:33 +00:00
Andrew Burke 3b41106834 Port ssm client to v2 sdk (#49733) 2024-12-04 18:57:15 +00:00
Andrew Burke 98ba4c9673 Migrate discovery EC2 clients to AWS SDK v2 (#48950)
This change migrates the EC2 clients used in the discovery service
to the v2 AWS SDK.
2024-11-19 19:02:53 +00:00
Sakshyam Shah c6c62beeac add sso:ListPermissionSetsProvisionedToAccount to StatementForAWSIdentityCenterAccess (#48496) 2024-11-06 14:20:53 +00:00
Nic Klaassen 77f531d317 eliminate hardcoded from lib/cloud/gcp (#47606) 2024-10-17 00:22:22 +00:00
Tiago Silva cfc0d3d645 [gcp] support project discovery (#47434)
* [gcp] support project discovery

This PR extends Teleport discovery service to be able to support find all GKE and VM servers in every project a user has access to.

```
discovery_service:
  enabled: true
  discovery_group: "test"
  gcp:
  - types: ["gke"]
    locations: ["*"]
    project_ids: ["*"]
    tags:
     '*': '*'
```

* simplify docs by adding examples
2024-10-14 16:50:47 +00:00
Sakshyam Shah 3eaab34ff2 feat: AWS OIDC integration role policy-preset for identity center integration (#47164)
* feat: adds a new 'policy-preset' flag to 'integration configure awsoidc-idp' command

* adapt to new awsactions

* output formatting and golden test

* run ui prettier, fix getAwsOidcConfigureIdpScriptUrl test

* comments cleanup, mend TestBuildAWSOIDCIdPConfigureScript test

* address review:
- use AwsOidcPolicyPreset in UrlAwsOidcConfigureIdp
- use NoSuchEntityException instead of EntityAlreadyExistsException in PutRolePolicy mock
- fix typo

* use empty string as unspecified value

* add optional field comment

* Merge branch 'master' of github.com:gravitational/teleport into sshah/aws-oidc-preset-policy

* Revert "Merge branch 'master' of github.com:gravitational/teleport into sshah/aws-oidc-preset-policy"

This reverts commit ad2a0904e9.
2024-10-08 15:13:40 +00:00
Gavin Frazar c74835d219 integration configure commands prompt for changes (#47224)
* integration configure commands prompt for changes

This applies to the following "teleport integration configure" subcommands:
* deployservice-iam
* eice-iam
* ec2-ssm-iam
* aws-app-access-iam
* eks-iam
* access-graph
* listdatabases-iam

These commands will now describe the actions they will take, the
resources that will be created/configured, and will by default prompt
the user to confirm the changes.

Confirmation prompt can be skipped by passing the new --confirm flag.

The confirmation prompt is enabled by default because the most common
case, if not the only case, where a user runs these commands is via an
opaque "bash -c $(curl ...)" script generated by a web UI enrollment
wizard.

* address feedback

* fix test

* pluralize only when there are multiple actions

* remove leading newline from func body

* remove extra newline in ec2 iam configure request

* improve --confirm flag description

* fix test

* remove extraneous else

* dont display escaped ssm doc for op plan
2024-10-08 00:20:14 +00:00
Gavin Frazar a3e1316260 make configure awsoidc-idp actions transparent (#46747)
Applies to the integration command that the web UI discover flows tell
users to run in AWS CloudShell to setup the AWS OIDC identity provider:
    teleport integration configure awsoidc-idp

The command describes itself, its actions, and the desired state after
it runs. It then prompts the user (by default) to confirm the action
plan before proceeding.
The confirmation prompt can be overridden with cli flag --confirm
if desired.

The IAM role it configures is no longer required to have the "ownership"
tags that teleport applies if it's created by teleport, since the user is
now prompted for confirmation before making changes.
This allows a user to configure an existing IAM role without tagging the
role for configuration by teleport.
The command will still attempt to ensure the IAM role it configures has
teleport tags, but failing to do so is only a warning.
2024-10-03 20:50:02 +00:00
Nic Klaassen 559ea705f5 eliminate hardcoded RSA from lib/srv/db (#46660) 2024-09-17 20:07:36 +00:00
Gavin Frazar 9694550f5e migrate aws configurator to sdk v2 (#46367)
* migrate aws configurator to sdk v2

* rename package imports with lowercase

* export iam client interface

* mock loading aws config

* remove underscore from test name

* remove loop var reassignment
2024-09-09 21:17:30 +00:00
Gavin Frazar 2f1abc880d update AWS IAM configurator permissions (#46053)
* add ListTags permissions for memorydb/elasticache managed users, which
  is needed to find users managed by Teleport
* remove obsolete boundary policy
* deprecate the --boundary flag
* replace dynamic iam policies with static permissions
2024-09-05 22:41:43 +00:00
Gavin Frazar 81f5b40a15 update AWS OIDC ECS task role permissions (#45880)
Add permissions to describe RDS instances and clusters so that the db
service can fetch metadata updates and check the IAM auth status of the
database
2024-08-26 23:40:39 +00:00
Marco DinisandAlan Parra eed43cffa9 Auto Discover GCP GCE: add project id label (#45737)
* Auto Discover GCP GCE: add project id label

This PR adds a new label when auto configuring the teleport.yaml for a
VM in GCP.
This new label has the project id.
We already had the project id, but it was in a protected/internal only
label and so the users couldn't see it in the WebUI.

* Update api/types/constants.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Update api/types/constants.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Update lib/srv/server/installer/autodiscover_test.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* fix var name and remove godoc from not implemented methods

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2024-08-26 08:26:23 +00:00
Marco Dinis 6e38b30353 Add ownership tags to AWS OIDC EKS Enrollment (#44736)
* Add ownership tags to AWS OIDC EKS Enrollment

This PR adds the ownership tags to the temporary EKS Access Entry
created during the EKS Enrollment.

There might happen that the user already completed the set up once, and
so they won't be asked to run the configuration script (using oneoff +
cloudshell) again. If there's a access denied, the Access Entry is
created without the tags.

With or without the tags, the Access Entry is removed after the
enrollment process.

* log message asking users to add eks:TagResource action

* fix indentation in docs

* fix new tests
2024-08-23 07:35:30 +00:00
Tiago Silva 045880f4f5 [access-graph] extract S3 bucket tags (#45364)
* [access-graph] extract S3 bucket tags

This PR extracts the AWS bucket tags by calling `GetBucketTagging`.

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

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

* add tests

* handle comments

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2024-08-16 08:21:43 +00:00
Gavin Frazar 558d71a456 update aws oidc db enrollment role permissions (#44717) 2024-07-29 22:22:04 +00:00
Krzysztof Skrzętnicki 8a8537355b Database objects periodic import (#43790)
* Add periodic import of database objects from supported databases.

A single implementation is included: for Postgres, along with necessary changes.

Also refactors SQLAdminClient interface to accept cert expiry instead of pulling that information from `tlsca.Identity`.

* fix logging, imports

* add missing license

* review feedback
- several minor changes
- apply import rules for all registered object fetchers using wrapper type
- refactor DAC to use object fetcher
- adjust tests

* add comment and missing log call

* support config overrides through unstable env vars, including disabling the service entirely

* refactoring and minor changes

- be more specific about required API for ObjectFetcherConfig
- measure scan time
- bump default scan interval
- call StopImporter from stopDatabase to fix issue with dynamic db resource updates
- add comments

* Refactor `connectAsAdmin`, add `withDefaultDatabase()` method for clarity of implementation.

* Reduce surface area for fetcher config

* make the not-implemented case less noisy by skipping the error

* lint fix

* decrease verbosity of reporting for unsupported configurations

* make `reason` field private

* move `unregisterObjectFetcher` to tests

* avoid exceedingly long lines with log calls

* correct formatting leftover from slog conversion

* tighten logic around disabled importer

if the scan interval is zero or less, the importer becomes disabled, which avoids panic from interval.New().

add some tests and comments for clarity.

* drop unused method
2024-07-25 18:47:56 +00:00
STeve (Xin) Huang f911ea67db Add teleport.dev/cluster label to AWS secrets for manging AWS redis users (#44391)
* Add teleport.dev/cluster label to AWS secrets used for managing ElastiCache/MemoryDB users

* fix lint
2024-07-23 19:26:01 +00:00
Gavin Frazar 8e7ff7efd3 add iam:CreateServiceLinkedRole to DeployService (#44194)
If the ECS service-linked role managed by AWS does not exist yet, then
when the OIDC integration calls ecs:CreateCluster it will fail.
Adding this permission will allow the API call to automatically
create the service-linked role on first use of ECS.
2024-07-16 19:57:11 +00:00
STeve (Xin) Huang 91d4360655 Amazon DocumentDB access part 2 (#43868)
* Amazon DocumentDB access part 1

* fix lint

* DocumentDB part 2

* review comments
2024-07-16 16:20:37 +00:00