Skip to content

Return a relative paginated nextLink so clients can reach the next page - #12842

Merged
nithyatsu merged 3 commits into
mainfrom
nithyatsu/nextlink-ucp-rewrite
Aug 27, 2026
Merged

nithyatsu merged 3 commits into
mainfrom
nithyatsu/nextlink-ucp-rewrite

Conversation

@nithyatsu

@nithyatsu nithyatsu commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

GetNextLinkURL built the paginated nextLink from the inbound request host:

url := url.URL{
    Host:   req.Host,        // ← the host *this server* was reached on
    Scheme: req.URL.Scheme,
    Path:   req.URL.Path,
    ...
}

A server has no reliable way to know the address the client actually dialed. The request may have been proxied by UCP, and in Kubernetes the API server aggregator explicitly replaces the original host with the address of the service it forwards to:

// k8s.io/apiserver/pkg/util/proxy/proxy.go
newReq.Host = location.Host

(see kubernetes/kubernetes#107435 — the same limitation already documented in pkg/sdk/connection_location.go).

So the link came back as http://dynamic-rp.radius-system:8082/planes/..., a cluster-internal address no out-of-cluster client can reach. Any client that follows it fails. That is why rad app delete aborts partway through enumerating resources and leaves the application undeletable, as reported in radius-project/ai-extensions#441.

Reason for change

Fixes #12837.

The bug only appears once a listing paginates, so it stays invisible until an application has more resources than one page holds — and then the application cannot be deleted at all.

Approach

The server cannot know the client's address, so it should stop trying to guess it. This change emits a relative reference (path and query only) and lets the client resolve it against the endpoint it already reached — which is routable for that client by definition.

This requires no client change. Every generated client already funnels the link through azcore, which resolves a relative nextLink against its configured endpoint:

// azcore/internal/exported/request.go — NewRequestForNextLink
if !hasScheme(nextLink) {
    nextLink = JoinPaths(endpoint, nextLink)
}

The path base is trimmed so the client supplies its own, which keeps both producers of nextLink consistent:

Producer Path the server sees Emitted link
Resource provider behind the UCP proxy /planes/... (UCP already trimmed its path base in proxy.go) /planes/...
UCP serving its own list /apis/api.ucp.dev/v1alpha3/planes/... (routes are mounted under the path base) /planes/...

UCP's configured path base (/apis/api.ucp.dev/v1alpha3) is exactly the path portion of the endpoint a Kubernetes connection builds, so repeating it would double-prefix the URL. Trimming it means both producers resolve to the same reachable URL. v1.ParsePathBase already implements this, so no configuration has to be plumbed through.

Alternatives considered

Rewriting the link on the way out — either in the UCP proxy or in the SDK round tripper, mirroring how Location and Azure-AsyncOperation are handled — was implemented first and discarded. Both stages depend on the Referer header, whose host is also the address UCP itself was reached on and therefore wrong behind the aggregator. Rewriting also means parsing and re-serializing every paginated response body in the proxy. Not embedding an unknowable host in the first place is smaller and removes the failure mode rather than compensating for it.

Auto-generated summary

File Change
pkg/armrpc/frontend/controller/util.go GetNextLinkURL returns a relative reference, dropping the scheme and authority the server cannot know, and trims the path base so the client supplies its own.
pkg/armrpc/frontend/controller/util_test.go Adds value-level coverage for GetNextLinkURL.

Testing

GetNextLinkURL had no value-level coverage before this change. The existing tests only asserted that a link was non-empty (require.NotNil(t, actualOutput.NextLink)), which is precisely why the leaked host went unnoticed. The new tests assert the link itself:

  • the link is relative and never contains the inbound host, for a proxied RP, a UCP-served list, and an Azure-plane list;
  • resolving it against the endpoint a Kubernetes connection builds yields the same reachable URL whether it came from the RP or from UCP;
  • api-version, top and an opaque skipToken containing reserved characters survive the round trip;
  • the last page yields an empty link.

All six subtests fail against the previous implementation and pass with this change. ./pkg/armrpc/..., ./pkg/ucp/..., ./pkg/dynamicrp/..., ./pkg/sdk/... and ./pkg/corerp/frontend/... pass, and golangci-lint reports no issues.

Manual verification

With a resource group holding more than one page of resources:

kubectl get --raw "/apis/api.ucp.dev/v1alpha3/planes/radius/local/resourcegroups/<rg>/providers/Radius.Compute/containers?api-version=2025-08-01-preview&top=5" | jq -r .nextLink

Before: http://dynamic-rp.radius-system:8082/planes/...
After: /planes/...

Then confirm rad app delete completes against that resource group.

Contributor checklist

  • Considered malicious use cases and addressed them.
  • Considered UX impact.
  • Considered security implications.
  • Added relevant tests.
  • Documentation updated (no user-facing documentation describes the shape of nextLink).

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Unit Tests

    2 files  ±0    459 suites  ±0   8m 30s ⏱️ -8s
6 527 tests +9  6 525 ✅ +9  2 💤 ±0  0 ❌ ±0 
7 803 runs  +9  7 801 ✅ +9  2 💤 ±0  0 ❌ ±0 

Results for commit 2267593. ± Comparison against base commit 745ce9c.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.00%. Comparing base (f00bb86) to head (2267593).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12842      +/-   ##
==========================================
+ Coverage   59.97%   60.00%   +0.02%     
==========================================
  Files         776      776              
  Lines       46410    46413       +3     
==========================================
+ Hits        27836    27848      +12     
+ Misses      18574    18565       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

GetNextLinkURL built the link from the inbound request host. A server has
no reliable way to know the address the client actually dialed: the
request may have been proxied by UCP and, in Kubernetes, the API server
aggregator replaces the original host with the address of the service it
forwards to (kubernetes/kubernetes#107435). The link therefore leaked a
cluster-internal address such as http://dynamic-rp.radius-system:8082/...
that no out-of-cluster client can reach. Following it fails, which is why
`rad app delete` aborts while enumerating resources and leaves the
application undeletable.

Emit a relative reference instead, dropping the scheme and authority the
server cannot know. Clients resolve it against the endpoint they already
reached, which is routable for them by definition; generated clients do
this automatically in azcore's runtime.NewRequestForNextLink.

The path base is trimmed so the client can supply its own. UCP serves its
own lists mounted under /apis/api.ucp.dev/v1alpha3, which is already part
of every client's endpoint and would otherwise be repeated, while a
proxied resource provider sees a path that already begins at /planes/ and
so has nothing to trim. Both now yield the same reachable URL.

GetNextLinkURL previously had no value-level coverage; the existing tests
only asserted that a link was non-empty, which is why this went unnoticed.
The new tests assert the link itself and that it resolves to a reachable
URL. All six fail against the old implementation.

Fixes #12837

Signed-off-by: Nithya Subramanian <nithyasu@microsoft.com>

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nithyatsu
nithyatsu force-pushed the nithyatsu/nextlink-ucp-rewrite branch from 12b5f49 to c152409 Compare August 27, 2026 15:44
@nithyatsu nithyatsu changed the title Rewrite paginated nextLink so it points back through UCP Return a relative paginated nextLink so clients can reach the next page Aug 27, 2026
@nithyatsu nithyatsu added the pr:standard Ongoing maintenance, minor improvements, documentation updates, and routine development work label Aug 27, 2026

@nithyatsu nithyatsu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified the fix end-to-end against the current tree. Summary of what I checked and one nit worth addressing.

Correctness in production: ✅

  • All Radius-facing generated clients (corerp v20231001preview + v20250801preview, daprrp, datastoresrp, messagingrp, ucp, and pkg/cli/clients_new/generated/zz_generated_genericresources_client.go) use runtime.NewRequestForNextLink(ctx, GET, client.internal.Endpoint(), nextLink). The raw runtime.NewRequest call sites (pkg/sdk/v20241101preview/*, pkg/sdk/clients/resourcedeploymentoperationsclient.go) talk to Azure ARM only and are unaffected.
  • Dynamic-rp resources like Radius.Compute/containers (the exact repro in #12837) are enumerated by the CLI through GenericResourcesClient, so the fix covers them.
  • azcore runtime.NewRequestForNextLink (v1.23.0) joins a scheme-less link via JoinPaths(endpoint, nextLink). pkg/sdk/connection_kubernetes.go sets endpoint to <host>/apis/api.ucp.dev/v1alpha3, so the client dials <host>/apis/api.ucp.dev/v1alpha3/planes/... — the URL UCP actually serves through the aggregated APIService.

Test run

Checked out util.go + util_test.go from this PR on top of upstream/main and ran the affected tests:

=== RUN   TestGetNextLinkURL_IsRelativeSoTheClientSuppliesTheAddress
--- PASS (3 subtests)
=== RUN   TestGetNextLinkURL_ResolvesAgainstTheEndpointTheClientDialed
--- PASS (2 subtests)
=== RUN   TestGetNextLinkURL_CarriesThePaginationState
--- PASS
=== RUN   TestGetNextLinkURL_IsEmptyOnTheLastPage
--- PASS
PASS
ok      github.com/radius-project/radius/pkg/armrpc/frontend/controller 0.464s

Nit — TestGetNextLinkURL_ResolvesAgainstTheEndpointTheClientDialed models the client with url.URL.ResolveReference, but the real client uses runtime.JoinPaths. They diverge:

Given endpoint https://kubernetes.example.com/apis/api.ucp.dev/v1alpha3 and the emitted link /planes/radius/local/.../Radius.Compute/containers?…:

Method Resolved URL
url.URL.ResolveReference (used in the test) https://kubernetes.example.com/planes/radius/local/.../containers?…
runtime.JoinPaths (used by the CLI via NewRequestForNextLink) https://kubernetes.example.com/apis/api.ucp.dev/v1alpha3/planes/radius/local/.../containers?…

Per RFC 3986, ResolveReference treats an absolute-path reference as replacing the base path — so it drops /apis/api.ucp.dev/v1alpha3. JoinPaths concatenates. The URL that actually reaches UCP through the aggregated APIService is the JoinPaths one; the current test asserts the ResolveReference one. Both look plausible in isolation, but a future change that produced planes/... (no leading slash) would silently break production while the test kept passing.

Suggest replacing the base.ResolveReference(...) block with runtime.JoinPaths(endpoint, link) and updating the expected string to include /apis/api.ucp.dev/v1alpha3. That closes the loop between what the server emits and what the client dials.

The resolution test modelled the client with url.URL.ResolveReference,
which is not how azcore resolves a nextLink. Per RFC 3986 an absolute-path
reference replaces the base path, so ResolveReference dropped the
/apis/api.ucp.dev/v1alpha3 path base, while azcore's JoinPaths
concatenates and keeps it. The test therefore asserted a URL the API
server does not route, and a link emitted without a leading slash would
have broken production while the test kept passing.

Call runtime.NewRequestForNextLink directly instead of modelling it, and
assert the emitted link is an absolute-path reference.

Signed-off-by: Nithya Subramanian <nithyasu@microsoft.com>

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nithyatsu

Copy link
Copy Markdown
Contributor Author

Good catch, and it was more than a nit — thanks. Fixed in 7dbd142.

You're right that ResolveReference and JoinPaths diverge, and the test was asserting the wrong side of that divergence. I confirmed it by running both against azcore v1.23.0 rather than reasoning about it:

NewRequestForNextLink -> https://kubernetes.example.com/apis/api.ucp.dev/v1alpha3/planes/radius/local/.../containers?api-version=2025-08-01-preview&skipToken=page2&top=10
ResolveReference      -> https://kubernetes.example.com/planes/radius/local/.../containers?api-version=2025-08-01-preview&skipToken=page2&top=10

So the production behaviour was correct all along, but the test asserted a URL the API server does not route — it had quietly dropped the path base.

Rather than swap in runtime.JoinPaths, I went one step further and called runtime.NewRequestForNextLink itself, since that is the exact function the generated clients invoke and it also exercises EncodeQueryParams on the way through. That removes the modelling step entirely instead of replacing one model with a closer one:

req, err := runtime.NewRequestForNextLink(t.Context(), http.MethodGet, endpoint, link)
require.NoError(t, err)

require.Equal(t,
    "https://kubernetes.example.com/apis/api.ucp.dev/v1alpha3/planes/radius/local/resourcegroups/default/providers/Radius.Compute/containers?api-version=2025-08-01-preview&skipToken=page2&top=10",
    req.Raw().URL.String())

I also added an explicit assertion for the failure mode you called out, since it is a property of the emitted link rather than of the resolution:

require.True(t, strings.HasPrefix(link, "/"), "link must start at the root")

Verified both regressions are now caught by deliberately breaking the implementation:

Injected regression Failing subtests
Previous absolute-URL implementation 5
Link emitted without a leading slash (planes/...) 3

The second one previously passed, which is precisely the gap you identified. gofmt, golangci-lint and ./pkg/armrpc/... are clean.

Thanks also for independently checking the generated-client call sites and confirming the raw runtime.NewRequest ones are Azure-ARM only — that was the main residual risk I had flagged in the description, so it is good to have it closed.

Empty commit to re-run the pull request checks, which were stuck pending.

Signed-off-by: Nithya Subramanian <nithyasu@microsoft.com>

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@radius-functional-tests

radius-functional-tests Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Radius functional test overview

🔍 Go to test action run

Click here to see the test run details
Name Value
Repository radius-project/radius
Commit ref 2267593
Unique ID funcc0f94ae96d
Image tag pr-funcc0f94ae96d
  • Dapr: 1.14.4
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funcc0f94ae96d
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funcc0f94ae96d
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funcc0f94ae96d
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funcc0f94ae96d
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funcc0f94ae96d
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@nithyatsu
nithyatsu marked this pull request as ready for review August 27, 2026 17:43
Copilot AI lite review requested due to automatic review settings August 27, 2026 17:43
@nithyatsu
nithyatsu requested review from a team as code owners August 27, 2026 17:43

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

This PR fixes paginated ARM list nextLink generation so that servers no longer emit an absolute URL derived from the inbound request host (which may be an unroutable, cluster-internal address when requests are proxied/aggregated). Instead, it returns a relative link (path + query), trimming any UCP path base so clients can reliably resolve the next page against the endpoint they actually dialed.

Changes:

  • Update GetNextLinkURL to emit a relative reference and trim any path base before /planes/ or /subscriptions/.
  • Add value-level tests asserting the exact nextLink format and verifying client-side resolution behavior via azcore/runtime.NewRequestForNextLink.
  • Add test coverage for query parameter preservation (including opaque skipToken) and last-page behavior.

Reviewed changes

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

File Description
pkg/armrpc/frontend/controller/util.go Switch nextLink to relative (no scheme/host) and trim path base using v1.ParsePathBase so clients supply their own routable endpoint.
pkg/armrpc/frontend/controller/util_test.go Add focused tests validating relative nextLink, correct trimming for UCP vs proxied RP paths, correct azcore resolution, and query round-tripping.

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

nithyatsu added a commit to nithyatsu/traderX that referenced this pull request Aug 27, 2026
Temporarily override the ucp, dynamic-rp and applications-rp images on the
per-run k3d control plane so the paginated nextLink fix in
radius-project/radius#12842 is exercised end to end by deploy and delete.

Remove once that pull request merges.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nithya Subramanian <nithyasu@microsoft.com>
@nithyatsu
nithyatsu enabled auto-merge August 27, 2026 21:58

@DariuszPorowski DariuszPorowski 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

@nithyatsu
nithyatsu added this pull request to the merge queue Aug 27, 2026
Merged via the queue into main with commit 6824146 Aug 27, 2026
84 of 85 checks passed
@nithyatsu
nithyatsu deleted the nithyatsu/nextlink-ucp-rewrite branch August 27, 2026 23:13
willdavsmith pushed a commit that referenced this pull request Sep 3, 2026
…ge (#12842)

# Description

`GetNextLinkURL` built the paginated `nextLink` from the inbound request
host:

```go
url := url.URL{
    Host:   req.Host,        // ← the host *this server* was reached on
    Scheme: req.URL.Scheme,
    Path:   req.URL.Path,
    ...
}
```

A server has no reliable way to know the address the client actually
dialed. The request may have been proxied by UCP, and in Kubernetes the
API server aggregator explicitly replaces the original host with the
address of the service it forwards to:

```go
// k8s.io/apiserver/pkg/util/proxy/proxy.go
newReq.Host = location.Host
```

(see kubernetes/kubernetes#107435 — the same limitation already
documented in `pkg/sdk/connection_location.go`).

So the link came back as
`http://dynamic-rp.radius-system:8082/planes/...`, a cluster-internal
address no out-of-cluster client can reach. Any client that follows it
fails. That is why `rad app delete` aborts partway through enumerating
resources and leaves the application undeletable, as reported in
radius-project/ai-extensions#441.

## Reason for change

Fixes #12837.

The bug only appears once a listing paginates, so it stays invisible
until an application has more resources than one page holds — and then
the application cannot be deleted at all.

## Approach

The server cannot know the client's address, so it should stop trying to
guess it. This change emits a **relative** reference (path and query
only) and lets the client resolve it against the endpoint it already
reached — which is routable for that client by definition.

This requires no client change. Every generated client already funnels
the link through azcore, which resolves a relative `nextLink` against
its configured endpoint:

```go
// azcore/internal/exported/request.go — NewRequestForNextLink
if !hasScheme(nextLink) {
    nextLink = JoinPaths(endpoint, nextLink)
}
```

The path base is trimmed so the client supplies its own, which keeps
both producers of `nextLink` consistent:

| Producer | Path the server sees | Emitted link |
|---|---|---|
| Resource provider behind the UCP proxy | `/planes/...` (UCP already
trimmed its path base in `proxy.go`) | `/planes/...` |
| UCP serving its own list | `/apis/api.ucp.dev/v1alpha3/planes/...`
(routes are mounted *under* the path base) | `/planes/...` |

UCP's configured path base (`/apis/api.ucp.dev/v1alpha3`) is exactly the
path portion of the endpoint a Kubernetes connection builds, so
repeating it would double-prefix the URL. Trimming it means both
producers resolve to the same reachable URL. `v1.ParsePathBase` already
implements this, so no configuration has to be plumbed through.

## Alternatives considered

Rewriting the link on the way out — either in the UCP proxy or in the
SDK round tripper, mirroring how `Location` and `Azure-AsyncOperation`
are handled — was implemented first and discarded. Both stages depend on
the `Referer` header, whose host is *also* the address UCP itself was
reached on and therefore wrong behind the aggregator. Rewriting also
means parsing and re-serializing every paginated response body in the
proxy. Not embedding an unknowable host in the first place is smaller
and removes the failure mode rather than compensating for it.

## Auto-generated summary

<!-- GENERATED BY COPILOT -->

| File | Change |
|---|---|
| `pkg/armrpc/frontend/controller/util.go` | `GetNextLinkURL` returns a
relative reference, dropping the scheme and authority the server cannot
know, and trims the path base so the client supplies its own. |
| `pkg/armrpc/frontend/controller/util_test.go` | Adds value-level
coverage for `GetNextLinkURL`. |

## Testing

`GetNextLinkURL` had **no value-level coverage** before this change. The
existing tests only asserted that a link was non-empty
(`require.NotNil(t, actualOutput.NextLink)`), which is precisely why the
leaked host went unnoticed. The new tests assert the link itself:

- the link is relative and never contains the inbound host, for a
proxied RP, a UCP-served list, and an Azure-plane list;
- resolving it against the endpoint a Kubernetes connection builds
yields the same reachable URL whether it came from the RP or from UCP;
- `api-version`, `top` and an opaque `skipToken` containing reserved
characters survive the round trip;
- the last page yields an empty link.

All six subtests fail against the previous implementation and pass with
this change. `./pkg/armrpc/...`, `./pkg/ucp/...`, `./pkg/dynamicrp/...`,
`./pkg/sdk/...` and `./pkg/corerp/frontend/...` pass, and
`golangci-lint` reports no issues.

### Manual verification

With a resource group holding more than one page of resources:

```console
kubectl get --raw "/apis/api.ucp.dev/v1alpha3/planes/radius/local/resourcegroups/<rg>/providers/Radius.Compute/containers?api-version=2025-08-01-preview&top=5" | jq -r .nextLink
```

Before: `http://dynamic-rp.radius-system:8082/planes/...`
After: `/planes/...`

Then confirm `rad app delete` completes against that resource group.

## Contributor checklist

- [x] Considered malicious use cases and addressed them.
- [x] Considered UX impact.
- [x] Considered security implications.
- [x] Added relevant tests.
- [ ] Documentation updated (no user-facing documentation describes the
shape of `nextLink`).

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 6824146)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:standard Ongoing maintenance, minor improvements, documentation updates, and routine development work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paginated nextLink leaks the RP's cluster-internal address, breaking any out-of-cluster client

3 participants