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

Support AWS IMDSv2 #28

Closed arossert closed 7 months ago

arossert commented 7 months ago

Added support for IMDSv2 https://github.com/dgzlopes/cloud-detect/issues/27

kshivakumar commented 7 months ago

@arossert Can you call the two APIs concurrently using asyncio.gather. As per the documentation, each instance is user-configured to use only one of the APIs. It seems in your case, your Windows EC2 instances are configured to use v2.

arossert commented 7 months ago

@kshivakumar yes I tested it on both Windows and Linux, what I don't know to tell is if V2 can be disabled and api/token call can fail.

If this is the case we can try to do what you suggested and do both, one to try with V1 (without token) and the other with.

Let me know if you think it will work better

kshivakumar commented 7 months ago

I tested it on both Windows and Linux...

Great! @arossert Yeah, please go ahead with concurrently calling both the APIs.

arossert commented 7 months ago

@kshivakumar I ended up keeping the old _get_metadata flow and added _get_metadata_v2 that generates a token and calls the _get_metadata with the needed header.

I removed the try...catch block and just ignored the exceptions with the return_exceptions flag. I will run some more tests on this new changes and report back

Let me know if this looks good to you.

kshivakumar commented 7 months ago

@arossert Please fix the "DCO" check.

arossert commented 7 months ago

@arossert Please fix the "DCO" check.

Fixed