Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/instructions/extensions.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
applyTo:
- cli/azd/extensions/**
---
- When accessing a `Subscription` from `PromptSubscription()`, always use
`Subscription.UserTenantId` (user access tenant) for credential creation,
NOT `Subscription.TenantId` (resource tenant). For multi-tenant/guest users
these differ, and using `TenantId` causes authentication failures.
The `LookupTenant()` API already returns the correct user access tenant.
2 changes: 1 addition & 1 deletion cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func ensureAzureContext(
}

azureContext.Scope.SubscriptionId = subscriptionResponse.Subscription.Id
azureContext.Scope.TenantId = subscriptionResponse.Subscription.TenantId
azureContext.Scope.TenantId = subscriptionResponse.Subscription.UserTenantId

// Set the subscription ID in the environment
_, err = azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func (a *InitFromCodeAction) ensureSubscription(ctx context.Context) error {
}

a.azureContext.Scope.SubscriptionId = subscriptionResponse.Subscription.Id
a.azureContext.Scope.TenantId = subscriptionResponse.Subscription.TenantId
a.azureContext.Scope.TenantId = subscriptionResponse.Subscription.UserTenantId
} else {
tenantResponse, err := a.azdClient.Account().LookupTenant(ctx, &azdext.LookupTenantRequest{
SubscriptionId: a.azureContext.Scope.SubscriptionId,
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/extensions/azure.ai.finetune/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func ensureEnvironment(ctx context.Context, flags *initFlags, azdClient *azdext.
return nil, fmt.Errorf("failed to prompt for subscription: %w", err)
}
subscriptionId = subscriptionResponse.Subscription.Id
tenantId = subscriptionResponse.Subscription.TenantId
tenantId = subscriptionResponse.Subscription.UserTenantId
} else {
// Get tenant ID from subscription
tenantResponse, err := azdClient.Account().LookupTenant(ctx, &azdext.LookupTenantRequest{
Expand Down Expand Up @@ -598,7 +598,7 @@ func ensureAzureContext(
}

azureContext.Scope.SubscriptionId = subscriptionResponse.Subscription.Id
azureContext.Scope.TenantId = subscriptionResponse.Subscription.TenantId
azureContext.Scope.TenantId = subscriptionResponse.Subscription.UserTenantId

// Set the subscription ID in the environment
_, err = azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func promptForProject(ctx context.Context, flags *customFlags, azdClient *azdext
return fmt.Errorf("failed to prompt for subscription: %w", err)
}
subscriptionId = resp.Subscription.Id
tenantId = resp.Subscription.TenantId
tenantId = resp.Subscription.UserTenantId
} else {
tenantResp, err := azdClient.Account().LookupTenant(ctx, &azdext.LookupTenantRequest{
SubscriptionId: subscriptionId,
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/extensions/azure.ai.models/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func ensureEnvironment(ctx context.Context, flags *initFlags, azdClient *azdext.
return nil, fmt.Errorf("failed to prompt for subscription: %w", err)
}
subscriptionId = resp.Subscription.Id
tenantId = resp.Subscription.TenantId
tenantId = resp.Subscription.UserTenantId
} else {
tenantResp, err := azdClient.Account().LookupTenant(ctx, &azdext.LookupTenantRequest{
SubscriptionId: subscriptionId,
Expand Down Expand Up @@ -365,7 +365,7 @@ func ensureAzureContext(
}

azureContext.Scope.SubscriptionId = resp.Subscription.Id
azureContext.Scope.TenantId = resp.Subscription.TenantId
azureContext.Scope.TenantId = resp.Subscription.UserTenantId

if err := setEnvValue(ctx, azdClient, env.Name, "AZURE_TENANT_ID", azureContext.Scope.TenantId); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func ensureAzureContext(
}

azureContext.Scope.SubscriptionId = subscriptionResponse.Subscription.Id
azureContext.Scope.TenantId = subscriptionResponse.Subscription.TenantId
azureContext.Scope.TenantId = subscriptionResponse.Subscription.UserTenantId

// Set the subscription ID in the environment
_, err = azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newPromptCommand() *cobra.Command {
}

azureContext.Scope.SubscriptionId = selectedSubscription.Subscription.Id
azureContext.Scope.TenantId = selectedSubscription.Subscription.TenantId
azureContext.Scope.TenantId = selectedSubscription.Subscription.UserTenantId

filterByResourceTypeResponse, err := azdClient.
Prompt().
Expand Down
Loading