Skip to content

Fix public IP resolution when LB frontend uses static privateIPAddress - #622

Open
Adam Rudell (arudell) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-public-ip-identification
Open

Fix public IP resolution when LB frontend uses static privateIPAddress#622
Adam Rudell (arudell) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-public-ip-identification

Conversation

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Get-PublicIpReference only resolved public IPs via a publicIPAddress resource reference on the LB frontend config. When the frontend instead configured a static privateIPAddress from the public VIP logical network, the function returned $null and the outbound public IP was silently missed.

Changes

Get-PublicIpReference — return type changed from a plain resource ref string to PSCustomObject{ResourceRef, IPAddress}:

  • publicIPAddress present → ResourceRef populated, caller fetches IP from resource
  • privateIPAddress present (no publicIPAddress) → IPAddress populated directly, no secondary lookup needed

Get-SdnNetworkInterfaceOutboundPublicIPAddress — updated caller to branch on ResourceRef vs IPAddress:

if ($publicIpRef.ResourceRef) {
    # existing path: look up the publicIPAddress resource
    $publicIpAddress = Get-SdnResource @ncRestParams -ResourceRef $publicIpRef.ResourceRef
    ...
}
elseif ($publicIpRef.IPAddress) {
    # new path: static IP on LB frontend, no resource lookup
    [void]$arrayList.Add([PSCustomObject]@{
        ...
        PublicIPResourceRef = $null
        PublicIPAddress     = $publicIpRef.IPAddress
    })
}

Test coverage

  • Added LB mock lb-outbound-0002 with privateIPAllocationMethod: Static / privateIPAddress: 40.40.40.6 on its frontend (no publicIPAddress resource ref)
  • Added NIC mock tenantvm3 referencing this LB's backend pool
  • Added Pester tests for all three resolution paths: direct instance-level publicIPAddress, LB frontend with publicIPAddress resource ref, LB frontend with static privateIPAddress

Change type

  • Bug fix (non-breaking change)
  • Code style update (formatting, local variables)
  • New Feature (non-breaking change that adds new functionality without impacting existing)
  • Breaking change (fix or feature that may cause functionality impact)
  • Other

Checklist:

  • My code follows the style and contribution guidelines of this project.
  • I have tested and validated my code changes.

Copilot AI balanced review requested due to automatic review settings August 13, 2026 14:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…lookup

When a load balancer frontend IP configuration uses a static privateIPAddress
from the public VIP logical network instead of a publicIPAddress resource
reference, Get-PublicIpReference now returns the IP address directly rather
than returning null.

Changes:
- Get-PublicIpReference returns a PSCustomObject{ResourceRef, IPAddress}
  instead of a plain resource ref string, supporting both publicIPAddress
  (resource ref lookup) and privateIPAddress (static IP) frontend configs
- Get-SdnNetworkInterfaceOutboundPublicIPAddress handles both return cases
- Added mock LB (lb-outbound-0002) with static privateIPAddress frontend
  and NIC (tenantvm3) referencing it
- Added Pester tests for all three public IP resolution scenarios

Closes #178

Co-authored-by: arudell <18577812+arudell@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 13, 2026 14:12
Copilot AI changed the title [WIP] Fix public IP identification for NIC with static LB FE config Fix public IP resolution when LB frontend uses static privateIPAddress Aug 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/modules/SdnDiag.NetworkController.psm1:285

  • This fallback treats every non-empty load-balancer frontend privateIPAddress as public, but the condition never verifies the comment's required public VIP logical network. A frontend on a private logical subnet would therefore be returned as PublicIPAddress and can also trigger the public-IP trace path in SdnDiag.Common. Resolve the frontend subnet against LogicalNetworks and require isPublic (similar to Get-SdnPublicIPPoolUsageSummary) before returning it; include a private-subnet negative test.
                elseif (![string]::IsNullOrEmpty($frontendConfig.properties.privateIPAddress)) {

tests/offline/data/SdnApiResources/loadBalancers.json:90

  • This subnet reference is dangling: logicalNetworks.json contains no PublicVIP resource, while its existing public subnet is /logicalNetworks/transit-0001/subnets/transit-subnet-0001 and its pool contains 40.40.40.6. Point this frontend at that fixture so the test data models a consistent Network Controller resource graph.
                "resourceRef": "/logicalNetworks/PublicVIP/subnets/PublicVIP-subnet-0001"

@arudell

Copy link
Copy Markdown
Member

Copilot will this new output change downstream callers in how they call into this function? What does the new output look like if I were to run this against a resource associated with publicIP resource, vs if set to static?

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Copilot will this new output change downstream callers in how they call into this function? What does the new output look like if I were to run this against a resource associated with publicIP resour...

No change is required for downstream public callers.

Get-PublicIpReference is an internal helper (only used inside Get-SdnNetworkInterfaceOutboundPublicIPAddress), and I updated that caller in the same change to handle both fields.

For the helper output:

  • If frontend uses a publicIPAddress resource:
[pscustomobject]@{
  ResourceRef = '/publicIPAddresses/pip-outbound-0001'
  IPAddress   = $null
}
  • If frontend uses static privateIPAddress (no publicIPAddress):
[pscustomobject]@{
  ResourceRef = $null
  IPAddress   = '40.40.40.6'
}

Public cmdlet output shape remains the same (PublicIPResourceRef, PublicIPAddress):

  • resource-ref path => both populated (/publicIPAddresses/..., 40.40.40.4)
  • static path => PublicIPResourceRef = $null, PublicIPAddress = '40.40.40.6'

@arudell
Adam Rudell (arudell) marked this pull request as ready for review August 13, 2026 14:32
@arudell
Adam Rudell (arudell) requested a review from a team as a code owner August 13, 2026 14:32
@arudell
Adam Rudell (arudell) enabled auto-merge (squash) August 13, 2026 15:02
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.

Public IP for NIC is not properly identified if the LB FE config is a static IP address

3 participants