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

forced az login even when authenticated #10236

Closed
13 tasks
Xander-Rudolph opened this issue Jul 15, 2024 · 2 comments
Closed
13 tasks

forced az login even when authenticated #10236

Xander-Rudolph opened this issue Jul 15, 2024 · 2 comments

Comments

@Xander-Rudolph
Copy link

Description

when using the ./helpers/GenerateResourcesAndImage.ps1, even when already authenticated, a login is forced if an identity is already provided.

https://github.com/actions/runner-images/blob/main/helpers/GenerateResourcesAndImage.ps1#L243

        # Login to Azure subscription
        if ([string]::IsNullOrEmpty($AzureClientId)) {
            Write-Verbose "No AzureClientId was provided, will use interactive login."
            az login --output none
        }
        else {
            Write-Verbose "AzureClientId was provided, will use service principal login."
            az login --service-principal --username $AzureClientId --password=$AzureClientSecret --tenant $AzureTenantId --output none
        }
        az account set --subscription $SubscriptionId
        if ($LastExitCode -ne 0) {
            throw "Failed to login to Azure subscription '$SubscriptionId'."
        }

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04
  • macOS 12
  • macOS 13
  • macOS 13 Arm64
  • macOS 14
  • macOS 14 Arm64
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

this issue doesn't effect runners, only runner provisioners

Is it regression?

no

Expected behavior

when running the image create script, if already logged in, the current profile should be used

Actual behavior

when logged in, az login should be skipped

Repro steps

first login az login
Then

Import-Module ./runner-images/helpers/GenerateResourcesAndImage.ps1
GenerateResourcesAndImage -SubscriptionId $SUBSCRIPTION_ID -ResourceGroupName $RESOURCE_GROUP_NAME -ReuseResourceGroup -ImageGenerationRepositoryRoot ./runner-images -ImageType $IMAGETYPE -AzureLocation $REGION -Tag @{source='https://github.com/actions/runner-images'}

and an auth prompt will be shown

suggested workaround (i've already tested this locally and with my pipelines and it works):

        # Login to Azure subscription
        try {
            $azAccount = az account show -o none
            Write-Warning "Already logged in..."
        }
        catch {
            if ([string]::IsNullOrEmpty($env:AzureClientId)) {
                Write-Verbose "No AzureClientId was provided, will use interactive login."
                az login --output none
            }
            else {
                Write-Verbose "AzureClientId was provided, will use service principal login."
                az login --service-principal --username $AzureClientId --password=$AzureClientSecret --tenant $AzureTenantId --output none
            }
        }
@RaviAkshintala
Copy link
Contributor

@Xander-Rudolph Thank you for bringing this issue to us. We are looking into this issue and will update you on this issue after investigating.

@subir0071
Copy link
Contributor

Closing this issue as of now. Please feel free to open an issue in case problem is faced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants