dgzlopes / cloud-detect

Module that determines a host's cloud provider.
https://pypi.org/project/cloud-detect/
MIT License
35 stars 13 forks source link

AWS IMDSv2 not supported #27

Closed arossert closed 7 months ago

arossert commented 8 months ago

I have an issue that I'm getting 'unknown' even when on an AWS instance (windows). It seems that the API for http://169.254.169.254/latest/dynamic/instance-identity/document is returning a 401 status code.

According to the documentation we need first to acquire a token and then to the call instance-metadata-returns

You can look at this project to see how it is implemented in here https://pypi.org/project/ec2-metadata/

arossert commented 8 months ago

There are also some alternatives that I can think of, like looking to see if one of these directories exists

Also according to this https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/identify_ec2_instances.html, we can also use wmic to check if the UUID starts with EC2

kshivakumar commented 8 months ago

@arossert I think this package was never tested on Window VMs. Even the CI only covers Ubuntu. It's highly probable it fails with other vendors as well. I think Windows was never in the scope of this package(or the go package Satellite where it's inspired from). @dgzlopes can you confirm?

arossert commented 8 months ago

Since this lib is using the metadata API I will assume this can also happen in Linux if only V2 is supported.

arossert commented 7 months ago

@dgzlopes @kshivakumar Any suggestions on this issue? I'm using it to detect if running on cloud for multiple OS (Windows + Linux).

Also I have a Linux instance that does return 401 error without the authentication token

I can give some suggestions:

I'm willing to create a PR on any of these suggestions

If this module is only intended for Linux, it should be in the project details.

arossert commented 7 months ago

I created a pull request, can you consider adding this?

kshivakumar commented 7 months ago

Resolved by #28