Skip to content

Commit

Permalink
Add support for AWS IMDSv2 in Availability Zone resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
zipkid committed Apr 12, 2024
1 parent 82b8cc7 commit 62f9312
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/facter/resolvers/az.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ def read_facts(fact_name)

def get_data_from(url)
headers = { Metadata: 'true' }
headers['X-aws-ec2-metadata-token'] = v2_token if v2_token
Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout })
end

def determine_session_timeout
session_env = ENV['AZ_SESSION_TIMEOUT']
session_env ? session_env.to_i : AZ_SESSION_TIMEOUT
end

def v2_token
@v2_token ||= begin
token = Facter::Util::Resolvers::AwsToken.get
token == '' ? nil : token
end
end
end
end
end
Expand Down

0 comments on commit 62f9312

Please sign in to comment.