Forum Discussion

nverma2023's avatar
nverma2023
Copper Contributor
Nov 13, 2023

Removing self from Global Administrator built-in role is not allowed

Hi - I am using Java APIs to assign "Security Administrator".

The java code looks like this.

 

 

 

 

  final DirectoryObject dirObjectCreated = Objects.requireNonNull(graphClient
                            .directoryRoles(ROLE_TEMPLATE_ID + "=" + SECURITY_ADMIN_TEMPLATE_ID)
                            .members()
                            .references())
                    .buildRequest()
                    .post(directoryObject);

 

 

 

 

This works fine.

 

When I try to remove this "Security Administrator", I am getting the error 

 

 

 

Removing self from Global Administrator built-in role is not allowed.

 

 

I have tried following URL

Method: DELETE

URL: https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments/y-RKG-FULL-ID

 
I am able to remove the role after I manually login into the Office 365.
 
It seems removing the role is not allowed. I looked the example 11 at this link https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/custom-assign-graph
 
This link at example 11 says 

 

 

 

We prevent users from deleting their own Global Administrator role to avoid a scenario where a tenant has zero Global Administrators. Removing other roles assigned to self is allowed.

 

 

 

My token has following roles

 

 

 

"roles": [
    "Mail.ReadWrite",
    "Domain.ReadWrite.All",
    "Group.Read.All",
    "Directory.Read.All",
    "User.Read.All",
    "Domain.Read.All",
    "RoleManagement.ReadWrite.Directory",
    "Application.Read.All"
  ]

 

 

 

 

Question: How can I remove "Security Administrator" role?

 

6 Replies

  • Are you passing the correct ID? The error message above suggests that you are trying to remove the Global admin role, not Security admin one.
    • nverma2023's avatar
      nverma2023
      Copper Contributor

      VasilMichev 

      Yes I am. I can assure you that I am passing the correct ID.

      I think the error message is generic if you try to remove any admin (Security Admin or Office Administrator etc)

      • VasilMichev's avatar
        VasilMichev
        MVP

        Still, double-check things. I just tried to reproduce the issue, and I have no problem removing any additional roles assigned to the (only) Global admin. Only when trying to remove the GA role I get the error above.

         

         

Resources