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

Set httpPutResponseHopLimit to 2 when creating instances #4250

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1beta2/awsmachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestAWSMachineTemplateValidateUpdate(t *testing.T) {
InstanceType: "test",
InstanceMetadataOptions: &InstanceMetadataOptions{
HTTPEndpoint: InstanceMetadataEndpointStateEnabled,
HTTPPutResponseHopLimit: 1,
HTTPPutResponseHopLimit: 2,
HTTPTokens: HTTPTokensStateRequired,
InstanceMetadataTags: InstanceMetadataEndpointStateDisabled,
},
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (obj *InstanceMetadataOptions) SetDefaults() {
obj.HTTPEndpoint = InstanceMetadataEndpointStateEnabled
}
if obj.HTTPPutResponseHopLimit == 0 {
obj.HTTPPutResponseHopLimit = 1
obj.HTTPPutResponseHopLimit = 2 // Defaults to 2 in container environment
}
if obj.HTTPTokens == "" {
obj.HTTPTokens = HTTPTokensStateRequired // Defaults to IMDSv2
Expand Down
2 changes: 1 addition & 1 deletion controllers/awsmachine_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,7 @@ func TestAWSMachineReconcilerReconcileDefaultsToLoadBalancerTypeClassic(t *testi
},
MetadataOptions: &ec2.InstanceMetadataOptionsResponse{
HttpEndpoint: aws.String(string(infrav1.InstanceMetadataEndpointStateEnabled)),
HttpPutResponseHopLimit: aws.Int64(1),
HttpPutResponseHopLimit: aws.Int64(2),
HttpTokens: aws.String(string(infrav1.HTTPTokensStateRequired)),
InstanceMetadataTags: aws.String(string(infrav1.InstanceMetadataEndpointStateDisabled)),
},
Expand Down
3 changes: 2 additions & 1 deletion docs/book/src/topics/instance-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Instance metadata is data about your instance that you can use to configure or m
* Instance Metadata Service Version 2 (IMDSv2) – a session-oriented method

CAPA defaults to IMDSv2 when creating instances, as it provides a [better level of security](https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/).
CAPA defaults to 2 hot limit when creating instances with IMDSv2, as it is recommended in container environment according to [AWS document](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#imds-considerations).

It is possible to configure the instance metadata options using the field called `instanceMetadataOptions` in the `AWSMachineTemplate`.

Expand All @@ -21,7 +22,7 @@ spec:
spec:
instanceMetadataOptions:
httpEndpoint: enabled
httpPutResponseHopLimit: 1
httpPutResponseHopLimit: 2
httpTokens: required
instanceMetadataTags: disabled
```
Expand Down