Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
# Pulled from instance metadata endpoint for EC2
# see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
category=$1
curl -fsSL "http://169.254.169.254/latest/meta-data/${category}"
curl -H "X-aws-ec2-metadata-token: $(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 30")" -fsSL "http://169.254.169.254/latest/meta-data/${category}"
}
echo "ami-id: $(get_ec2_metadata ami-id)"
echo "instance-id: $(get_ec2_metadata instance-id)"
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
# Pulled from instance metadata endpoint for EC2
# see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
category=$1
curl -fsSL "http://169.254.169.254/latest/meta-data/${category}"
curl -H "X-aws-ec2-metadata-token: $(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 30")" -fsSL "http://169.254.169.254/latest/meta-data/${category}"
}
echo "ami-id: $(get_ec2_metadata ami-id)"
echo "instance-id: $(get_ec2_metadata instance-id)"
Expand Down
21 changes: 20 additions & 1 deletion setup-ssh/src/ec2-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@ export async function getEC2Metadata(category: string): Promise<string> {
allowRetries: true,
maxRetries
})
// convert these two curls:
// curl -H "X-aws-ec2-metadata-token: $(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 30")" -fsSL "http://169.254.169.254/latest/meta-data/${category}"
const tokenResponse = await http.put(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bit could be tested by identifying a workflow that uses it and modifying the reference to point to this PR's branch. Let me know if you need help with that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`http://169.254.169.254/latest/api/token`, undefined, {
headers: {
'X-aws-ec2-metadata-token-ttl-seconds': '30'
}
}
)

if (tokenResponse.message.statusCode !== 200) {
return ''
}

const resp = await http.get(
`http://169.254.169.254/latest/meta-data/${category}`
`http://169.254.169.254/latest/meta-data/${category}`, {
headers: {
'X-aws-ec2-metadata-token': tokenResponse.result
}
}
)

if (resp.message.statusCode !== 200) {
return ''
}
Expand Down
Loading