-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add support for AWS IMDS v2 #10324
Add support for AWS IMDS v2 #10324
Conversation
Hi @bharath-123. 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/test-infra repository. |
/assign @rifelpet |
I will rebase the PR. forgot to run make gofmt and co :) |
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.
The new API fields look good to me but I'll let others review as well. Thanks for doing this!
Let me know if you need help with the new cloudmock functions.
04fbe84
to
681ab1d
Compare
@rifelpet I think this should be feature complete. Have fixed up the integration tests by mocking CreateLaunchTemplateVersion in the cloudmock. Do review it |
/ok-to-test |
pkg/apis/kops/validation/aws.go
Outdated
" for more details")) | ||
} | ||
|
||
if httpPutResponseLimit <= 0 || httpPutResponseLimit > 64 { |
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.
Would 1 actually work with kops? Don't we have containers that use the IMDS?
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.
are you referencing to IMDv1 or httpPutResponseLimit?
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 believe your referring to the httpPutHopReponseLimit if i m right. I was not aware of the fact that we had some containers using IMDS in kops. I will cross check this with aws documentation.
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 believe the IMDS is a special link local address as stated in the aws docs. This may not be an issue. But I am not sure whether overlay networks like Calico will subtract the ttl before sending it out of the cluster.
I believe AWS kept the default ttl 1 to mitigate issues against misconfigured NAT and router instances.
IMDv2
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 refer to HttpPutResponseHopLimit
yes. TTL of 1 would mean no routing. So pods with hostNetwork will work, but pods using overlay IPs will not. CNIs using ENIs (lyft, cilium-eni, vpc) will probably also work, while those using overlay networks will not.
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 this insight.
@olemarkus correct me if I wrong here. when i grepped for 169.254.169.254 ip, i see it being used only here https://github.com/kubernetes/kops/blob/master/upup/models/cloudup/resources/addons/metadata-proxy.addons.k8s.io/v0.1.12.yaml
in the context of a container. hostNetworking is enabled for this container. I think a ttl of 1 should work in this case, if this is the only container in kops which is accessing the instance metadata service.
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.
Fairly sure there are more containers using it, but I cannot think of anything using overlay network.
Easy enough to change later if this fails.
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.
got it. makes sense.
Could you change |
@olemarkus apologies for the late reply. We just finished doing an A/B upgrade of our production k8s clusters. had no sleep for 2 days :) I actually believe it is already linked to the issue. I just felt that this PR does not fix anything as much as it is adding a new feature. I shall change it regardless. |
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.
@bharath-123 I found a few ways to simplify things and also added various comments changes. After adding these changes, please squash the commits to be easier to do another review pass.
upup/pkg/fi/cloudup/awstasks/launchtemplate_target_cloudformation.go
Outdated
Show resolved
Hide resolved
upup/pkg/fi/cloudup/awstasks/launchtemplate_target_terraform.go
Outdated
Show resolved
Hide resolved
16f6d5c
to
25338c0
Compare
tests/integration/update_cluster/complex/in-legacy-v1alpha2.yaml
Outdated
Show resolved
Hide resolved
upup/pkg/fi/cloudup/awstasks/launchtemplate_target_cloudformation.go
Outdated
Show resolved
Hide resolved
upup/pkg/fi/cloudup/awstasks/launchtemplate_target_terraform.go
Outdated
Show resolved
Hide resolved
d9b29b9
to
9386119
Compare
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.
Nice. I think these are pretty much the last changes from my point of view. Please squash the code changes into a single commit.
@rifelpet @olemarkus please take another look at this before merging.
9386119
to
eaf5018
Compare
881df27
to
f5a4d19
Compare
A new field is add to the InstanceGroup spec with 2 sub fields, HTTPPutResponseHopLimit and HTTPTokens. These fields enable the user to disable IMDv1 for instances within an instance group. By default, both IMDv1 and IMDv2 are enabled in instances in an instance group.
f5a4d19
to
ee5d8a3
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bharath-123, hakman 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 |
…-upstream-release-1.19 Automated cherry pick of #10324: Add support for AWS IMDS v2
MetadataOptions: &terraformLaunchTemplateInstanceMetadata{ | ||
HTTPTokens: e.HTTPTokens, | ||
HTTPPutResponseHopLimit: e.HTTPPutResponseHopLimit, | ||
}, |
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've found that this breaks using Terraform 0.12.26, with an error message like this:
Error: error creating Launch Template (lt-0f27a1c3cb68aba0f) Version: InvalidParameterValue: A value of ‘’ is not valid for http-endpoint. Valid values are ‘enabled’ or ‘disabled’.
status code: 400, request id: fd0c6d8c-ad70-4877-9adf-00e6e35f2edc
on kubernetes.tf line 695, in resource "aws_launch_template" "bastions-redacted":
695: resource "aws_launch_template" "bastions-redacted" {
There's an open Terraform issue describing this problem: hashicorp/terraform-provider-aws#12564. If I add the "http_endpoint" attribute in manually, it works. The documentation for that attribute says that it's optional with a reasonable default value, but in practice either Terraform is not sending a value at all, or it's sending the wrong 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.
Using terraform is such a joy... Never a dull moment. 😁
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.
Please see #10393.
This PR adds support for enabling instance metadata v2 support on aws kops clusters. This can enable users to allow only IMDv2 on their instances to securely fetch their instance metadata.
I have tested this out by creating kops clusters and ssh into the nodes to check whether IMDv1 was unauthorized or not.
Have added support for launch configuration and launch templates for now.
Fixes: 9970