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

Add support for PIM AAD Group assignments #253

Closed
wants to merge 8 commits into from
Closed

Add support for PIM AAD Group assignments #253

wants to merge 8 commits into from

Conversation

oWretch
Copy link
Contributor

@oWretch oWretch commented Aug 11, 2023

This is the first PR to provide support for Privileged Management of AAD Groups. This implements part of #248. Depends on #276.

@oWretch
Copy link
Contributor Author

oWretch commented Aug 11, 2023

I haven't worked out how to run the tests under a delegated token, so I've added an environment variable with default in the test file to use a pre-existing group. Happy for assistance on getting the group activated for PIM under a delegated token.

Had been in one client to try and automate the PIM activation which didn’t work.
Copy link
Owner

@manicminer manicminer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @oWretch, thank you for submitting this! Overall this is looking really great.

For the delegated auth, we don't have any built-in support in the auth package right now, as such implementations are largely application specific and so are left to the application to implement. However, you could use the Azure CLI authentication to authenticate as a user, which would then obtain a delegated token for you, e.g. az login --username [email protected] --password sUpErSeCrEt. I believe that for a noninteractive flow you're going to need no MFA enforcement for that user. I'll look at adding support for this to the GitHub runner, if you can look at configuring the tests to use CLI auth?

@manicminer
Copy link
Owner

@oWretch I can't seem to find an endpoint in MS Graph for registering groups for PIM. The portal uses the PIM data plane, and the closest thing I can find in MS Graph docs is for PIMv2, and seems to be only for Azure resources. Any ideas?

@oWretch
Copy link
Contributor Author

oWretch commented Sep 28, 2023

There isn't an API for activating in v3 - it is all meant to be seamless and happen when you use one of the standard APIs for PIM. The issue is that, for some reason, service principals can't enable a group for PIM (see the v2 documentation).

When I manually enable a group for PIM in the Azure AD portal, it uses an undocumented API to perform the registration, which we can't do outside of the portal (and therefore can't use a service principal).

This is why I defaulted to testing on a group that was already enabled for PIM. It seems to be a limitation of the Microsoft APIs. The only other option is to get a delegated token (as you have suggested) from a user instead of principal to do the testing. I just haven't had any time recently to look further into this.

@manicminer
Copy link
Owner

@oWretch Thanks, I'll give that a try and see how far I get! We should be able to support working with a user principal for specific tests, we already have prior works for this due to other APIs also failing to support being invoked by service principals. Whilst we could revert to using a pre-existing group, I'd much prefer not to as it would interfere with other tooling that we have.

@oWretch
Copy link
Contributor Author

oWretch commented Feb 23, 2024

@manicminer Did you make any progress on looking into how best to do the tests here? I may have some more time in the next couple of weeks to look into it a bit further.

From an initial look, it seems that Microsoft may have resolved the permission issue and now allow service principals to enable groups for PIM. But I can't test it as I need to create a new tenant with a P2 license to validate.

@oWretch
Copy link
Contributor Author

oWretch commented Feb 25, 2024

@manicminer A service principal can now activate the PIM groups. I've updated the tests to create the group, and they run successfully under the SP. It just needs to have the following Graph permissions:

  • PrivilegedAccess.ReadWrite.AzureADGroup
  • PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup
  • PrivilegedEligibilitySchedule.ReadWrite.AzureADGroup

Test passes happily 🙂

=== RUN   TestPrivilegedAccessGroupAssignmentScheduleClient
--- PASS: TestPrivilegedAccessGroupAssignmentScheduleClient (34.19s)
PASS
ok  	github.com/manicminer/hamilton/msgraph	34.939s

@oWretch oWretch marked this pull request as draft February 29, 2024 02:10
@oWretch
Copy link
Contributor Author

oWretch commented Mar 6, 2024

Replaced by #277

@oWretch oWretch closed this Mar 6, 2024
@oWretch oWretch deleted the f/pim-group-assign-schedule branch March 6, 2024 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants