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

fix: priroitise azure pipelines creds #709

Conversation

jaredfholgate
Copy link
Member

@jaredfholgate jaredfholgate commented Jan 8, 2025

This PR is to re-order the creds, so that settings for Azure Pipelines OIDC auth are prioritised over static token creds.

For example with these pipeline settings, it will prioritise azure pipeline auth over the ARM_OIDC_TOKEN:

steps:
  - task: AzureCLI@2
    displayName: Terraform Plan
    inputs:
      azureSubscription: "My-Service-Conbnection"
      scriptType: pscore
      scriptLocation: inlineScript
      addSpnToEnvironment: true
      inlineScript: |
        # Get settings from service connection
        az account show 2>$null | ConvertFrom-Json | Set-Variable account
        $clientId = $account.user.name
        $oidcToken = $env:idToken
        $subscriptionId = $account.id
        $tenantId = $account.tenantId

        $env:ARM_TENANT_ID = $account.tenantId
        $env:ARM_SUBSCRIPTION_ID = $account.id
       
        $env:ARM_USE_OIDC = "true"
        $env:ARM_CLIENT_ID = $clientId
        $env:ARM_USE_AZUREAD = "true"

        # Prioritise for `azapi` provider
        $env:ARM_OIDC_AZURE_SERVICE_CONNECTION_ID = "My-Service-Conbnection"
        $env:ARM_OIDC_REQUEST_TOKEN ="$(System.AccessToken)"

        # Fallback for `azurerm` and `azuread` providers
        $env:ARM_OIDC_TOKEN = $oidcToken

        # Run Terraform Plan
        $command = "terraform"
        $arguments = @()
        $arguments += "plan"
        $arguments += "-out=tfplan"
        $arguments += "-input=false"

        Write-Host "Running: $command $arguments"
        & $command $arguments

@jaredfholgate jaredfholgate force-pushed the fix-prioritise-azure-pipelines-creds branch from 2a1c274 to 9d3f0b7 Compare January 8, 2025 10:30
@magodo
Copy link
Contributor

magodo commented Jan 30, 2025

@jaredfholgate This PR is unnecessary once the ADO OIDC supports in azurerm/azuread providers are available?

@jaredfholgate
Copy link
Member Author

@jaredfholgate This PR is unnecessary once the ADO OIDC supports in azurerm/azuread providers are available?

Yes, so long as we match the env vars as discussed elsewhere then it will not be needed.

@ms-henglu
Copy link
Member

I'll close this PR in favor of #784 which adds support for same environment variables as azurerm provider.

@ms-henglu ms-henglu closed this Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants