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. A
17//!   host with [`Requests`] rules (ADR-062 step 0, a proof of concept) is
18//!   terminated the same way, and a request its `deny` rules name is refused.
19//! - A request that carries a brokered secret's placeholder or value to a host
20//!   other than the secret's own is refused ([`Broker`]).
21//! - Every decision is recorded through a [`Recorder`]; a failed record is a
22//!   refused connection.
23//! - In session mode ([`Sessions`], ADR-027, ADR-044) every request must
24//!   carry its session's credential: one the proxy holds ([`Credential`]) or
25//!   one a [`Verify`] accepts. The session's audit id goes on each row, a
26//!   session that read secret material reaches only that secret's host, and
27//!   no session holds more than half the connections.
28//! - A connection that starts with a [`LocalService`]'s prefix goes to that
29//!   service of the proxy's own process (ADR-028), not upstream.
30//!
31//! Plain `std::net` and one thread per connection, capped by [`Limits`]; the
32//! choice is explained in `docs/ARCHITECTURE.md` ยง12.
33
34#![warn(missing_docs)]
35// A library reports to its caller; only the `moat` binary prints.
36#![warn(clippy::print_stdout, clippy::print_stderr)]
37
38mod audit;
39mod body;
40mod broker;
41pub mod coalesce;
42mod decide;
43mod exchange;
44mod local;
45mod request;
46mod requests;
47mod server;
48mod session;
49mod slots;
50mod sni;
51mod tls;
52mod tunnel;
53mod upstream;
54
55pub use audit::{Connection, RecordError, Recorder};
56pub use broker::{Broker, BrokerError, Carried, Leak, RULE_SECRET, RULE_SECRET_ROUTE};
57pub use decide::{
58    DEFAULT_PORTS, Forbidden, RULE_ADDRESS, RULE_AUDIT, RULE_PORT, RULE_REQUEST, RULE_SNI,
59    RULE_UPSTREAM, address_policy, denied as address_denied, forbidden, host as decide_host,
60    host_port as decide_host_port, named as address_named, named_on as address_named_on,
61    port_policy, tainted as decide_tainted,
62};
63pub use local::LocalService;
64pub use request::{
65    MAX_HEADERS, ProxyCredential, Request, RequestError, Target, parse as parse_request,
66};
67pub use requests::{RULE_REQUEST_RULE, RequestRuleError, Requests};
68pub use server::{Limits, Proxy, RULE_CAPACITY};
69pub use session::{
70    AuthError, Credential, CredentialError, MIN_TOKEN_LEN, RULE_SESSION, Sessions, TaintLookup,
71    Verify, constant_time_eq,
72};
73pub use sni::{Hello, HelloError, MAX_HELLO, server_name};
74pub use tls::{CA_VALID_DAYS, CaFiles, RULE_TLS, Roots, Tls, TlsError, new_ca};
75pub use upstream::{Refusal, Resolve, SystemResolver, connect};