cli-microsoft365 icon indicating copy to clipboard operation
cli-microsoft365 copied to clipboard

New command: 'm365 entra pim role assignment eligibility list' - Retrieves a list of roles a user or group is eligible to be assigned.

Open martinlingstuyl opened this issue 1 year ago • 21 comments

Aside from checking the list of active pim roles, an important part of pim is checking what roles you are eligible for.

Usage

m365 entra pim role assignment eligibility list [options]

Description

Retrieves a list of eligible roles a user or group can be assigned to

Options

Option Description
--userId [userId] Id of the user for which to list eligible roles. Specify either userId, userName, groupId or groupName. If not specified, all eligible roles will be listed.
--userName [userName] UPN of the user for which to list eligible roles. Specify either userId, userName, groupId or groupName. If not specified, all eligible roles will be listed.
--groupId [groupId] Id of the group for which to list eligible roles. Specify either userId, userName, groupId or groupName. If not specified, all eligible roles will be listed.
--groupName [groupName] Display name of the group for which to list eligible roles. Specify either userId, userName, groupId or groupName. If not specified, all eligible roles will be listed.
--includePrincipalDetails An optional flag to include details of the principals

Examples

Get a list of eligible roles for any user

m365 entra pim role assignment eligibility list

Get a list of eligible roles for the current user.

m365 entra pim role assignment eligibility list --userId '@meID'

Response

[
        {
            "id": "8MYkhImhnkm70CbBdTyW1BbHHAdHgZdDpbqyEFlRzAs-1-e",
            "principalId": "071cc716-8147-4397-a5ba-b2105951cc0b",
            "roleDefinitionId": "8424c6f0-a189-499e-bbd0-26c1753c96d4",
            "directoryScopeId": "/",
            "appScopeId": null,
            "startDateTime": "2022-04-12T14:44:50.287Z",
            "endDateTime": "2024-04-10T00:00:00Z",
            "memberType": "Direct",
            "roleEligibilityScheduleId": "77f71919-62f3-4d0c-9f88-0a0391b665cd",
            "roleDefinitionName": "Global Administrator"
        }
    ]

The roleDefinitionName property will need to be added to the objects, based on the expanded property roleDefinition.

Default properties

From the response output in text mode we'll show roleDefinitionId and roleDefinitionName and principalId

Additional information

Needs Entra permission scopes "RoleAssignmentSchedule.ReadWrite.Directory" and/or "RoleManagement.Read.Directory" OR "Directory.ReadWrite.All" which we already may have. (I'm using ReadWrite, as we're also writing in other subcommands of pim.)

https://learn.microsoft.com/en-us/graph/api/rbacapplication-list-roleeligibilityscheduleinstances?view=graph-rest-1.0&tabs=http

And maybe use this one for the current user: https://learn.microsoft.com/en-us/graph/api/unifiedroleeligibilityscheduleinstance-filterbycurrentuser?view=graph-rest-1.0&tabs=http

By default, we need to expand/request the displayName of the role definition when calling the endpoint, using ?$expand=roleDefinition($select=displayName)

martinlingstuyl avatar Jan 16 '24 13:01 martinlingstuyl

Nice! Since it's a list command, which properties are we going to show by default?

waldekmastykarz avatar Jan 21 '24 09:01 waldekmastykarz

What about role definition name, Id and principal id? @waldekmastykarz

We'd have to flatten the roleDefinitionName into the response output, but that's a good idea anyway...

martinlingstuyl avatar Jan 21 '24 12:01 martinlingstuyl

What about role definition name, Id and principal id? @waldekmastykarz

I know too little about pim to decide which values would be useful. I'll go with your gut feeling given you're more experienced in the area.

waldekmastykarz avatar Jan 21 '24 12:01 waldekmastykarz

You would typically use this command to check for eligible roles, so role definition name and Id are helpful. You can use those when creating a pim request.

