Skip to content

Commit 6496655

Browse files
eviehowardSDAChess
authored andcommitted
refactor(prover): remove legacy unused reachability constraints
Remove can_write_to_endpoint() and the solver variables and encoding methods that exist solely to support it. No active query calls this method; confirmed zero callers across the monorepo. Crate is not published externally, so no public API concern. Removed as root cause: - can_write_to_endpoint(): zero callers in the codebase Removed as direct consumers of can_write_to_endpoint(): - binary_can_write: only read inside can_write_to_endpoint() - credential_has_write: only read inside can_write_to_endpoint() Removed as directly dead (no query ever read them): - credential_has_destructive: flagged by compiler, silenced with #[allow(dead_code)] rather than removed - filesystem_readable: flagged by compiler, silenced with #[allow(dead_code)] rather than removed Removed as now-empty encoding methods: - encode_credentials(): exclusively populated credential_has_write and credential_has_destructive - encode_filesystem(): exclusively populated filesystem_readable Also removed two #[allow(dead_code)] allowances and the corresponding HashMap::new() initialisers and build() call sites. Active query behavior is unchanged. All existing prover tests pass without modification and cover all four finding categories end-to-end. No new tests added as they would duplicate existing coverage exactly. Note: removing encode_credentials() leaves write_actions_for_scopes() and destructive_actions_for_scopes() in credentials.rs with no callers. Left as a follow-up outside the scope of this change. Closes NVIDIA#2412 Signed-off-by: Evie Howard <[email protected]>
1 parent db94c17 commit 6496655

1 file changed

Lines changed: 0 additions & 114 deletions

File tree

‎crates/openshell-prover/src/model.rs‎

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ pub struct ReachabilityModel {
5454
l7_enforced: HashMap<String, Bool>,
5555
l7_allows_write: HashMap<String, Bool>,
5656
binary_bypasses_l7: HashMap<String, Bool>,
57-
binary_can_write: HashMap<String, Bool>,
5857
binary_can_exfil: HashMap<String, Bool>,
5958
binary_can_construct_http: HashMap<String, Bool>,
60-
credential_has_write: HashMap<String, Bool>,
61-
#[allow(dead_code)]
62-
credential_has_destructive: HashMap<String, Bool>,
63-
#[allow(dead_code)]
64-
filesystem_readable: HashMap<String, Bool>,
6559
}
6660

