Query `allowed_ips` from the matched endpoint config for a CONNECT decision.
(
engine: &OpaEngine,
decision: &ConnectDecision,
host: &str,
port: u16,
)
| 2728 | |
| 2729 | /// Query `allowed_ips` from the matched endpoint config for a CONNECT decision. |
| 2730 | fn query_allowed_ips( |
| 2731 | engine: &OpaEngine, |
| 2732 | decision: &ConnectDecision, |
| 2733 | host: &str, |
| 2734 | port: u16, |
| 2735 | ) -> Vec<String> { |
| 2736 | // Only query if action is Allow with a matched policy |
| 2737 | let has_policy = match &decision.action { |
| 2738 | NetworkAction::Allow { matched_policy } => matched_policy.is_some(), |
| 2739 | NetworkAction::Deny { .. } => false, |
| 2740 | }; |
| 2741 | if !has_policy { |
| 2742 | return vec![]; |
| 2743 | } |
| 2744 | |
| 2745 | let input = crate::opa::NetworkInput { |
| 2746 | host: host.to_string(), |
| 2747 | port, |
| 2748 | binary_path: decision.binary.clone().unwrap_or_default(), |
| 2749 | binary_sha256: String::new(), |
| 2750 | ancestors: decision.ancestors.clone(), |
| 2751 | cmdline_paths: decision.cmdline_paths.clone(), |
| 2752 | }; |
| 2753 | |
| 2754 | match engine.query_allowed_ips(&input) { |
| 2755 | Ok(ips) => ips, |
| 2756 | Err(e) => { |
| 2757 | let event = NetworkActivityBuilder::new(openshell_ocsf::ctx::ctx()) |
| 2758 | .activity(ActivityId::Fail) |
| 2759 | .severity(SeverityId::Low) |
| 2760 | .status(StatusId::Failure) |
| 2761 | .dst_endpoint(Endpoint::from_domain(host, port)) |
| 2762 | .message(format!( |
| 2763 | "Failed to query allowed_ips from endpoint config: {e}" |
| 2764 | )) |
| 2765 | .build(); |
| 2766 | ocsf_emit!(event); |
| 2767 | vec![] |
| 2768 | } |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | /// Query whether the matched endpoint was declared as this exact hostname. |
| 2773 | fn query_exact_declared_endpoint_host( |
no test coverage detected