## Description Relay client: When dialing via an HTTP proxy whose URL includes the user’s username and password, the password was included in debug-level log output in two places: in the URL, and in the `Proxy-Authorization` header in the `Debug` output of the `CONNECT` request. This PR masks the password as `***` in the URL that is logged, while leaving the username in place so the log line is still useful. It also marks the `Proxy-Authorization` header value as sensitive, which causes the `Debug` impl of the request to show `Sensitive` instead of the base64-encoded username and password. This doesn’t change the bytes that are sent over the wire. There’s a new test that dials the fake proxy with a password and asserts that the output log contains `user:***@` and does not contain either the password or its base64-encoded form. This was reported privately first, and you asked for the fix as a public PR, so here it is. ## API Changes None. ## Notes & open questions There are two other places the proxy URL is printed: in the `warn!` in the pkarr client in `iroh/src/address_lookup/pkarr.rs` when the reqwest client doesn’t accept the URL because of its scheme, and in the `DialError::ProxyInvalidUrl` error. The latter cannot contain credentials as far as I can tell, but if you’d like me to mask the URL in those two places as well I can do that. ## Change checklist - [x] Self-review. - [ ] Documentation updates following the [style guide], if relevant. - [x] Tests if relevant. - [x] All API changes documented. - [ ] `cargo make` passes locally. I ran `cargo fmt --check`, the `client::tls` tests, and clippy with `-D warnings` for iroh-relay with all, no and default features. [style guide]: https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text
Iroh Relay
Iroh's relay is a feature within iroh, a peer-to-peer networking system designed to facilitate direct, encrypted connections between devices. Iroh aims to simplify decentralized communication by automatically handling connections through "relays" when direct connections aren't immediately possible. The relay server helps establish connections by temporarily routing encrypted traffic until a direct, P2P connection is feasible. Once this direct path is set up, the relay server steps back, and the data flows directly between devices. This approach allows Iroh to maintain a secure, low-latency connection, even in challenging network situations.
This crate provides a complete setup for creating and interacting with iroh relays, including:
- Relay Protocol: The protocol used to communicate between relay servers and clients
- Relay Server: A fully-fledged iroh-relay server over HTTP or HTTPS. Optionally will also expose a QAD endpoint and metrics.
- Relay Client: A client for establishing connections to the relay.
- Server Binary: A CLI for running your own relay server. It can be configured to also expose metrics.
Used in iroh, created with love by the n0 team.
Build the server
You can build an optimised release of iroh-relay by running cargo build
with the appropriate flags from the workspace parent directory as follows.
cd ../
cargo build \
--profile optimized-release \
--package iroh-relay \
--features server
You will find the optimised binary at target/optimized-release/iroh-relay.
Access control
The relay server supports several access control modes, configured via the
access field in the TOML config file.
Allow everyone (default)
access = "everyone"
Allowlist / Denylist by endpoint ID
# Allow only specific endpoints
access.allowlist = ["<endpoint-id>", "<endpoint-id>"]
# Or block specific endpoints and allow everyone else
access.denylist = ["<endpoint-id>"]
Shared token (local, no external service)
Requires connecting clients to present one of the configured shared secrets via an
Authorization: Bearer <token> header, or a ?token= URL query parameter.
access.shared_token = ["token-a", "token-b"]
The token list can also be overridden by the IROH_RELAY_ACCESS_TOKEN environment
variable, which sets a single allowed token and takes precedence over the config file
value. A single value is used (rather than a comma-separated list) to avoid restricting
the character set of tokens.
The token list must not be empty, and no token may be an empty string; the server will fail to start if either condition is violated.
On the client side, set the token using
RelayConfig::with_auth_token
or
RelayMap::with_auth_token.
Note: this shared token does not support revocation other than updating the config and restarting the service.
HTTP callout (external auth service)
The relay calls an external HTTP endpoint for each incoming connection, passing the connecting endpoint's ID. The token below authenticates the relay to your auth service (machine-to-machine), not the connecting client.
access.http.url = "https://your-auth-service.example.com/relay-auth"
# Optional: authenticate the relay's outbound request to your service
access.http.bearer_token = "service-to-service-secret"
The bearer token can also be set via the IROH_RELAY_HTTP_BEARER_TOKEN
environment variable.
For every connection, the relay sends a POST request with no body to
access.http.url. The connecting endpoint's ID is sent in the
X-Iroh-Endpoint-Id header. If a bearer token is configured, it is sent in an
Authorization: Bearer <token> header.
To allow the connection, your service must respond with status 200 and the
response body true.
Example request:
POST /relay-auth HTTP/1.1
x-iroh-endpoint-id: da1ee49ba54d124a2e2b0f043bac3d63ec086b0b40e7d0895914898b237e847e
x-iroh-nodeid: da1ee49ba54d124a2e2b0f043bac3d63ec086b0b40e7d0895914898b237e847e
authorization: Bearer service-to-service-secret
accept: */*
host: your-auth-service.example.com
Note: the endpoint ID is also sent in the deprecated
X-Iroh-NodeIdheader for backwards compatibility. It will be removed in a future release. New services should useX-Iroh-Endpoint-Id.
Local testing
Advice for testing your application that uses iroh with a locally running iroh-relay server
dev mode
When running the relay server using the --dev flag, you will:
- only run the server over http, not https
- will NOT run the QUIC endpoint that enables QUIC address discovery
The relay can be contacted at "http://localhost:3340".
Both https and QUIC address discovery require TLS certificates. It's possible to run QUIC address discovery using locally generated TLS certificates, but it takes a few extra steps and so, is disabled by default for now.
dev mode with QUIC address discovery
So you want to test out QUIC address discovery locally?
In order to do that you need TLS certificates.
The easiest get that is to generate self-signed certificates using rcgen
- get rcgen (
git clone https://github.com/rustls/rcgen) - cd to the
rcgendirectory - generate local certs using
cargo run -- -o path/to/certs
Next, add the certificate paths to your iroh-relay config, here is an example of a config.toml file that will enable quic address discovery.
enable_quic_addr_discovery = true
[tls]
cert_mode = "Manual"
manual_cert_path = "/path/to/certs/cert.pem"
manual_key_path = "/path/to/certs/cert.key.pem"
Then run the server with the --dev flag, like you would when normally testing locally:
cargo run --features="server" --bin iroh-relay -- --config-path=/path/to/config.toml --dev
The relay server will run over http on port 3340, as it does using the --dev flag, but it will also run a QUIC server on port 7824.
The relay will use the configured TLS certificates for the QUIC connection, but use http (rather than https) for the server.
Using iroh-relay as a library to run in-process relays in integration tests
When using iroh as a transport library in an application or other library, there is a simple way of running an in-process relay server:
- Enable
test-utilsfeature of theirohcrate
iroh = { version = "0.95", features = ["test-utils"] }
- Spawn a relay server by calling
iroh::test_utils::run_relay_server().awaitThis will start a relay server with a self-signed TLS certificate, listening on a localhost port, and return the server's URL. - For the iroh endpoints to successfully connect to the relay, disable TLS certificate verification by calling
Endpoint::ca_tls_configwithCaRootConfig::insecure_skip_verify().
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.