Azure / Azure/azure-rest-api-specs

[BUG] Role Assignment API returns 500 instead of validation error for invalid principalId

Open
#37,044 0 comments 0 reactions 0 assignees View on GitHub
Authorization bug customer-reported question Service Attention
Dominant language
TypeSpec
Stars
3.1k
Forks
5.9k
Avg merge
2d 22h
Merged PRs (30d)
444

Description

### API Spec link

https://learn.microsoft.com/en-us/rest/api/authorization/role-assignments/create?tabs=HTTP

### API Spec version

2022-04-01

### Describe the bug

When creating a role assignment for an Azure AD group, the `properties.principalId` should be the object ID (GUID) of the AD group.

If an **invalid GUID** (non-existent principalId) is passed:
- The API returns **500 Internal Server Error** with a generic message.
- Instead, it should return a **descriptive 4xx error** (e.g., 400 BadRequest or 404 NotFound).

---

### Expected behavior
Return an error message clearly stating that the provided `principalId` is invalid, e.g.:

```json
{
"error": {
"code": "InvalidPrincipalId",
"message": "The specified principalId is not valid or does not exist."
}
}

### Expected behavior

{
"error": {
"code": "InvalidPrincipalId",
"message": "The specified principalId is not valid or does not exist."
}
}

### Actual behavior

{
"error": {
"code": "InternalServerError",
"message": "Encountered internal server error. diagnostic information..."
}
}

### Reproduction Steps

# Login
az login
$subscriptionId = ""
$resourceGroup = ""
$scope = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup"

$roleDefinitionId = "/subscriptions/$subscriptionId/providers/Microsoft.Authorization/roleDefinitions/"

$body = @{
properties = @{
principalId = "00000000-0000-0000-0000-000000000000" # Invalid objectId
roleDefinitionId = $roleDefinitionId
scope = $scope
}
} | ConvertTo-Json -Depth 3

$uri = "https://management.azure.com$scope/providers/Microsoft.Authorization/roleAssignments/$(New-Guid)?api-version=2022-04-01"
Invoke-RestMethod -Uri $uri -Method Put -Headers @{Authorization = "Bearer $((az account get-access-token --query accessToken -o tsv))"} -Body $body -ContentType "application/json"

### Environment

---

### 🔹 5. Click **Create**
Hit the green **Create** button at the bottom.

---

✅ Done! Your bug is now officially reported to Microsoft.

Do you want me to also give you a **short version** (just 3–4 lines) that you can submit on [Azure Feedback](https://feedback.azure.com/) for extra visibility?

Contributor guide

Open the contributing guide

Research direction

No repository files or tests are named. Start by reviewing the linked Azure Role Assignments create specification and running the PowerShell reproduction with the invalid principalId; done would require the service or specification to produce a descriptive 4xx validation error instead of a generic 500 response.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.