feat: scoped cf-access-token header for internal endpoints - #46
Merged
Conversation
Add optional Cloudflare Access support via the MACH_CF_ACCESS_TOKEN env var. When set, mach attaches a redacted cf-access-token header to test requests, scoped to speed.cloudflare.com with strict domain-label matching so it never leaks to unrelated origins. Covers rpm, download, upload, saturate, rtt, and packet-loss. Closes #43.
HenriqueSFernandes
requested review from
andre-j3sus,
carlosefr,
Copilot and
devandrepascoa
July 17, 2026 10:45
There was a problem hiding this comment.
Pull request overview
Adds optional Cloudflare Access support to mach by introducing a scoped-header mechanism that attaches a sensitive cf-access-token header only to requests whose host matches an allowlisted domain suffix (intended to prevent token leakage to unrelated origins).
Changes:
- Introduces
nq_core::ScopedHeadersand integrates it into core HTTP clients so headers can be conditionally applied per-request based on the URI host. - Threads
scoped_headersthrough load-generation and multiple test paths (rpm/responsiveness, packet loss, latency, download/upload, saturate). - Adds CLI plumbing to read
MACH_CF_ACCESS_TOKEN, mark it sensitive for log redaction, and document the feature in the README.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents Cloudflare-internal Access-token support and scoping guarantees. |
| crates/nq-rpm/src/lib.rs | Adds optional scoped_headers to responsiveness config and applies it to probe requests. |
| crates/nq-packetloss/src/lib.rs | Adds scoped_headers to packet loss config and passes it into load generation. |
| crates/nq-load-generator/src/lib.rs | Carries scoped_headers through LoadConfig/LoadGenerator and applies them to throughput requests. |
| crates/nq-latency/src/lib.rs | Applies scoped_headers directly to the latency (RTT) request headers. |
| crates/nq-core/src/scoped_headers.rs | New core utility implementing host-suffix scoping for header attachment. |
| crates/nq-core/src/lib.rs | Exposes the new ScopedHeaders type from nq-core. |
| crates/nq-core/src/client.rs | Adds scoped-header support to ThroughputClient and Client request construction. |
| cli/src/up_down.rs | Applies optional Access scoped headers to download/upload subcommands. |
| cli/src/saturate.rs | Passes optional Access scoped headers into the saturate/rpm config path. |
| cli/src/rpm.rs | Fetches rpm config using optional scoped headers and propagates them into subsequent tests. |
| cli/src/packet_loss.rs | Passes optional scoped headers into packet-loss flows and TURN-cred fetch. |
| cli/src/main.rs | Registers the new access module. |
| cli/src/latency.rs | Applies optional scoped headers to the latency subcommand. |
| cli/src/access.rs | New CLI helper to build ScopedHeaders from MACH_CF_ACCESS_TOKEN with sensitivity redaction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 2 commits
July 17, 2026 14:01
…e trailing-dot FQDNs DNS hostnames are case-insensitive and may be fully qualified with a trailing dot. Normalize both the configured suffixes and the request host (lowercase + strip trailing dot) before matching so hosts like Staging.Speed.Cloudflare.com and speed.cloudflare.com. correctly receive the scoped cf-access-token header.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add optional Cloudflare Access support via the
MACH_CF_ACCESS_TOKENenv var.When set, mach attaches a redacted
cf-access-token headerto test requests, scoped to speed.cloudflare.com with strict domain-label matching so it never leaks to unrelated origins.Closes #43