Share via

Powershell Azure Function throws EXCEPTION: Connect-AzAccount : An attempt was made to access a socket in a way forbidden by its access permissions

Roman Muntyanu 1 Reputation point
2020-07-27T14:17:55.217+00:00

Hi

I have Powershell Azure function which is called directly by logic app as one of the steps in the workflow. Authentication was established by using system assigned managed identity approach and all was working.

I needed to refactor the way how this function app is called as the function was long running and implemented orchestration durable function approach. Now I call the function from another Azure function using HttpClient using the code below

var authenticationContext = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}");
var clientCredential = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(audienceId, clientCredential);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
HttpResponseMessage result = await _client.PostAsync(url, null);

I successfully passed authentication and execution reached the code in the function but it throws exception when it reaches the line Connect-AzAccount -Identity in my profile.ps1 file

EXCEPTION: Connect-AzAccount : An attempt was made to access a socket in a way forbidden by its access permissions

Both functions have system Assigned managed identity. I assigned "Contributor" role to the caller function with a scope of the function

that I am calling.

I read posts about similar issue but for the case when User assigned managed identity was used which is not in my case.

Any tips/help would be appreciated

Thanks,

Romanm

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

Windows for business | Windows Server | User experience | PowerShell

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.