aws / amazon-ec2-metadata-mock

A tool to simulate Amazon EC2 instance metadata
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
Apache License 2.0
269 stars 44 forks source link

Incorrect Content-Type response header #207

Closed ash211 closed 1 year ago

ash211 commented 1 year ago

Describe the bug The real http://169.254.169.254/latest/meta-data/iam/security-credentials/instant-launch endpoint returns an HTTP response with header Content-Type: text/plain but this mock docker container returns with header Content-Type: application/json. This makes the docker container non-representative of actual AWS EC2 metadata endpoint behavior, and causes problems with some libraries that expect JSON objects to be returned with Content-Type: application/json.

Steps to reproduce On an EC2 instance:

$ export TOKEN=`curl -XPUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" http://169.254.169.254/latest/api/token`
$ export ROLE_NAME=`curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/`
$ curl -s -vvv -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/$ROLE_NAME 2>&1 | grep 'Content-Type'
< Content-Type: text/plain
$

Against this docker container running at localhost:1339:

$ export TOKEN=`curl -XPUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" http://localhost:1339/latest/api/token`
$ export ROLE_NAME=`curl -H "X-aws-ec2-metadata-token: $TOKEN" http://localhost:1339/latest/meta-data/iam/security-credentials/`
$  curl -s -vvv -H "X-aws-ec2-metadata-token: $TOKEN" http://localhost:1339/latest/meta-data/iam/security-credentials/$ROLE_NAME 2>&1 | grep 'Content-Type'
< Content-Type: application/json
$

Expected outcome The second sequence of curl requests above should result in Content-Type: text/plain instead of Content-Type: application/json

Environment

flags: -p 1339 -I -c /aemm-config-overrides.json

And that file's contents:

{
  "metadata": {
    "paths": {
      "placement-availability-zone": "/latest/meta-data/placement/availability-zone"
    },
    "values": {
      "placement-availability-zone": "us-west-1c"
    }
  }
}
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want this issue to never become stale, please ask a maintainer to apply the "stalebot-ignore" label.

ash211 commented 1 year ago

Not stale

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want this issue to never become stale, please ask a maintainer to apply the "stalebot-ignore" label.

github-actions[bot] commented 1 year ago

This issue was closed because it has become stale with no activity.