Open gurretl opened 6 months ago
As far as I know the token expiration time controlled by service, I cannot extend the token life time based on the request.
Hi @xuzhang3
Thanks for your reply.
I found a solution, it was not related to the token I guess. I had to create more resources to be close to the "Automatic" method.
Maybe we just need to update the example provided in the Terraform documentation for the "Automatic" WIF service connection.
What I did is the following: I used it with an App registration resource (as it works behind the scenes in "Automatic") instead of a User assigned Managed Identity (manual).
resource "azuread_application" "application" {
display_name = local.service_principal_name
}
resource "azuread_service_principal" "service_principal" {
client_id = azuread_application.application.client_id
}
resource "azuredevops_serviceendpoint_azurerm" "azure_connection" {
project_id = data.azuredevops_project.main.id
service_endpoint_name = local.azdo_service_endpoint_name
description = local.azdo_service_endpoint_description
service_endpoint_authentication_scheme = "WorkloadIdentityFederation"
credentials {
serviceprincipalid = azuread_application.application.client_id
}
azurerm_spn_tenantid = var.tenant_id
azurerm_subscription_id = var.subscription_id
azurerm_subscription_name = data.azurerm_subscription.main.display_name
}
resource "azuread_application_federated_identity_credential" "main" {
application_id = "/applications/${azuread_application.application.object_id}"
display_name = "example-federated-credential"
description = "Test"
audiences = ["api://AzureADTokenExchange"]
issuer = azuredevops_serviceendpoint_azurerm.azure_connection.workload_identity_federation_issuer
subject = azuredevops_serviceendpoint_azurerm.azure_connection.workload_identity_federation_subject
}
If you use the example provided in the Terraform documentation, you may face the error I mentioned in this issue.
Community Note
Terraform (and Azure DevOps Provider) Version
Affected Resource(s)
azuredevops_serviceendpoint_azurerm
Terraform Configuration Files
Debug Output
Panic Output
The token seems to be valid for 10 minutes, and our pipeline duration is less than 3 minutes.
Expected Behavior
Actual Behavior
Steps to Reproduce
Important Factoids
We have successfully created a manual Workload Identity Federation service connection (let's call it "my-root-serviceconnection") in Azure DevOps.
Using this "my-root-serviceconnection" service connection in our pipelines, we have tried to create additional Workload Identity Federation (Automatic) service connections for other projects using Terraform through a pipeline and face this error.
The terraform code above works when we use a PAT. We set use_oidc to false and pass the PAT in the environment variables.
With the PAT and the WIF “my-root-serviceconnection”, the underlying azure identity has the following permissions : • Azure DevOps : Project Collection Administrator. • Azure : "Application Developer" role, which allows it to create app registrations.
Permissions have been verified with Azure CLI.
References
https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/serviceendpoint_azurerm#workload-identity-federation-automatic-azurerm-service-endpoint
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_oidc
0000