Is there any way how can I add Azure Managed Identity to VM agent running my Azure DevOps pipeline? I want to be able to run curl
command inside bash task and obtain the access token.
The command I want to run inside a pipeline is similar to this one, as per Microsoft Docs page
curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F&client_id=$(IDENTITY)' -H Metadata:true -s
I know I can use various builtin tasks for Azure authentication, but none of them (up to my knowledge) is enabling to query metadata service.
My idea would be to have some ADO task which will add managed identity to a VM where the task is running. Once a pipeline (actually an agent) finishes all my tasks, then managed identity will be removed. Managed identity can be for example specified via service principal. Is this existing or is it possible at all?
Currently, I am using these two approaches, but both of them look a bit overkill for such a small task:
- I have private ADO agents pool and these machines have preconfigured managed identity I can use (I cannot configure it in the pipeline later)
- I use a combination of two pipelines
- the helper pipeline that is provisioning and cleaning custom VMs and
- the primary pipeline which is configuring these custom VMs (accesses via service connection) and then running my bash code on them