6761
impl ReachabilityModel {
@@ -83,12 +77,8 @@ impl ReachabilityModel {
8377
l7_enforced: HashMap::new(),
8478
l7_allows_write: HashMap::new(),
8579
binary_bypasses_l7: HashMap::new(),
86-
binary_can_write: HashMap::new(),
8780
binary_can_exfil: HashMap::new(),
8881
binary_can_construct_http: HashMap::new(),
89-
credential_has_write: HashMap::new(),
90-
credential_has_destructive: HashMap::new(),
91-
filesystem_readable: HashMap::new(),
9282
};
9383
model.build();
9484
model
@@ -100,8 +90,6 @@ impl ReachabilityModel {
10090
self.encode_policy_allows();
10191
self.encode_l7_enforcement();
10292
self.encode_binary_capabilities();
103-
self.encode_credentials();
104-
self.encode_filesystem();
10593
}
10694

10795
fn index_endpoints(&mut self) {
@@ -210,14 +198,6 @@ impl ReachabilityModel {
210198
}
211199
self.binary_bypasses_l7.insert(bpath.clone(), bypass_var);
212200

213-
let write_var = Bool::new_const(format!("binary_can_write_{bpath}"));
214-
if cap.can_write() {
215-
self.solver.assert(&write_var);
216-
} else {
217-
self.solver.assert(&!write_var.clone());
218-
}
219-
self.binary_can_write.insert(bpath.clone(), write_var);
220-
221201
let exfil_var = Bool::new_const(format!("binary_can_exfil_{bpath}"));
222202
if cap.can_exfiltrate {
223203
self.solver.assert(&exfil_var);
@@ -237,106 +217,12 @@ impl ReachabilityModel {
237217
}
238218
}
239219

240-
fn encode_credentials(&mut self) {
241-
let hosts: HashSet<String> = self.endpoints.iter().map(|e| e.host.clone()).collect();
242-
243-
for host in &hosts {
244-
let creds = self.credentials.credentials_for_host(host);
245-
let api = self.credentials.api_for_host(host);
246-
247-
let mut has_write = false;
248-
let mut has_destructive = false;
249-
250-
for cred in &creds {
251-
if let Some(api) = api {
252-
if !api.write_actions_for_scopes(&cred.scopes).is_empty() {
253-
has_write = true;
254-
}
255-
if !api.destructive_actions_for_scopes(&cred.scopes).is_empty() {
256-
has_destructive = true;
257-
}
258-
} else if !cred.scopes.is_empty() {
259-
has_write = true;
260-
}
261-
}
262-
263-
let cw_var = Bool::new_const(format!("credential_has_write_{host}"));
264-
if has_write {
265-
self.solver.assert(&cw_var);
266-
} else {
267-
self.solver.assert(&!cw_var.clone());
268-
}
269-
self.credential_has_write.insert(host.clone(), cw_var);
270-
271-
let destructive_var = Bool::new_const(format!("credential_has_destructive_{host}"));
272-
if has_destructive {
273-
self.solver.assert(&destructive_var);
274-
} else {
275-
self.solver.assert(&!destructive_var.clone());
276-
}
277-
self.credential_has_destructive
278-
.insert(host.clone(), destructive_var);
279-
}
280-
}
281-
282-
fn encode_filesystem(&mut self) {
283-
for path in self.policy.filesystem_policy.readable_paths(None) {
284-
let var = Bool::new_const(format!("fs_readable_{path}"));
285-
self.solver.assert(&var);
286-
self.filesystem_readable.insert(path, var);
287-
}
288-
}
289-
290220
// --- Query helpers ---
291221

292222
fn false_val() -> Bool {
293223
Bool::from_bool(false)
294224
}
295225

296-
/// Build a Z3 expression for whether a binary can write to an endpoint.
297-
pub fn can_write_to_endpoint(&self, bpath: &str, eid: &EndpointId) -> Bool {
298-
let ek = eid.key();
299-
let access_key = format!("{}:{bpath}:{ek}", bpath.len());
300-
301-
let has_access = match self.policy_allows.get(&access_key) {
302-
Some(v) => v.clone(),
303-
None => return Self::false_val(),
304-
};
305-
306-
let bypass = self
307-
.binary_bypasses_l7
308-
.get(bpath)
309-
.cloned()
310-
.unwrap_or_else(Self::false_val);
311-
let l7_enforced = self
312-
.l7_enforced
313-
.get(&ek)
314-
.cloned()
315-
.unwrap_or_else(Self::false_val);
316-
let l7_write = self
317-
.l7_allows_write
318-
.get(&ek)
319-
.cloned()
320-
.unwrap_or_else(Self::false_val);
321-
let binary_write = self
322-
.binary_can_write
323-
.get(bpath)
324-
.cloned()
325-
.unwrap_or_else(Self::false_val);
326-
let cred_write = self
327-
.credential_has_write
328-
.get(&eid.host)
329-
.cloned()
330-
.unwrap_or_else(Self::false_val);
331-
332-
Bool::and(&[
333-
has_access,
334-
binary_write,
335-
Bool::or(&[!l7_enforced, l7_write, bypass]),
336-
cred_write,
337-
])
338-
}
339-
340226
/// Build a Z3 expression for whether data can be exfiltrated via this path.
341227
pub fn can_exfil_via_endpoint(&self, bpath: &str, eid: &EndpointId) -> Bool {
342228
let ek = eid.key();

0 commit comments

Comments
 (0)