I’ve setup an Azure Function app that will spin up an custom azure container using the inputs received. I’m having some permissions issues and not sure how to go from here.
In my function app the following code is responsible for the identity:
var defaultCredential = new DefaultAzureCredential();
var defaultToken = defaultCredential.GetToken(new TokenRequestContext(new[] { "https://management.azure.com/.default" })).Token;
var defaultTokenCredentials = new Microsoft.Rest.TokenCredentials(defaultToken);
var azureCredentials = new Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials(defaultTokenCredentials, defaultTokenCredentials, null, AzureEnvironment.AzureGlobalCloud);
// Initialize the Azure management client
var azure = Microsoft.Azure.Management.Fluent.Azure
.Configure()
.Authenticate(azureCredentials)
.WithSubscription("06bbdd51-XXXX-XXXX-XXXX-f6f6ca95be64");
The function app has been enabled with managed identity as shown below over my resource group as an contributor.
Upon execution and monitoring the live metrics and log I’m receiving permission issues as shown below:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: RequestHandler ---> Microsoft.Rest.Azure.CloudException: The client 'a151aed5-XXXX-XXXX-XXXX-f267790603ea' with object id 'a151aed5-XXXX-XXXX-XXXX-f267790603ea' does not have authorization to perform action 'Microsoft.ContainerInstance/containerGroups/write' over scope '/subscriptions/06bbdd51-XXXX-XXXX-XXXX-f6f6ca95be64/resourceGroups/asm/providers/Microsoft.ContainerInstance/containerGroups/asmexecution' or the scope is invalid. If access was recently granted, please refresh your credentials. at Microsoft.Azure.Management.ContainerInstance.Fluent.ContainerGroupsOperations.BeginCreateOrUpdateWithHttpMessagesAsync(String resourceGroupName, String containerGroupName, ContainerGroupInner containerGroup, Dictionary`2 customHeaders, CancellationToken cancellationToken) at Microsoft.Azure.Management.ContainerInstance.Fluent.ContainerGroupsOperations.CreateOrUpdateWithHttpMessagesAsync(String resourceGroupName, String
I’m not sure what the next steps in getting this to work would by any help or assistance would be appreciated.