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

skip service validation to get the default regions endpoint #733

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

kmala
Copy link
Contributor

@kmala kmala commented Jul 10, 2024

What this PR does / why we need it:

We had previously made changes to validate token if the hostname matches the instance metadata region in #556 . However it won't work if this is a new partition as the new partition may not have the sdk updated with the services. Hence extending the same logic to validate token even if the service doesn't exist in the sdk. This should be fine as we are only validating the instance metadata region and just ignoring if the service exists in the partition in the sdk which is the done by the default sdk client also https://github.com/aws/aws-sdk-go/blob/main/aws/session/session.go#L936

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 10, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @kmala. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 10, 2024
@@ -392,6 +392,18 @@ type tokenVerifier struct {
validSTShostnames map[string]bool
}

func getDefaultHostNameForRegion(partition *endpoints.Partition, region string) (string, error) {
rep, err := partition.EndpointFor(stsServiceID, region, endpoints.STSRegionalEndpointOption, endpoints.ResolveUnknownServiceOption)
Copy link
Contributor

Choose a reason for hiding this comment

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

qs for familiarity: Looks like endpoints.ResolveUnknownServiceOption will return an error [here[(https://github.com/aws/aws-sdk-go/blob/fbe26bf118cf10a5c6aef4a105e2a5609c617b1a/aws/endpoints/v3model.go#L218-L221). What was the current behavior of partition.EndpointFor when endpoints.ResolveUnknownServiceOption was false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently it would throw service not found https://github.com/kubernetes-sigs/aws-iam-authenticator/blob/master/pkg/token/token.go#L412-L413 as the services are not yet updated in the sdk go

Copy link
Contributor

Choose a reason for hiding this comment

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

discussed offline, will add an unit test here

if err != nil {
logrus.WithError(err).Error("Error getting default hostname")
} else {
validSTShostnames[stsHostName] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

qs for familiarity: can you describe how this helps? when the sdk does not have the partition, the else block will not be taken. How does the rest of the flow succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when the sdk doesn't have partition we fail as we are now aware of what a default dns hostname should be. This would help where there is partition but the services are not yet defined under the partition.

@nnmin-aws
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 11, 2024
@nnmin-aws
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2024
@nnmin-aws
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2024
@jyotimahapatra
Copy link
Contributor

/lgtm

@jyotimahapatra
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jyotimahapatra, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 11, 2024
@jyotimahapatra
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2024
@jyotimahapatra
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot merged commit 2596d17 into kubernetes-sigs:master Jul 11, 2024
8 checks passed
@nnmin-aws
Copy link
Contributor

/lgtm

nnmin-aws added a commit that referenced this pull request Jul 11, 2024
cherry pick of #733 onto release-0.6 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants