Skip to content

Commit 27d24f0

Browse files
committed
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 541b97f commit 27d24f0

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
@@ -45,14 +45,8 @@ pub struct ReachabilityModel {
4545
l7_enforced: HashMap<String, Bool>,
4646
l7_allows_write: HashMap<String, Bool>,
4747
binary_bypasses_l7: HashMap<String, Bool>,
48-
binary_can_write: HashMap<String, Bool>,
4948
binary_can_exfil: HashMap<String, Bool>,
5049
binary_can_construct_http: HashMap<String, Bool>,
51-
credential_has_write: HashMap<String, Bool>,
52-
#[allow(dead_code)]
53-
credential_has_destructive: HashMap<String, Bool>,
54-
#[allow(dead_code)]
55-
filesystem_readable: HashMap<String, Bool>,
5650
}
5751

5852
impl ReachabilityModel {
@@ -74,12 +68,8 @@ impl ReachabilityModel {
7468
l7_enforced: HashMap::new(),
7569
l7_allows_write: HashMap::new(),
7670
binary_bypasses_l7: HashMap::new(),
77-
binary_can_write: HashMap::new(),
7871
binary_can_exfil: HashMap::new(),
7972
binary_can_construct_http: HashMap::new(),
80-
credential_has_write: HashMap::new(),
81-
credential_has_destructive: HashMap::new(),
82-
filesystem_readable: HashMap::new(),
8373
};
8474
model.build();
8575
model
@@ -91,8 +81,6 @@ impl ReachabilityModel {
9181
self.encode_policy_allows();
9282
self.encode_l7_enforcement();
9383
self.encode_binary_capabilities();
94-
self.encode_credentials();
95-
self.encode_filesystem();
9684
}
9785

9886
fn index_endpoints(&mut self) {
@@ -198,14 +186,6 @@ impl ReachabilityModel {
198186
}
199187
self.binary_bypasses_l7.insert(bpath.clone(), bypass_var);
200188

201-
let write_var = Bool::new_const(format!("binary_can_write_{bpath}"));
202-
if cap.can_write() {
203-
self.solver.assert(&write_var);
204-
} else {
205-
self.solver.assert(&!write_var.clone());
206-
}
207-
self.binary_can_write.insert(bpath.clone(), write_var);
208-
209189
let exfil_var = Bool::new_const(format!("binary_can_exfil_{bpath}"));
210190
if cap.can_exfiltrate {
211191
self.solver.assert(&exfil_var);
@@ -225,106 +205,12 @@ impl ReachabilityModel {
225205
}
226206
}
227207

228-
fn encode_credentials(&mut self) {
229-
let hosts: HashSet<String> = self.endpoints.iter().map(|e| e.host.clone()).collect();
230-
231-
for host in &hosts {
232-
let creds = self.credentials.credentials_for_host(host);
233-
let api = self.credentials.api_for_host(host);
234-
235-
let mut has_write = false;
236-
let mut has_destructive = false;
237-
238-
for cred in &creds {
239-
if let Some(api) = api {
240-
if !api.write_actions_for_scopes(&cred.scopes).is_empty() {
241-
has_write = true;
242-
}
243-
if !api.destructive_actions_for_scopes(&cred.scopes).is_empty() {
244-
has_destructive = true;
245-
}
246-
} else if !cred.scopes.is_empty() {
247-
has_write = true;
248-
}
249-
}
250-
251-
let cw_var = Bool::new_const(format!("credential_has_write_{host}"));
252-
if has_write {
253-
self.solver.assert(&cw_var);
254-
} else {
255-
self.solver.assert(&!cw_var.clone());
256-
}
257-
self.credential_has_write.insert(host.clone(), cw_var);
258-
259-
let destructive_var = Bool::new_const(format!("credential_has_destructive_{host}"));
260-
if has_destructive {
261-
self.solver.assert(&destructive_var);
262-
} else {
263-
self.solver.assert(&!destructive_var.clone());
264-
}
265-
self.credential_has_destructive
266-
.insert(host.clone(), destructive_var);
267-
}
268-
}
269-
270-
fn encode_filesystem(&mut self) {
271-
for path in self.policy.filesystem_policy.readable_paths() {
272-
let var = Bool::new_const(format!("fs_readable_{path}"));
273-
self.solver.assert(&var);
274-
self.filesystem_readable.insert(path, var);
275-
}
276-
}
277-
278208
// --- Query helpers ---
279209

280210
fn false_val() -> Bool {
281211
Bool::from_bool(false)
282212
}
283213

284-
/// Build a Z3 expression for whether a binary can write to an endpoint.
285-
pub fn can_write_to_endpoint(&self, bpath: &str, eid: &EndpointId) -> Bool {
286-
let ek = eid.key();
287-
let access_key = format!("{bpath}:{ek}");
288-
289-
let has_access = match self.policy_allows.get(&access_key) {
290-
Some(v) => v.clone(),
291-
None => return Self::false_val(),
292-
};
293-
294-
let bypass = self
295-
.binary_bypasses_l7
296-
.get(bpath)
297-
.cloned()
298-
.unwrap_or_else(Self::false_val);
299-
let l7_enforced = self
300-
.l7_enforced
301-
.get(&ek)
302-
.cloned()
303-
.unwrap_or_else(Self::false_val);
304-
let l7_write = self
305-
.l7_allows_write
306-
.get(&ek)
307-
.cloned()
308-
.unwrap_or_else(Self::false_val);
309-
let binary_write = self
310-
.binary_can_write
311-
.get(bpath)
312-
.cloned()
313-
.unwrap_or_else(Self::false_val);
314-
let cred_write = self
315-
.credential_has_write
316-
.get(&eid.host)
317-
.cloned()
318-
.unwrap_or_else(Self::false_val);
319-
320-
Bool::and(&[
321-
has_access,
322-
binary_write,
323-
Bool::or(&[!l7_enforced, l7_write, bypass]),
324-
cred_write,
325-
])
326-
}
327-
328214
/// Build a Z3 expression for whether data can be exfiltrated via this path.
329215
pub fn can_exfil_via_endpoint(&self, bpath: &str, eid: &EndpointId) -> Bool {
330216
let ek = eid.key();

0 commit comments

Comments
 (0)