MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / evaluate_opa_tcp

Function evaluate_opa_tcp

crates/openshell-supervisor-network/src/proxy.rs:1549–1642  ·  view source on GitHub ↗
(
    peer_addr: SocketAddr,
    engine: &OpaEngine,
    identity_cache: &BinaryIdentityCache,
    entrypoint_pid: &AtomicU32,
    host: &str,
    port: u16,
)

Source from the content-addressed store, hash-verified

1547/// Evaluate OPA policy for a TCP connection with identity binding via /proc/net/tcp.
1548#[cfg(target_os = "linux")]
1549fn evaluate_opa_tcp(
1550 peer_addr: SocketAddr,
1551 engine: &OpaEngine,
1552 identity_cache: &BinaryIdentityCache,
1553 entrypoint_pid: &AtomicU32,
1554 host: &str,
1555 port: u16,
1556) -> ConnectDecision {
1557 use crate::opa::NetworkInput;
1558 use std::sync::atomic::Ordering;
1559
1560 let deny = |reason: String,
1561 binary: Option<PathBuf>,
1562 binary_pid: Option<u32>,
1563 ancestors: Vec<PathBuf>,
1564 cmdline_paths: Vec<PathBuf>|
1565 -> ConnectDecision {
1566 ConnectDecision {
1567 action: NetworkAction::Deny { reason },
1568 generation: engine.current_generation(),
1569 binary,
1570 binary_pid,
1571 ancestors,
1572 cmdline_paths,
1573 }
1574 };
1575
1576 let pid = entrypoint_pid.load(Ordering::Acquire);
1577 if pid == 0 {
1578 return deny(
1579 "entrypoint process not yet spawned".into(),
1580 None,
1581 None,
1582 vec![],
1583 vec![],
1584 );
1585 }
1586
1587 let total_start = std::time::Instant::now();
1588 let peer_port = peer_addr.port();
1589
1590 let identity = match resolve_process_identity(pid, peer_port, identity_cache) {
1591 Ok(id) => id,
1592 Err(err) => {
1593 return deny(
1594 err.reason,
1595 err.binary,
1596 err.binary_pid,
1597 err.ancestors,
1598 vec![],
1599 );
1600 }
1601 };
1602
1603 let ResolvedIdentity {
1604 bin_path,
1605 binary_pid,
1606 ancestors,

Callers 2

handle_tcp_connectionFunction · 0.85
handle_forward_proxyFunction · 0.85

Calls 4

current_generationMethod · 0.80
resolve_process_identityFunction · 0.70
loadMethod · 0.45

Tested by

no test coverage detected