Consuming multi-tenant Shared Image Gallery image with Golang SDK

Rokas 1 Reputation point
2020-08-03T15:10:50.477+00:00

Hey,

I'm trying to find a way how to use VM image from Shared Image Gallery of one tenant with another tenant using just Azure Golang SDK
There are several guides on official Azure docs how to do it with CLI or PowerShell, but that's not enough for my use case.

As both the CLI and SDK are calling same API theoretically it should be possible to mimic the behaviour with both. (Unless something is not implemented on client side)

So I gave it a try.

Creating an app registration is straightforward and for my use case can be done through UI as it's one time thing.
Then item in question is giving Tenant 2 access. Is this possible with a REST or SDK call?
But even if I've done previous step in UI Portal I couldn't make the last part work with SDK.

Everything goes down to permissions:
It's not trivial to sign in using both tenant IDs with SDK.
I tried doing that by injecting authorization headers into SKD calls Preparer.

But even then I'm getting the following:

Code="LinkedAuthorizationFailed" Message="The client has permission to perform action 'Microsoft.Compute/galleries/images/versions/read' on scope '/subscriptions/6e2176f7-20ea-40ee-9992-xxxxxxxx/resourceGroups/shared-gallery-core-477-26b00094/providers/Microsoft.Compute/virtualMachines/shared-gallery-core-477-26b00094-azure-f6f5', however the current tenant '355ab177-8713-414b-a0f0-aaaaaaaaa' is not authorized to access linked subscription '697e39d3-4b01-469d-b330-yyyyyyyyy'.";

Getting this error required lot of manual actions in UI, not with SDK. Main goal is to be able to consume shared images with Golang SDK.
Any ideas?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,157 questions
{count} votes