microsoft / vscode-azureAutomation

MIT License
17 stars 4 forks source link

How to have the script executed using ManagedIdentity context? #51

Open obriankevin11 opened 1 year ago

obriankevin11 commented 1 year ago

Hi,

When I run the runbook ps1 script from vscode, it runs as current user (me). I want it to run using Azure Automation resource managed identity.

I have the following

try
{
    Connect-AzAccount -Identity | out-null
}
catch {
    Write-Error -Message $_.Exception
    throw $_.Exception
}

# Get the current Azure context
$azureContext = Get-AzContext

# Display the Azure account information
$azureContext | Format-Table -AutoSize

Thank you

mortenlerudjordet commented 10 months ago

Normally you cant reach the protected endpoint for smi as it is only accessible from inside Azure (like a vNet). I have one suggestion to use a service principal here: https://github.com/microsoft/vscode-azureAutomation/discussions/46