Skip to content

ACM-38826 fix(backend): use GET /api with body drain instead of HEAD [release-2.15] - #6598

Open
Randy424 wants to merge 2 commits into
stolostron:release-2.15from
Randy424:ACM-38826-token-validation-fix-release-2.15
Open

ACM-38826 fix(backend): use GET /api with body drain instead of HEAD [release-2.15]#6598
Randy424 wants to merge 2 commits into
stolostron:release-2.15from
Randy424:ACM-38826-token-validation-fix-release-2.15

Conversation

@Randy424

@Randy424 Randy424 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes 405 regression from the original HEAD /api approach — HEAD /api is rejected by some cluster API server / proxy configurations
  • Switches isAuthenticated() to GET /api with explicit body drain (.resume())
  • Preserves the memory leak fix: /api response is ~200 bytes (vs several MB for /apis), drained immediately so sockets return to the keepAlive pool

Changes

  • backend/src/lib/token.ts: GET /api with body drain, returns Promise<number>
  • 12 test files: nock interceptors updated from .get('/apis') to .get('/api')

Test plan

  • All backend unit tests pass (214 tests)

Backport of #6600 to release-2.15

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: stolostron/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 45602779-3307-435c-90d5-3fad8722a967

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Randy424

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Randy424
Randy424 force-pushed the ACM-38826-token-validation-fix-release-2.15 branch from d84a76b to dbabbc9 Compare July 29, 2026 02:13
@Randy424

Copy link
Copy Markdown
Contributor Author

/retest

@Randy424 Randy424 changed the title ACM-38826 fix(backend): use HEAD /api for token validation [release-2.15] ACM-38826 fix(backend): use GET /api with body drain instead of HEAD [release-2.15] Jul 29, 2026
@sonarqubecloud

Copy link
Copy Markdown

Randy424 and others added 2 commits August 16, 2026 21:50
…te response body drain (stolostron#6537)

getAuthenticatedToken() called isAuthenticated() on every authenticated
request, which issued GET /apis to the kube API. The response body (up to
several MB on CRD-heavy clusters) was never consumed on the success path,
preventing the socket from returning to the keepAlive pool. Under sustained
load, native (external) memory accumulated proportionally to request volume.

Replace GET /apis with HEAD /api:
- HEAD responses have no message body by HTTP spec — nothing to drain
- /api (core group) is ~200 bytes of headers; it does not grow with CRDs
- Returns HTTP status so callers preserve 401/403/5xx distinctions
- No client-side caching required: OpenShift oauth-apiserver caches valid
  tokens ~30 seconds server-side; failures are not cached

isAuthenticated() now returns Promise<number> (HTTP status) instead of
Promise<Response> so callers preserve upstream status codes. authenticated.ts
updated accordingly. All route tests updated to mock HEAD /api instead of
GET /apis.

Signed-off-by: Randy Bruno Piverger <21374229+Randy424@users.noreply.github.com>
Co-authored-by: Randy Bruno Piverger <21374229+Randy424@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
HEAD /api returns 405 on clusters where the API server or proxy chain
rejects HEAD requests, causing every auth check to fail. Switch to
GET /api with explicit body drain — the response is ~200 bytes (core
API group only), drained immediately so the socket returns to the
keepAlive pool. This preserves the memory optimization while restoring
compatibility.

Signed-off-by: Randy Bruno Piverger <21374229+Randy424@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Randy424
Randy424 force-pushed the ACM-38826-token-validation-fix-release-2.15 branch from ba4599b to 1406bd1 Compare August 17, 2026 04:52
@Randy424

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest release-2.15 to resolve the merge conflict.

Conflict: backend/test/routes/ansibletower.test.tsrelease-2.15 had since picked up the glasswing RBAC-secret fix, which added nockCredentialSecret(TOWER_HOST) calls and new tests to this file. This PR's two commits (original HEAD /api attempt, then the GET /api correction) each touched the same test blocks, so both replayed with conflicts.

Resolution: Followed the same approach used for the release-2.14 backport (#6671), which itself mirrored how main resolved this code: for each conflicting test, kept upstream's new nockCredentialSecret/RBAC-field additions and applied only this PR's intended line-level change (rename + mock method) on top.

Additional fix: Several .get('/apis') auth-check mocks in the same file were never touched by either commit's diff (new tests release-2.15 added independently) but would have failed silently once isAuthenticated() calls GET /apinock.disableNetConnect() is on, so an unmatched request throws instead of returning the mocked response. Converted those too for consistency.

Verified: all 227 backend tests pass, lint clean.

@openshift-ci

openshift-ci Bot commented Aug 17, 2026

Copy link
Copy Markdown

@Randy424: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/unit-tests-sonarcloud 1406bd1 link true /test unit-tests-sonarcloud

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant