Skip to content

fix: authenticate TLS before buffering hook payloads - #1770

Merged
greysonlalonde merged 2 commits into
NVIDIA:release/0.11from
bbednarski9:bbednarski/aep-278-release-0.11-hook-tls-setup
Nov 20, 2026
Merged

greysonlalonde merged 2 commits into
NVIDIA:release/0.11from
bbednarski9:bbednarski/aep-278-release-0.11-hook-tls-setup

Conversation

@bbednarski9

@bbednarski9 bbednarski9 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

A stalled TLS handshake starts lazily during the buffered hook payload flush. On failure, dropping the buffer retries the flush and consumes another socket timeout. Complete pinned TLS authentication first: a two-second timeout now takes about two seconds instead of four and reports a handshake failure before payload delivery.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Preserve the configured timeout and the documented 30-second hook allowance.
  • Keep readiness fallback disabled after the tunnel upgrade; do not retry hook delivery.
  • Regress stalled upgrade/TLS paths and a valid delayed handshake followed by a slow guardrail denial.

Validation: all 20 authenticated-client tests, NEXTEST_TEST_THREADS=4 just test-rust (6,729 passed, 4 skipped), uv run pre-commit run, and just docs passed. Fern skipped authenticated redirect checking.

Where should the reviewer start?

Start with post_authenticated in crates/cli/src/gateway/client.rs and the daemon_hook_stalled_* / daemon_hook_preserves_slow_valid_tls_and_guardrail_budget tests in crates/cli/tests/coverage/shared/gateway_client_tests.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • Relates to AEP-278. This fixes a reproduced setup failure, without establishing the original incident's trigger.

Summary by CodeRabbit

  • Bug Fixes
    • Gateway connections now complete TLS authentication before sending hook payloads. Handshake failures are reported before payload delivery, and stalled tunnel setup respects the configured timeout.
    • Delayed but successful TLS handshakes can still complete, allowing the request to proceed and return the gateway’s response.
    • Route tokens and payloads are not sent before tunnel authentication succeeds.
  • Documentation
    • Updated Hook Forwarding guidance to describe TLS authentication, timeout behavior, and handshake failure reporting.

@bbednarski9
bbednarski9 requested review from a team as code owners November 18, 2026 17:34
@github-actions github-actions Bot added size:S PR is small Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Nov 18, 2026
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The authenticated gateway client completes the TLS handshake before buffering hook payloads. Tests cover stalled tunnel setup and delayed valid TLS. The hook forwarding documentation describes the handshake and timeout behavior.

Changes

Hook forwarding TLS handshake

Layer / File(s) Summary
Complete TLS authentication before payload delivery
crates/cli/src/gateway/client.rs, crates/cli/tests/coverage/shared/gateway_client_tests.rs, docs/nemo-relay-cli/basic-usage.mdx
post_authenticated completes the TLS handshake before buffering or writing application data. Tests cover stalled setup, verify route tokens and payload are not sent before authentication, and confirm a delayed valid handshake can return a later HTTP 403 response. The documentation describes the handshake and timeout behavior.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Possibly related PRs

  • NVIDIA/NeMo-Relay#1356: Adds pinned TLS for local daemon hooks and defines the tunnel TLS handshake timeout used by this authentication flow.
  • NVIDIA/NeMo-Relay#1379: Changes the hook client’s authenticated connection and payload delivery behavior, which is also addressed by this change.
Merge Risk: Minimal · up to 62f93

Hook forwarding now finishes TLS authentication before sending payloads, so a stalled handshake fails once within the configured timeout instead of taking about twice as long. No remaining merge-blocking risk was found.

Architecture risk: Low · up to 62f93

The change affects 2 systems.

