Skip to content

Commit 21990e2

Browse files
committed
ec2: support option HTTPProtocolIPv6 for EC2 IMDS
The httpProtocolIPv6 field enables or disables the IPv6 endpoint of the instance metadata service. The SDK only applies this field if httpEndpoint is enabled. When running on single-stack IPv6, pods only have IPv6, thus requiring an IPv6 endpoint to query IMDS as IPv4 network is unreachable.
1 parent 36585e2 commit 21990e2

11 files changed

+100
-0
lines changed

api/v1beta2/awsmachinetemplate_webhook_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func TestAWSMachineTemplateValidateUpdate(t *testing.T) {
127127
InstanceType: "test",
128128
InstanceMetadataOptions: &InstanceMetadataOptions{
129129
HTTPEndpoint: InstanceMetadataEndpointStateEnabled,
130+
HTTPProtocolIPv6: InstanceMetadataEndpointStateDisabled,
130131
HTTPPutResponseHopLimit: 1,
131132
HTTPTokens: HTTPTokensStateOptional,
132133
InstanceMetadataTags: InstanceMetadataEndpointStateDisabled,

api/v1beta2/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ type InstanceMetadataOptions struct {
336336
// +kubebuilder:default=enabled
337337
HTTPEndpoint InstanceMetadataState `json:"httpEndpoint,omitempty"`
338338

339+
// Enables or disables the IPv6 endpoint for the instance metadata service.
340+
// This applies only if you enabled the HTTP metadata endpoint.
341+
//
342+
// Default: disabled
343+
//
344+
// +kubebuilder:validation:Enum:=enabled;disabled
345+
// +kubebuilder:default=disabled
346+
HTTPProtocolIPv6 InstanceMetadataState `json:"httpProtocolIpv6,omitempty"`
347+
339348
// The desired HTTP PUT response hop limit for instance metadata requests. The
340349
// larger the number, the further instance metadata requests can travel.
341350
//
@@ -382,6 +391,9 @@ func (obj *InstanceMetadataOptions) SetDefaults() {
382391
if obj.HTTPEndpoint == "" {
383392
obj.HTTPEndpoint = InstanceMetadataEndpointStateEnabled
384393
}
394+
if obj.HTTPProtocolIPv6 == "" {
395+
obj.HTTPProtocolIPv6 = InstanceMetadataEndpointStateDisabled
396+
}
385397
if obj.HTTPPutResponseHopLimit == 0 {
386398
obj.HTTPPutResponseHopLimit = 1
387399
}

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,17 @@ spec:
12591259
- enabled
12601260
- disabled
12611261
type: string
1262+
httpProtocolIpv6:
1263+
default: disabled
1264+
description: |-
1265+
Enables or disables the IPv6 endpoint for the instance metadata service.
1266+
This applies only if you enabled the HTTP metadata endpoint.
1267+
1268+
Default: disabled
1269+
enum:
1270+
- enabled
1271+
- disabled
1272+
type: string
12621273
httpPutResponseHopLimit:
12631274
default: 1
12641275
description: |-
@@ -3453,6 +3464,17 @@ spec:
34533464
- enabled
34543465
- disabled
34553466
type: string
3467+
httpProtocolIpv6:
3468+
default: disabled
3469+
description: |-
3470+
Enables or disables the IPv6 endpoint for the instance metadata service.
3471+
This applies only if you enabled the HTTP metadata endpoint.
3472+
3473+
Default: disabled
3474+
enum:
3475+
- enabled
3476+
- disabled
3477+
type: string
34563478
httpPutResponseHopLimit:
34573479
default: 1
34583480
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,17 @@ spec:
22412241
- enabled
22422242
- disabled
22432243
type: string
2244+
httpProtocolIpv6:
2245+
default: disabled
2246+
description: |-
2247+
Enables or disables the IPv6 endpoint for the instance metadata service.
2248+
This applies only if you enabled the HTTP metadata endpoint.
2249+
2250+
Default: disabled
2251+
enum:
2252+
- enabled
2253+
- disabled
2254+
type: string
22442255
httpPutResponseHopLimit:
22452256
default: 1
22462257
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinepools.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,17 @@ spec:
689689
- enabled
690690
- disabled
691691
type: string
692+
httpProtocolIpv6:
693+
default: disabled
694+
description: |-
695+
Enables or disables the IPv6 endpoint for the instance metadata service.
696+
This applies only if you enabled the HTTP metadata endpoint.
697+
698+
Default: disabled
699+
enum:
700+
- enabled
701+
- disabled
702+
type: string
692703
httpPutResponseHopLimit:
693704
default: 1
694705
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,17 @@ spec:
858858
- enabled
859859
- disabled
860860
type: string
861+
httpProtocolIpv6:
862+
default: disabled
863+
description: |-
864+
Enables or disables the IPv6 endpoint for the instance metadata service.
865+
This applies only if you enabled the HTTP metadata endpoint.
866+
867+
Default: disabled
868+
enum:
869+
- enabled
870+
- disabled
871+
type: string
861872
httpPutResponseHopLimit:
862873
default: 1
863874
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,17 @@ spec:
777777
- enabled
778778
- disabled
779779
type: string
780+
httpProtocolIpv6:
781+
default: disabled
782+
description: |-
783+
Enables or disables the IPv6 endpoint for the instance metadata service.
784+
This applies only if you enabled the HTTP metadata endpoint.
785+
786+
Default: disabled
787+
enum:
788+
- enabled
789+
- disabled
790+
type: string
780791
httpPutResponseHopLimit:
781792
default: 1
782793
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmanagedmachinepools.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,17 @@ spec:
698698
- enabled
699699
- disabled
700700
type: string
701+
httpProtocolIpv6:
702+
default: disabled
703+
description: |-
704+
Enables or disables the IPv6 endpoint for the instance metadata service.
705+
This applies only if you enabled the HTTP metadata endpoint.
706+
707+
Default: disabled
708+
enum:
709+
- enabled
710+
- disabled
711+
type: string
701712
httpPutResponseHopLimit:
702713
default: 1
703714
description: |-

controllers/awsmachine_controller_unit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,7 @@ func TestAWSMachineReconcilerReconcileDefaultsToLoadBalancerTypeClassic(t *testi
27332733
},
27342734
MetadataOptions: &ec2types.InstanceMetadataOptionsResponse{
27352735
HttpEndpoint: ec2types.InstanceMetadataEndpointState(string(infrav1.InstanceMetadataEndpointStateEnabled)),
2736+
HttpProtocolIpv6: ec2types.InstanceMetadataProtocolState(string(infrav1.InstanceMetadataEndpointStateDisabled)),
27362737
HttpPutResponseHopLimit: aws.Int32(1),
27372738
HttpTokens: ec2types.HttpTokensState(string(infrav1.HTTPTokensStateOptional)),
27382739
InstanceMetadataTags: ec2types.InstanceMetadataTagsState(string(infrav1.InstanceMetadataEndpointStateDisabled)),

pkg/cloud/services/ec2/instances.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ func (s *Service) SDKToInstance(v types.Instance) (*infrav1.Instance, error) {
955955
metadataOptions.HTTPEndpoint = infrav1.InstanceMetadataState(string(v.MetadataOptions.HttpEndpoint))
956956
metadataOptions.HTTPTokens = infrav1.HTTPTokensState(string(v.MetadataOptions.HttpTokens))
957957
metadataOptions.InstanceMetadataTags = infrav1.InstanceMetadataState(string(v.MetadataOptions.InstanceMetadataTags))
958+
metadataOptions.HTTPProtocolIPv6 = infrav1.InstanceMetadataState(v.MetadataOptions.HttpProtocolIpv6)
958959
if v.MetadataOptions.HttpPutResponseHopLimit != nil {
959960
metadataOptions.HTTPPutResponseHopLimit = int64(*v.MetadataOptions.HttpPutResponseHopLimit)
960961
}
@@ -1110,6 +1111,7 @@ func (s *Service) ModifyInstanceMetadataOptions(instanceID string, options *infr
11101111
HttpPutResponseHopLimit: utils.ToInt32Pointer(&options.HTTPPutResponseHopLimit),
11111112
HttpTokens: types.HttpTokensState(string(options.HTTPTokens)),
11121113
InstanceMetadataTags: types.InstanceMetadataTagsState(string(options.InstanceMetadataTags)),
1114+
HttpProtocolIpv6: types.InstanceMetadataProtocolState(string(options.HTTPProtocolIPv6)),
11131115
InstanceId: aws.String(instanceID),
11141116
}
11151117

@@ -1262,6 +1264,9 @@ func getInstanceMetadataOptionsRequest(metadataOptions *infrav1.InstanceMetadata
12621264
if metadataOptions.HTTPEndpoint != "" {
12631265
request.HttpEndpoint = types.InstanceMetadataEndpointState(string(metadataOptions.HTTPEndpoint))
12641266
}
1267+
if metadataOptions.HTTPProtocolIPv6 != "" {
1268+
request.HttpProtocolIpv6 = types.InstanceMetadataProtocolState(string(metadataOptions.HTTPProtocolIPv6))
1269+
}
12651270
if metadataOptions.HTTPPutResponseHopLimit != 0 {
12661271
request.HttpPutResponseHopLimit = utils.ToInt32Pointer(&metadataOptions.HTTPPutResponseHopLimit)
12671272
}

0 commit comments

Comments
 (0)