The principalId is may be only useful when running the command without principalId... you might never want to do that. (I don't see why an admin would use that in that way) so maybe we can also start simple, just the two properties.

martinlingstuyl avatar Jan 21 '24 19:01 martinlingstuyl

Can I take it?

MartinM85 avatar Feb 15 '24 12:02 MartinM85

Same here. This needs to be peer reviewed and some last i's dotted and t's crossed...

martinlingstuyl avatar Feb 15 '24 16:02 martinlingstuyl

At first sight, I don't have any comments. However, I find eligibility a weird word to use in a command name.

milanholemans avatar Feb 25 '24 23:02 milanholemans

Is eligibility a term that's already used in PIM in this context or is it a word we decided to use? If the latter, we could look for alternatives such as role assignment available list

waldekmastykarz avatar Mar 29 '24 16:03 waldekmastykarz

In PIM you have assigned roles and roles you are eligible to be assigned, so yes.

martinlingstuyl avatar Mar 29 '24 21:03 martinlingstuyl

so yes.

yes, as in: it's a standard word in PIM that we're aligning with, correct?

waldekmastykarz avatar Mar 30 '24 10:03 waldekmastykarz

Correct, you'll find the concept of Eligible roles in both the user interface of Entra ID as well as in the Microsoft Graph API surface.

martinlingstuyl avatar Mar 30 '24 13:03 martinlingstuyl

LGTM, lets open it up 👍

Adam-it avatar Apr 05 '24 22:04 Adam-it

Additional info probably contains wrong link. I guess the correct one is

https://learn.microsoft.com/en-us/graph/api/rbacapplication-list-roleeligibilityscheduleinstances?view=graph-rest-1.0&tabs=http

Maybe we can add options startDateTime and includePrincipalDetails similar to entra pim role assignment list

MartinM85 avatar Apr 08 '24 06:04 MartinM85

@martinlingstuyl Any update on this? Can I start working on it?

MartinM85 avatar Apr 10 '24 06:04 MartinM85

I'll update the endpoint indeed. I've also added the options.

We must be sure by the way to also use https://learn.microsoft.com/en-us/graph/api/unifiedroleeligibilityscheduleinstance-filterbycurrentuser?view=graph-rest-1.0&tabs=http

...for the current user. We don't want people to need an administrative role to retrieve their own eligibility

martinlingstuyl avatar Apr 10 '24 06:04 martinlingstuyl

By the way, I'm not sure how useful a startDateTime option is here. What about you? You generally search for any eligible roles I'd say.

martinlingstuyl avatar Apr 10 '24 06:04 martinlingstuyl

@martinlingstuyl

I'll update the endpoint indeed. I've also added the options.

We must be sure by the way to also use https://learn.microsoft.com/en-us/graph/api/unifiedroleeligibilityscheduleinstance-filterbycurrentuser?view=graph-rest-1.0&tabs=http

...for the current user. We don't want people to need an administrative role to retrieve their own eligibility

We can still filter eligible roles by principalId for the current user.

Ok, startDateTime doesn't make sense in this case, can be removed

MartinM85 avatar Apr 10 '24 07:04 MartinM85

We can still filter eligible roles by principalId for the current user.

But can you call the endpoint without a administrative role?

martinlingstuyl avatar Apr 10 '24 12:04 martinlingstuyl

We can still filter eligible roles by principalId for the current user.

But can you call the endpoint without a administrative role?

Quick test on my side...a user without any role mentioned in the doc (Global Reader, Security Operator, Security Reader, Security Administrator, or Privileged Role Administrator) can list eligible roles for all users. Maybe the doc is obsolete.

MartinM85 avatar Apr 10 '24 12:04 MartinM85

hmmm, but that seems rather odd and insecure. Are you really sure? :-)

martinlingstuyl avatar Apr 12 '24 08:04 martinlingstuyl

hmmm, but that seems rather odd and insecure. Are you really sure? :-)

Yep, I've tried two users. One user is global admin and the second one is a common user without any role. Both of them were able to read eligible roles. I sent a feedback two days ago through the Microsoft Doc about it. Microsoft Doc is not the best place to report possible issues in Graph API, but there is no other way to report bugs.

MartinM85 avatar Apr 12 '24 08:04 MartinM85