question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Linux Hybrid Runbook Worker VM's Managed Identity

See original GitHub issue

Describe the bug

Running python script in az automation hybrid worker that uses azure.cli.core library to authenticate with a managed identity:

Command Name “az login --identity”

Error:

ERROR: Failed to connect to MSI. Please make sure MSI is configured correctly.

that’s the output for the job in the automation account.

To Reproduce

  • Configure a linux hybrid worker
  • create a python3 runbook
  • use the following code:

#!/usr/bin/env python3

import sys
import os
from azure.cli.core import get_default_cli

def main():
    commnd = f'login --identity'
    exAzCli(commnd, False) #login to azure cli using service principal credentials
    subs = exAzCli('account list --all', False) #executing cli command
    showingSubs(subs)

def exAzCli(str):
    ipt = str.split()
    azc = get_default_cli()
    azc.invoke(ipt, out_file = open(os.devnull, 'w'))
    if azc.result.result:
        return azc.result.result
    elif azc.result.error:
        return '{"return": "error"}'

def showingSubs(subs):
    for sub in subs:
        print('Subscription "' + str(sub['name']) + '" is currently ' + str(sub['state']) + ' and has the Id: ' + str(sub['id']))

if __name__ == "__main__":
    main()

Expected behavior The runbook should be able to authenticate using the managed identity

If we execute the script manually, without using the runbook, it will work

Environment summary

azure-cli 2.32.0 *core 2.32.0 * telemetry 1.0.6Extensions: automation 0.1.1Dependencies: msal 1.16.0 azure-mgmt-resource 20.0.0

Install Method

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
sudo apt-get install python3-pip
sudo -H pip3 install azure-cli-core
sudo -H pip3 install azure-cli
sudo apt-get install glibc-source
sudo apt-get install openssl
sudo apt-get install libpam-modules

Additional context

When we run the python code in the hybrid worker (in the console) it works fine, however when we execute the same code, through Azure automation, we are unable to login, and we received the error.

• If the same code uses SPN, it will work fine • We need to use an hybrid worker because the azure sandbox won’t allow to install the azure.core.cli dependencies • We can’t use powershell due to standardization of their cloud automation in all clouds

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yonzhancommented, May 2, 2022

@jiasli for awareness

0reactions
jiaslicommented, Dec 9, 2022

It has been finalized that MSAL will support all variations of Managed Identity (https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/58). Once MSAL code is ready, we will adopt the latest MSAL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Azure Automation runbooks on a Hybrid Runbook Worker
Hybrid Runbook Workers on Azure virtual machines can use managed identities to authenticate to Azure resources. Using managed identities for ...
Read more >
Extension-based User Hybrid Runbook Worker in Azure ...
This video describes how to deploy a user Hybrid Runbook Worker on a Windows or Linux machine in a Hybrid Runbook Worker group....
Read more >
Azure Automation (@AzureAutomation) / Twitter
Azure Automation announces General Availability of Hybrid Runbook Worker Extension. It is supported for Windows & Linux Azure VMs and Azure Arc-enabled ...
Read more >
Design and Build an Azure Automation in a hybrid environment
Hybrid Runbook Worker Group: Group with multiple Hybrid runbook workers for higher availability and scale to run a set of runbooks. Runbook: A ......
Read more >
SCCM Automation using Azure Runbook Hybrid Worker
A Runbook: A collection of one or more linked activities that together automate a process or operation. On-premises machines and VMs. On- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found