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

OIDC based Azurerm backend authentication not working for Azure China Cloud #35565

Open
ankitatdnv opened this issue Aug 14, 2024 · 3 comments
Open
Labels
backend/azure bug new new issue not yet triaged

Comments

@ankitatdnv
Copy link

Terraform Version

Terraform v1.8.0
on windows_amd64

Terraform Configuration Files

"terraform": {
    "backend": {
      "azurerm": {
        "container_name": "tfstates",
        "environment": "china",
        "key": "prod.terraform.tfstate",
        "resource_group_name": "RG_Name",
        "storage_account_name": "saaccount",
        "use_oidc": true
      }
    },
    "required_providers": {
      "azuread": {
        "source": "hashicorp/azuread",
        "version": "2.50.0"
      },
      "azurerm": {
        "source": "azurerm",
        "version": "3.99.0"
      }
    }
  },
"provider": {
    "azuread": [
      {
        "environment": "china",
        "use_oidc": true
      }
    ],
    "azurerm": [
      {
        "environment": "china",
        "features": {
        },
        "use_oidc": true
      }
    ]
  }

Debug Output

Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "saaccount": autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: clientCredentialsToken: received HTTP status 401 with response: {"error":"invalid_client","error_description":"AADSTS700212: No matching federated identity record found for presented assertion audience 'api://AzureADTokenExchange'. Please check your federated identity credential Subject, Audience and Issuer against the presented assertion. https://learn.microsoft.com/entra/workload-id/workload-identity-federation Trace ID: 4e74bc4f-80b6-434d-aba7-73c124dc5800 Correlation ID: 61f558e1-841a-4b19-96af-5ddadc2c3cb6 Timestamp: 2024-08-14 13:37:59Z","error_codes":[700212],"timestamp":"2024-08-14 13:37:59Z","trace_id":"4e74bc4f-80b6-434d-aba7-73c124dc5800","correlation_id":"61f558e1-841a-4b19-96af-5ddadc2c3cb6"}

Expected Behavior

It should be able to authenticate

Actual Behavior

It's failing in authentication and the reason looks like due to wrong assertion audience.
Because for Azure China Cloud default assertion audience for federated credential is api://AzureADTokenExchangeChina in EntraId where as as per above logs it's trying to use 'api://AzureADTokenExchange' assertion audience while looking for federated credentials.

Steps to Reproduce

  1. terraform init

Additional Context

No response

References

No response

@ankitatdnv ankitatdnv added bug new new issue not yet triaged labels Aug 14, 2024
@crw
Copy link
Collaborator

crw commented Aug 14, 2024

Thanks for this report! The Azure Provider team (at HashiCorp) maintains the Azure backend, and so we will need that team to triage and comment on this issue. Thanks again!

@ankitatdnv
Copy link
Author

Thanks @crw . Also, I think the behavior is same for Azurerm and Azuread provider

@crw
Copy link
Collaborator

crw commented Aug 16, 2024

@ankitatdnv You would want to file that against the providers directly. https://github.com/terraform-providers/terraform-provider-azurerm/issues (for example).

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
Development

No branches or pull requests

3 participants