Skip to main content

openmoat_proxy/
lib.rs

1//! `openmoat-proxy`: the default-deny egress proxy behind `moat proxy` (ADR-020).
2//!
3//! It serves HTTP `CONNECT` tunnels and absolute-form plain-HTTP requests on a
4//! loopback port:
5//!
6//! - Hosts are decided by openmoat-core's [`CompiledPolicy`](openmoat_core::CompiledPolicy)
7//!   as `moat guard` decides a fetch tool's URL: only an `allow` passes. A host
8//!   is reached on 443 and 80 unless a rule names `host:port` ([`port_policy`]).
9//! - Cloud metadata and link-local addresses are refused whatever the policy
10//!   says, by name and on every address the proxy resolves. Private and CGNAT
11//!   addresses are refused unless an allow rule names the address.
12//! - A tunnel's TLS `ClientHello` must name the CONNECT host (SNI). Nothing is
13//!   decrypted except, with [`Tls`] set, a tunnel to the host of a secret that
14//!   says `tls: terminate` (ADR-043): its one request is checked against the
15//!   leak check and the secret's `allow` rules, given the value, sent over the
16//!   proxy's own verified TLS, and its answer searched for every value.
17//! - A request that carries a brokered secret's placeholder or value to a host
18//!   other than the secret's own is refused ([`Broker`]).
19//! - Every decision is recorded through a [`Recorder`]; a failed record is a
20//!   refused connection.
21//! - In session mode ([`Sessions`], ADR-027, ADR-044) every request must
22//!   carry its session's credential: one the proxy holds ([`Credential`]) or
23//!   one a [`Verify`] accepts. The session's audit id goes on each row, a
24//!   session that read secret material reaches only that secret's host, and
25//!   no session holds more than half the connections.
26//! - A connection that starts with a [`LocalService`]'s prefix goes to that
27//!   service of the proxy's own process (ADR-028), not upstream.
28//!
29//! Plain `std::net` and one thread per connection, capped by [`Limits`]; the
30//! choice is explained in `docs/ARCHITECTURE.md` ยง12.
31
32#![warn(missing_docs)]
33// A library reports to its caller; only the `moat` binary prints.
34#![warn(clippy::print_stdout, clippy::print_stderr)]
35
36mod audit;
37mod body;
38mod broker;
39mod decide;
40mod exchange;
41mod local;
42mod request;
43mod server;
44mod session;
45mod slots;
46mod sni;
47mod tls;
48mod tunnel;
49mod upstream;
50
51pub use audit::{Connection, RecordError, Recorder};
52pub use broker::{Broker, BrokerError, Carried, Leak, RULE_SECRET, RULE_SECRET_ROUTE};
53pub use decide::{
54    DEFAULT_PORTS, Forbidden, RULE_ADDRESS, RULE_AUDIT, RULE_PORT, RULE_REQUEST, RULE_SNI,
55    RULE_UPSTREAM, address_policy, denied as address_denied, forbidden, host as decide_host,
56    host_port as decide_host_port, named as address_named, named_on as address_named_on,
57    port_policy, tainted as decide_tainted,
58};
59pub use local::LocalService;
60pub use request::{
61    MAX_HEADERS, ProxyCredential, Request, RequestError, Target, parse as parse_request,
62};
63pub use server::{Limits, Proxy, RULE_CAPACITY};
64pub use session::{
65    AuthError, Credential, CredentialError, MIN_TOKEN_LEN, RULE_SESSION, Sessions, TaintLookup,
66    Verify, constant_time_eq,
67};
68pub use sni::{Hello, HelloError, MAX_HELLO, server_name};
69pub use tls::{CA_VALID_DAYS, CaFiles, RULE_TLS, Roots, Tls, TlsError, new_ca};
70pub use upstream::{Refusal, Resolve, SystemResolver, connect};