Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Retrieving Security Credentials from Instance Metadata

This is not a duplicate of the question "Getting my AWS credentials using an API call" because I am asking specifically about what Amazon means in the example that they give.

I am looking here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

I see this bit:

Warning

If you use services that use instance metadata with IAM roles, ensure that you don't expose your credentials when the services make HTTP calls on your behalf. The types of services that could expose your credentials include HTTP proxies, HTML/CSS validator services, and XML processors that support XML inclusion.

The following command retrieves the security credentials for an IAM role named s3access.

$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access

Where does this IP address come from? What is 169.254.169.254? It can't be my server, since I don't have software running on port 80, nor would I grant Amazon an alias on my server.

But I did actually run the above, and it simply timed out. So the IP address 169.254.169.254 is not a service that Amazon is actively running. So what is it?

Does anyone understand this example that Amazon offers?

like image 393
LRK9 Avatar asked Dec 07 '16 18:12

LRK9


People also ask

Where are credentials stored in EC2 instance?

In this example output, the IAM user credentials are stored in the . aws/credentials file.

What is http 169.254 169.254 latest meta data IAM security credentials?

169.254. 169.254 is the address of the AWS metadata service. You can query this address from an EC2 server to obtain information about the server. The metadata that can be obtained in this manner is documented here.

How do I find the instance metadata on an EC2 instance?

To view instance metadata, you can only use the link-local address of 169.254. 169.254 to access. Requests to the metadata via the URI are free, so there are no additional charges from AWS. Using the curl tool on Linux or the PowerShell cmdlet Invoke-WebRequest on Windows, you will first create your token.

Where do I find my AWS credentials?

Environment variables – You can store values in your system's environment variables. CLI credentials file – The credentials and config file are updated when you run the command aws configure . The credentials file is located at ~/. aws/credentials on Linux or macOS, or at C:\Users\ USERNAME \.


2 Answers

169.254 is within the link-local address space: https://en.wikipedia.org/wiki/Link-local_address

It's usually used for a lot of localhost/local-subnet use cases. Amazon happens to put their metadata service at 169.254.169.254 so that it can be queried from EC2 Instances.

curl http://169.254.169.254/latest/meta-data

Should always return something, the full http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access will only return something if you had an IAM role attached to your instance named s3access.

like image 145
sidewinder12s Avatar answered Oct 08 '22 11:10

sidewinder12s


169.254.169.254 is the address of the AWS metadata service. You can query this address from an EC2 server to obtain information about the server. The metadata that can be obtained in this manner is documented here.

Are you saying that when you run that curl command from an EC2 server it is timing out?

like image 31
Mark B Avatar answered Oct 08 '22 09:10

Mark B