Skip to content

Comments

Make ado token command environment-aware for SYSTEM_ACCESSTOKEN#447

Draft
dggsax wants to merge 5 commits intoAzureAD:mainfrom
dggsax:users/danigon/system-access-token-surprises
Draft

Make ado token command environment-aware for SYSTEM_ACCESSTOKEN#447
dggsax wants to merge 5 commits intoAzureAD:mainfrom
dggsax:users/danigon/system-access-token-surprises

Conversation

@dggsax
Copy link

@dggsax dggsax commented Feb 21, 2026

Summary

Addresses #422

Makes the ado token command environment-aware so that SYSTEM_ACCESSTOKEN is handled appropriately based on context, and adds authenticated NuGet feed configuration.

Behavior

Environment AZUREAUTH_ADO_PAT SYSTEM_ACCESSTOKEN Result
Any ✅ Set (any) Uses AZUREAUTH_ADO_PAT (explicit user override, always honored)
ADO Pipeline ❌ Not set ✅ Set Uses SYSTEM_ACCESSTOKEN
ADO Pipeline ❌ Not set ❌ Not set Error — interactive auth is impossible in a pipeline
Developer machine ❌ Not set ✅ Set Warning logged (unusual), token ignored, continues to AAD auth
Developer machine ❌ Not set ❌ Not set Normal AAD token auth

Changes

  • nuget.config — Added packageSourceCredentials for authenticated package restore via ADO_TOKEN env var
  • EnvVars.cs — Added TfBuild constant for the TF_BUILD env var
  • IEnvExtensions.cs — Added IsAdoPipeline() extension method (checks TF_BUILD == "True")
  • PatFromEnv.cs — Kept as a pure environment lookup (unchanged behavior); CommandToken now applies environment-aware policy on top of its results
  • CommandToken.cs — After calling PatFromEnv.Get(), checks the token source: if SYSTEM_ACCESSTOKEN was found outside a pipeline, logs a warning and falls through to AAD auth
  • PatFromEnvTest.cs — Original tests preserved
  • IEnvExtensionsTest.cs — 6 test cases for IsAdoPipeline()
  • CommandTokenTest.cs — 5 new OnExecute tests covering all environment/token combinations

Why

Previously, the ado token command would silently return SYSTEM_ACCESSTOKEN even on developer machines where it was unexpectedly set, causing confusing auth behavior. This change ensures the token is only used in pipeline environments where it is expected, and provides clear feedback in all other cases.

@dggsax dggsax requested a review from a team as a code owner February 21, 2026 07:59
@dggsax dggsax marked this pull request as draft February 21, 2026 17:49
Refactor the ado token command to detect ADO Pipeline environments
via the TF_BUILD env var and adjust SYSTEM_ACCESSTOKEN handling:

- AZUREAUTH_ADO_PAT is always checked first (explicit user override)
- In ADO Pipeline: use SYSTEM_ACCESSTOKEN if found, error if missing
  (interactive auth is not possible in pipelines)
- Outside ADO Pipeline: warn if SYSTEM_ACCESSTOKEN is unexpectedly
  set, ignore it, and continue to normal AAD token auth

Addresses AzureAD#422

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dggsax dggsax force-pushed the users/danigon/system-access-token-surprises branch from c51cc91 to 13ae83b Compare February 21, 2026 17:58
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.

1 participant