Class: Conjur::API::AzureAuthenticator

Inherits:
Object
  • Object
show all
Includes:
TokenExpiration
Defined in:
lib/conjur/api/authn_azure.rb

Overview

Authenticator that uses an Azure Managed Identity JWT to obtain Conjur access tokens. Fetches a JWT from the Azure Instance Metadata Service (IMDS), then POSTs it to the Conjur authn-azure endpoint.

Constant Summary collapse

IMDS_TOKEN_PATH =
'/metadata/identity/oauth2/token'.freeze
DEFAULT_RESOURCE =
'https://management.azure.com/'.freeze
DEFAULT_IMDS_BASE =
'http://169.254.169.254'.freeze
DEFAULT_IMDS_VER =
'2018-02-01'.freeze

Constants included from TokenExpiration

TokenExpiration::TOKEN_STALE

Instance Attribute Summary collapse

Attributes included from TokenExpiration

#token_born

Instance Method Summary collapse

Methods included from TokenExpiration

#gettime, #needs_token_refresh?, #token_age, #update_token_born

Constructor Details

#initialize(account, service_id, identity, resource_uri: DEFAULT_RESOURCE, client_id: nil, imds_base_url: DEFAULT_IMDS_BASE, imds_api_version: DEFAULT_IMDS_VER) ⇒ AzureAuthenticator

Returns a new instance of AzureAuthenticator.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/conjur/api/authn_azure.rb', line 24

def initialize(, service_id, identity,
               resource_uri: DEFAULT_RESOURCE,
               client_id: nil,
               imds_base_url: DEFAULT_IMDS_BASE,
               imds_api_version: DEFAULT_IMDS_VER)
  @account          = 
  @service_id       = service_id
  @identity         = identity
  @resource_uri     = resource_uri
  @client_id        = client_id
  @imds_base_url    = imds_base_url
  @imds_api_version = imds_api_version
  update_token_born
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def 
  @account
end

#client_idObject (readonly)

Returns the value of attribute client_id.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def client_id
  @client_id
end

#identityObject (readonly)

Returns the value of attribute identity.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def identity
  @identity
end

#imds_api_versionObject (readonly)

Returns the value of attribute imds_api_version.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def imds_api_version
  @imds_api_version
end

#imds_base_urlObject (readonly)

Returns the value of attribute imds_base_url.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def imds_base_url
  @imds_base_url
end

#resource_uriObject (readonly)

Returns the value of attribute resource_uri.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def resource_uri
  @resource_uri
end

#service_idObject (readonly)

Returns the value of attribute service_id.



21
22
23
# File 'lib/conjur/api/authn_azure.rb', line 21

def service_id
  @service_id
end

Instance Method Details

#refresh_tokenObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/conjur/api/authn_azure.rb', line 39

def refresh_token
  Conjur::API.authenticate_azure(service_id, identity,
                                 account: ,
                                 resource_uri: resource_uri,
                                 client_id: client_id,
                                 imds_base_url: imds_base_url,
                                 imds_api_version: imds_api_version).tap do
    update_token_born
  end
end