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

Azure backend with OIDC auth seems broken in version 1.11.0 #36595

Open
audunsolemdal opened this issue Feb 27, 2025 · 9 comments · May be fixed by #36623
Open

Azure backend with OIDC auth seems broken in version 1.11.0 #36595

audunsolemdal opened this issue Feb 27, 2025 · 9 comments · May be fixed by #36623
Labels
backend/azure bug new new issue not yet triaged

Comments

@audunsolemdal
Copy link

audunsolemdal commented Feb 27, 2025

Terraform Version

1.11.0

Terraform Configuration Files

providers.tf

  backend "azurerm" {
    subscription_id      = xxx
    resource_group_name  = yyy
    storage_account_name = zzz
    container_name       = ...
    key                  = "terraform.tfstate"
    use_azuread_auth     = true
  }
}

env vars set in my github actions workflow:

  ARM_CLIENT_ID: ${{vars.AZURE_OIDC_CLIENT_ID}}
  ARM_USE_OIDC: true
  ARM_TENANT_ID: ${{vars.TENANT_ID}}

Debug Output



Error: retrieving Storage Account (Subscription: "xxxxxxxx"
Resource Group Name: yyyyyy"
Storage Account Name: "aaaaa"): unexpected status 403 (403 Forbidden) with error: AuthorizationFailed: The client '.... does not have authorization to perform action 'Microsoft.Storage/storageAccounts/read' over scope `resourceid to storage account `or the scope is invalid. If access was recently granted, please refresh your credentials.


Expected Behavior

OIDC authentication towards azurerm backend should work without breaking changes

Actual Behavior

Seems that this PR broke OIDC auth towards azurerm backends(?) and the release notes do not mention breaking changes.
#36258

It is not immediately obvious how to fix this apart from downgrading to version 1.10.x

Steps to Reproduce

terraform init

Additional Context

No response

References

No response

Generative AI / LLM assisted development?

No response

@audunsolemdal audunsolemdal added bug new new issue not yet triaged labels Feb 27, 2025
@r-poirier
Copy link

We also encoutered this error with the upgrade.
Giving the identity accessing the backend the Reader role on the storage account seems to fix the issue.

@audunsolemdal
Copy link
Author

We also encoutered this error with the upgrade. Giving the identity accessing the backend the Reader role on the storage account seems to fix the issue.

Interesting, in our current setup we only grant Storage Blob Data Owner to managed identities at the blob container level, no assignments at the storage account level. Seems to be a regression with regards to permissions which hopefully can be improved?

@audunsolemdal
Copy link
Author

Semi-related, would be interesting to see if this issue is resolved by the mentioned PR #28423

@OskarKlintrot
Copy link

OskarKlintrot commented Feb 27, 2025

I seem to have hit this as well. I couldn't for the life of me figure out what I had changed until I noticed I had a new version of TF. If I revert back to 1.10.5 everything works as before.

@iantriggs
Copy link

Exact same error here, rolling back to 1.10 has worked for me too.

@adelinn
Copy link

adelinn commented Feb 28, 2025

Same issue here. For some reason the azurerm backend now requires an additional permission to work, Microsoft.Storage/storageAccounts/read on the whole storage account. This new permission is not strictly needed and shouldn't be required for the backend to work.

@jaredfholgate
Copy link
Contributor

@magodo It looks like an extra read has been introduced as part of the backend updates. Previously the minimum permissions required were Storage Blob Data Owner on the container when use_azuread_auth was set. It is now asking for read access to the whole storage account and breaking many existing implementations. I'll try to take a look at the code and see where it is happening.

In the short term we are pinning to 1.10.5 where we can.

@jaredfholgate
Copy link
Contributor

jaredfholgate commented Mar 3, 2025

@magodo It looks like an extra read has been introduced as part of the backend updates. Previously the minimum permissions required were Storage Blob Data Owner on the container when use_azuread_auth was set. It is now asking for read access to the whole storage account and breaking many existing implementations. I'll try to take a look at the code and see where it is happening.

In the short term we are pinning to 1.10.5 where we can.

@magodo Looks like we may be missing a return here?

Looks like it is trying to query the storage account meta data here:

resp, err := client.storageAccountsClient.GetProperties(ctx, storageAccountId, storageaccounts.DefaultGetPropertiesOperationOptions())

I'm guessing it only needs that client.accountDetail when getting a SAS, which is not required for Entra ID auth?

Update: I now see the comment on the PR: One implementation detail is that the using the same Azure storage dataplane SDK, the storage client requires a base URI of the storage account, which is derived by sending a GET to the storage account. This is skipped in case the storage shared access key or sas token is specified, which is to behave identically as the current version.

This appears to be the root cause problem. Hopefully there is a way to derive the URI without needing to query the end point?

PR: #36258

@magodo
Copy link
Contributor

magodo commented Mar 4, 2025

Sorry * for the breaking change.. I've made a fix in #36623, and tested it as much as possible to ensure all the cases are covered (see the PR description).

@audunsolemdal About your specific case, you'll probably have to remove resource_group_name from your configuration even after #36623 is merged. This is to allow users who uses private DNS zone in the storage account can get the blob endpoint via a management plane API call, which is indicated by the precense of resource_group_name and subscription_id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend/azure bug new new issue not yet triaged
Projects
None yet
8 participants