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 AzureRM Privileged Identity Management to Provider #2455

Closed
phantlantis opened this issue May 12, 2023 · 4 comments · Fixed by #3959
Closed

Add AzureRM Privileged Identity Management to Provider #2455

phantlantis opened this issue May 12, 2023 · 4 comments · Fixed by #3959
Assignees
Labels
area/providers customer/lighthouse Lighthouse customer bugs and enhancements impact/missing-api kind/enhancement Improvements or new features resolution/fixed This issue was fixed size/L Estimated effort to complete (up to 10 days).

Comments

@phantlantis
Copy link

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Hello! Looking through the available resources, one set that is missing that could be majorly helpful is the Privileged Identity Management endpoint (the ones specifically for ARM, not the ones for Graph).

These currently sit under the Microsoft.Authorization namespace - the ones I'm specifically hoping for are:
https://management.azure.com/{scope}/providers/Microsoft.Authorization/roleEligibilityScheduleRequests/{roleEligibilityScheduleRequestName} as documented here.

Furthermore, the role management policies that govern PIM activation on each resource scope:
https://management.azure.com/{scope}/providers/Microsoft.Authorization/roleManagementPolicies/{roleManagementPolicyId}?api-version=2020-10-01 - as documented here

Affected area/feature

Likely the authorization section of the SDKs as a new resource.

Thanks!

@phantlantis phantlantis added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels May 12, 2023
@kpitzen
Copy link
Contributor

kpitzen commented May 16, 2023

Hi @phantlantis - thank you for bringing this to our attention! This is due to Azure's API specs neither defining an endpoint to DELETE this resource nor a reasonable default to set this resource to when Pulumi runs its delete procedures. What we'll want to do to add support here is to add these endpoints and a corresponding default state here:

var defaultResourcesStateRaw = map[string]map[string]interface{}{

From there, a simple make generate command should get us the rest of the way!

We'll get this queued up when we can, but if there are any enterprising souls out there, that would be the desired starting point.

Thank you again!

@kpitzen kpitzen added good-first-issue Start here if you'd like to start contributing to Pulumi size/S Estimated effort to complete (1-2 days). area/providers and removed needs-triage Needs attention from the triage team labels May 16, 2023
@thomas11 thomas11 added size/L Estimated effort to complete (up to 10 days). impact/missing-api and removed good-first-issue Start here if you'd like to start contributing to Pulumi size/S Estimated effort to complete (1-2 days). labels Jan 23, 2024
@thomas11
Copy link
Contributor

I just spent a couple of hours looking into this under-documented API and I’m afraid it’s a size L task.

I don’t think our existing "reset to default state" mechanism actually applies here.

  • /roleManagementPolicies does have a DELETE method but is missing PUT ("You do not need to Create role management policies as each role within each resource has a default policy")
  • /roleEligibilityScheduleRequests is missing DELETE but doesn’t have a default state to be reset to, instead requiring explicit revocation.

The way to support both would be through custom resources.

RoleEligibilityScheduleRequests would be pretty simple, we’d only need to override DELETE and replace it with a PUT request.

RoleManagementPolicies would probably required custom-implementing all CRUD methods since it has weird semantics. I don’t even know what its DELETE method really does since there’s no creation of this resource and no PUT.

Another complication is that we cannot simply try the API to see how it behaves until we get the required "AAD Premium 2" license.

@thomas11
Copy link
Contributor

RoleEligibilityScheduleRequests would be pretty simple, we’d only need to override DELETE and replace it with a PUT request.

I take that back, since its PUT endpoint is only for creation, not for updates, so those would be custom.

@mjeffryes mjeffryes modified the milestones: 0.108, 0.107 Jul 24, 2024
@mjeffryes mjeffryes removed this from the 0.108 milestone Aug 19, 2024
@rshade rshade added the customer/lighthouse Lighthouse customer bugs and enhancements label Jan 2, 2025
@mjeffryes mjeffryes added this to the 0.115 milestone Jan 17, 2025
@mikhailshilkov mikhailshilkov removed this from the 0.115 milestone Jan 31, 2025
thomas11 added a commit that referenced this issue Feb 10, 2025
## About

This PR adds support for [Role Management
Policies](https://learn.microsoft.com/en-us/rest/api/authorization/privileged-role-policy-rest-sample),
part of [Privileged Identity Management
(PIM)](https://learn.microsoft.com/en-us/entra/id-governance/privileged-identity-management/pim-configure)
in the Microsoft.Authentication namespace. It's one part of #2455.

Note that this is about the ARM part of PIM; there's also a Microsoft
Graph API part which is not covered by this provider.

This resource wasn't automatically included because it supports only GET
and PATCH. The policies are singletons that cannot be created or
deleted, only modified via PATCH.

## Implementation

Role Management Policies essentially consist of a name which is actually
a GUID, and a list of ~20 rules.

Using our existing singleton support `defaults.GetDefaultResourceState`
was tricky because
1. there are many policies with many rules, for a total of ~300k lines
of JSON for a subscription scope, and there are more scopes, plus
2. I believe the defaults can vary per scope and possibly also per
customer.

So instead, I've implemented a custom resource that captures the
original state of a policy when it's first "created", i.e., added to
Pulumi state. When a rule or the whole policy is removed from Pulumi, we
look up the original state and re-apply it.

## Testing

The e2e/integration test for this resource is special because using PIM
requires a paid [Entra ID P2
license](https://www.microsoft.com/en-us/security/business/microsoft-entra-pricing).
We have one that you can see
[here](https://admin.microsoft.com/Adminportal/Home?referrer=entra#/licensedetailpage/84a661c4-e949-4bd2-a560-ed7766fcaf2b).
@thomas11
Copy link
Contributor

We just released v2.87 of the provider which adds support for Role Management Policies via the authorization.RoleManagementPolicy resource.

Role Eligibility Schedules are in progress.

thomas11 added a commit that referenced this issue Feb 20, 2025
Resolves #2455 - add support for PIM (Privileged Identity Management)
Role Eligibility Schedules.

- [Azure docs](https://learn.microsoft.com/en-us/rest/api/authorization/privileged-role-eligibility-rest-sample)
-
[Spec](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/authorization/resource-manager/Microsoft.Authorization/stable/2020-10-01)

This API has some peculiarities that required writing a custom resource:

1. It's divided into schedules and schedule requests (an endpoint
`/roleEligibilityScheduleRequests`, not HTTP requests). Requests are
created to create and also delete schedules; there's no DELETE endpoint.
Requests are short-lived but can require approval.

2. Because of this duality where two types are used, schedule and
schedule request, I extended custom resources with the ability to derive
their schema from type A in the spec but define a different resource
name B. We want the resource to be named `...Schedule` but need the
`...ScheduleRequest` types.

3. While a schedule request is pending, a `/cancel` endpoint is used to
delete the request.

4. Both schedules and schedule requests cannot be modified; new ones
must be created instead. This isn't properly annotated in the spec,
though. The SDKs are correct in that they don't offer update operations.

I tried to comment the code pretty well, please refer to the Godoc
comments for more in-depth information.
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/providers customer/lighthouse Lighthouse customer bugs and enhancements impact/missing-api kind/enhancement Improvements or new features resolution/fixed This issue was fixed size/L Estimated effort to complete (up to 10 days).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants