-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_pim_eligible_role_assignment 400 error when using null or empty schedule block #22766
Comments
The issue still occurs in 3.68. |
The issue is still occurring in 3.70. |
Still occurring in 3.71. |
Still occurring in 3.72. |
Still occurring in 3.73. @manicminer could I trouble you for a rough idea on when this will be worked on? |
Hi @MohnJadden |
@IntergalacticBVBA By default, it's 1 year, but in the settings for a scope, you can allow permanent membership. In our case, all the resource groups we're trying to have TF manage are already enabled for permanent membership - example of one below. |
Hey @MohnJadden, I think this is why you are experiencing this issue. What @IntergalacticBVBA was mentioning is true, and what you were showing in the screenshot is also true. The question is how could you still have the issue then? What's happening is that you are creating a new resource group, and then try to apply a PIM on that scope. But that scope (i.e: resource group scope) doesn't have the "Permanent eligible assigment" enabled. What you were showing on your screenshot, was probably at the subscription level, but it should be at the resource group level. If you go check on the PIM, filter by resource group, then you can check the "Allow permanent eligible" should be disabled, hence why the terraform is failing; because at the creation of the resource group, the option is not enabled. When you enable the option at the subscription level, the resources below don't inherit it. It's really a 1 x 1 relation. If you create a PIM assignment at the subscription level, only that specific subscription has that option enabled, but not the resources below it (i,.e: resource, or resource group). If you enable "Permanent eligibility" at the subscription level, and add a PIM at the resource group level, the resource group won't have that option, unless you enable it explicitly. Hope that makes sense, you can confirm once you check please. Thanks |
@ynden That nailed it on the head. In the past I'd enabled permanent assignments for other resource groups, but the test RG did not have permanent assignment enabled. After enabling permanent assignment, the error did not persist, and the PIM eligible role assignment completed successfully. Unfortunately this reveals a bit of a flaw in that we now have to create the RG, navigate manually to it in the Azure portal (there is no support for this in the CLI as far as I can tell), enable permanent assignment, and then create the azurerm_pim_eligible_role. Since the default maximum time limit is 1 year, we'd have to do something to configure the azurerm_pim_eligible_role schedule block to operate on an end date of current date + 364 days and have it update the role every time we run terraform apply, or configure some other form of automation to keep extending the renewal date. Would this be a separate issue to request the role settings eligibility to be added to TF or is this issue enough to cover it? |
Amazing, glad it worked! Yeah this is true, there would be a need to do it manually for every scope. When we talk about subscription, it's ok, but at the resource group level, it's when it becomes problematic.
I think it's another issue, because this needs to be done at a scope level, for a specific role. Like:
So the way I see it, is that it needs to have its own resource type. |
@ynden You're right, this does merit having a separate TF resource. I opened a request; hopefully it gets considered quickly. Failing that, @manicminer - as a stopgap/bridge fix, would there possibly be a way to implement more clarification on the TF error for this issue? The 400/ExpirationRule error doesn't say why the expiration rule failed; maybe a generic error that says "please make sure you are assigning a PIM eligible role within the settings for the scope" or otherwise would help other folks that might get the issue in the future. |
Doing some piggyback on what @MohnJadden is experiencing, we are currently doing our PIM assignements / enabling elligilibity through a null resource and api calls. For each PIM call, we check is the isExpirationRequired is configured, if not, we change it. Then we do the PIM assignment. @ynden Can you explain why it'd be better to have a new ressource type for this? The way I see it, using the PIM assignment resource block, having a option block for the role/resource to configure the PIM policy would make sense. By seperating them, you would have to create multiple resource for each role configured for a particular resource and have the PIM assignment resource block depends on the specific PIMPolicy. Example of a possible terraform resource block :
Additionals options from the API could be added if needed. |
@Darkfogel I could see a situation where the same people who are setting PIM role settings aren't the same people creating PIM eligible role assignments. I've been in megacorps where the decision/permission to change PIM settings for an Azure subscriptions rests with Team X, while Team Y has permissions to add new PIM users or groups to the subscription. Team X's responsibility is risk management/security, Team Y is engineering, and it's logical in this case that Team Y shouldn't be dictating what happens to Team X's resources without approval. Team Y's accounts or TF service principals/app registrations/pipelines may not have User Access Administrator or equivalent rights to change settings (likely through some horrible custom role) or they may get flagged if they take actions which attempt to change the settings in logs. Thus, if Terraform says "this PIM assignment needs to last for 3 years" and company policy is "max assignment length is 1 year with annual review", Team Y's TF would have a fixed assignment start/end which would need to be updated every year. It's a really awful use case and I can't stand that I'm advocating for it, but to me it makes sense to have separate TF resources for this: one that says what you can/cannot do with PIM as policy, and one that creates PIM assignments. |
Hey @Darkfogel, It's a great question, and you might be right actually. The reason I suggested two resources, is because Azure separates them at the API & ARM level. The The For practical reason we can have the And/Or have a specific terraform resource, something like: |
Still a problem, will this be fixed in any upcoming releases? |
Is there any other option to enable this other than manually navigating to the portal? you mentioned nothing in the CLI but is there any API calls we could use? |
It's buried in here: https://learn.microsoft.com/en-us/graph/api/unifiedrolemanagementpolicy-update?view=graph-rest-1.0&tabs=http Look for unifiedRoleManagementPolicyExpirationRule Now the trick is getting TF to do this using modules and not a hodgepodge of API calls. |
This functionality would need to go into the AzureAD provider as it uses MS Graph. |
Counterpoint: this is an Azure resource role, and the PIM setting affects Azure resource roles. It's functionality that should be related to the azurerm provider; without trying to sound like a jerk, it shouldn't matter to me what has to be called as long as Terraform can manage it. Since it's stopping azurerm_pim_eligible_role_assignment from functioning in a usable way if we want any roles to be eligible for longer than 365 days, it merits fixing in some way. Is there some way to bring this issue and #23458 to the attention of the team who works on AzureAD or is there an internal process that TF/MS uses to put it on the roadmap? |
@MohnJadden you need to update the role policy to allow permeant assignments. You can check the role setting details: |
@xuzhang3 The problem is there's no way to do that with Terraform yet. If we're using PIM just for a resource group which is being created by Terraform, we have to create the RG, manually edit the role assignment policy at the RG scope, and then add the PIM role via Terraform. |
@manicminer #23295 will support manage role polies. |
fwiw, IMO it seems like the issue reported here isn't actually an issue and its' working exactly as it should. and this should probably be closed. but the feature request spawned from this convo #23458 (so close to 23456 :D) def has merit and appears to have a proposed solution with #23295 thanks for having this thread and being vigilant about it @MohnJadden it really caught me up with my ability to leverage PIM in our terraform only azure stuff which is as of now...a no u can't. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Is there an existing issue for this?
Community Note
Terraform Version
1.5.3
AzureRM Provider Version
3.67.0
Affected Resource(s)/Data Source(s)
azurerm_pim_eligible_role_assignment
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
Terraform should create an Azure AD PIM eligible role with no expiration date/time.
Actual Behaviour
Terraform throws an error:
│ Role Eligibility Schedule Request Name: "596b4579-6944-e996-1f2b-e1b5fbdcb67a"): unexpected status 400 with error: RoleAssignmentRequestPolicyValidationFailed: The following policy rules failed: ["ExpirationRule"]
│
│ with azurerm_pim_eligible_role_assignment.role-vdi-vmadminpim["Team12"],
│ on AzureVDI.tf line 56, in resource "azurerm_pim_eligible_role_assignment" "role-vdi-vmadminpim":
│ 56: resource "azurerm_pim_eligible_role_assignment" "role-vdi-vmadminpim" {
│
│ waiting for Role Management Policy: (Principal Id "01b95094-3727-42de-9bfe-f1bd55734554" / Scope "/subscriptions/ourSubscriptionGUID/resourceGroups/rgName" / Role Definition Id
│ "/subscriptions/ourSubscriptionGUID/providers/Microsoft.Authorization/roleDefinitions/1c0163c0-47e6-4577-8991-ea5c82e286e4") to be created: creating Scoped Role Eligibility Schedule
│ Request (Scope: "/subscriptions/ourSubscriptionGUID/resourceGroups/rgName"
│ Role Eligibility Schedule Request Name: "596b4579-6944-e996-1f2b-e1b5fbdcb67a"): unexpected status 400 with error: RoleAssignmentRequestPolicyValidationFailed: The following policy rules failed:
│ ["ExpirationRule"]
Steps to Reproduce
Important Factoids
No response
References
Possibly related to #22608 - that threw a 400 error but with different error text.
The text was updated successfully, but these errors were encountered: