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 (`requests:`, ADR-062) is terminated the
18//! same way for a session that trusts the CA ([`Trust`]), and a request its
19//! rules refuse is refused; a session it cannot terminate is refused or
20//! relayed as the policy's `requests_untrusted` says, and after a secret read
21//! only reads without a body pass there.
22//! - A request that carries a brokered secret's placeholder or value to a host
23//! other than the secret's own is refused ([`Broker`]).
24//! - Every decision is recorded through a [`Recorder`]; a failed record is a
25//! refused connection.
26//! - In session mode ([`Sessions`], ADR-027, ADR-044) every request must
27//! carry its session's credential: one the proxy holds ([`Credential`]) or
28//! one a [`Verify`] accepts. The session's audit id goes on each row, a
29//! session that read secret material reaches only that secret's host, and
30//! no session holds more than half the connections.
31//! - A connection that starts with a [`LocalService`]'s prefix goes to that
32//! service of the proxy's own process (ADR-028), not upstream.
33//! - Apart from the proxy, [`Poster`] makes live audit delivery's one `POST`
34//! (ADR-081) with the same upstream TLS and address checks.
35//!
36//! Plain `std::net` and one thread per connection, capped by [`Limits`]; the
37//! choice is explained in `docs/ARCHITECTURE.md` ยง12.
38
39#![warn(missing_docs)]
40// A library reports to its caller; only the `moat` binary prints.
41#![warn(clippy::print_stdout, clippy::print_stderr)]
42
43mod audit;
44mod body;
45mod broker;
46pub mod coalesce;
47mod decide;
48mod exchange;
49mod local;
50mod post;
51mod request;
52mod requests;
53mod server;
54mod session;
55mod slots;
56mod sni;
57mod tls;
58mod tunnel;
59mod upstream;
60
61pub use audit::{Connection, RecordError, Recorder};
62pub use broker::{Broker, BrokerError, Carried, HandOut, Leak, Rotation};
63pub use decide::{
64 DEFAULT_PORTS, Forbidden, address_policy, denied as address_denied, forbidden,
65 host as decide_host, host_port as decide_host_port, named as address_named,
66 named_on as address_named_on, port_policy, tainted as decide_tainted,
67};
68pub use local::LocalService;
69pub use post::{Answer, Endpoint, MAX_BODY, PostError, Poster, Scheme};
70pub use request::{
71 MAX_HEADERS, ProxyCredential, Request, RequestError, Target, parse as parse_request,
72};
73pub use requests::{RequestRuleError, Requests};
74pub use server::helper::{HELPER_PREFIX, helper_request};
75pub use server::{Limits, Proxy};
76pub use session::{
77 Admitted, AuthError, Credential, CredentialError, MIN_TOKEN_LEN, Sessions, TaintLookup, Trust,
78 Verify, base64, constant_time_eq,
79};
80pub use sni::{Hello, HelloError, MAX_HELLO, server_name};
81pub use tls::{CA_VALID_DAYS, CaFiles, Roots, Tls, TlsError, new_ca};
82pub use upstream::{Refusal, Resolve, SystemResolver, connect};