-
Couldn't load subscription status.
- Fork 353
Bump KMS and Metadata Clients to AWS SDK Go V2 #1169
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
Bump KMS and Metadata Clients to AWS SDK Go V2 #1169
Conversation
|
Hi @gargipanatula. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
This issue is currently awaiting triage. If cloud-provider-aws contributors determine this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
| signingRegion, signingMethod string | ||
| signingName string | ||
| } | ||
|
|
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.
Note: This test used to test both ValidateOverride and the endpoint/signingname/signingregion overriding functionality. Now, it only tests ValidateOverride, and checking the overrides themselves has been moved to aws_sdk_test.go since override logic is configured directly with the clients.
|
/ok-to-test |
| "fmt" | ||
| "strings" | ||
|
|
||
| awsv2 "github.com/aws/aws-sdk-go-v2/aws" |
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.
nit: i see that the aws is only use for converting pointer to values and vice versa, can we remove that usage and such that we need not use awsv2
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.
Totally agree, but I think I'll punt this to my final PR in this migration, which will be solely focused on upgrading the remaining packages (just github.com/aws/aws-sdk-go/aws and github.com/aws/aws-sdk-go/aws/awserr). Wanted to keep this PR as simple as possible for ease of review.
| return results, nil | ||
| } | ||
|
|
||
| func (s *awsSdkEC2) DescribeInstanceTopology(ctx context.Context, input *ec2.DescribeInstanceTopologyInput, optFns ...func(*ec2.Options)) ([]ec2types.InstanceTopology, 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.
I see we are moving the functionality of the https://github.com/kubernetes/cloud-provider-aws/blob/master/pkg/services/aws_ec2.go to here, can we deprecate that file or is it used somewhere else?
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.
Thanks for the catch - these have indeed been moved over so we can deprecate these files.
pkg/providers/v1/aws.go
Outdated
| instance, err := c.getInstanceByID(ctx, instanceID) | ||
| instanceIDBytes, err := io.ReadAll(instanceIDMetadata.Content) | ||
| if err != nil { | ||
| panic("unable to parse instance id") |
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.
why panic here?
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.
Ah yeah, this should probably be an error to match the rest of the code. Will change this in the next commit.
pkg/providers/v1/aws_sdk.go
Outdated
| p.addAPILoggingMiddleware(&cfg) | ||
| imdsClient := imds.New(imds.Options{ClientEnableState: imds.ClientEnabled}) | ||
| getInstanceIdentityDocumentOutput, err := imdsClient.GetInstanceIdentityDocument(context.Background(), &imds.GetInstanceIdentityDocumentInput{}) | ||
| identity := getInstanceIdentityDocumentOutput.InstanceIdentityDocument |
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.
will getInstanceIdentityDocumentOutput have any value if there is 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.
Thanks for the catch - we should check if err != nil here and return an error, because we get an error if the request fails/is unable to be parsed.
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.
Yeah this line identity := getInstanceIdentityDocumentOutput.InstanceIdentityDocument should be moved under err==nil
|
|
||
| func (p *awsSDKProvider) Metadata() (config.EC2Metadata, error) { | ||
| sess, err := session.NewSession(&aws.Config{ | ||
| EndpointResolver: p.cfg.GetResolver(), |
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.
This should be migrated right?
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.
Thanks for the catch - migrated endpoint resolution. IMDS doesn't support signing, so its resolver will only override the URL. Standard SDK clients use SigV4 while IMDS uses a different protocol.
pkg/providers/v1/aws_sdk.go
Outdated
| sess, err := session.NewSession(&aws.Config{ | ||
| EndpointResolver: p.cfg.GetResolver(), | ||
| }) | ||
| cfg, err := awsConfig.LoadDefaultConfig(context.TODO()) |
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.
nit: use the default mode whenever possible
pkg/providers/v1/aws_sdk.go
Outdated
| p.addAPILoggingMiddleware(&cfg) | ||
| imdsClient := imds.New(imds.Options{ClientEnableState: imds.ClientEnabled}) | ||
| getInstanceIdentityDocumentOutput, err := imdsClient.GetInstanceIdentityDocument(context.Background(), &imds.GetInstanceIdentityDocumentInput{}) | ||
| identity := getInstanceIdentityDocumentOutput.InstanceIdentityDocument |
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.
Yeah this line identity := getInstanceIdentityDocumentOutput.InstanceIdentityDocument should be moved under err==nil
| func (cfg *CloudConfig) GetIMDSEndpointOpts() []func(*imds.Options) { | ||
| opts := []func(*imds.Options){} | ||
| for _, override := range cfg.ServiceOverride { | ||
| if override.Service == imds.ServiceID { |
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.
Note: Instead of checking the ServiceID and region here, like we do for other clients, we only check ServiceID. This does not result in a behavioral change - the resolver for the SDK V1 ec2metadata package always had an empty value for the region at the time of the request, so only the serviceID field was used for determining whether to override.
Also, we are not overriding the signing name and region here since IMDS does not support signing.
pkg/providers/v1/aws.go
Outdated
| } | ||
| macsBytes, err := io.ReadAll(macsMetadata.Content) | ||
| if err != nil { | ||
| panic("unable to parse macs") |
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.
i don't think we should panic here?
pkg/providers/v1/aws_sdk.go
Outdated
| // But IMDS uses a different request pattern: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html | ||
| var opts []func(*imds.Options) = p.cfg.GetIMDSEndpointOpts() | ||
| opts = append(opts, func(o *imds.Options) { | ||
| o.ClientEnableState = imds.ClientEnabled // enable requests, otherwise the AWS_EC2_METADATA_DISABLED env var will need to be set |
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.
for my understanding what is the difference between default enabled and enabled https://github.com/aws/aws-sdk-go-v2/blob/feature/ec2/imds/v1.16.32/feature/ec2/imds/api_client.go#L37 as that is the default value ?
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.
If we do not configure this variable, it is set to defaultEnable and falls back to whatever the AWS_EC2_METADATA_DISABLED env var is set to.
If we do configure it, then this overrides the value of AWS_EC2_METADATA_DISABLED and acts as if AWS_EC2_METADATA_DISABLED = false.
However, I dug into the old ec2metadata code and it essentially behaves the same way (it needs the same env var to be set to make successful requests). So, I'm going to remove this line so we don't override AWS_EC2_METADATA_DISABLED with o.ClientEnableState = imds.ClientEnabled and we can maintain parity with the old code. Thanks for the callout!
Info about AWS_EC2_METADATA_DISABLED from the docs:
AWS_EC2_METADATA_DISABLED - environment variable
Whether or not to attempt to use Amazon EC2 Instance Metadata Service (IMDS) to obtain credentials.
Default value: false.
Valid values:
true – Do not use IMDS to obtain credentials.
false – Use IMDS to obtain credentials.
pkg/providers/v1/aws.go
Outdated
| } | ||
| macsBytes, err := io.ReadAll(macsMetadata.Content) | ||
| if err != nil { | ||
| panic("unable to parse macs") |
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.
there shouldn't be panic here right?
| t.Errorf("Should succeed for case: %s, got %v", test.name, err) | ||
| } | ||
|
|
||
| if len(cfg.ServiceOverride) != len(test.servicesOverridden) { |
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.
why is this removed? can't we test some if not all?
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.
This part of the test was checking that the signing fields and URL were properly overridden using the generic resolver from V1. Since we now have resolvers on a per client basis, we are now testing the resolvers on a more e2e scale, creating a client and making mock requests (all in aws_sdk_test.go). We're still testing the override functionality, just in a different place.
This test used to test both ValidateOverride() and overriding, now it just tests ValidateOverride().
Let me know if I'm missing something here, though.
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.
i was thinking if we can keep the check len(cfg.ServiceOverride) != len(test.servicesOverridden) but i think it should be okay as this should be tested indirectly in the other function.
21f4dd2 to
23058a7
Compare
|
/retest |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kmala The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Continues work on upgrading repo to AWS SDK Go V2. (PR 1: #1146, PR 2: #1157)
Notable Changes:
The IMDS client's signing name and signing region can no longer be overridden. This is because IMDS, unlike other SDK clients, doesn't support signing. (Standard SDK clients use SigV4 while IMDS uses a different protocol).
Trivial Changes:
Testing:
Ran unit tests with
make testand e2e tests with the following commands:Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: