Skip to content

Commit ef9b003

Browse files
AWS: Increase IMDS hop limit for EC2 instances (#1834)
Signed-off-by: Waleed Malik <[email protected]> Co-authored-by: Waleed Malik <[email protected]>
1 parent ac3065c commit ef9b003

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/cloudprovider/provider/aws/provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const (
6161
// Interval and timeout for polling.
6262
pollInterval = 2 * time.Second
6363
pollTimeout = 5 * time.Minute
64+
// The maximum number of hops that the metadata service can be forwarded to, defaults to 2.
65+
// We need to set this to a higher value i.e. 3 to ensure that it is not blocked by extra hops that are introduced either by CNI or other networking components. With lower
66+
// limits AWS metadata service is not reachable from the container network in such a scenario.
67+
// For example: https://github.com/cilium/cilium/issues/25232
68+
awsMetadataHTTPPutResponseHopLimit = 3
6469
)
6570

6671
var (
@@ -760,6 +765,9 @@ func (p *provider) Create(ctx context.Context, log *zap.SugaredLogger, machine *
760765
assignPublicIP := config.AssignPublicIP == nil || *config.AssignPublicIP
761766

762767
instanceRequest := &ec2.RunInstancesInput{
768+
MetadataOptions: &ec2types.InstanceMetadataOptionsRequest{
769+
HttpPutResponseHopLimit: aws.Int32(awsMetadataHTTPPutResponseHopLimit),
770+
},
763771
ImageId: aws.String(amiID),
764772
InstanceMarketOptions: instanceMarketOptions,
765773
BlockDeviceMappings: []ec2types.BlockDeviceMapping{

0 commit comments

Comments
 (0)