Skip to main content

ProxyAccessConfig

Struct ProxyAccessConfig 

Source
pub struct ProxyAccessConfig {
    pub cors: CorsConfig,
    pub api_key: Option<String>,
    pub api_key_source: ApiKeySource,
    pub allowed_hosts: Vec<String>,
    pub remote: Option<Arc<dyn RemoteGatewayPort>>,
}
Expand description

Who may reach the proxy, and how they prove it.

Two independent gates that happen to travel together, because both are decided at bind time and both are needed by the same layer of the router:

  • api_key is opt-in. None leaves the endpoint exactly as it behaved before authentication existed.
  • allowed_hosts is always enforced. It is the DNS-rebinding defence, and it does not depend on a token being set.

Fields§

§cors: CorsConfig

Which origins the CORS layer accepts.

§api_key: Option<String>

Bearer token required on /v1/* and /mcp. None disables the check.

§api_key_source: ApiKeySource

Where api_key came from, which decides whether it may later be replaced by a settings write. A flag or environment value outranks the stored setting, so it must not be overridden by one; every other source is the stored setting, or absent, and tracks it.

§allowed_hosts: Vec<String>

Host-header values accepted in addition to loopback, normalized to lowercase with any port stripped. Loopback is always accepted and is deliberately not listed here — it is a predicate (is_loopback_host), so 127.0.0.2 and ::1 are covered without anyone having to enumerate them.

§remote: Option<Arc<dyn RemoteGatewayPort>>

The remote tunnel’s owner, when this proxy may be reached through one (ADR 0012). Travels with the access policy because it is one: it decides whether a request that arrived through the tunnel may reach /mcp. None for an embedded server or a test, where nothing is listening for the answers.

Implementations§

Source§

impl ProxyAccessConfig

Source

pub fn new( cors: CorsConfig, api_key: Option<String>, bind_host: &str, extra_hosts: Vec<String>, ) -> Self

Build the access policy for a proxy about to bind bind_host.

The bound address joins the allowlist automatically when it is a concrete non-loopback address: someone who asked to bind 192.168.1.5 plainly intends to be reached at 192.168.1.5, and making them repeat it as --allowed-host would be a rule with no purpose.

A wildcard bind (0.0.0.0 / ::) gets no such inference. It names no reachable address, so there is nothing to infer, and guessing the machine’s interface addresses would re-open exactly the hole the allowlist exists to close. Those deployments must name their hostname with --allowed-host.

Source

pub fn with_remote(self, remote: Option<Arc<dyn RemoteGatewayPort>>) -> Self

Attach the remote tunnel’s owner.

Separate from new for the reason with_key_source is: only the supervisor has one to attach, and every other construction site means “no tunnel”.

Source

pub const fn with_key_source(self, source: ApiKeySource) -> Self

Record where the token came from.

Separate from new so that adding it did not change a signature every caller spells out; the supervisor is the only layer that knows the answer, and every other construction site means ApiKeySource::None.

Source

pub fn host_allowed(&self, host_header: &str) -> bool

Whether a request carrying this Host header may proceed.

This is the DNS-rebinding guard. A rebound page reaches the loopback socket but still asks for the attacker’s hostname, so a Host that is neither loopback nor explicitly allowed did not come from anyone who knows where this proxy actually lives.

An absent or unparseable Host is rejected: HTTP/1.1 requires the header, and a request that omits it has no claim to check.

Trait Implementations§

Source§

impl Clone for ProxyAccessConfig

Source§

fn clone(&self) -> ProxyAccessConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProxyAccessConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProxyAccessConfig

Source§

fn default() -> ProxyAccessConfig

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ProxyAccessConfig

Equality is over the policy — CORS, token, source, hosts — and not over remote, which is a live object rather than a value. Two configs that differ only in whether a tunnel owner is attached describe the same access rules.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ProxyAccessConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more