-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
lib/cloud/aws/config/config.go
Outdated
"github.com/aws/aws-sdk-go-v2/service/sts" | ||
"github.com/gravitational/trace" | ||
|
||
"github.com/gravitational/teleport/lib/cloud" |
There was a problem hiding this comment.
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.
lib/srv/discovery/discovery.go
Outdated
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) | ||
} |
There was a problem hiding this comment.
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?
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) | |
} | |
lib/srv/server/ec2_watcher_test.go
Outdated
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{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output := ec2.DescribeInstancesOutput{} | |
var output ec2.DescribeInstancesOutput |
lib/cloud/aws/config/config.go
Outdated
return aws.Config{}, trace.BadParameter("missing aws integration credential provider") | ||
} | ||
|
||
slog.DebugContext(ctx, "Initializing AWS config with integration.", "region", region, "integration", options.integration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
lib/cloud/aws/config/config.go
Outdated
return aws.Config{}, trace.Wrap(err) | ||
} | ||
} else { | ||
slog.DebugContext(ctx, "Initializing AWS config from environment.", "region", region) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.DebugContext(ctx, "Initializing AWS config from environment.", "region", region) | |
slog.DebugContext(ctx, "Initializing AWS config from environment", "region", region) |
lib/srv/server/ec2_watcher.go
Outdated
for paginator.HasMorePages() { | ||
page, err := paginator.NextPage(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) |
There was a problem hiding this comment.
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):
teleport/lib/cloud/aws/errors.go
Lines 91 to 92 in 3db72b0
// ConvertIAMv2Error converts common errors from IAM clients to trace errors. | |
func ConvertIAMv2Error(err error) error { |
There was a problem hiding this 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.
94c1158
to
d3a486c
Compare
This change migrates the EC2 clients used in the discovery service to the v2 AWS SDK.
d3a486c
to
eefd522
Compare
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).