Add max-context-population input to override Azure PowerShell MaxCont… - #642
Conversation
…extPopulation Azure PowerShell loads a maximum of 25 subscription contexts by default (MaxContextPopulation = 25). When enable-AzPSSession is true and the identity can access more than 25 subscriptions, only a subset of contexts is loaded, so downstream cmdlets that enumerate or target other subscriptions behave inconsistently. Previously the only workaround was to disable the PowerShell session and call Connect-AzAccount manually. Expose the existing Connect-AzAccount -MaxContextPopulation parameter through a new optional max-context-population input: - action.yml: new optional input (no default). - LoginConfig: reads and trims the value; validate() rejects non-integer or out-of-range values (must be -1 or a positive integer) and warns when it is set without enable-AzPSSession, where it has no effect. - AzPSScriptBuilder: passes -MaxContextPopulation only when the input is set. - AzPSLogin.ps1: adds an [int]$MaxContextPopulation param, forwarded to Connect-AzAccount only when bound so the default behavior is unchanged. - README: input table row and a max-context-population section, including a note that -1 loads all contexts and can slow login for large tenants. - Tests: cover the arg being passed when set and omitted when unset. Fully backward-compatible: when the input is unset, the parameter is never passed and the Azure PowerShell default of 25 applies. Only affects the enable-AzPSSession path. Fixes #606. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The current max-context-population validation can accept formats/ranges that will fail or behave unexpectedly when bound to PowerShell’s Int32 parameter (e.g., 1e3 or out-of-range values).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR exposes Azure PowerShell’s existing Connect-AzAccount -MaxContextPopulation knob via a new max-context-population action input, so large tenants (with >25 subscriptions) can reliably load more (or all) subscription contexts when enable-AzPSSession: true.
Changes:
- Added a new optional
max-context-populationinput (documented inaction.ymlandREADME.md). - Threaded the value through
LoginConfig→AzPSScriptBuilder→AzPSLogin.ps1, applying it only when provided. - Added unit tests to verify the argument is included when set and omitted when unset.
File summaries
| File | Description |
|---|---|
src/PowerShell/AzPSScriptBuilder.ts |
Adds -MaxContextPopulation <value> to the PowerShell script invocation when configured. |
src/PowerShell/AzPSLogin.ps1 |
Accepts MaxContextPopulation and forwards it to Connect-AzAccount only when bound. |
src/common/LoginConfig.ts |
Reads max-context-population input and validates it; warns when irrelevant (AzPSSession disabled). |
README.md |
Documents the new input, default behavior (25), and the -1 performance tradeoff. |
action.yml |
Declares the new max-context-population input and describes its semantics. |
__tests__/PowerShell/AzPSScriptBuilder.test.ts |
Adds coverage for passing/omitting -MaxContextPopulation. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ange Validate the raw input string rather than Number(), which accepts scientific, hex and float forms (1e3, 0x10, 5.0) and out-of-range values that then fail Connect-AzAccount's [int] binding with a confusing error. Accept only -1 or a plain positive integer within 1..2147483647, matching the cmdlet's ValidateRange(-1, 2147483647). Add unit tests for the accepted and rejected cases, and note the bound in the README. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-population # Conflicts: # README.md # action.yml # src/common/LoginConfig.ts
|
|
||
| Refer to [Login With System-assigned Managed Identity](#login-with-system-assigned-managed-identity) and [Login With User-assigned Managed Identity](#login-with-user-assigned-managed-identity) for its usage. | ||
|
|
||
| ### `max-context-population` |
There was a problem hiding this comment.
Could use a label like "Available in v3" since we support two major versions concurrently - this could be a chance to promote v3
… azure/login@v3 Add an 'Available in azure/login@v3' label under each input heading. Both are v3-only inputs (not present in v2), so this documents the version and points consumers at v3. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Adds a
max-context-populationinput that exposes Azure PowerShell's existingConnect-AzAccount -MaxContextPopulationparameter through the action.Fixes #606.
Problem
When
enable-AzPSSession: true, the action callsConnect-AzAccountinternally. Azure PowerShell loads a maximum of 25 subscription contexts by default (MaxContextPopulation = 25). When the authenticated identity can access more than 25 subscriptions, only a subset of contexts is loaded, so downstream cmdlets that enumerate or target other subscriptions (e.g.Get-AzSubscriptionfollowed by per-subscription calls) behave inconsistently. The only workaround today is to disable the PowerShell session and runConnect-AzAccountmanually in a separate step, which platform teams have to roll out everywhere.Change
action.yml— new optionalmax-context-populationinput, no default.LoginConfig.ts— reads and trims the value;validate()rejects non-integer or out-of-range values (must be-1or a positive integer) with a clear error, and warns when it's set withoutenable-AzPSSession(where it has no effect).AzPSScriptBuilder.ts— passes-MaxContextPopulation <value>to the invocation only when the input is set.AzPSLogin.ps1— adds an[int]$MaxContextPopulationparam, forwarded toConnect-AzAccountonly when bound ($PSBoundParameters.ContainsKey).README.md— input-table row and amax-context-populationsection, including a note that-1loads all contexts and can slow login for large tenants.Backward compatibility
Fully backward-compatible. When the input is unset,
-MaxContextPopulationis never passed and the Azure PowerShell default of 25 applies, so existing workflows are unaffected. The input only affects theenable-AzPSSessionpath; Azure CLI login is untouched.Testing
npm run buildandnpm testpass locally (33/33), including the PowerShell test that executesAzPSLogin.ps1with the new parameter.Connect-AzAccountexposes-MaxContextPopulationas anInt32parameter (Az.Accounts).Example