Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
412 stars 201 forks source link

Crash when logging into another tenant #1573

Closed ctolkien closed 1 year ago

ctolkien commented 1 year ago

Output from azd version azd version 0.6.0-beta.2 (commit c4a201e55a13eba77f9037b296a90e0f81b00dbe)

Output from az version

{
  "azure-cli": "2.44.1",
  "azure-cli-core": "2.44.1",
  "azure-cli-telemetry": "1.0.8",
  "extensions": {
    "containerapp": "0.3.20"
  }
}

Describe the bug Crash after logging into another tenant, I can type the command, it pops a browser, I can login in the browser successfully, and it briefly displays "Retrieving subscriptions" before crashing with the below stack trace:

[signal 0xc0000005 code=0x0 addr=0x0 pc=0x594292]

goroutine 1 [running]:
github.com/azure/azure-dev/cli/azd/pkg/tools/azcli.(*SubscriptionsService).ListTenants.func1(0xc00071ee70?, 0x9?)
        D:/a/_work/1/s/cli/azd/pkg/tools/azcli/subscriptions.go:174 +0x32
sort.partition_func({0xc00071f020?, 0xc00057e300?}, 0x0, 0xe, 0xbdd28?)
        C:/hostedtoolcache/windows/go/1.19.0/x64/src/sort/zsortfunc.go:142 +0xaf
sort.pdqsort_func({0xc00071f020?, 0xc00057e300?}, 0xc0005c84e0?, 0x0?, 0x300?)
        C:/hostedtoolcache/windows/go/1.19.0/x64/src/sort/zsortfunc.go:114 +0x254
sort.Slice({0x923d80, 0xc0005c84e0}, 0x10?)
        C:/hostedtoolcache/windows/go/1.19.0/x64/src/sort/slice.go:23 +0x97
github.com/azure/azure-dev/cli/azd/pkg/tools/azcli.(*SubscriptionsService).ListTenants(0xc000492d00?, {0xc4e4b8, 0xc0004a1530})
        D:/a/_work/1/s/cli/azd/pkg/tools/azcli/subscriptions.go:173 +0x1d5
github.com/azure/azure-dev/cli/azd/pkg/account.(*SubscriptionsManager).ListSubscriptions(0xc000326c80, {0xc4e4b8, 0xc0004a1530})
        D:/a/_work/1/s/cli/azd/pkg/account/subscriptions_manager.go:171 +0x1c8
github.com/azure/azure-dev/cli/azd/pkg/account.(*SubscriptionsManager).RefreshSubscriptions(0xc000326c80, {0xc4e4b8?, 0xc0004a1530?})
        D:/a/_work/1/s/cli/azd/pkg/account/subscriptions_manager.go:74 +0x2c
github.com/azure/azure-dev/cli/azd/cmd.(*loginAction).Run(0xc000093d60, {0xc4e4b8, 0xc0004a1530})
        D:/a/_work/1/s/cli/azd/cmd/login.go:201 +0x2b2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0xc4e4b8?, 0xc0004a1530?})
        D:/a/_work/1/s/cli/azd/cmd/middleware/middleware.go:109 +0x23e
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*TelemetryMiddleware).Run(0xc00000a810, {0xc4e4b8, 0xc0004a06f0}, 0xc000326d00)
        D:/a/_work/1/s/cli/azd/cmd/middleware/telemetry.go:40 +0x175
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0xc4e4b8, 0xc0004a06f0})
        D:/a/_work/1/s/cli/azd/cmd/middleware/middleware.go:107 +0x1f2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*DebugMiddleware).Run(0xc000009878, {0xc4e4b8, 0xc0004a06f0}, 0xc000326d00)
        D:/a/_work/1/s/cli/azd/cmd/middleware/debug.go:48 +0x2af
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0xc4e4b8, 0xc0004a06f0})
        D:/a/_work/1/s/cli/azd/cmd/middleware/middleware.go:107 +0x1f2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction(0xc00034a560, {0xc4e4b8, 0xc0004a06f0}, 0x903b80?, {0xc44e20?, 0xc000093d60})
        D:/a/_work/1/s/cli/azd/cmd/middleware/middleware.go:113 +0x23d
github.com/azure/azure-dev/cli/azd/cmd.(*CobraBuilder).configureActionResolver.func1(0xc00037e780, {0xc00034ae80, 0x0, 0x2})
        D:/a/_work/1/s/cli/azd/cmd/cobra_builder.go:132 +0x426
github.com/spf13/cobra.(*Command).execute(0xc00037e780, {0xc00034ae60, 0x2, 0x2})
        C:/Users/cloudtest/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000337900)
        C:/Users/cloudtest/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        C:/Users/cloudtest/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        C:/Users/cloudtest/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:895
main.main()
        D:/a/_work/1/s/cli/azd/main.go:61 +0x24d

To Reproduce azd login --tenant-id <anotherTenantHostname>

Expected behavior Not crash?

Additional context Note that we are CSP Indirect Provider. Access is being provided via Delegated Admin Permissions.

vhvb1989 commented 1 year ago

Hello @ctolkien While we investigate this error, can you try running this: azd config set auth.useAzCliAuth "true"

This will make azd to use the Azure cli for authentication (as it used to be before version 0.5.0).
I assume you don't have this issue when working with the Azure cli (i.e. az login --tenant-id XXXXX) , right?

Some other questions.. can you tell if the name of the Tenant you are trying to authenticate contains some special characters ?

vhvb1989 commented 1 year ago

@weikanglim @wbreza , the signal error: signal 0xc0000005 means Access violation.

Since the error is coming from:

sort.Slice(tenants, func(i, j int) bool {
        return *tenants[i].DisplayName < *tenants[j].DisplayName
    })

I assume that the tenants client is not setting the DisplayName for one of the subs. (Might be related to the Delegated Admin Permissions).

ctolkien commented 1 year ago

While we investigate this error, can you try running this: azd config set auth.useAzCliAuth "true"

OK I think the plot is a little bit thicker (I actually had that config set from 0.5 to allow us to deploy to other tenants, but had removed it).

Noting this worked in 0.3 OK, and in 0.5 it also worked with auth.useAzCliAuth "true"

I assume you don't have this issue when working with the Azure cli (i.e. az login --tenant-id XXXXX) , right?

Correct, az cli works fine. Noting that they use --tenant as their param name (would be good to be aligned, but I digress).

can you tell if the name of the Tenant you are trying to authenticate contains some special characters ?

Nothing special.

ctolkien commented 1 year ago

MASSIVE EDIT - I was totally wrong, here is a sample anyway

Sample response when I az login --tenant foo.onmicrosoft.com:

[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "tenantId of the tenant I have logged into",
    "id": "id of the subscription listed below",
    "isDefault": true,
    "managedByTenants": [
      {
        "tenantId": "my home tenant id"
      }
    ],
    "name": "SubscriptionName",
    "state": "Enabled",
    "tenantId": "tenantId of the tenant I have logged into",
    "user": {
      "name": "my email",
      "type": "user"
    }
  }
]