Changed systems: crates, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in docs/nemo-relay-cli/basic-usage.mdx: Hook forwarding documentation now specifies that pinned TLS authentication completes before payload buffering; a stalled handshake uses the configured socket timeout once and fails before payload delivery. The previous text ended after noting that timed-out requests are not retried.
  • observed — Modified behavior in crates/cli/src/gateway/client.rs: post_authenticated now completes TLS negotiation before buffering application bytes. Handshake errors and an incomplete handshake are reported as pre-payload failures; previously, the first buffered flush could initiate TLS lazily, leaving failures classified as ambiguous payload delivery and allowing BufWriter drop to retry the flush.
  • observed — Modified behavior in crates/cli/tests/coverage/shared/gateway_client_tests.rs: Adds a shared test helper that stalls daemon tunnel setup, checking that failure occurs between 1.8 and 3.5 seconds for a configured two-second timeout and that route tokens and payload are absent before authentication. It distinguishes withheld upgrade from TLS failure after upgrade, which must report a TLS handshake failure without readiness fallback; the latter case also includes a partial TLS record test.
  • observed — Modified behavior in crates/cli/tests/coverage/shared/gateway_client_tests.rs: Adds tests for withheld upgrade, withheld TLS handshake, and a partial TLS handshake record, each using the shared bounded-setup assertions.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the allowed type "fix" with a lowercase imperative summary, is 52 characters, has no trailing period, and is not a breaking change. It names the main change: TLS authentication now comp…
Description check Passed The description follows the repository template. It has the Overview with both checklist items checked, a Details section listing the timeout, readiness fallback, and regression coverage, a Where shou…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses the allowed type "fix" with a lowercase imperative summary, is 52 characters, has no trailing period, and is not a breaking change. It names the main change: TLS authentication now completes before hook payloads are buffered, which matches the objectives and the summary of changes to post_authenticated.

Full details: Description check

Explanation

The description follows the repository template. It has the Overview with both checklist items checked, a Details section listing the timeout, readiness fallback, and regression coverage, a Where should the reviewer start section naming the file and tests, and a Related Issues section using the Relates to keyword with AEP-278. The author also states the validation results. The Overview says the change fixes a reproduced setup failure, but the Related Issues entry uses Relates to, so the wording is slightly inconsistent but not blocking.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a1475a1 and 62f935f.

Files selected for processing: 2

  • crates/cli/src/gateway/client.rs
  • crates/cli/tests/coverage/shared/gateway_client_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: Preview docs
  • GitHub Check: Changes / Detect
Additional context used

Path-based instructions: 1

Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

CodeRabbit configuration file

Files:

  • crates/cli/tests/coverage/shared/gateway_client_tests.rs
Learnings: 1

Common learnings

Learnt from: CR
Repo: NVIDIA/NeMo-Relay

Timestamp: 2026-11-18T22:02:53.842Z
Learning: Applicability reference:
AGENTS.md: # NeMo Relay Repository Guidance
## On-Demand Guidance
See `CONTRIBUTING.md` and `docs/contribute/testing-and-docs.mdx` for contributor
details, and `.agents/skills/README.md` for the maintainer skill boundary.

Source excerpt:
# Contributing to NeMo Relay

## SPDX License Headers

All source files must include an SPDX license header. Use the appropriate comment syntax for the file type:
Additional comments: 3

crates/cli/src/gateway/client.rs: 1

348-353: LGTM!

crates/cli/tests/coverage/shared/gateway_client_tests.rs: 2

462-462: LGTM!

Also applies to: 481-481, 487-487, 492-499

566-566: LGTM!

Also applies to: 571-577

@github-actions

Copy link
Copy Markdown

Comment thread crates/cli/src/gateway/client.rs Resolved

@mnajafian-nv mnajafian-nv 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.

Lgtm once Greyson’s comment is addressed, no additional findings on my side.

@bbednarski9

Copy link
Copy Markdown
Collaborator Author

/coderabbit review

@greysonlalonde
greysonlalonde merged commit ed7948b into NVIDIA:release/0.11 Nov 20, 2026
46 checks passed
@willkill07 willkill07 added this to the 0.11 milestone Nov 20, 2026

This branch was previously deployed

1 inactive deployment
fern — 62f935f9 Deployed Nov 20, 2026 by greysonlalonde via Clean up docs preview #7436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants