Azure / Azure/azure-libraries-for-java
[BUG] Cannot access CDN profiles when using `AppServiceMSICredentials`+`withDefaultSubscription`.
- Dominant language
- Java
- Stars
- 97
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When using `AppServiceMSICrednetials` for authentication and `withDefaultSubscription`, the default subscription ID does not appear to propagate to CDN API client.
***Exception or Stack Trace***
```
Exception: IllegalArgumentException: Parameter this.client.subscriptionId() is required and cannot be null.
Stack: java.lang.IllegalArgumentException: Parameter this.client.subscriptionId() is required and cannot be null.
at com.microsoft.azure.management.cdn.implementation.ProfilesInner.getByResourceGroupWithServiceResponseAsync(ProfilesInner.java:415)
at com.microsoft.azure.management.cdn.implementation.ProfilesInner.getByResourceGroupAsync(ProfilesInner.java:391)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl.getInnerAsync(TopLevelModifiableResourcesImpl.java:64)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl.getByResourceGroupAsync(GroupableResourcesImpl.java:115)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl.getByResourceGroup(GroupableResourcesImpl.java:110)
```
**To Reproduce**
Deploy the following code in an Azure Function in Java:
***Code Snippet***
```java
import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.cdn.CdnProfile;
//...
//Inside the function body:
Azure azure = Azure.authenticate(new AppServiceMSICredentials(AzureEnvironment.AZURE)).withDefaultSubscription();
CdnProfile cdnProfile = azure.cdnProfiles().getByResourceGroup(cdnResourceGroup, cdnProfileId);
//...
```
**Expected behavior**
The code should work, as the account does have a default subscription as verified via `az account list -otable`.
**Setup (please complete the following information):**
Client library 1.0.22.
Setup for MSI, CDN, and RBAC via PowerShell:
```powershell
Set-AzWebApp -AssignIdentity $true -Name $appName -ResourceGroupName $resourceGroupName
$cdnProfile = New-AzCdnProfile -ProfileName uploadCdnProfile -ResourceGroupName $resourceGroupName -Sku Standard_Verizon -Location $appRegion
$cdnEndpoint = New-AzCdnEndpoint -EndpointName $uploadCdnProfile -CdnProfile $cdnProfile -OriginName $storageAccountName -OriginHostName $cdnHost
New-AzRoleAssignment -ResourceName $cdnProfile.Name -ResourceGroupName $resourceGroupName -RoleDefinitionName Contributor -ApplicationId $appServicePrincipal.ApplicationId -ResourceType Microsoft.Cdn/profiles
```
**Information Checklist**
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Bug Description Added
- [x] Repro Steps Added
- [x] Setup information Added
Contributor guide
Assessment
This issue has not been assessed yet.