Repository navigation
Return a relative paginated nextLink so clients can reach the next page - #12842
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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>
12b5f49 to
c152409
Compare
nithyatsu
left a comment
There was a problem hiding this comment.
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) useruntime.NewRequestForNextLink(ctx, GET, client.internal.Endpoint(), nextLink). The rawruntime.NewRequestcall 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 throughGenericResourcesClient, so the fix covers them. - azcore
runtime.NewRequestForNextLink(v1.23.0) joins a scheme-less link viaJoinPaths(endpoint, nextLink).pkg/sdk/connection_kubernetes.gosets 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>
|
Good catch, and it was more than a nit — thanks. Fixed in 7dbd142. You're right that 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 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:
The second one previously passed, which is precisely the gap you identified. Thanks also for independently checking the generated-client call sites and confirming the raw |
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 test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
There was a problem hiding this comment.
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
GetNextLinkURLto emit a relative reference and trim any path base before/planes/or/subscriptions/. - Add value-level tests asserting the exact
nextLinkformat and verifying client-side resolution behavior viaazcore/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.
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>
…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)
Description
GetNextLinkURLbuilt the paginatednextLinkfrom 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 explicitly replaces the original host with the address of the service it forwards to:
(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 whyrad app deleteaborts 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
nextLinkagainst its configured endpoint:The path base is trimmed so the client supplies its own, which keeps both producers of
nextLinkconsistent:/planes/...(UCP already trimmed its path base inproxy.go)/planes/.../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.ParsePathBasealready 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
LocationandAzure-AsyncOperationare handled — was implemented first and discarded. Both stages depend on theRefererheader, 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
pkg/armrpc/frontend/controller/util.goGetNextLinkURLreturns 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.goGetNextLinkURL.Testing
GetNextLinkURLhad 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:api-version,topand an opaqueskipTokencontaining reserved characters survive the round trip;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, andgolangci-lintreports 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 .nextLinkBefore:
http://dynamic-rp.radius-system:8082/planes/...After:
/planes/...Then confirm
rad app deletecompletes against that resource group.Contributor checklist
nextLink).