Skip to content

Add max-context-population input to override Azure PowerShell MaxCont… - #642

Merged
MaddyMicrosoft merged 5 commits into
masterfrom
feature/max-context-population
Sep 10, 2026
Merged

Add max-context-population input to override Azure PowerShell MaxCont…#642
MaddyMicrosoft merged 5 commits into
masterfrom
feature/max-context-population

Conversation

@MaddyMicrosoft

@MaddyMicrosoft MaddyMicrosoft commented Sep 9, 2026

Copy link
Copy Markdown
Member

Summary

Adds a max-context-population input that exposes Azure PowerShell's existing Connect-AzAccount -MaxContextPopulation parameter through the action.

Fixes #606.

Problem

When enable-AzPSSession: true, the action calls Connect-AzAccount internally. 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-AzSubscription followed by per-subscription calls) behave inconsistently. The only workaround today is to disable the PowerShell session and run Connect-AzAccount manually in a separate step, which platform teams have to roll out everywhere.

Change

  • action.yml — new optional max-context-population input, no default.
  • LoginConfig.ts — reads and trims the value; validate() rejects non-integer or out-of-range values (must be -1 or a positive integer) with a clear error, and warns when it's set without enable-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]$MaxContextPopulation param, forwarded to Connect-AzAccount only when bound ($PSBoundParameters.ContainsKey).
  • README.md — 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 argument being passed when set and omitted when unset.

Backward compatibility

Fully backward-compatible. When the input is unset, -MaxContextPopulation is never passed and the Azure PowerShell default of 25 applies, so existing workflows are unaffected. The input only affects the enable-AzPSSession path; Azure CLI login is untouched.

Testing

  • npm run build and npm test pass locally (33/33), including the PowerShell test that executes AzPSLogin.ps1 with the new parameter.
  • Verified Connect-AzAccount exposes -MaxContextPopulation as an Int32 parameter (Az.Accounts).
  • End-to-end validation of context loading against an identity with >25 subscriptions to be run via the release gate before merge.

Example

- uses: azure/login@v3
  with:
    client-id: ${{ vars.AZURE_CLIENT_ID }}
    tenant-id: ${{ vars.AZURE_TENANT_ID }}
    subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
    enable-AzPSSession: true
    max-context-population: -1

…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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-population input (documented in action.yml and README.md).
  • Threaded the value through LoginConfigAzPSScriptBuilderAzPSLogin.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.

Comment thread src/common/LoginConfig.ts
MaddyMicrosoft and others added 2 commits September 9, 2026 03:01
…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
@MaddyMicrosoft
MaddyMicrosoft marked this pull request as ready for review September 9, 2026 03:45
Comment thread README.md

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`

@isra-fel Yeming Liu (isra-fel) Sep 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a label like "Available in v3" since we support two major versions concurrently - this could be a chance to promote v3

@isra-fel Yeming Liu (isra-fel) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please check the inline comment and let me know what you think

MaddyMicrosoft and others added 2 commits September 10, 2026 10:40
… 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>
@MaddyMicrosoft
MaddyMicrosoft merged commit 3c5b5ce into master Sep 10, 2026
8 checks passed
@MaddyMicrosoft
MaddyMicrosoft deleted the feature/max-context-population branch September 10, 2026 01:44
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.

[Feature]: Support MaxContextPopulation Configuration in azure/login

3 participants