-
Notifications
You must be signed in to change notification settings - Fork 301
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
intermittent failure to create service principal #535
Comments
Hi @dimbleby, thanks for reporting. It's possible this could be a consistency-related error. I believe that particular 403 error may sometimes be returned if the linked application can't be found. I will try to reproduce and work out where this can be mitigated if that's the case. However it may indeed be permissions-related. Can you assign the |
Alas, I don't have the power to do that in my organisation |
I have the same issue and I can confirm Application.ReadWrite.All works, but this is not allowed in my case too. I am using service principal with permission "Application.ReadWrite.OwnedBy" |
@dimbleby, @callppatel I've done some testing and this appears to be an API bug. The docs state that Application.ReadWrite.OwnedBy is sufficient for creating service principals, but this doesn't appear to be the case. Whilst testing, I needed to have Application.ReadWrite.All, and having only Application.ReadWrite.OwnedBy consistently produced a 403 with the message We'll update the provider docs to reflect this, and I will report this to the relevant team. In the meantime we can keep this issue open for tracking. |
Thanks! My experience is that creating the service principal sometimes works which maybe hints that there is something more complicated going on, but I will watch with interest. |
@manicminer Could you please explain and provide more details about API bug, I used API which is mentioned here https://docs.microsoft.com/en-us/graph/api/serviceprincipal-post-serviceprincipals?view=graph-rest-1.0&tabs=http and I was able to create service principal by using credential which has "Application.ReadWrite.OwnedBy" permission. Mandatory Input for this API is only "displayName" Which other API terraform use to create this resource? If you provide more details and error then we will contact our MS support as well. |
Here's a trace of one test attempt: https://gist.github.com/manicminer/9d343cdc8c9cb7765121f74c75acf586 This is the provider making these requests. As you can see the same endpoints are being used ( With these permissions: EDIT: The only difference seems to be the API version. At the moment we are forced to use beta and not 1.0 because there are features missing from 1.0. |
That's kind of scary - Microsoft's take on this is:
Should I infer that it would be unwise to rely on azuread 2.0 in production, until you can move off the beta API? |
At present the API version that's used applies to a given service package (e.g. users, groups, applications) but we are planning to introduce more fine grained control to enable us to select the minimum version for a given resource or operation. It's quite common for Azure APIs to remain in preview or beta status for extended periods, and we regularly make use of APIs versioned as such in both the AzureRM and AzureAD providers. The AzureAD provider will be settling into a weekly release cadence just like AzureRM so there will be plenty of opportunity to issue fixes on the rare occasion an API has a breaking change. |
@manicminer @dimbleby - With my API test, version 1.0 doesn't give any error, while beta API give 403 issue. |
@callppatel I just tried again, making sure to use the 1.0 API but I still get the same 403 :/ I also checked to see whether we could move to the 1.0 API for this resource, but we use the field |
Could you please share the log for 1.0 API, as pe my test it worked, This was my API call.
|
I just re-tested with version 1.0 and beta and am now getting a 200 response with both 😕 There definitely seem to be some consistency issues here. |
@dimbleby Have you set the One thing I also noticed is that if you don't set an owner for the application, Terraform will set the initial owner and then remove it, unless you explicitly include the caller in the |
my test, never worked with beta and always worked with 1.0 :) |
@callppatel Did you set owner(s) on both the app and SP when creating them (to include "yourself")? If you assume the API will do that implicitly, it sometimes doesn't. |
yes |
This comment has been minimized.
This comment has been minimized.
No, I didnt set owner. I will check with owner as well. |
@manicminer @dimbleby
Issue was with resource azuread_application where owner field was missing. Here is the my finding,
|
I also haven't seen the original error recently, but in testing that today I did hit this.
@manicminer is this all likely to have the same root cause, or shall I raise a fresh issue? |
@dimbleby If you could open a new issue that'd be great. Please include logs (via |
After speaking with several parties seemingly affected by this issue, for each case it was resolved by double checking the Terraform configuration in question and ensuring that the To clarify, owners must be set for both the application and the service principal, e.g. data "azuread_client_config" "current" {}
resource "azuread_application" "myapp" {
display_name = "myapp"
owners = [
data.azuread_client_config.current.object_id,
# ... plus any other desired owners
]
}
resource "azuread_service_principal" "myapp" {
application_id = azuread_application.myapp.application_id
owners = [
data.azuread_client_config.current.object_id,
# ... plus any other desired owners
]
} As such I'm going to close this issue as resolved. Terraform appears to be doing the right thing given the correct configuration. If anyone is still experiencing this after double checking their configuration, please feel free to post a further comment with your exact configuration and debug logs, and I will be happy to help investigate. Thanks! |
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. |
Community Note
Terraform (and AzureAD Provider) Version
terraform 1.0.2, azuread 2.0.1
Affected Resource(s)
azuread_service_principal
Terraform Configuration Files
Part of larger configuration that I mostly can't share, but configuring service principals like this:
Will do my best to provide more details if needed.
Debug Output
Panic Output
Expected Behavior
We have a large configuration that creates several
azuread_application
andazuread_service_principal
, all following the same pattern.Expect all configuration to succeed,
Actual Behavior
Intermittently, some of the service principals fail to create:
Can this really be an Azure permissions error?
Application.ReadWrite.OwnedBy
permission in the Graph API.terraform apply
where others failSteps to Reproduce
terraform apply
Important Factoids
References
The text was updated successfully, but these errors were encountered: