Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #5669
martinlingstuyl opened this issue Jan 16, 2024 · 21 comments · May be fixed by #5973

Comments

@martinlingstuyl
Copy link
Contributor

martinlingstuyl commented Jan 16, 2024

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)

@waldekmastykarz
Copy link
Member

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

@martinlingstuyl
Copy link
Contributor Author

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...

@waldekmastykarz
Copy link
Member

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.

@martinlingstuyl
Copy link
Contributor Author

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 martinlingstuyl added help wanted good first issue and removed needs peer review Needs second pair of eyes to review the spec or PR labels Feb 4, 2024
@martinlingstuyl martinlingstuyl changed the title New command: 'm365 entra pim roleassignment eligibleroles list' - Retrieves a list of roles a user or group is eligible to be assigned. New command: 'm365 entra pim roleassignment eligibility list' - Retrieves a list of roles a user or group is eligible to be assigned. Feb 10, 2024
@martinlingstuyl martinlingstuyl added needs peer review Needs second pair of eyes to review the spec or PR and removed help wanted labels Feb 13, 2024
@MartinM85
Copy link
Contributor

Can I take it?

@martinlingstuyl
Copy link
Contributor Author

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

@martinlingstuyl martinlingstuyl changed the title New command: 'm365 entra pim roleassignment eligibility list' - Retrieves a list of roles a user or group is eligible to be assigned. New command: 'm365 entra pim role assignment eligibility list' - Retrieves a list of roles a user or group is eligible to be assigned. Feb 18, 2024
@milanholemans
Copy link
Contributor

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

@waldekmastykarz
Copy link
Member

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

@martinlingstuyl
Copy link
Contributor Author

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

@waldekmastykarz
Copy link
Member

so yes.

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

@martinlingstuyl
Copy link
Contributor Author

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.

@Adam-it
Copy link
Contributor

Adam-it commented Apr 5, 2024

LGTM, lets open it up 👍

@MartinM85
Copy link
Contributor

MartinM85 commented Apr 8, 2024

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
Copy link
Contributor

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

@martinlingstuyl
Copy link
Contributor Author

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 martinlingstuyl removed the needs peer review Needs second pair of eyes to review the spec or PR label Apr 10, 2024
@martinlingstuyl
Copy link
Contributor Author

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.

@MartinM85
Copy link
Contributor

MartinM85 commented Apr 10, 2024

@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

@martinlingstuyl
Copy link
Contributor Author

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

But can you call the endpoint without a administrative role?

@MartinM85
Copy link
Contributor

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.

@martinlingstuyl
Copy link
Contributor Author

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

@MartinM85
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants