Azure flexible federated identity using app registrations to assist with wildcard branch setup

It is a common frustration because we need to federate our app registration credential everytime we are trying to create a branch and do a build. Now we have Azure Flexible federated credential enabled for only App Registrations.  

Let's say you an existing app registration we can federate it easily using the following command:- 


az rest --method post --url https://graph.microsoft.com/beta/applications/your-app-registration-client-id/federatedIdentityCredentials --body "{'name': 'FlexFic1', 'issuer': 'https://token.actions.githubusercontent.com', 'audiences': ['api://AzureADTokenExchange'],'claimsMatchingExpression': {'value': 'claims[\'sub\'] matches \'  repo:kepungnzai/dot-net-gw:ref:refs/heads/*\'','languageVersion': 1}}"

 This will create the necessary federated credentials as shown here:- 


And in your pipeline 

 name: 'Login to Azure'
        uses: azure/login@v3
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

After trigger the pipeline you will see the following 

Run azure/login@v3
Running Azure CLI Login.
/usr/bin/az cloud set -n azurecloud
Done setting cloud: "azurecloud"
Federated token details:
subject claim - repo:kepungnzai/dot-net-gw:ref:refs/heads/main
audience - api://AzureADTokenExchange

In case you run into this error, please ensure you have grant necessary permission to your target subscription 

Error: No subscriptions found for ***.








Comments

Popular posts from this blog

mongosh install properly

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type