Skip to content

Commit

Permalink
aws: use IDMSv2 in zone shell cmd (skypilot-org#4052)
Browse files Browse the repository at this point in the history
* aws: use IDMSv2 in zone shell cmd

Usage of IDMSv2 is considered a best practice for security.
see: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html

This change was tested manually on an ec2 instance using a test script.

* fix formatting

* fix whitespace

* prefer idmsv2 in aws template for node config
  • Loading branch information
JayThomason authored Oct 10, 2024
1 parent 3f898ab commit ea881b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sky/clouds/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ def get_zone_shell_cmd(cls) -> Optional[str]:
# The command for getting the current zone is from:
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html # pylint: disable=line-too-long
command_str = (
'curl -s http://169.254.169.254/latest/dynamic/instance-identity/document' # pylint: disable=line-too-long
'TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" '
'-H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && '
'curl -H "X-aws-ec2-metadata-token: $TOKEN" -s '
'http://169.254.169.254/latest/dynamic/instance-identity/document'
f' | {constants.SKY_PYTHON_CMD} -u -c "import sys, json; '
'print(json.load(sys.stdin)[\'availabilityZone\'])"')
return command_str
Expand Down
3 changes: 3 additions & 0 deletions sky/templates/aws-ray.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ available_node_types:
- Key: {{ label_key }}
Value: {{ label_value|tojson }}
{%- endfor %}
# Use IDMSv2
MetadataOptions:
HttpTokens: required

head_node_type: ray.head.default

Expand Down

0 comments on commit ea881b4

Please sign in to comment.