> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/m/microsoft-azure-virtual-machines.md).

# Microsoft Azure Virtual Machines

Microsoft Azure Virtual Machines covers the virtual machines of one Azure subscription. OctoXLabs reads the machines and can also read Key Vault certificates and network security group (NSG) rules.

## Use cases

* List the Azure virtual machines in the inventory.

```
Adapters = azure
```

* Find Azure virtual machines that no EDR agent covers.

```
Adapters = azure AND NOT Groups = edr
```

## Before you begin

### Network

| Source              | Destination                                                                             | Port | Protocol |
| ------------------- | --------------------------------------------------------------------------------------- | ---- | -------- |
| OctoXLabs connector | login.microsoftonline.com (or the host in the IP parameter)                             | 443  | HTTPS    |
| OctoXLabs connector | management.azure.com                                                                    | 443  | HTTPS    |
| OctoXLabs connector | vault.azure.net and `<vault name>.vault.azure.net` (only when Fetch Certificates is on) | 443  | HTTPS    |

### Required permissions

| Scope or role                                                                          | Permission | Needed for                                                                    |
| -------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------- |
| Reader (Azure RBAC, subscription scope)                                                | Read       | Virtual machines (`Microsoft.Compute/virtualMachines`)                        |
| Key Vault Reader                                                                       | Read       | Listing key vaults (Fetch Certificates)                                       |
| Key Vault Certificate User                                                             | Read       | Reading certificates from the vaults (Fetch Certificates)                     |
| Microsoft.Network/networkSecurityGroups/read, Microsoft.Network/networkInterfaces/read | Read       | NSG rules and device policy attachment (both are in the built-in Reader role) |

Without the network permissions the device inventory still works, but no policy is collected.

## Create credentials in Microsoft Azure Virtual Machines

{% stepper %}
{% step %}

### Register an application

Sign in to the Azure Portal as an administrator, open App registrations and select New registration. Fill in the details and select Register. The Application (client) ID and Directory (tenant) ID are shown.
{% endstep %}

{% step %}

### Create a client secret

In the left menu, select Certificates & Secrets and then New client secret. Select Add and copy the secret.
{% endstep %}

{% step %}

### Assign roles

Give the application the Reader role on the subscription. For certificates, also give it Key Vault Certificate User and Key Vault Reader.
{% endstep %}

{% step %}

### Copy the subscription ID

Under Azure services, select Subscriptions and copy the Subscription ID.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter                                                     | Required | Type    | Default                   | Description                                                                                           |
| ------------------------------------------------------------- | -------- | ------- | ------------------------- | ----------------------------------------------------------------------------------------------------- |
| IP (`ip`)                                                     | No       | String  | login.microsoftonline.com | Login host.                                                                                           |
| Tenant ID (`tenant_id`)                                       | Yes      | String  |                           | Directory (tenant) ID.                                                                                |
| Client ID (`client_id`)                                       | Yes      | String  |                           | Application (client) ID.                                                                              |
| Client Secret (`client_secret`)                               | Yes      | String  |                           | Client secret value.                                                                                  |
| Subscription ID (`subscription_id`)                           | Yes      | String  |                           | Subscription to read.                                                                                 |
| Proxy (`proxy`)                                               | No       | String  |                           | Proxy host and port, sent as an `http://` proxy URL.                                                  |
| Is Secure (`is_secure`)                                       | No       | Boolean | True                      | Use HTTPS.                                                                                            |
| Fetch Devices (`fetch_devices`)                               | No       | Boolean | True                      | Fetch virtual machines.                                                                               |
| Fetch Certificates (`fetch_certificates`)                     | No       | Boolean | False                     | Fetch Key Vault certificates.                                                                         |
| Fetch Network Security Rules (`fetch_network_security_rules`) | No       | Boolean | False                     | Collect NSG rules as policy assets.                                                                   |
| Fetch Default Security Rules (`fetch_default_security_rules`) | No       | Boolean | False                     | Also collect the default rules Azure adds to every NSG, including DenyAllInBound and DenyAllOutBound. |
| Attach Policies to Devices (`attach_policies_to_devices`)     | No       | Boolean | False                     | Attach the NSG rules of the machine's network interface and subnet to the machine record.             |
| Timeout (`timeout`)                                           | No       | Integer | 30                        | Seconds to wait for API responses.                                                                    |

## Troubleshooting

| Error message | Cause | Fix                                    |
| ------------- | ----- | -------------------------------------- |
| Not verified  |       | No adapter-specific error text in code |

## Change history
