Repository navigation
feat(pacquet): honor NODE_EXTRA_CA_CERTS for custom CA trust - #12508
Conversation
pacquet's reqwest client trusts only its bundled webpki roots plus the .npmrc ca/cafile material — it ignores NODE_EXTRA_CA_CERTS. pnpm running on Node picks that variable up transitively via Node's TLS runtime, so a native port has to read it explicitly to keep real-world parity for users behind a corporate MITM proxy or a self-signed registry. Load the named PEM bundle as additional trust roots in default_client_builder (the single chokepoint every client routes through), keeping the .npmrc-derived TlsConfig env-free. Additive and lowest-priority; a missing, unreadable, or malformed file is silently ignored, matching pnpm's silent treatment of a missing cafile. Documented as the one deliberate exception to the TlsConfig no-env-vars parity note.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesNODE_EXTRA_CA_CERTS TLS trust root injection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoHonor NODE_EXTRA_CA_CERTS for pacquet registry TLS trust Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Unbounded CA bundle read
|
There was a problem hiding this comment.
Pull request overview
Adds NODE_EXTRA_CA_CERTS support to pacquet’s registry HTTP client so native TLS trust matches pnpm’s behavior when run under Node (where Node implicitly honors this env var).
Changes:
- Apply
NODE_EXTRA_CA_CERTS(PEM bundle) as additional trust roots in the shared reqwestClientBuilderpath. - Document the env-var exception to the “
.npmrc-only TLS config” policy inTlsConfigmodule docs. - Add a unit test that mutates
NODE_EXTRA_CA_CERTSand asserts client construction is tolerant of missing paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
pacquet/crates/network/src/lib.rs |
Adds apply_node_extra_ca_certs() and wires it into default_client_builder(). |
pacquet/crates/network/src/tls.rs |
Updates TLS module docs to record the NODE_EXTRA_CA_CERTS exception. |
pacquet/crates/network/src/tests.rs |
Adds an env-var mutation test for NODE_EXTRA_CA_CERTS behavior/tolerance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Code review by qodo was updated up to the latest commit 493ac9b |
Addresses review on the NODE_EXTRA_CA_CERTS change: - Read and parse the bundle once in for_installs via load_node_extra_ca_certs(), then clone the parsed certs into the default client and each per-registry client. Previously default_client_builder re-read and re-parsed the file on every call, i.e. once per per-registry override. - Use the existing EnvGuard test helper (process-wide lock + restore on drop, panic-safe) instead of a hand-rolled lock with manual restore. The test now also asserts a valid bundle parses to one root and a missing file yields none.
|
Thanks for the review. Addressed in 01560b8:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pacquet/crates/network/src/lib.rs (1)
435-436: 💤 Low valueDoc comment references
Self::for_installsbut this is a free function.The doc comment uses
Self::for_installsandSelf::for_installs(line 435, 439), butload_node_extra_ca_certsis a module-level free function, not an inherent method.Selfhas no meaning here. Reference the function directly or use the full path.📝 Suggested fix
-/// The certs are added in [`Self::for_installs`] +/// The certs are added in [`ThrottledClient::for_installs`] ... -/// Read and parsed once per [`Self::for_installs`] call — `for_installs` +/// Read and parsed once per [`ThrottledClient::for_installs`] call — `for_installs`🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pacquet/crates/network/src/lib.rs` around lines 435 - 436, The doc comment for the free function `load_node_extra_ca_certs` incorrectly references `Self::for_installs` in multiple places, but `Self` is not valid in a free function context. Replace all instances of `Self::for_installs` with a direct reference to the function, either using just the function name `for_installs` or the full module path depending on where it is located relative to `load_node_extra_ca_certs`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pacquet/crates/network/src/lib.rs`:
- Around line 435-436: The doc comment for the free function
`load_node_extra_ca_certs` incorrectly references `Self::for_installs` in
multiple places, but `Self` is not valid in a free function context. Replace all
instances of `Self::for_installs` with a direct reference to the function,
either using just the function name `for_installs` or the full module path
depending on where it is located relative to `load_node_extra_ca_certs`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8eed889f-0d40-45b7-8be3-592d4543b505
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (4)
pacquet/crates/network/Cargo.tomlpacquet/crates/network/src/lib.rspacquet/crates/network/src/tests.rspacquet/crates/network/src/tls.rs
✅ Files skipped from review due to trivial changes (1)
- pacquet/crates/network/src/tls.rs
|
Code review by qodo was updated up to the latest commit 01560b8 |
Make the pacquet and aube tests mirror each other in form and coverage: exercise the same four cases in the same order — empty value, valid bundle (asserting one parsed root plus a successful client build), a readable non-PEM file, and a missing file — each asserting load_node_extra_ca_certs() yields the expected roots. Also align the env-var read in load_node_extra_ca_certs to the same let-else + filter form aube uses (no behavior change).
|
Code review by qodo was updated up to the latest commit dc5aa5c |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pacquet/crates/network/src/tests.rs (1)
457-463: ⚡ Quick winUse
tempfilefor the invalid-PEM fixture instead of a predictable temp path.Building a filename from
temp_dir + pidis collision-prone and less robust in parallel/CI runs. Prefertempfile::NamedTempFile(orTempDir) so creation/cleanup is atomic and isolated.Suggested update
- let bad = - std::env::temp_dir().join(format!("pacquet-node-extra-ca-{}.pem", std::process::id())); - std::fs::write(&bad, b"not a certificate").expect("write temp ca bundle"); - env.set("NODE_EXTRA_CA_CERTS", &bad); + let bad = tempfile::NamedTempFile::new().expect("create temp ca bundle"); + std::fs::write(bad.path(), b"not a certificate").expect("write temp ca bundle"); + env.set("NODE_EXTRA_CA_CERTS", bad.path()); assert!(super::load_node_extra_ca_certs().is_empty()); - let _ = std::fs::remove_file(&bad);As per coding guidelines, “Prefer real fixtures using tempfile::TempDir ... for testing” in
pacquet/**/*.rs.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pacquet/crates/network/src/tests.rs` around lines 457 - 463, The test fixture is creating a temporary file using a predictable path combining std::env::temp_dir() and std::process::id(), which is collision-prone and not suitable for parallel or CI environments. Replace this manual temp file creation with tempfile::NamedTempFile to ensure atomic creation and automatic cleanup. Create the NamedTempFile, write the invalid PEM content to it, obtain its path to set in the NODE_EXTRA_CA_CERTS environment variable via env.set(), and then invoke super::load_node_extra_ca_certs() for the assertion. Remove the explicit std::fs::remove_file call since NamedTempFile handles cleanup automatically when dropped.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pacquet/crates/network/src/tests.rs`:
- Around line 457-463: The test fixture is creating a temporary file using a
predictable path combining std::env::temp_dir() and std::process::id(), which is
collision-prone and not suitable for parallel or CI environments. Replace this
manual temp file creation with tempfile::NamedTempFile to ensure atomic creation
and automatic cleanup. Create the NamedTempFile, write the invalid PEM content
to it, obtain its path to set in the NODE_EXTRA_CA_CERTS environment variable
via env.set(), and then invoke super::load_node_extra_ca_certs() for the
assertion. Remove the explicit std::fs::remove_file call since NamedTempFile
handles cleanup automatically when dropped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f3402ced-1db1-4b51-bc98-c1b8f012e897
📒 Files selected for processing (2)
pacquet/crates/network/src/lib.rspacquet/crates/network/src/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pacquet/crates/network/src/lib.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12508 +/- ##
=======================================
Coverage 88.18% 88.19%
=======================================
Files 313 313
Lines 43074 43085 +11
=======================================
+ Hits 37983 37997 +14
+ Misses 5091 5088 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The free function's doc used [`Self::for_installs`], but `Self` only resolves in impl/trait contexts, so rustdoc flagged it as an unresolved intra-doc link and the Rust CI Doc job (RUSTDOCFLAGS=-D warnings) failed. Reference [`ThrottledClient::for_installs`] instead.
|
Code review by qodo was updated up to the latest commit fc96cc1 |
|
Congrats on merging your first pull request! 🎉🎉🎉 |
|
👯 🕺 👯 |
What
Make pacquet's registry HTTP client honor the
NODE_EXTRA_CA_CERTSenvironment variable.Why
pacquet's reqwest client trusts only its bundled webpki roots plus the
.npmrcca/cafilematerial — it consults no environment for CA trust. pnpm running on Node, however, does trustNODE_EXTRA_CA_CERTS— implicitly, via Node's TLS runtime. So users behind a corporate MITM proxy or a self-signed registry who setNODE_EXTRA_CA_CERTS(the standard Node convention) have working TLS under pnpm-on-Node today and would silently lose it under the native path. Reading the variable explicitly restores real-world parity rather than diverging from it.This is the class of breakage tracked in #5400 (native fetch path not seeing the JS-config CA), approached from the env-var side.
How
apply_node_extra_ca_certsreadsNODE_EXTRA_CA_CERTS; when set and non-empty, every certificate in the named PEM bundle is added as an additional trust root.default_client_builder— the single chokepoint every client (default + per-registry) routes through — so the.npmrc-derivedTlsConfigstays env-free and the existing "TLS config is.npmrc-only, no env vars" parity policy is preserved. Thetls.rsmodule doc is updated to record this as the one deliberate, documented exception (it's a process-global Node convention, not a pnpm setting)..npmrcca/cafilerootsapply_tlsadds afterward and under the built-in webpki roots; the rustls root store is a union so ordering is immaterial.cafile.Test
Adds
node_extra_ca_certs_env_adds_root_and_tolerates_bad_path(serialized env mutation + restore), pointing the var at the existingtests/fixtures/test-ca.pemand then at a missing file, assertingfor_installsbuilds in both cases.cargo fmt,cargo clippy -p pacquet-network --tests, andcargo test -p pacquet-networkall clean. No changeset added — the change is confined to thepacquet-*Rust crates; happy to add one if the workflow expects it.Related: Socket Firewall (sfw)
This is also helpful with Socket Firewall (
sfw, repo SocketDev/sfw-free) — a free tool that wraps your package manager behind a local MITM CA proxy to block known-malicious packages at install time. pnpm-on-Node works with it today because Node trusts the proxy CA viaNODE_EXTRA_CA_CERTS; honoring that variable in the native client letssfw pnpm …keep working as pnpm moves onto the pacquet path — no per-.npmrccafilewiring required.Summary by CodeRabbit
NODE_EXTRA_CA_CERTSto trust additional certificate authorities for secure connections.NODE_EXTRA_CA_CERTShandling.NODE_EXTRA_CA_CERTSparsing and non-fatal behavior across valid, empty, and invalid inputs.