Skip to content

Add configuration for cross-account AWS database-access#23158

Merged
GavinFrazar merged 7 commits intomasterfrom
gavinfrazar/support-cross-account-aws-discovery-config
Mar 24, 2023
Merged

Add configuration for cross-account AWS database-access#23158
GavinFrazar merged 7 commits intomasterfrom
gavinfrazar/support-cross-account-aws-discovery-config

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar commented Mar 16, 2023

I am splitting up PRs for the implementation of #21872 to reduce PR size.

This PR adds configuration for AWS assume_role_arn in database config and discovery matchers.
It does not add the logic that actually uses this new configuration - that will be added in PRs to follow.

This new config is available in:

  • teleport db configure create
  • teleport db start
    • I know we want to avoid adding flags to this command because we don't recommend it in our docs, but --aws-external-id was already a flag and --aws-assume-role-arn naturally pairs with that flag.
  • tctl create/edit
  • yaml config file loaded by teleport

merge base is set to the branch for #23157 which has various changes I split out for backporting and will update to master once that branch merges.

@GavinFrazar GavinFrazar added tctl tctl - Teleport admin tool aws Used for AWS Related Issues. database-access Database access related issues and PRs labels Mar 16, 2023
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/improve-aws-utils-and-database-validation branch from abbc5ca to 834bc0b Compare March 16, 2023 01:35
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/support-cross-account-aws-discovery-config branch from 5299b24 to eb0f6c6 Compare March 16, 2023 01:39
* log a warning when an invalid AWS IAM role ARN is filtered out
* add tests for nested role arn path and remove superfluous test parallelism
* add extra godoc info for BuildRoleARN
* improve mock IAM error messages
  - Failing tests' error messages were not specific enough to know what
    happened.
* refactor code to call GetAWS() once
  - Avoids constantly fetching a full copy of the AWS metadata.
  - Reduces verbosity of code.
* reuse MetadataFromRedshiftCluster in meta fetcher
  - Avoids repeating the same logic inside the fetcher.
* improve database-access DynamoDB config checking
  - Don't early return from database CheckAndSetDefaults so AWS account ID
    is checked properly, and any other future checks added will apply to
    DynamoDB as well.
* add aws utils for parsing AWS IAM roles
  - ParseRoleARN will parse an AWS ARN and verify that it is a valid
    AWS IAM Role resource
  - CheckARNPartitionAndAccount is a helper that verifies an ARN partition
    and account ID matches the caller's expectations.
* use cmp.Diff instead of require.Equal in db tests
  - require.Equal spams a lot of protobuf noise.
  - cmp.Diff yields a precise, readable diff on test failure.
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/improve-aws-utils-and-database-validation branch from 90126a8 to 0b75973 Compare March 16, 2023 23:22
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/support-cross-account-aws-discovery-config branch from eb0f6c6 to 0a629bc Compare March 16, 2023 23:44
Comment thread api/types/database_test.go
Comment thread lib/service/servicecfg/database.go Outdated
Base automatically changed from gavinfrazar/improve-aws-utils-and-database-validation to master March 17, 2023 21:27
GavinFrazar and others added 3 commits March 17, 2023 20:47
Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
* external_id does not require assume_role_arn
  for DynamoDB, Keyspaces, or Redshift Serverless
* keyspaces gives a hint that URI could not be
  derived because region was also empty
* make some error messages more consistent with
  each other regarding missing/empty fields.
Comment on lines +103 to +113
// If AWS account ID is missing, but assume role ARN is given,
// try to parse the role arn and set the account id to match.
if d.AWS.AccountID == "" && d.AWS.AssumeRoleARN != "" {
parsed, err := awsutils.ParseRoleARN(d.AWS.AssumeRoleARN)
if err != nil {
return trace.BadParameter("database %q invalid AWS assume_role_arn: %v",
d.Name, err)
}
d.AWS.AccountID = parsed.AccountID
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not a problem started by this change but ideally we should do this in api.Database's CheckAndSetDefaults so that databases created by tctl and webapi can benefit from it. (maybe the same for the TLS and AD CheckAndSetDefaults above, if we can move them to api if possible)

@smallinsky @GavinFrazar do you think if worth copying the AWS arn implementation into our api lib?
https://github.com/aws/aws-sdk-go/blob/v1.44.224/aws/arn/arn.go
It's not that much code. And if we have our own implementation, we can even enhance it with more functions we need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yeah I put it here to avoid pulling AWS sdk into our api. I have the same check in ValidateDatabase, but it just errors for empty AccountID because we don't set defaults in that function. Would definitely be a better UX for tctl and webapi if we can move these all into the api CheckAndSetDefaults.

Copy link
Copy Markdown
Contributor

@smallinsky smallinsky Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think if worth copying the AWS arn implementation into our api lib?
https://github.com/aws/aws-sdk-go/blob/v1.44.224/aws/arn/arn.go

Yea we can do that but why not just embed the aws.ARN into own custom type and add additional logic ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea we can do that but why not just embed the aws.ARN into own custom type and add additional logic ?

I think we hesitate whether to bring the whole AWS SDK dependency to api's go.mod.

Another alternative is to get aws-sdk-go-v2 without other services.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I want to just pull in aws-sdk-go-v2 since the stripped binary size change is tiny and v2 doesn't download the whole sdk when fetching dependencies, but I should move this code in another PR to get feedback from other people first. It enables only a small UX improvement for tctl and web api. I can move the TLS and AD stuff too in that PR.

@GavinFrazar GavinFrazar enabled auto-merge March 22, 2023 21:17
@GavinFrazar GavinFrazar added this pull request to the merge queue Mar 24, 2023
Merged via the queue into master with commit 7184946 Mar 24, 2023
@GavinFrazar GavinFrazar deleted the gavinfrazar/support-cross-account-aws-discovery-config branch March 24, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws Used for AWS Related Issues. database-access Database access related issues and PRs size/md tctl tctl - Teleport admin tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants