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

S3: fix issue with EC2 IDMSv2 request failing inside Docker container… #6752

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

rouault
Copy link
Member

@rouault rouault commented Nov 20, 2022

… with default networking

and causing later unrelated issues when opening a dataset. Cf https://lists.osgeo.org/pipermail/gdal-dev/2022-November/056488.html thread

https://community.grafana.com/t/imdsv2-is-not-working-from-docker/65944 points that the curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 10 request doesn't work inside Docker with default networking settings. docker run --network=host avoids that issue

The issue was that the failure of the EC2 IDMSv2 request set a CPLError() that was hidden, but not cleared. Hence when GDALOpen() run, after probing a first driver (VRT e.g.) that doesn't detect the dataset, the fact that the error state was in error made GDALOpen() abort without trying subsequent drivers.

So make sure to clear the error reset after EC2 HTTP requests, and when EC2 IDMSv2 fails but http://169.254.169.254/latest/meta-data succeeds, emit a debug message with a hint when we detect we are inside Docker.

… with default networking

and causing later unrelated issues when opening a dataset.
Cf https://lists.osgeo.org/pipermail/gdal-dev/2022-November/056488.html
thread

https://community.grafana.com/t/imdsv2-is-not-working-from-docker/65944
points that the ``curl -X PUT "http://169.254.169.254/latest/api/token" -H
"X-aws-ec2-metadata-token-ttl-seconds: 10`` request doesn't work inside
Docker with default networking settings. ``docker run
--network=host`` avoids that issue

The issue was that the failure of the EC2 IDMSv2 request set a
CPLError() that was hidden, but not cleared. Hence when GDALOpen() run,
after probing a first driver (VRT e.g.) that doesn't detect the dataset,
the fact that the error state was in error made GDALOpen() abort without
trying subsequent drivers.

So make sure to clear the error reset after EC2 HTTP requests, and when
EC2 IDMSv2 fails but http://169.254.169.254/latest/meta-data succeeds,
emit a debug message with a hint when we detect we are inside Docker.
Comment on lines +963 to +964
"/latest/api/token EC2 IDMSv2 request timed out, but /latest/metadata succeeded. "
"Trying with IDMSv1. "
Copy link
Contributor

Choose a reason for hiding this comment

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

Instance Metadata Service (IMDS) v1 is disabled on Amazon Linux 2023. When running in a Docker container on an Amazon instance you'll need to update metadata allowing 2 HTTP Hops. Here's one adhoc way to do that:

aws ec2 modify-instance-metadata-options \
    --instance-id <instance_id> \
    --http-put-response-hop-limit 2 \
    --http-endpoint enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants