Repository navigation
feat(browser): gate Chromium traffic through authorized proxy #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
9cf0ab8
chore(handoff): preserve browser proxy work in progress
senamakel c52ad1b
Merge remote-tracking branch 'origin/main' into epic-7328-browser-res…
senamakel 36668e1
test(bus): avoid float equality lint
senamakel 98b4ca1
test(tinycomputer): keep browser egress host async
senamakel d7d1bf1
fix(browser): try later authorized egress addresses
senamakel c49e951
chore(deps): refresh rustls and yoke lock entries
senamakel 525c4e7
fix(bus): bump contract for browser egress host
senamakel 52a0507
Address browser egress review feedback
senamakel 25afb0b
Make unreachable proxy test deterministic
senamakel 8b2d7b4
Bump vendored browser and bus security fixes
senamakel 69346e5
fix(tinycomputer-browser): recheck browser liveness after acquiring e…
senamakel e1b4de0
test(linked): gate live browser test helpers behind cfg
senamakel 655f002
test(egress): split proxy tests into per-protocol modules
senamakel 9d1da13
refactor(egress): split browser proxy into submodules
senamakel 6491e75
docs(tinycomputer): drop browser executable and args from config example
senamakel 8a30d61
test(egress): add shared fixture authorizer helpers
senamakel ca05bad
refactor(egress-tests): widen simulator fixture visibility to super
senamakel f313e14
style: format egress imports and signatures
senamakel cf2e63d
test(egress): narrow test imports to what each module uses
senamakel 86aed71
refactor(egress): widen visibility of proxy request helpers
senamakel d871d69
test(egress): give each egress test module a specific doc comment
senamakel 4313f29
refactor(egress): tidy imports and gate test-only re-export
senamakel 72ed1b6
test(egress): import SocketAddr in retry tests
senamakel 86920e6
fix(browser-egress): stream request bodies to upstream instead of buf…
senamakel e2d64fa
test(browser-egress): cover large request bodies and tidy round-trip …
senamakel 8870e0b
refactor(egress): drop unused mut on proxy request binding
senamakel 32e1080
refactor(egress): collapse let-else onto one line
senamakel 5d8f335
fix(egress): correct proxy header validation condition
senamakel 98ed104
Document live browser test toggle
senamakel 8356f04
test(linked): cover enforced browser rejecting process-side reads wit…
senamakel 3364507
fix(browser): reject process-side reads with a url under egress policy
senamakel f9476cd
docs(tinycomputer-bus): clarify minor version compatibility example
senamakel c33fb4b
fix(egress): validate lease while forwarding request bodies
senamakel f7a1514
refactor(browser): make ambient browser config check injectable
senamakel 4b399e3
feat(egress): forward chunked request bodies to upstream
senamakel 6436247
fix(egress): hoist chunk read length out of timeout future
senamakel e4d9682
test(egress): fix chunked upload assertion window size
senamakel 10db35d
docs(egress): add README for the egress module
senamakel 956342c
refactor(tinycomputer-browser): split linked tests into launch and li…
senamakel b6a757c
refactor(egress): extract chunked request body handling
senamakel 22e42b5
refactor(egress): genericize forwarding over async read and write
senamakel c763e13
fix(egress): forward early upstream responses during uploads
senamakel 43be533
test(egress): move request body tests into their own module
senamakel c51b452
refactor(egress): box the serve future before spawning
senamakel dbcd931
test(linked): update live test imports
senamakel a9e91db
Merge main into PR 150
senamakel 0211f8f
refactor(egress): move request body handling into a body module
senamakel 102c71b
refactor(egress): widen request body helper visibility
senamakel 3cec61e
fix(egress): import write_all_bounded in request module
senamakel f462873
chore(browser): drop feature gate from action gate re-export
senamakel ee58766
test(egress): add chunked body tests and fix flaky egress test assert…
senamakel 739db17
test(egress): update chunked body test import path
senamakel 1f4ceb3
test(egress): ignore timeout result in revoked lease upload test
senamakel 2e19215
test(linked): cover enforced launcher private session without implici…
senamakel b56d7a9
fix(egress): keep response future alive across upload completion
senamakel f68762d
test(egress): assert upload body is fully read in backpressure test
senamakel 2848059
test(egress): read request body into pre-split buffer
senamakel 6bc2734
test(egress): allow unwrap in chunked body tests
senamakel d9d2145
test(egress): use broadcast address for unreachable retry candidate
senamakel 13561ce
test(egress): use loopback alias for unreachable address
senamakel 901e495
fix(browser): keep egress proxy alive on transient accept errors
senamakel fbf5915
style(egress): format imports and function signature
senamakel 6f53928
fix(browser): log proxy accept errors via log crate
senamakel 3383a7e
chore(deps): add log dependency to lockfile
senamakel 1233161
test(egress): harden retry test against port races
senamakel dc04ec8
fix(browser): revalidate lease while writing response to client
senamakel 18af5d0
test(egress): move forward lease tests under egress_tests
senamakel 9fcae36
test(browser_egress): relocate adapter tests into module directory
senamakel 8a1c49a
test(egress): bind a reserved port for the unreachable address
senamakel 6f6175a
test(egress): use port zero for unreachable retry candidate
senamakel be07779
test(egress): reserve unreachable port with bound socket in retry test
senamakel 3e2b7ab
test(egress): collapse socket bind chain onto one line
senamakel 25b179f
test(egress): inject connector to make retry test deterministic
senamakel 2123fbd
refactor(egress): box serve future and widen connector visibility
senamakel a25738f
test(egress): remove redundant proxy stream unwrap
senamakel bda33ce
test(egress): shut down client before reading retry response
senamakel e99da0a
test(egress): stop unwrapping the service result in retry test
senamakel bb7840b
test(egress): remove premature client shutdown in retry test
senamakel 7d3d6aa
refactor(egress): extract address connection retry into a helper
senamakel 4450601
test(linked): cover closing an exited enforced browser
senamakel 5a7ee95
fix(linked): allow close action when enforced browser has exited
senamakel 074d966
refactor(egress): move egress tests into the egress module
senamakel 38f1971
test(egress): register egress test submodules
senamakel 753457b
refactor(browser_egress): move egress request types into a types module
senamakel a8da814
test(browser): wait for denied egress attempts in live tests
senamakel 72c6706
style: reflow imports to satisfy rustfmt
senamakel 88927e7
fix(egress): reject oversized chunk lines
senamakel cf0336b
test(egress): remove egress test module aggregator
senamakel 4938977
fix(egress): validate lease during upstream request writes
senamakel 131509c
fix(egress): share lease validation interval across request write phases
senamakel 499ca17
Document egress launch environment restrictions
senamakel e0a0072
fix(egress): share lease validation schedule across request and response
senamakel b9480ab
fix(egress): drop unnecessary mut on validation interval
senamakel cf70a99
fix(egress): accept lease validation clock in initialize_upstream
senamakel ebbfb42
refactor(egress): match unit pattern in lease validation select arms
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //! Selects opt-in browser tests at compile time. | ||
|
|
||
| fn main() { | ||
| println!("cargo:rustc-check-cfg=cfg(live_browser_tests)"); | ||
| println!("cargo:rerun-if-env-changed=TINYCOMPUTER_LIVE_BROWSER_TESTS"); | ||
|
|
||
| if std::env::var_os("TINYCOMPUTER_LIVE_BROWSER_TESTS").is_some() { | ||
| println!("cargo:rustc-cfg=live_browser_tests"); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Browser egress proxy | ||
|
|
||
| This module gives an explicitly launched Chromium session a private HTTP proxy | ||
| whose destination decisions come from the TinyComputer host callback. It keeps | ||
| the engine adapter (`EgressAuthorizer`) small: the host authorizes the parsed | ||
| destination, returns a one-use grant and exact socket addresses, consumes a | ||
| grant before each dial, and revalidates active leases. | ||
|
|
||
| ## Structure | ||
|
|
||
| - `mod.rs` defines the public `BrowserDialTarget`, `DialGrant`, | ||
| `EgressAuthorizer`, and `EgressProxy` surface and owns the loopback listener. | ||
| - `request.rs` authenticates each local proxy client, parses HTTP proxy | ||
| requests, validates authorities and framing, and streams fixed-length and | ||
| chunked request bodies with bounded buffers. | ||
| - `forward.rs` writes sanitized upstream headers and forwards request and | ||
| response data while checking active leases. | ||
| - `serve.rs` sequences authorization, grant consumption, exact-address | ||
| connection, request forwarding, and response handling for one connection. | ||
|
|
||
| ## Operational constraints | ||
|
|
||
| The proxy binds IPv4 loopback and requires Basic authentication with a random | ||
| per-session password. It never resolves destination names; it dials only an | ||
| address returned by the host and consumes the matching one-use grant first. | ||
| Only absolute `http` proxy requests, CONNECT requests, WebSocket upgrades, | ||
| fixed-length uploads, and valid HTTP/1.1 chunked uploads are accepted. Ambiguous | ||
| framing, caller-selected transfer encodings, unauthenticated clients, malformed | ||
| chunk framing, and bytes following a framed request body are refused. | ||
|
|
||
| HTTPS payloads remain opaque after CONNECT. The proxy checks the lease at least | ||
| once per second while uploading, tunneling, or receiving a response, and closes | ||
| the connection when validation is denied or fails. Do not add a direct-dial | ||
| fallback or locally resolve a host here: destination policy belongs to the | ||
| authenticated host callback. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //! Listener lifecycle tests for the browser egress proxy. | ||
|
|
||
| #![allow(clippy::expect_used, clippy::unwrap_used)] | ||
|
|
||
| use std::io; | ||
| use tokio::net::{TcpListener, TcpStream}; | ||
|
|
||
| mod authority_tests; | ||
| mod body_tests; | ||
| mod connect_tests; | ||
| mod forward_tests; | ||
| mod http_tests; | ||
| mod lease_tests; | ||
| mod lifecycle_tests; | ||
| mod retry_tests; | ||
| mod simulator; | ||
| mod websocket_tests; | ||
|
|
||
| #[tokio::test] | ||
| async fn an_accept_error_waits_then_allows_later_connections() { | ||
| let failed = super::accept_connection(std::future::ready(Err(io::Error::other( | ||
| "transient accept failure", | ||
| )))) | ||
| .await; | ||
| assert!(failed.is_none()); | ||
|
|
||
| let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); | ||
| let address = listener.local_addr().unwrap(); | ||
| let client = TcpStream::connect(address); | ||
| let (accepted, connected) = tokio::join!(listener.accept(), client); | ||
| let accepted = super::accept_connection(std::future::ready(accepted)).await; | ||
|
|
||
| assert!(accepted.is_some()); | ||
| connected.unwrap(); | ||
| } |
48 changes: 48 additions & 0 deletions
48
crates/tinycomputer-browser/src/egress/egress_tests/authority_tests.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //! Authority parsing and redaction tests. | ||
|
|
||
| use crate::{BrowserDialTarget, DialGrant, egress::parse_authority}; | ||
|
|
||
| #[test] | ||
| fn browser_dial_target_debug_does_not_disclose_session_or_destination() { | ||
| let target = BrowserDialTarget { | ||
| scheme: "https".into(), | ||
| hostname: "private.example.test".into(), | ||
| port: 443, | ||
| session_id: "private-browser-session".into(), | ||
| }; | ||
| let debug = format!("{target:?}"); | ||
| assert!(!debug.contains("private.example.test")); | ||
| assert!(!debug.contains("private-browser-session")); | ||
| assert!(debug.contains("REDACTED")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn dial_grant_debug_does_not_disclose_lease_or_destination() { | ||
| let grant = DialGrant { | ||
| lease: "private-opaque-nonce".into(), | ||
| addresses: vec!["203.0.113.77:8443".parse().unwrap()], | ||
| }; | ||
| let debug = format!("{grant:?}"); | ||
| assert!(!debug.contains("private-opaque-nonce")); | ||
| assert!(!debug.contains("203.0.113.77")); | ||
| assert!(debug.contains("REDACTED")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn proxy_authority_uses_scheme_defaults_and_canonical_ipv6_literals() { | ||
| assert_eq!( | ||
| parse_authority("example.test", "http", "session") | ||
| .unwrap() | ||
| .port, | ||
| 80 | ||
| ); | ||
| assert_eq!( | ||
| parse_authority("example.test", "https", "session") | ||
| .unwrap() | ||
| .port, | ||
| 443 | ||
| ); | ||
| let ipv6 = parse_authority("[2001:4860:4860::8888]:443", "https", "session").unwrap(); | ||
| assert_eq!(ipv6.hostname, "2001:4860:4860::8888"); | ||
| assert!(parse_authority("https://example.test:443", "https", "session").is_err()); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.