Azure / Azure/azure-linux-extensions

[Bug] AADLoginForLinux VM extension does not write status file

Open
#1,070 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
333
Forks
278
Avg merge
2d 9h
Merged PRs (30d)
4

Description

I'm trying to install the AADLoginForLinux extension via Terraform.

I use the following code snippet, **but this issue is not specific to Terraform** (see below).

```hcl
resource "azurerm_virtual_machine_extension" "azrm_vm_extension" {
name = "aadlogin"
virtual_machine_id =
publisher = "Microsoft.Azure.ActiveDirectory.LinuxSSH"
type = "AADLoginForLinux"
type_handler_version = "1.0"
auto_upgrade_minor_version = true
settings = "{}"
protected_settings = "{}"
}
```

The apply operation fails, since the extension does not write the needed status file `/var/lib/waagent/Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/status/0.status` after the installation is finished.

The Azure API throws the following error:

```
Error: Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing
extension 'test'. Error message: \"Failed to get status file [Errno 2] No such fileor directory:
'/var/lib/waagent/Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/status/0.status'\"\r\n\r\n
More information on troubleshooting is available at https://aka.ms/vmextensionlinuxtroubleshoot "
```

Same error when checking the state via the Azure CLI:

```
$ az vm get-instance-view --resource-group azrm_rg --name azrm_vm --query "instanceView.extensions"
[
{
"name": "aadlogin",
"statuses": [
{
"code": "ProvisioningState/failed/-1",
"displayStatus": "Provisioning failed",
"level": "Error",
"message": "Failed to get status file [Errno 2] No such file or directory: '/var/lib/waagent/Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/status/0.status'",
"time": null
}
],
"substatuses": null,
"type": "Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux",
"typeHandlerVersion": "1.0.8370001"
}
]
```

Despite of the error message, the installation was successful. The needed packages were successfully installed:

```
# rpm -qa | grep aad
aadlogin-selinux-1.0.011360001-1.x86_64
aadlogin-1.0.011360001-1.x86_64
```

The extension dir has the following files present

```
drwxr-xr-x root/root 0 2020-04-01 13:24 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/
drwx------ root/root 0 2020-04-01 11:34 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/config/
-rwxr--r-- root/root 7 2020-04-01 11:34 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/config/HandlerState
-rw-r--r-- root/root 0 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/config/0.settings
-rw-r--r-- root/root 172 2020-04-01 11:34 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/config/HandlerStatus
-rwxr--r-- root/root 396 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/HandlerManifest.json
-rwxr--r-- root/root 904 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/manifest.xml
-rwxr--r-- root/root 9334 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/installer.sh
drwx------ root/root 0 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/status/
-rw-r--r-- root/root 547 2020-04-01 11:32 Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux-1.0.8370001/HandlerEnvironment.json
```

I tried to do the same thing via the AZ CLI (see [here](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/login-using-aad)).

```
$ az vm extension set --publisher Microsoft.Azure.ActiveDirectory.LinuxSSH --name AADLoginForLinux --resource-group azrm_rg --vm-name azrm_vm
{
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/azrm_rg/providers/Microsoft.Compute/virtualMachines/azrm_vm/extensions/AADLoginForLinux",
"instanceView": null,
"location": "westeurope",
"name": "AADLoginForLinux",
"protectedSettings": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.Azure.ActiveDirectory.LinuxSSH",
"resourceGroup": "azrm_rg",
"settings": null,
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "1.0",
"virtualMachineExtensionType": "AADLoginForLinux"
}
```

The `0.status` file is still not written so this is not an issue with calling the extension via Terraform.

But the Azure CLI seems to get different status now:

```
[
{
"name": "AADLoginForLinux",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "Plugin enabled",
"time": null
}
],
"substatuses": null,
"type": "Microsoft.Azure.ActiveDirectory.LinuxSSH.AADLoginForLinux",
"typeHandlerVersion": "1.0.8370001"
}
]
```

**Unfortunately, VM extensions (and this one in particular) are not very well documented.**

**What are my options here?** As far as I can see, the installation script is only adding another repository and installs the two packages via yum. Are there any configuration tasks to be done? Can those packages be preinstalled into an image or do they have to be installed during runtime?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the extension's installer.sh and the files under its status/ directory, then compare the Terraform and Azure CLI provisioning results described here. Done means determining why 0.status is absent despite package installation and documenting or correcting the extension behavior so provisioning reports the intended status.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, linux
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.