Hello Albert Ventura,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that AZURE_FEDERATED_TOKEN not injected in pipeline using Workload Identity Federation.
To resolve the issues:
- Check that the Issuer URL follows this pattern: https://vstoken.dev.azure.com/<org-id> For references: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops#workload-identity-federation You can go to Project Settings > Service Connections > to ensure the connection uses workload Identity Federation (OIDC).
- In your pipeline YAML Configuration, replace the incorrect settings (
addSpnToEnvironment: true
) and use a properly configuredAzureCLI@2
task:
For references: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-cli-v2?view=azure-pipelines- task: AzureCLI@2 inputs: azureSubscription: <Service-Connection-Name> scriptType: pscore script: | az login --federated-token "$env:AZURE_FEDERATED_TOKEN" --service-principal -u $env:ARM_CLIENT_ID -t $env:ARM_TENANT_ID
- Use windows-2022 (or Ubuntu 20.04+) to run a compatible agent. By ensure agent has:
- Azure CLI 2.30+
- Azure PowerShell 9.0+
- You can also add a step to check if the
AZURE_FEDERATED_TOKEN
is present:
If the token is missing, it means OIDC is not configured correctly.- script: env | sort displayName: Print environment variables
- About the service pricipal, you will need to check if the Service Principal has the correct RBAC role on the target Azure resource using shell command:
For a reference: https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-cliaz role assignment create --assignee <Client-ID> --role "Contributor" --scope <Azure-Resource-ID>
- Finally, check organization Security Policies (If Required) by navigate to: Organization Settings > Security > Policies. This is to affirm Third-party application access via OAuth is enabled. For a reference: https://learn.microsoft.com/en-us/azure/devops/organizations/security/change-application-access-policies?view=azure-devops&tabs=preview-page
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer.