Skip to main content

SubprocessEvaluator

Struct SubprocessEvaluator 

Source
pub struct SubprocessEvaluator { /* private fields */ }
Available on crate features pac-subprocess and pac only.
Expand description

PacEvaluator that runs each evaluation in a fresh worker process and kills it at the deadline.

worker is the absolute path of a proxy-watch-pac-worker binary from this same release (built with the pac-subprocess and pac-quickjs features). A relative path is refused with Error::Io at evaluation: a bare name would be looked up on the PATH, and whoever controls the lookup would choose the program that sees every script and URL.

Of PacPolicy’s settings, the timeout covers the whole evaluation (starting the worker, running the script, and every name lookup it asks for) and a worker still running at the deadline is killed. DNS and the internal-address filter are applied here in the parent. myIpAddress, the clock and the UTC offset are handed to the worker. The worker runs QuickJS with a 64 MiB heap, and on Windows and Linux the process has an OS memory limit as well.

Each running worker holds one of the process-wide evaluation slots QuickJS uses too, so Error::PacSaturated bounds worker processes as it bounds threads. A name lookup still running at the deadline keeps its slot until it returns.

The worker starts with an empty environment (Windows keeps SystemRoot) and its own directory as the working directory, and its standard error is discarded.

On Linux (x86-64 and AArch64) the worker runs the script under a seccomp filter that leaves it no system call to open a file, a socket or a process. The parent knows this only from the worker’s own report, so the guarantee is the worker binary’s. On other platforms, or where the kernel refuses the filter, the worker is unconfined, and evaluation fails with Error::Io (io::ErrorKind::PermissionDenied) before the script is sent, unless allow_unsandboxed was called. A worker the filter kills fails the evaluation with Error::PacEvaluation.

Implementations§

Source§

impl SubprocessEvaluator

Source

pub fn new(worker: impl Into<PathBuf>, policy: PacPolicy) -> Self

An evaluator that starts worker for each evaluation and runs scripts under policy.

Source

pub fn allow_unsandboxed(self) -> Self

Also run scripts in a worker that could not confine itself: everywhere but Linux on x86-64 and AArch64, any worker. The worker keeps the memory limit and the deadline, but one a memory-safety bug has taken over can reach the network and the files of the user it runs as.

Source

pub fn worker(&self) -> &Path

The worker binary this evaluator starts.

Source

pub fn policy(&self) -> &PacPolicy

The policy this evaluator applies.

Trait Implementations§

Source§

impl Clone for SubprocessEvaluator

Source§

fn clone(&self) -> Self

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 SubprocessEvaluator

Source§

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

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

impl PacEvaluator for SubprocessEvaluator

Source§

fn evaluate( &self, script: &PacScript, url: &Url, host: &str, ) -> Result<Vec<ProxyStep>, Error>

Run FindProxyForURL(url, host) and parse the result. Read more

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.

Source§

impl<T> Instrument for T

Source§

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

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

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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