Skip to content

Validate tenant ID match against subscription's actual tenant in agent init - #6997

Merged
Travis Angevine (trangevi) merged 2 commits into
trangevi/autorun-improvementsfrom
copilot/sub-pr-6980-again
Mar 4, 2026
Merged

Validate tenant ID match against subscription's actual tenant in agent init#6997
Travis Angevine (trangevi) merged 2 commits into
trangevi/autorun-improvementsfrom
copilot/sub-pr-6980-again

Conversation

Copilot AI commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

When AZURE_TENANT_ID was already set in the azd environment, tenant resolution was skipped entirely — meaning a stale or mismatched tenant could silently cause auth failures when targeting a Foundry project in a different tenant.

Changes

  • exterrors/codes.go: Added CodeTenantMismatch = "tenant_mismatch" to validation error codes.
  • cmd/init.go: LookupTenant now runs unconditionally. After the lookup:
    • Empty AZURE_TENANT_ID → set from lookup (unchanged behavior)
    • Non-empty AZURE_TENANT_ID that differs from the subscription's tenant → return a Validation error, consistent with the existing subscription_mismatch / location_mismatch pattern:
} else if currentTenant.Value != tenantResp.TenantId {
    return nil, exterrors.Validation(
        exterrors.CodeTenantMismatch,
        fmt.Sprintf("tenant ID mismatch: environment has %s but project uses %s", currentTenant.Value, tenantResp.TenantId),
        "update or recreate your environment with 'azd env new'",
    )
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix agent init issues based on review feedback Validate tenant ID match against subscription's actual tenant in agent init Mar 4, 2026
@trangevi
Travis Angevine (trangevi) marked this pull request as ready for review March 4, 2026 19:20
@trangevi
Travis Angevine (trangevi) merged commit 48e9bc7 into trangevi/autorun-improvements Mar 4, 2026
13 checks passed
Travis Angevine (trangevi) added a commit that referenced this pull request Mar 5, 2026
…lot/CICD scenarios (#6980)

* Some default handling updates for `azd ai agent init`

Signed-off-by: trangevi <trangevi@microsoft.com>

* Add support for new parameter for an existing model deployment

Signed-off-by: trangevi <trangevi@microsoft.com>

* Fix surfacing of noPrompt

Signed-off-by: trangevi <trangevi@microsoft.com>

* Add proper tenant handling for -p scenario

Signed-off-by: trangevi <trangevi@microsoft.com>

* Add model parameter as well so the model default isn't necessarily implicit

Signed-off-by: trangevi <trangevi@microsoft.com>

* Update cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* code comments

Signed-off-by: trangevi <trangevi@microsoft.com>

* Unit testability for noprompt model selection

Signed-off-by: trangevi <trangevi@microsoft.com>

* Validate tenant ID match against subscription's actual tenant in agent init (#6997)

* Initial plan

* Return validation error on tenant ID mismatch in agent init

Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>

* Lint fix?

Signed-off-by: trangevi <trangevi@microsoft.com>

---------

Signed-off-by: trangevi <trangevi@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
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.

2 participants