Class: Kitchen::Driver::Azure::ManagedIdentityToken
- Inherits:
-
TokenProvider
- Object
- TokenProvider
- Kitchen::Driver::Azure::ManagedIdentityToken
- Defined in:
- lib/kitchen/driver/azure/token_provider.rb
Overview
Authenticates as a managed identity, via the Instance Metadata Service.
This replaces the legacy MSI extension endpoint on port 50342 that the old SDK used; IMDS is the supported endpoint on modern Azure VMs.
Constant Summary collapse
- IMDS_URL =
Returns the IMDS token endpoint.
"http://169.254.169.254/metadata/identity/oauth2/token".freeze
- API_VERSION =
Returns IMDS API version.
"2018-02-01".freeze
Constants inherited from TokenProvider
Instance Attribute Summary
Attributes inherited from TokenProvider
Instance Method Summary collapse
- #fetch_token ⇒ Array(String, Integer)
-
#initialize(environment:, client_id: nil) ⇒ ManagedIdentityToken
constructor
A new instance of ManagedIdentityToken.
Methods inherited from TokenProvider
#access_token, #authorization_header
Constructor Details
#initialize(environment:, client_id: nil) ⇒ ManagedIdentityToken
Returns a new instance of ManagedIdentityToken.
198 199 200 201 |
# File 'lib/kitchen/driver/azure/token_provider.rb', line 198 def initialize(environment:, client_id: nil) super(environment:) @client_id = client_id end |
Instance Method Details
#fetch_token ⇒ Array(String, Integer)
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/kitchen/driver/azure/token_provider.rb', line 204 def fetch_token query = { "api-version" => API_VERSION, "resource" => environment.token_audience } query["client_id"] = @client_id if @client_id response = Http.request( method: :get, url: "#{IMDS_URL}?#{URI.encode_www_form(query)}", headers: { "Metadata" => "true" } ) token_from(response, "the instance metadata service") end |