Skip to content

Commit

Permalink
feat(rust): rename ebpf portals -> privileged portals
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Nov 7, 2024
1 parent c84c401 commit e1ed746
Show file tree
Hide file tree
Showing 41 changed files with 62 additions and 118 deletions.
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repository = "https://github.com/ockam-network/ockam/implementations/rust/ockam/
description = "Ockam's request-response API"

[features]
default = ["std", "rust-crypto", "ebpf"]
default = ["std", "rust-crypto", "privileged_portals"]
test-utils = []
std = [
"either/use_std",
Expand All @@ -43,7 +43,7 @@ std = [
storage = ["ockam/storage"]
aws-lc = ["ockam_vault/aws-lc", "ockam_transport_tcp/aws-lc"]
rust-crypto = ["ockam_vault/rust-crypto", "ockam_transport_tcp/ring"]
ebpf = ["ockam_transport_tcp/ebpf"]
privileged_portals = ["ockam_transport_tcp/privileged_portals"]

[build-dependencies]
cfg_aliases = "0.2.1"
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn hash() {
fn main() {
hash();
cfg_aliases! {
ebpf_alias: { all(target_os = "linux", feature = "ebpf") }
privileged_portals_support: { all(target_os = "linux", feature = "ebpf") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl InletSessionReplacer {
None => {
let options = self.inlet_options(node_manager).await?;
let inlet = if self.ebpf {
#[cfg(ebpf_alias)]
#[cfg(privileged_portals_support)]
{
node_manager
.tcp_transport
Expand All @@ -178,7 +178,7 @@ impl InletSessionReplacer {
)
.await?
}
#[cfg(not(ebpf_alias))]
#[cfg(not(privileged_portals_support))]
{
return Err(ockam_core::Error::new(
Origin::Node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ impl NodeManager {
};

let res = if ebpf {
#[cfg(ebpf_alias)]
#[cfg(privileged_portals_support)]
{
self.tcp_transport
.create_raw_outlet(worker_addr.clone(), to.clone(), options)
.await
}
#[cfg(not(ebpf_alias))]
#[cfg(not(privileged_portals_support))]
{
Err(ockam_core::Error::new(
Origin::Node,
Expand Down
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ tempfile = "3.10.1"
time = { version = "0.3", default-features = false, features = ["std", "local-offset"] }

[features]
default = ["orchestrator", "rust-crypto", "ebpf"]
ebpf = ["ockam_api/ebpf"]
default = ["orchestrator", "rust-crypto", "privileged_portals"]
privileged_portals = ["ockam_api/privileged_portals"]
orchestrator = []
aws-lc = ["ockam_vault/aws-lc", "ockam_api/aws-lc", "rustls/aws-lc-rs"]
rust-crypto = ["ockam_vault/rust-crypto", "ockam_api/rust-crypto", "rustls/ring"]
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn hash() {
fn main() {
hash();
cfg_aliases! {
ebpf_alias: { all(target_os = "linux", feature = "ebpf") }
privileged_portals_support: { all(target_os = "linux", feature = "ebpf") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ UDP Puncture
- OCKAM_RENDEZVOUS_SERVER: set this variable to the hostname and port of the Rendezvous service

TCP Portals
- OCKAM_EBPF: if variable is set, all TCP Inlets/Outlets will be eBPF Inlets/Outlets (overrides `--ebpf` argument for `ockam tcp-inlet create` and `ockam tcp-outlet create`).
- OCKAM_PRIVILEGED: if variable is set, all TCP Inlets/Outlets will use eBPF (overrides `--privileged` argument for `ockam tcp-inlet create` and `ockam tcp-outlet create`).

Devs Usage
- OCKAM: a `string` that defines the path to the ockam binary to use.
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ResetCommand {
opts.state.reset().await?;
}

#[cfg(ebpf_alias)]
#[cfg(privileged_portals_support)]
ockam::tcp::TcpTransport::detach_all_ockam_ebpfs_globally();

opts.terminal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ pub struct CreateCommand {
pub no_tcp_fallback: bool,

/// Use eBPF and RawSocket to access TCP packets instead of TCP data stream.
/// If `OCKAM_EBPF` env variable is set to 1, this argument will be `true`.
#[arg(long, env = "OCKAM_EBPF", value_parser = FalseyValueParser::default(), hide = true)]
/// If `OCKAM_PRIVILEGED` env variable is set to 1, this argument will be `true`.
#[arg(long, env = "OCKAM_PRIVILEGED", value_parser = FalseyValueParser::default(), hide = true)]
pub ebpf: bool,

#[arg(long, value_name = "BOOL", default_value_t = false, hide = true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ pub struct CreateCommand {
pub allow: Option<PolicyExpression>,

/// Use eBPF and RawSocket to access TCP packets instead of TCP data stream.
/// If `OCKAM_EBPF` env variable is set to 1, this argument will be `true`.
#[arg(long, env = "OCKAM_EBPF", value_parser = FalseyValueParser::default(), hide = true)]
pub ebpf: bool,
/// If `OCKAM_PRIVILEGED` env variable is set to 1, this argument will be `true`.
#[arg(long, env = "OCKAM_PRIVILEGED", value_parser = FalseyValueParser::default(), hide = true)]
pub privileged: bool,
}

#[async_trait]
Expand All @@ -97,7 +97,7 @@ impl Command for CreateCommand {
self.tls,
self.from.clone().map(Address::from).as_ref(),
self.allow.clone(),
self.ebpf,
self.privileged,
)
.await?
};
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/tests/bats/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fi

if [ "$local_as_root_suite" = true ]; then
echo "Running local root suite..."
OCKAM_EBPF=1 bats "$current_directory/local/portals.bats" --timing -j 3
OCKAM_PRIVILEGED=1 bats "$current_directory/local/portals.bats" --timing -j 3
fi

if [ -z "${ORCHESTRATOR_TESTS}" ]; then
Expand Down
56 changes: 0 additions & 56 deletions implementations/rust/ockam/ockam_ebpf/ubuntu_x86.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_transport_tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ TCP Transport for the Ockam Routing Protocol.
"""

[features]
default = ["std", "ring", "ebpf"]
default = ["std", "ring", "privileged_portals"]
std = ["ockam_macros/std", "ockam_transport_core/std", "opentelemetry", "binary-layout?/std"]
no_std = ["ockam_macros/no_std", "ockam_transport_core/no_std"]
alloc = []
aws-lc = ["tokio-rustls/aws-lc-rs"]
ring = ["tokio-rustls/ring"]
ebpf = ["aya", "aya-log", "binary-layout", "caps", "nix"]
privileged_portals = ["aya", "aya-log", "binary-layout", "caps", "nix"]

[build-dependencies]
cfg_aliases = "0.2.1"
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_transport_tcp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use cfg_aliases::cfg_aliases;

fn main() {
cfg_aliases! {
ebpf_alias: { all(target_os = "linux", feature = "ebpf") }
privileged_portals_support: { all(target_os = "linux", feature = "privileged_portals") }
}
}
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_transport_tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub use protocol_version::*;
pub use registry::*;
pub use transport::*;

#[cfg(ebpf_alias)]
#[cfg(privileged_portals_support)]
/// eBPF backed TCP portals that works on TCP level rather than on top of TCP
pub mod ebpf_portal;
pub mod privileged_portal;

pub(crate) const CLUSTER_NAME: &str = "_internals.transport.tcp";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum PortalMessage<'de> {
/// or from the target to the Inlet was dropped
Disconnect,
/// Message with binary payload and packet counter
// TODO: Add route_index. May not be as important as for eBPF portals, as regular portals
// TODO: Add route_index. May not be as important as for privileged portals, as regular portals
// require reliable channel anyways. And if PortalMessage is sent over a channel that
// guarantees ordering, we don't need route_index
Payload(&'de [u8], Option<u16>),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unsafe_code)]

use crate::ebpf_portal::{
use crate::privileged_portal::{
Iface, InletRegistry, OutletRegistry, Port, Proto, RawSocketProcessor, TcpPacketWriter,
};
use aya::maps::{MapData, MapError};
Expand Down Expand Up @@ -344,7 +344,7 @@ fn map_map_error(map_error: MapError) -> Error {
#[cfg(test)]
// requires root to run
mod tests {
use crate::ebpf_portal::TcpTransportEbpfSupport;
use crate::privileged_portal::TcpTransportEbpfSupport;
use ockam_core::Result;
use ockam_node::Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod ebpf_support;
mod portals;
mod privileged_portals;
mod raw_socket;
mod registry;
mod transport;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::{InternalProcessor, Port, RemoteWorker};
use crate::portal::InletSharedState;
use crate::privileged_portal::{InternalProcessor, Port, RemoteWorker};
use crate::{TcpInlet, TcpInletOptions, TcpOutletOptions, TcpTransport};
use caps::Capability::{CAP_BPF, CAP_NET_ADMIN, CAP_NET_RAW, CAP_SYS_ADMIN};
use caps::{CapSet, Capability};
Expand All @@ -17,7 +17,7 @@ use tokio::sync::mpsc::channel;
use tracing::instrument;

impl TcpTransport {
/// Check if eBPF portals can be run with current permissions
/// Check if privileged portals can be run with current permissions
pub fn check_capabilities() -> Result<()> {
let caps = caps::read(None, CapSet::Effective)
.map_err(|e| TransportError::ReadCaps(e.to_string()))?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::ebpf_portal::packet::{
use crate::privileged_portal::packet::{
Ipv4Info, RawSocketReadResult, TcpInfo, TcpStrippedHeaderAndPayload,
};
use crate::ebpf_portal::packet_binary::{ipv4_header, tcp_header};
use crate::ebpf_portal::TcpPacketReader;
use crate::privileged_portal::packet_binary::{ipv4_header, tcp_header};
use crate::privileged_portal::TcpPacketReader;
use async_trait::async_trait;
use log::{error, trace};
use nix::sys::socket::MsgFlags;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ebpf_portal::packet::TcpStrippedHeaderAndPayload;
use crate::ebpf_portal::packet_binary::tcp_header_ports;
use crate::ebpf_portal::{tcp_set_checksum, Port, TcpPacketWriter};
use crate::privileged_portal::packet::TcpStrippedHeaderAndPayload;
use crate::privileged_portal::packet_binary::tcp_header_ports;
use crate::privileged_portal::{tcp_set_checksum, Port, TcpPacketWriter};
use async_trait::async_trait;
use log::{debug, error};
use nix::sys::socket::{MsgFlags, SockaddrIn};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet_binary::tcp_header;
use crate::ebpf_portal::ChecksumAccumulator;
use crate::privileged_portal::packet_binary::tcp_header;
use crate::privileged_portal::ChecksumAccumulator;
use std::net::Ipv4Addr;

/// Calculate and set checksum for a TCP packet
Expand Down Expand Up @@ -33,7 +33,7 @@ fn tcp_checksum(source_ip: Ipv4Addr, destination_ip: Ipv4Addr, packet: &[u8]) ->

#[cfg(test)]
mod tests {
use crate::ebpf_portal::raw_socket::checksum_helpers::tcp_checksum;
use crate::privileged_portal::raw_socket::checksum_helpers::tcp_checksum;
use std::net::Ipv4Addr;

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ebpf_portal::packet::TcpStrippedHeaderAndPayload;
use crate::privileged_portal::packet::TcpStrippedHeaderAndPayload;
use minicbor::{Decode, Encode};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ebpf_portal::{
use crate::privileged_portal::{
AsyncFdPacketReader, AsyncFdPacketWriter, Proto, TcpPacketReader, TcpPacketWriter,
};
use nix::errno::Errno;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet_binary::{ipv4_header, stripped_tcp_header, tcp_header};
use crate::ebpf_portal::Port;
use crate::privileged_portal::packet_binary::{ipv4_header, stripped_tcp_header, tcp_header};
use crate::privileged_portal::Port;
use std::net::Ipv4Addr;

/// Result of reading packet from RawSocket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ebpf_portal::packet::RawSocketReadResult;
use crate::privileged_portal::packet::RawSocketReadResult;
use async_trait::async_trait;
use ockam_core::Result;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet::TcpStrippedHeaderAndPayload;
use crate::ebpf_portal::Port;
use crate::privileged_portal::packet::TcpStrippedHeaderAndPayload;
use crate::privileged_portal::Port;
use async_trait::async_trait;
use ockam_core::Result;
use std::net::Ipv4Addr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ebpf_portal::packet::RawSocketReadResult;
use crate::ebpf_portal::{ConnectionIdentifier, Port};
use crate::portal::InletSharedState;
use crate::privileged_portal::packet::RawSocketReadResult;
use crate::privileged_portal::{ConnectionIdentifier, Port};
use ockam_core::compat::sync::Arc;
use ockam_core::compat::sync::RwLock as SyncRwLock;
use ockam_core::{Address, LocalInfoIdentifier};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet::RawSocketReadResult;
use crate::ebpf_portal::{ConnectionIdentifier, Port};
use crate::privileged_portal::packet::RawSocketReadResult;
use crate::privileged_portal::{ConnectionIdentifier, Port};
use ockam_core::{Address, LocalInfoIdentifier, Route};
use std::collections::HashMap;
use std::net::Ipv4Addr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ebpf_portal::{Iface, TcpPacketWriter};
use crate::privileged_portal::{Iface, TcpPacketWriter};
use crate::TcpTransport;
use aya::programs::tc::{qdisc_detach_program, TcAttachType};
use log::{error, info, warn};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet::RawSocketReadResult;
use crate::ebpf_portal::{Inlet, InletConnection, OckamPortalPacket, Outlet, PortalMode};
use crate::privileged_portal::packet::RawSocketReadResult;
use crate::privileged_portal::{Inlet, InletConnection, OckamPortalPacket, Outlet, PortalMode};
use log::{debug, trace, warn};
use ockam_core::{async_trait, route, LocalInfoIdentifier, LocalMessage, Processor, Result};
use ockam_node::Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ebpf_portal::packet::RawSocketReadResult;
use crate::ebpf_portal::{
use crate::privileged_portal::packet::RawSocketReadResult;
use crate::privileged_portal::{
create_async_fd_raw_socket, Inlet, InletRegistry, Outlet, OutletRegistry, TcpPacketReader,
TcpPacketWriter,
};
Expand Down
Loading

0 comments on commit e1ed746

Please sign in to comment.