turbot/azure

steampipe plugin install azuresteampipe plugin install azure

Azure + Steampipe

Azure provides on-demand cloud computing platforms and APIs to authenticated customers on a metered pay-as-you-go basis.

Steampipe is an open source CLI to instantly query cloud APIs using SQL.

For example:

select
name,
access_tier,
sku_name,
resource_group
from
azure_storage_account;
+-------------------------+-------------+--------------+----------------------------------+
| name | access_tier | sku_name | resource_group |
+-------------------------+-------------+--------------+----------------------------------+
| parkerrajmodtesting2021 | Hot | Standard_LRS | azurebackuprg_westus2_1 |
| testsumitsa | Cool | Standard_LRS | test_sumit_rg |
| sqlvaskpahgwu6znae | Hot | Standard_LRS | lalit_test |
| sqlvaoggbf26f2ajye | Hot | Standard_LRS | turbot_rg |
| csg1003200098033c2d | Hot | Standard_LRS | cloud-shell-storage-centralindia |
+-------------------------+-------------+--------------+----------------------------------+

Documentation

Get started

Install

Download and install the latest Azure plugin:

steampipe plugin install azure

Credentials

ItemDescription
CredentialsUse the az login command to setup your Azure Default Connection.
PermissionsGrant the Global Reader permission to your user.
RadiusEach connection represents a single Azure Subscription.
Resolution1. Credentials explicitly set in a steampipe config file (~/.steampipe/config/azuread.spc).
2. Credentials specified in environment variables, e.g., AZURE_SUBSCRIPTION_ID.

Configuration

Installing the latest azure plugin will create a config file (~/.steampipe/config/azure.spc) with a single connection named azure:

connection "azure" {
plugin = "azure"
# The Azure cloud environment to use, defaults to AZUREPUBLICCLOUD
# Valid environments are AZUREPUBLICCLOUD, AZURECHINACLOUD, AZUREGERMANCLOUD, AZUREUSGOVERNMENTCLOUD
# If using Azure CLI for authentication, make sure to also set the default environment: https://docs.microsoft.com/en-us/cli/azure/manage-clouds-azure-cli
# environment = "AZUREPUBLICCLOUD"
# You can connect to Azure using one of options below:
# Use client secret authentication (https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#option-2-create-a-new-application-secret)
# tenant_id = "00000000-0000-0000-0000-000000000000"
# subscription_id = "00000000-0000-0000-0000-000000000000"
# client_id = "00000000-0000-0000-0000-000000000000"
# client_secret = "~dummy@3password"
# Use client certificate authentication (https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#option-1-upload-a-certificate)
# tenant_id = "00000000-0000-0000-0000-000000000000"
# subscription_id = "00000000-0000-0000-0000-000000000000"
# client_id = "00000000-0000-0000-0000-000000000000"
# certificate_path = "~/home/azure_cert.pem"
# certificate_password = "notreal~pwd"
# Use resource owner password authentication (https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc)
# tenant_id = "00000000-0000-0000-0000-000000000000"
# subscription_id = "00000000-0000-0000-0000-000000000000"
# client_id = "00000000-0000-0000-0000-000000000000"
# username = "my-username"
# password = "plaintext password"
# Use a managed identity (https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview)
# This method is useful with Azure virtual machines
# tenant_id = "00000000-0000-0000-0000-000000000000"
# subscription_id = "00000000-0000-0000-0000-000000000000"
# client_id = "00000000-0000-0000-0000-000000000000"
# If no credentials are specified, the plugin will use Azure CLI authentication
}

Get involved

Configuring Azure Credentials

The Azure plugin support multiple formats/authentication mechanisms and they are tried in the below order:

  1. Client Secret Credentials if set; otherwise
  2. Client Certificate Credentials if set; otherwise
  3. Resource Owner Password if set; otherwise
  4. If no credentials are supplied, then the az cli credentials are used

If connection arguments are provided, they will always take precedence over Azure SDK environment variables, and they are tried in the below order:

Client Secret Credentials

You may specify the tenant ID, subscription ID, client ID, and client secret to authenticate:

  • tenant_id: Specify the tenant to authenticate with.
  • subscription_id: Specify the subscription to query.
  • client_id: Specify the app client ID to use.
  • client_secret: Specify the app secret to use.
connection "azure_via_sp_secret" {
plugin = "azure"
tenant_id = "00000000-0000-0000-0000-000000000000"
subscription_id = "00000000-0000-0000-0000-000000000000"
client_id = "00000000-0000-0000-0000-000000000000"
client_secret = "my plaintext password"
}

Client Certificate Credentials

You may specify the tenant ID, subscription ID, client ID, certificate path, and certificate password to authenticate:

  • tenant_id: Specify the tenant to authenticate with.
  • subscription_id: Specify the subscription to query.
  • client_id: Specify the app client ID to use.
  • certificate_path: Specify the certificate path to use.
  • certificate_password: Specify the certificate password to use.
connection "azure_via_sp_cert" {
plugin = "azure"
tenant_id = "00000000-0000-0000-0000-000000000000"
subscription_id = "00000000-0000-0000-0000-000000000000"
client_id = "00000000-0000-0000-0000-000000000000"
certificate_path = "path/to/file.pem"
certificate_password = "my plaintext password"
}

Resource Owner Password

Note: This grant type is not recommended, use device login instead if you need interactive login.

You may specify the tenant ID, subscription ID, client ID, username, and password to authenticate:

  • tenant_id: Specify the tenant to authenticate with.
  • subscription_id: Specify the subscription to query.
  • client_id: Specify the app client ID to use.
  • username: Specify the username to use.
  • password: Specify the password to use.
connection "password_not_recommended" {
plugin = "azure"
tenant_id = "00000000-0000-0000-0000-000000000000"
subscription_id = "00000000-0000-0000-0000-000000000000"
client_id = "00000000-0000-0000-0000-000000000000"
username = "my-username"
password = "plaintext password"
}

Azure Managed Identity

Steampipe works with managed identities (formerly known as Managed Service Identity), provided it is running in Azure, e.g., on a VM. All configuration is handled by Azure. See Azure Managed Identities for more details.

  • tenant_id: Specify the tenant to authenticate with.
  • subscription_id: Specify the subscription to query.
  • client_id: Specify the app client ID of managed identity to use.
connection "azure_msi" {
plugin = "azuread"
tenant_id = "00000000-0000-0000-0000-000000000000"
client_id = "00000000-0000-0000-0000-000000000000"
subscription_id = "00000000-0000-0000-0000-000000000000"
}

Azure CLI

If no credentials are specified and the SDK environment variables are not set, the plugin will use the active credentials from the Azure CLI. You can run az login to set up these credentials.

  • subscription_id: Specifies the subscription to connect to. If not set, use the subscription ID set in the Azure CLI (az account show)
connection "azure" {
plugin = "azure"
}

Credentials from Environment Variables

The Azure AD plugin will use the standard Azure environment variables to obtain credentials only if other arguments (tenant_id, client_id, client_secret, certificate_path, etc..) are not specified in the connection:

export AZURE_ENVIRONMENT="AZUREPUBLICCLOUD" # Defaults to "AZUREPUBLICCLOUD". Valid environments are "AZUREPUBLICCLOUD", "AZURECHINACLOUD", "AZUREGERMANCLOUD" and "AZUREUSGOVERNMENTCLOUD"
export AZURE_TENANT_ID="00000000-0000-0000-0000-000000000000"
export AZURE_SUBSCRIPTION_ID="00000000-0000-0000-0000-000000000000"
export AZURE_CLIENT_ID="00000000-0000-0000-0000-000000000000"
export AZURE_CLIENT_SECRET="my plaintext secret"
export AZURE_CERTIFICATE_PATH="path/to/file.pem"
export AZURE_CERTIFICATE_PASSWORD="my plaintext password"
connection "azure" {
plugin = "azure"
}