terraform-provider-azurerm: Breaking change - AzureRM provider 3.65 forces `Microsoft.Kubernetes` and `Microsoft.KubernetesConfiguration` resource provider registration
Is there an existing issue for this?
- I have searched the existing issues
Community Note
- Please vote on this issue by adding a đ reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave â+1â or âme tooâ comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.
Terraform Version
1.x
AzureRM Provider Version
3.65
Affected Resource(s)/Data Source(s)
Any
Terraform Configuration Files
Any
Debug Output/Panic Output
â Original Error: Cannot register providers: Microsoft.Kubernetes, Microsoft.KubernetesConfiguration. Errors were: Cannot register provider Microsoft.Kubernetes with Azure Resource Manager: providers.ProvidersClient#Register: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'redacted' with object id 'redacted' does not have authorization to perform action 'Microsoft.Kubernetes/register/action' over scope '/subscriptions/redacted' or the scope is invalid. If access was recently granted, please refresh your credentials.".
â Cannot register provider Microsoft.KubernetesConfiguration with Azure Resource Manager: providers.ProvidersClient#Register: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'redacted' with object id 'redacted' does not have authorization to perform action 'Microsoft.KubernetesConfiguration/register/action' over scope '/subscriptions/redacted' or the scope is invalid. If access was recently granted, please refresh your credentials.".
â
â with provider["registry.terraform.io/hashicorp/azurerm"],
â on provider.tf line 3, in provider "azurerm":
â 3: provider "azurerm" {
Expected Behaviour
Resource providers should not be force registered.
Actual Behaviour
Microsoft.Kubernetes and Microsoft.KubernetesConfiguration were added as a required resource provider in AzureRM 3.65.0. However, itâs not a mandatory resource, and is a breaking change.
Microsoftâs recommendation is to âOnly register a resource provider when youâre ready to use it. The registration step enables you to maintain least privileges within your subscription. A malicious user canât use resource providers that arenât registered.â.
The AzureRM provider requiring registration of a non-mainstream resource is not best practice.
The release notes for the AzureRM provider release 3.65.0 do not mention that a new resource registration is required.
Steps to Reproduce
Deploy any AzureRM resource (except Azure Kubernetes) to a subscription without the Kubernetes resource provider registered, using a service connection scoped at any level other than the subscription. The deployment fails with the error.
Important Factoids
This also happened in provider version 3.51 - see this 21363
References
https://github.com/hashicorp/terraform-provider-azurerm/pull/22463 https://github.com/hashicorp/terraform-provider-azurerm/issues/22462 https://github.com/hashicorp/terraform-provider-azurerm/issues/21363
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 23
- Comments: 24 (10 by maintainers)
Good Morning, @tombuildsstuff
According to https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/azure-services-resource-providers#registration, those providers arenât registered by default. As @bubbletroubles above noted, the recommendation by Microsoft is not to enable them unless theyâre going to be in use. This will probably result in those providers being disabled by default in a noticeable portion of accounts, and users running in pipelines with least-privilege permissions are likely to see the registration error.
Itâs probably worth at least a breaking change notification in the release notes for v3.65.0 mentioning the error message, and pointing people to the skip_provider_registration flag on the provider.
hi @bubbletroubles
Thanks for opening this issue.
Azureâs concept of a Resource Provider requires that the Resource Provider is registered before any APIâs within that Resource Provider can be called. As such, rather than failing during an API call / to improve the user experience Terraform automatically attempts to register any Resource Providers that it supports by default - to ensure that the APIâs are available when theyâre needed; and since this list is stored within Terraform, we extend this list from time to time as Terraform is updated to support new functionality (provided in new Resource Providers).
If youâd prefer to manage Resource Provider Registration outside of Terraform (for example youâre running in a restricted environment) - itâs possible to opt-out of this behaviour by setting this field in the Provider block.
Since this is working as intended Iâm going to close this issue for the moment - but please let us know if disabling this functionality doesnât work for you and weâll take another look.
Thanks!
@tombuildsstuff hoping you can read this (and the other comments in this bug) and see the impact it has on organisations large and small.
The AzureRM Terraform provider is used in many different organisations with various levels of cloud maturity and governance. I have no doubt its used in highly regulated environments such as banking and government.
I understand the stance that this is not a breaking change, however the other side of this is organisations have configured their Azure environments with Microsoft best practices (e.g., only register the providers required) and rely on timely updates to the AzureRM provider (as cloud is always evolving - if you pin to an older version for too long, itâs a big leap to get up to the latest, more testing, more coordination, a bigger release). I donât think itâs unreasonable for an organisation to make these decisions.
For many customers, they are now having to:
The option of disabling provider registration in the provider block may work, but in some organisations this may have to be done in 10âs or 100âs of configs, and requires communication with impacted development teams. Then there needs to be a way to register providers when teams do need them. Azure Infrastructure is not the focus of many of these development teams (they just want their app to work), and the work of core infrastructure teams to guide the wider developer community within an organisation through this could be large. Granted all of this is not the Hashicorp AzureRM provider problem, but the breaking change brings this issue to the forefront.
Great products donât just technically deliver, they also understand how their product is used and build trust within their userbase and community. This change is doing the opposite. Major changes can happen, but its how they are communicated and implemented that makes a difference.
Again, I understand that you donât see this as a breaking change, however the impact this has on customers who have configured their Azure clouds in good faith are now faced with a mountain of work to keep their platforms running and maintained, with no advance notice, without a major version update.
I donât expect you to change your decision (although it would be welcomed if you did), however I hope it helps realise how these decisions can have a downstream impact on 100âs of organisations, potentially costing 100âs of hours in large organisations, impacting productivity, creating noise around âTerraform problemsâ and taking away from delivering core business.
100% a breaking change.
To clarify, this breaks existing pipelines in environments where the identity executing the run does not have permission to register providers. This should only be required if kubernetes is actually being used in the context of the provider.
I have also just been hit with this issue and agree that this is a breaking change. I am trying to run a pipeline at a resource group level E.g. the SPN doesnât have subscription level access nor should it⌠least privilege access and all.
What you are saying now is I need to go and add the Kubernetes providers to all our subscriptions even when they are not needed or have the âskip_provider_registrationâ flag set in the provider block of all the pipelines that were working.
Note: the error from Terraform implies that setting the flag above isnât a good idea:
Someone has been very narrow minded in the approach taken here. I sure as hell donât want every developer in the organisation to have the level of rights expected here.
Also, closing the ticket so quickly (the same day it was raised) before understanding the impact, well lets just say its wrong.
Also in the required.go file it says:
I wouldnât call Kubernetes a core resource provider. Many organizations donât require or use Kubernetes.
Thank you all for your input and concerns on this issue.
Itâs unfortunate that these two RPs made it into the list of auto-registered providers since I agree that
KubernetesandKubernetesConfigurationshould not be considered core RPs.I do however agree with @tombuildsstuff in that it is documented that we expect/recommend the provider be run with a user that has sufficient permissions to be able to register RPs (albeit there is improvement to be made in the documentation to call that out) and so I would not consider this a breaking change.
Whether this is the right approach or requirement to have for AzureRM is something that we should probably revisit but to reiterate we are sadly bound by the current functionality available in core.
That said I can understand the disruption that this change has caused and I can empathise with the frustration. We have corrected oversights like this in the past and I believe we should do so here as well.
@bubbletroubles I hope you donât mind - instead of reopening your PR I will open a new one since I would like to lump the removal of these RPs from the list with an update to the documentation to call out the permissions more explicitly.
So to answer my own question aboveâŚ
The only built-in roles that have the permission to run the now required actions (
Microsoft.Kubernetes/register/action&Microsoft.KubernetesConfiguration/register/action) are:Which being that they have to be applied at the subscription level for this to work certainly goes against the best practice of providing least privilege access considering both of these essentially provide full access to the subscription.
@tombuildsstuff - What is the minimum level of permissions the azurerm provider now needs to work before we have to disable auto registration?
Previously this worked for us with a service principal that only had permissions to read secrets from keyvault but now the Kubernetes resource provider auto registration wants Microsoft.Kubernetes/register/action & Microsoft.KubernetesConfiguration/register/action at the subscription level despite not even using them?
This is a complete misunderstanding of what constitutes a breaking change. Yes, the credentials used donât have the permissions required to register the provider, but the list of providers required to be registered changed and changed in a breaking way.
Sorry, but simply listing this as an enhancement in the release notes is not enough here. This should have been a new major version and the breaking change explicitly pointed outâŚor should we grow accustomed to the idea that breaking changes will continue to be released in minor version updates of the provider?
Yes, this was a breaking change. My question is why was this allowed to occur on a minor version update???
NOT COOL
@rw-hardin Iâm glad we could resolve this, yours as well as the communityâs feedback is valuable to us.
From the discussions here it sounds like everyone is striving for the same outcome. The improvement we want to make isnât possible currently but Iâve linked the issue raised on core down below for those that want to understand the limitation.
It could help to get a đ on both the issue raised on core, as well as the feature request on our provider for improvement on how provider registration is done.
Core issue: https://github.com/hashicorp/terraform/issues/25568 AzureRM feature request: https://github.com/hashicorp/terraform-provider-azurerm/issues/20673
Can you re-open this issue, we are running as âOwnerâ and it is still failing.
Original Error: Cannot register providers: Microsoft.Kubernetes, Microsoft.KubernetesConfiguration. Errors were: Cannot register provider Microsoft.Kubernetes with Azure Resource Manager: providers.ProvidersClient#Register: Failure responding to request: StatusCode=403 â Original Error: autorest/azure: Service returned an error. Status=403 Code=âAuthorizationFailedâ
@davisowb @ivan909020 @tony-harverson-moonpig @bubbletroubles
As mentioned above, the Provider automatically registers Resource Providers as is needed - this is by design - and this list can be added to as needed. As such, this is not a breaking change since we assume the credentials used to launch the Provider have access to register Resource Providers by default.
If the credentials used to launch the Provider donât have permission to register Resource Providers, then as mentioned above (and in the documentation) youâll need to ensure the
skip_provider_registrationflag is set. This allows the Resource Provider registration to be managed outside of Terraform (for example, using a more privileged account) and have the Provider use only the permissions it needs.Whilst itâs unfortunate that this has broken your environments, since the Provider is being launched without the permissions needed to register Resource Providers, this is ultimately a configuration/permissions issue - and as such is not considered a breaking change on the Provider side (this is also documented in the changelog).
Based on the discussion above, it sounds like you may not be pinning the version of the Provider being used and so this change has rolled out unexpectedly - as such weâd recommend ensuring that youâre pinning the version of the Provider being used, which would have avoided this issue.
As such whilst itâs unfortunate that this has broken your pipelines, since this is not a breaking change we have no plans to revert this PR and youâll need to update the
providerblock to account for the fact that the Service Principal being used has a limited set of permissions.Thanks!
Iâm just glad someone listened. Thanks @stephybun.
I would like to reiterate a point that @bubbletroubles made previously. Microsoft recommends a least privileges approach for the resource providers. It seems like Hashi should hear that and consider use cases such as regulated environments.
If my pipeline needs to do one single thing in another subscription (letâs say register Private DNS), then it shouldnât need permission to register a resource provider in that subscriptionâŚespecially if that subscription is intentionally locked down to specific use cases and something like Kubernetes isnât deployed there at all.
To be honest, auto registering the providers has never made sense in these environments and actually strikes me as a lazy way to avoid logic that checks to see if a given provider is even needed during that run.
Anyway, thanks again for listening and getting this reverted.
âcreating noise around âTerraform problemsââ
And coming from someone that deals with these issues on a daily basis, this extra noise is bad for an organizationâs relationship with Hashi. Many see these issues occur and wonder why Terraform is required.
Support requests are raised for something that could have been avoided, and as @bubbletroubles mentioned above, teams are having to set version constraints to 3.64.0 to avoid pipeline disruption over something that isnât even related to their code/infrastructure.
Kubernetes may be widely used, but in a lot of environments, Kubernetes is isolated/limited to particular subscriptions. Not allowing the registration of this provider globally is actually seen as a protection against random Kubernetes clusters being built outside of the appropriate space.
A better option would have been to allow an âopt-inâ switch for Kubernetes.
EDIT:
@bubbletroubles, in reference to the use of the provider within regulated environments, I can speak with 100% confidence that it is, as I have direct knowledge/experience with this use case.
@ivan909020
Whilst thatâs something weâd like to support in the future, unfortunately Terraform Core doesnât expose the functionality needed to do that at this time - implementing this would require a change to the Terraform Protocol (which would require bumping the minimum of Core to account for that) - so thatâs not possible in the short-term.
At this point in time the âleast-badâ thing we can do is to work through this defined list of Resource Providers - since unfortunately the error messages returned from Azure are unclear (e.g.
API Version 2022-02-01 was not found) when the associated Resource Provider is not registered, which has caused a large amount of (new) user confusion over the years.On the flip side, if a user is opting to run Terraform with a more limited set of permissions, we have to assume theyâre more familiar with Azure and so will be aware of Resource Providers and the need to register these - which is why this flag in the
providerblock exists.All that to say, whilst weâd like to conditionally register the Resource Providers being used in advance, unfortunately this isnât possible at this time with the current Terraform Protocol design.
Thanks!
Done and done. I like those ideas. Thanks!
FWIW this is 100% a breaking change and blaming the poor UX on top of this on the AzureRM API is missing the point that Terraform wraps the API and has plenty of options to improve the UX.
Iâm not exactly sure what warrants this issue to be closed and shuffled off when #21363 was addressed? Not sure if you want to add any commentary @stephybun as you approved the rollback on the last occurrence
My Azure Pipelines have just been hit by this issue and I second https://github.com/hashicorp/terraform-provider-azurerm/issues/22515#issuecomment-1635653005 about the new requirement being against the best practices.
For the records, here is full error dump Iâm getting from Terraform 1.5.2
FYI - Via GitHub Actions we are seeing that it is registering âMicrosoft.Kubernetesâ âMicrosoft.KubernetesConfigurationâ and successfully registering in the azore portal, however the actions is still failing even re-running the job.