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

Function from_proto

crates/openshell-policy/src/lib.rs:786–918  ·  view source on GitHub ↗
(policy: &SandboxPolicy)

Source from the content-addressed store, hash-verified

784// ---------------------------------------------------------------------------
785
786fn from_proto(policy: &SandboxPolicy) -> PolicyFile {
787 let filesystem_policy = policy.filesystem.as_ref().map(|fs| FilesystemDef {
788 include_workdir: fs.include_workdir,
789 read_only: fs.read_only.clone(),
790 read_write: fs.read_write.clone(),
791 });
792
793 let landlock = policy.landlock.as_ref().map(|ll| LandlockDef {
794 compatibility: ll.compatibility.clone(),
795 });
796
797 let process = policy.process.as_ref().and_then(|p| {
798 if p.run_as_user.is_empty() && p.run_as_group.is_empty() {
799 None
800 } else {
801 Some(ProcessDef {
802 run_as_user: p.run_as_user.clone(),
803 run_as_group: p.run_as_group.clone(),
804 })
805 }
806 });
807
808 let network_policies = policy
809 .network_policies
810 .iter()
811 .map(|(key, rule)| {
812 let yaml_rule = NetworkPolicyRuleDef {
813 name: rule.name.clone(),
814 endpoints: rule
815 .endpoints
816 .iter()
817 .map(|e| {
818 // Use compact form: if ports has exactly 1 element,
819 // emit port (scalar). If >1, emit ports (array).
820 // Proto uses u32; YAML uses u16. Clamp at boundary.
821 let clamp = |v: u32| -> u16 { v.min(65535) as u16 };
822 let (port, ports) = if e.ports.len() > 1 {
823 (0, e.ports.iter().map(|&p| clamp(p)).collect())
824 } else {
825 (clamp(e.ports.first().copied().unwrap_or(e.port)), vec![])
826 };
827 let protocol = e.protocol.clone();
828 let mcp_allow_all_known_mcp_methods = !is_mcp_protocol(&protocol)
829 || e.mcp
830 .as_ref()
831 .and_then(|options| options.allow_all_known_mcp_methods)
832 .unwrap_or(false);
833 let rules = e
834 .rules
835 .iter()
836 .map(|r| L7RuleDef {
837 allow: allow_proto_to_def(
838 &protocol,
839 r.allow.clone().unwrap_or_default(),
840 mcp_allow_all_known_mcp_methods,
841 ),
842 })
843 .collect();

Calls 7

is_mcp_protocolFunction · 0.85
allow_proto_to_defFunction · 0.85
deny_proto_to_defFunction · 0.85
mcp_config_from_protoFunction · 0.85
lenMethod · 0.80
is_emptyMethod · 0.45