Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate EC2 clients in discovery service to AWS SDK v2 #48950

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

atburke
Copy link
Contributor

@atburke atburke commented Nov 14, 2024

This change migrates the EC2 clients used in the discovery service to use the v2 AWS SDK (and also removes EC2 from the giant shared client interface in lib/cloud).

@atburke atburke added the no-changelog Indicates that a PR does not require a changelog entry label Nov 14, 2024
@atburke atburke requested review from tigrato and greedy52 November 14, 2024 01:18
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/gravitational/trace"

"github.com/gravitational/teleport/lib/cloud"
Copy link
Contributor

@rosstimothy rosstimothy Nov 14, 2024

Choose a reason for hiding this comment

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

lib/cloud is a heavy dependency. Consider refactoring/duplicating code to keep this package as self contained as possible.

Comment on lines 229 to 235
token, err := c.AccessPoint.GenerateAWSOIDCToken(ctx, integrationName)
if err != nil {
return nil, trace.Wrap(err)
}
if integration.GetAWSOIDCIntegrationSpec() == nil {
return nil, trace.BadParameter("integration does not have aws oidc spec fields %q", integrationName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should a token be generated if the integration spec is nil? Change the order of operations here?

Suggested change
token, err := c.AccessPoint.GenerateAWSOIDCToken(ctx, integrationName)
if err != nil {
return nil, trace.Wrap(err)
}
if integration.GetAWSOIDCIntegrationSpec() == nil {
return nil, trace.BadParameter("integration does not have aws oidc spec fields %q", integrationName)
}
if integration.GetAWSOIDCIntegrationSpec() == nil {
return nil, trace.BadParameter("integration does not have aws oidc spec fields %q", integrationName)
}
token, err := c.AccessPoint.GenerateAWSOIDCToken(ctx, integrationName)
if err != nil {
return nil, trace.Wrap(err)
}

output *ec2.DescribeInstancesOutput
}

func instanceMatches(inst *ec2.Instance, filters []*ec2.Filter) bool {
func (m *mockEC2Client) DescribeInstances(ctx context.Context, input *ec2.DescribeInstancesInput, opts ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error) {
output := ec2.DescribeInstancesOutput{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
output := ec2.DescribeInstancesOutput{}
var output ec2.DescribeInstancesOutput

return aws.Config{}, trace.BadParameter("missing aws integration credential provider")
}

slog.DebugContext(ctx, "Initializing AWS config with integration.", "region", region, "integration", options.integration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
slog.DebugContext(ctx, "Initializing AWS config with integration.", "region", region, "integration", options.integration)
slog.DebugContext(ctx, "Initializing AWS config with integration", "region", region, "integration", options.integration)

return aws.Config{}, trace.Wrap(err)
}
} else {
slog.DebugContext(ctx, "Initializing AWS config from environment.", "region", region)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
slog.DebugContext(ctx, "Initializing AWS config from environment.", "region", region)
slog.DebugContext(ctx, "Initializing AWS config from environment", "region", region)

for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
return nil, trace.Wrap(err)
Copy link
Contributor

@greedy52 greedy52 Nov 18, 2024

Choose a reason for hiding this comment

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

We need to convert the SDK errors to trace errors. Multiple places check trace.IsAccessDenied and trace.IsNotFound.

Conversion example (which is ridiculously tedious):

// ConvertIAMv2Error converts common errors from IAM clients to trace errors.
func ConvertIAMv2Error(err error) error {

Copy link
Contributor

@greedy52 greedy52 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Thank you so much for the AWS config conversion!!!!!

Left one question on SDK error conversion.

This change migrates the EC2 clients used in the discovery service
to the v2 AWS SDK.
@atburke atburke force-pushed the atburke/ec2-discovery-v2-sdk branch from d3a486c to eefd522 Compare November 19, 2024 18:10
@atburke atburke enabled auto-merge November 19, 2024 18:10
@atburke atburke added this pull request to the merge queue Nov 19, 2024
Merged via the queue into master with commit 98ba4c9 Nov 19, 2024
39 checks passed
@atburke atburke deleted the atburke/ec2-discovery-v2-sdk branch November 19, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discovery no-changelog Indicates that a PR does not require a changelog entry size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants