ExAzureCore.Auth.ManagedIdentity.EnvironmentDetector (ex_azure_core v0.2.0)

Copy Markdown

Detects the Azure environment for managed identity authentication.

Detection order:

  1. AKS Workload Identity (AZURE_FEDERATED_TOKEN_FILE + AZURE_CLIENT_ID)
  2. App Service (IDENTITY_ENDPOINT + IDENTITY_HEADER)
  3. IMDS probe (169.254.169.254 reachable)

Summary

Functions

Checks if App Service environment is available.

Detects the current Azure environment.

Returns environment variables for the detected environment.

Checks if IMDS endpoint is reachable.

Checks if AKS Workload Identity environment is available.

Types

detection_result()

@type detection_result() ::
  {:ok, environment()}
  | {:error, ExAzureCore.Auth.Errors.ManagedIdentityError.t()}

environment()

@type environment() :: :workload_identity | :app_service | :imds

Functions

app_service_available?()

@spec app_service_available?() :: boolean()

Checks if App Service environment is available.

Requires both IDENTITY_ENDPOINT and IDENTITY_HEADER environment variables.

detect(opts \\ [])

@spec detect(keyword()) :: detection_result()

Detects the current Azure environment.

Returns the detected environment type or an error if no Azure environment is detected.

Options

  • :probe_timeout - Timeout in ms for IMDS probe (default: 1000)
  • :skip_imds_probe - Skip IMDS network probe, useful for testing (default: false)

get_environment_info()

@spec get_environment_info() :: map()

Returns environment variables for the detected environment.

Useful for debugging and logging.

imds_available?(opts \\ [])

@spec imds_available?(keyword()) :: boolean()

Checks if IMDS endpoint is reachable.

Makes a lightweight probe request to the IMDS endpoint.

workload_identity_available?()

@spec workload_identity_available?() :: boolean()

Checks if AKS Workload Identity environment is available.

Requires both AZURE_FEDERATED_TOKEN_FILE and AZURE_CLIENT_ID environment variables.