Skip to main content

ObservationOptions

Struct ObservationOptions 

Source
pub struct ObservationOptions {
    pub subject_ref: String,
    pub observed_at: Option<String>,
    pub probe_security_principal: bool,
    pub include_namespace_context_digest: bool,
    pub include_executable_digest: bool,
    pub include_arguments_digest: bool,
    pub include_security_context_digest: bool,
}
Expand description

Disclosure and probe budget options for observe_process and open_continuity_handle.

By default, probe_security_principal is true and all four digest context facts (namespace_context_digest, executable_digest, arguments_digest, security_context_digest) are false (status: "not-probed").

Fields§

§subject_ref: String

Report-local process subject ID (^[a-z][a-z0-9-]{0,63}$, default "process-target").

§observed_at: Option<String>

Optional explicit UTC timestamp (YYYY-MM-DDTHH:MM:SSZ); defaults to current system UTC time.

§probe_security_principal: bool

Probe execution_context.security_principal (default true).

§include_namespace_context_digest: bool

Opt in to execution_context.namespace_context_digest (default false).

§include_executable_digest: bool

Opt in to execution_context.executable_digest (default false).

§include_arguments_digest: bool

Opt in to execution_context.arguments_digest (default false).

§include_security_context_digest: bool

Opt in to execution_context.security_context_digest (default false).

Implementations§

Source§

impl ObservationOptions

Source

pub fn with_all_context_facts(self) -> Self

Enable all opt-in execution-context facts supported by the platform.

Examples found in repository?
examples/observe-process.rs (line 140)
14fn main() -> ExitCode {
15    let mut args = std::env::args().skip(1);
16    let mut pid: Option<u32> = None;
17    let mut observed_at: Option<String> = None;
18    let mut subject_ref = String::from("process-target");
19    let mut all_context = false;
20    let mut host_id_ref = Some(String::from("id-host-local"));
21    let mut host_ns = String::from("urn:3leaps:identity-evidence:host-scope:test-fixture:v0");
22    let mut host_val = String::from("local-qualification-host");
23    let mut host_deriv_id =
24        String::from("urn:3leaps:identity-evidence:derivation:caller-supplied-host-scope:v0");
25    let mut host_deriv_rev = String::from(DEFAULT_DERIVATION_REV);
26    let mut host_stability = String::from("boot");
27    let mut host_clone = String::from("regenerated");
28
29    while let Some(arg) = args.next() {
30        match arg.as_str() {
31            "--pid" => {
32                let Some(raw) = args.next() else {
33                    eprintln!("error: --pid requires a numeric value");
34                    return ExitCode::from(2);
35                };
36                match raw.parse::<u32>() {
37                    Ok(v) => pid = Some(v),
38                    Err(_) => {
39                        eprintln!("error: invalid --pid value: {raw}");
40                        return ExitCode::from(2);
41                    }
42                }
43            }
44            "--observed-at" => {
45                let Some(v) = args.next() else {
46                    eprintln!("error: --observed-at requires a value");
47                    return ExitCode::from(2);
48                };
49                observed_at = Some(v);
50            }
51            "--subject-ref" => {
52                let Some(v) = args.next() else {
53                    eprintln!("error: --subject-ref requires a value");
54                    return ExitCode::from(2);
55                };
56                subject_ref = v;
57            }
58            "--all-context" => {
59                all_context = true;
60            }
61            "--no-host-id-ref" => {
62                host_id_ref = None;
63            }
64            "--host-id-ref" => {
65                let Some(v) = args.next() else {
66                    eprintln!("error: --host-id-ref requires a value");
67                    return ExitCode::from(2);
68                };
69                host_id_ref = Some(v);
70            }
71            "--host-namespace" => {
72                let Some(v) = args.next() else {
73                    eprintln!("error: --host-namespace requires a value");
74                    return ExitCode::from(2);
75                };
76                host_ns = v;
77            }
78            "--host-value" => {
79                let Some(v) = args.next() else {
80                    eprintln!("error: --host-value requires a value");
81                    return ExitCode::from(2);
82                };
83                host_val = v;
84            }
85            "--host-derivation-id" => {
86                let Some(v) = args.next() else {
87                    eprintln!("error: --host-derivation-id requires a value");
88                    return ExitCode::from(2);
89                };
90                host_deriv_id = v;
91            }
92            "--host-derivation-rev" => {
93                let Some(v) = args.next() else {
94                    eprintln!("error: --host-derivation-rev requires a value");
95                    return ExitCode::from(2);
96                };
97                host_deriv_rev = v;
98            }
99            "--host-stability" => {
100                let Some(v) = args.next() else {
101                    eprintln!("error: --host-stability requires a value");
102                    return ExitCode::from(2);
103                };
104                host_stability = v;
105            }
106            "--host-clone-behavior" => {
107                let Some(v) = args.next() else {
108                    eprintln!("error: --host-clone-behavior requires a value");
109                    return ExitCode::from(2);
110                };
111                host_clone = v;
112            }
113            other => {
114                eprintln!("error: unrecognized flag {other}");
115                return ExitCode::from(2);
116            }
117        }
118    }
119
120    let Some(target_pid) = pid else {
121        eprintln!("error: --pid <1..=2147483647> is required");
122        return ExitCode::from(2);
123    };
124
125    let host_scope = HostScope {
126        identifier_ref: host_id_ref,
127        namespace: host_ns,
128        value: host_val,
129        derivation: ProfileRef::new(host_deriv_id, host_deriv_rev),
130        stability: host_stability,
131        clone_behavior: host_clone,
132    };
133
134    let mut options = ObservationOptions {
135        subject_ref,
136        observed_at,
137        ..ObservationOptions::default()
138    };
139    if all_context {
140        options = options.with_all_context_facts();
141    }
142
143    let obs = match observe_process(target_pid, &host_scope, &options) {
144        Ok(v) => v,
145        Err(refusal) => {
146            eprintln!("refused:{refusal}");
147            return ExitCode::from(1);
148        }
149    };
150
151    let raw = match serde_json::to_vec(&obs) {
152        Ok(b) => b,
153        Err(e) => {
154            eprintln!("serialization-error:{e}");
155            return ExitCode::from(1);
156        }
157    };
158    let admitted = match admit_report_bytes(&raw) {
159        Ok(a) => a,
160        Err(e) => {
161            eprintln!("canonicalization-error:{e}");
162            return ExitCode::from(1);
163        }
164    };
165
166    let mut out = std::io::stdout().lock();
167    if out.write_all(&admitted.canonical_bytes).is_err() || out.write_all(b"\n").is_err() {
168        return ExitCode::from(1);
169    }
170    ExitCode::SUCCESS
171}

Trait Implementations§

Source§

impl Clone for ObservationOptions

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 ObservationOptions

Source§

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

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

impl Default for ObservationOptions

Source§

fn default() -> Self

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

impl Eq for ObservationOptions

Source§

impl PartialEq for ObservationOptions

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ObservationOptions

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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.