Azure / Azure/azure-linux-extensions

AADLoginForLinux not working with Ubuntu 20.04 image?

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

Description

Hello!

I've recently been testing some virtual machines using Ubuntu 20.04 LTS, and it seems like the `AADLoginForLinux` extension doesn't appear to work correctly with this version of Ubuntu.

I first tried creating a VM with (substitute values as needed):
```
az vm create -g resourcegroup -n mynewvm \
--image "Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest" \
--admin-username admin --admin-password adminpassword --subnet \
"/subscriptions/subscriptionid/resourceGroups/resourcegroup/providers/Microsoft.Network/virtualNetworks/vnet/subnets/subnet"
```
And then installing the `AADLoginForLinux` extension thusly:
```
az vm extension set -n AADLoginForLinux --publisher Microsoft.Azure.ActiveDirectory.LinuxSSH \
--resource-group resourcegroup --vm-name mynewvm
```
And after enabling JIT Access for the new VM in the Azure Portal, tried ssh'ing into the VM with my Azure AD credentials:
```
ssh 9numbernine9@myorg.org@12.34.56.78 # Or whatever the IP address of this new VM happens to be
```
Instead of receiving the usual `use a web browser to open the page https://microsoft.com/devicelogin` prompt, I'm simply prompted for a password for my account. Using my password for my AD account, unsurprisingly, doesn't work.

Using the `admin` account that I created, however, if I log into the VM and `tail -f /var/log/auth.log` while trying to log in with my AD account, I see the following log entries:
```
Jan 12 19:26:21 mynewvm sshd[3128]: nss_aad: Managed System Identity is not enabled for this VM. Returning a user that may or may not exist.
Jan 12 19:26:21 mynewvm aad_certhandler[3130]: Version: 1.0.014460002; user: 9numbernine9@myorg.org
Jan 12 19:26:21 mynewvm aad_certhandler[3130]: The public key is of type ssh-ed25519, not a certificate.
Jan 12 19:26:21 mynewvm sshd[3128]: AuthorizedKeysCommand /usr/sbin/aad_certhandler 9numbernine9@myorg.org AAAAC3NzaC1lZDI1NTE5AAAAIJVu1e2oZYclyDdRVrSHy+M+OrByjAeijdfjxDrZ/Tkl failed, status 2
Jan 12 19:26:21 mynewvm sshd[3131]: pam_aad(sshd:auth): AadAuthenticate, Version: 1.0.014460002; CorrelationId: f241c6d6-9429-47f7-a894-52ce58449367
Jan 12 19:26:21 mynewvm sshd[3131]: pam_aad(sshd:auth): Cannot find the bearer challenge. ResponseHeaders: HTTP/2 401 #015#012cache-control: no-cache#015#012pragma: no-cache#015#012content-type: application/json; charset=utf-8#015#012expires: -1#015#012www-authenticate: Bearer authorization_uri="https://login.windows.net/7cc12d39-5552-4b22-80b6-70296cdd3312", error="invalid_token", error_description="The authentication failed because of missing 'Authorization' header."#015#012x-ms-failure-cause: gateway#015#012x-ms-request-id: 400076e0-9da6-4c0c-99e8-69c826bc76c9#015#012x-ms-correlation-request-id: 400076e0-9da6-4c0c-99e8-69c826bc76c9#015#012x-ms-routing-request-id: CANADACENTRAL:20210112T192621Z:400076e0-9da6-4c0c-99e8-69c826bc76c9#015#012strict-transport-security: max-age=31536000; includeSubDomains#015#012x-content-type-options: nosniff#015#012date: Tue, 12 Jan 2021 19:26:20 GMT#015#012content-length: 115#015#012#015
Jan 12 19:26:21 mynewvm sshd[3128]: error: PAM: Authentication service cannot retrieve authentication info for 9numbernine9@myorg.org from 111.111.111.111
Jan 12 19:26:22 mynewvm sshd[3128]: Connection closed by authenticating user 9numbernine9@myorg.org 111.111.111.111 port 62461 [preauth]
```
I'm not exactly sure what's going wrong here in this scenario, but it seems like `pam_aad` is perhaps having difficulty reaching AD or isn't configured correctly after installating the `AADLoginForLinux` extension? Note that the exact same set of steps works for a Ubuntu 18.04 VM (`Canonical:UbuntuServer:18_04-lts-gen2:18.04.202101081`) and `/var/log/auth.log` shows everything working correctly:
```
Jan 12 21:02:25 mynewvm_1804 sshd[3076]: nss_aad: Managed System Identity is not enabled for this VM. Returning a user that may or may not exist.
Jan 12 21:02:25 mynewvm_1804 aad_certhandler[3084]: Version: 1.0.014460002; user: 9numbernine9@myorg.org
Jan 12 21:02:25 mynewvm_1804 aad_certhandler[3084]: The public key is of type ssh-ed25519, not a certificate.
Jan 12 21:02:25 mynewvm_1804 sshd[3076]: AuthorizedKeysCommand /usr/sbin/aad_certhandler 9numbernine9@myorg.org AAAAC3NzaC1lZDI1NTE5AAAAIJVu1e2oZYclyDdRVrSHy+M+OrByjAeijdfjxDrZ/Tkl failed, status 2
Jan 12 21:02:25 mynewvm_1804 sshd[3085]: pam_aad(sshd:auth): AadAuthenticate, Version: 1.0.014460002; CorrelationId: 13b63ff9-4ede-4298-92b9-2d994dc2593a
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: pam_aad(sshd:account): AadAuthorize, Version: 1.0.014460002; CorrelationId: 13b63ff9-4ede-4298-92b9-2d994dc2593a
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: pam_aad(sshd:account): Login granted for 9numbernine9@myorg.org as an admin.
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: nss_aad: Managed System Identity is not enabled for this VM. Returning a user that may or may not exist.
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: pam_aad(sshd:account): First call for 9numbernine9@myorg.org. Provisioning user data.
Jan 12 21:02:39 mynewvm_1804 aaduseradd[3091]: new user: name=9numbernine9@myorg.org, UID=3544131, GID=3544131, home=/home/9numbernine9, shell=/bin/bash
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: pam_aad(sshd:account): Adding 9numbernine9@myorg.org to aad_admins.
Jan 12 21:02:39 mynewvm_1804 gpasswd[3097]: user 9numbernine9@myorg.org added by root to group aad_admins
Jan 12 21:02:39 mynewvm_1804 sshd[3085]: pam_aad(sshd:account): Adding 9numbernine9@myorg.org to admin.
Jan 12 21:02:39 mynewvm_1804 gpasswd[3101]: user 9numbernine9@myorg.org added by root to group admin
Jan 12 21:02:39 mynewvm_1804 sshd[3076]: Accepted keyboard-interactive/pam for 9numbernine9@myorg.org from 111.111.111.111 port 22626 ssh2
Jan 12 21:02:39 mynewvm_1804 sshd[3076]: pam_unix(sshd:session): session opened for user 9numbernine9@myorg.org by (uid=0)
```

Any suggestions or insights into this issue would be greatly appreciated!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the AADLoginForLinux installation on Ubuntu 20.04 with the provided az vm and SSH commands, then compare /var/log/auth.log with the working Ubuntu 18.04 case. Trace the pam_aad authentication flow around the missing bearer challenge. Done means Azure AD SSH login reaches the device-login prompt and completes successfully on Ubuntu 20.04.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, linux, ubuntu
Domain
authentication, cloud, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.