Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vpn #2607

Merged
merged 47 commits into from
Aug 22, 2024
Merged

Vpn #2607

Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a5de14c
Start on DNS
DmitryDodzin Jun 26, 2024
e38d8bb
Update
DmitryDodzin Jul 1, 2024
e4bddc4
Dis?
DmitryDodzin Jul 3, 2024
9742c18
tun2?
DmitryDodzin Jul 3, 2024
3dca2e7
Ops
DmitryDodzin Jul 3, 2024
1e4659c
Working???
DmitryDodzin Jul 4, 2024
b0dca1a
Update
DmitryDodzin Jul 4, 2024
a164c54
Update
DmitryDodzin Jul 4, 2024
c098336
Fix
DmitryDodzin Jul 4, 2024
8005f05
Merge branch 'main' into vpn
DmitryDodzin Jul 10, 2024
ef51879
Update
DmitryDodzin Jul 10, 2024
8196217
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Jul 16, 2024
aa29245
Update
DmitryDodzin Jul 16, 2024
5c3f33a
Update
DmitryDodzin Jul 17, 2024
9d7959b
Update
DmitryDodzin Jul 17, 2024
086dd13
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Jul 17, 2024
3ac7c48
Tiny
DmitryDodzin Jul 17, 2024
0abcfd9
Lint
DmitryDodzin Jul 17, 2024
49e45e0
One More
DmitryDodzin Jul 17, 2024
b894b20
Update requirements
DmitryDodzin Jul 17, 2024
3b77548
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 5, 2024
8a6f6d9
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 7, 2024
65a95ac
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 8, 2024
22c67a9
Tunnel
DmitryDodzin Aug 8, 2024
febfcdf
Merge branch 'main' into vpn
DmitryDodzin Aug 12, 2024
7521793
Update
DmitryDodzin Aug 12, 2024
b86b901
Sync
DmitryDodzin Aug 13, 2024
7bfed19
Tiny
DmitryDodzin Aug 13, 2024
432c15b
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 14, 2024
1e7ebf3
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 14, 2024
5cc61cf
No nix error
DmitryDodzin Aug 14, 2024
1b3a424
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 19, 2024
bd3f504
Combine macOS guards
DmitryDodzin Aug 19, 2024
fc443c1
Make vpn multi threaded
DmitryDodzin Aug 19, 2024
e0552e2
Keep it singlethreaded
DmitryDodzin Aug 19, 2024
5e51495
Drop it like it hot
DmitryDodzin Aug 19, 2024
af9f658
Ops
DmitryDodzin Aug 19, 2024
6a19786
Ops 2
DmitryDodzin Aug 19, 2024
81bc8d0
Lint
DmitryDodzin Aug 19, 2024
3c12f3f
Apply suggestions from code review
DmitryDodzin Aug 20, 2024
3890615
CR update
DmitryDodzin Aug 20, 2024
2f7fe23
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 20, 2024
cbea293
Update
DmitryDodzin Aug 20, 2024
f471843
Apply suggestions from code review
DmitryDodzin Aug 21, 2024
3bbf88e
Merge remote-tracking branch 'metalbear-co/main' into vpn
DmitryDodzin Aug 21, 2024
9e7f991
Merge branch 'main' into vpn
DmitryDodzin Aug 21, 2024
a6316b8
Ephh
DmitryDodzin Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 105 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ tokio = { version = "1" }
tokio-stream = { version = "0.1", features = ["sync"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_yaml = "0.9"
nix = { version = "0.29", features = ["net"] }
clap = { version = "4", features = ["derive"] }
tracing = "0.1"
Expand Down
1 change: 1 addition & 0 deletions changelog.d/2387.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add initial and very basic implementation of vpn
2 changes: 2 additions & 0 deletions mirrord/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tokio = { workspace = true, features = [
"process",
"signal",
] }
procfs = "0.16.0"
serde.workspace = true
serde_json.workspace = true
pnet = "0.35"
Expand Down Expand Up @@ -69,6 +70,7 @@ tokio-rustls = "0.26"
x509-parser = "0.16"
rustls.workspace = true
envy = "0.4"
socket2.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
iptables = { git = "https://github.com/metalbear-co/rust-iptables.git", rev = "e66c7332e361df3c61a194f08eefe3f40763d624" }
Expand Down
11 changes: 11 additions & 0 deletions mirrord/agent/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use crate::{
StealerCommand, TcpConnectionStealer, TcpStealerApi,
},
util::{run_thread_in_namespace, ClientId},
vpn::VpnApi,
watched_task::{TaskStatus, WatchedTask},
*,
};
Expand Down Expand Up @@ -200,6 +201,7 @@ struct ClientConnectionHandler {
tcp_outgoing_api: TcpOutgoingApi,
udp_outgoing_api: UdpOutgoingApi,
dns_api: DnsApi,
vpn_api: VpnApi,
state: State,
/// Whether the client has sent us [`ClientMessage::ReadyForLogs`].
ready_for_logs: bool,
Expand All @@ -224,6 +226,7 @@ impl ClientConnectionHandler {

let tcp_outgoing_api = TcpOutgoingApi::new(pid);
let udp_outgoing_api = UdpOutgoingApi::new(pid);
let vpn_api = VpnApi::new(pid);

let client_handler = Self {
id,
Expand All @@ -234,6 +237,7 @@ impl ClientConnectionHandler {
tcp_outgoing_api,
udp_outgoing_api,
dns_api,
vpn_api,
state,
ready_for_logs: false,
};
Expand Down Expand Up @@ -372,6 +376,10 @@ impl ClientConnectionHandler {
Ok(message) => self.respond(DaemonMessage::GetAddrInfoResponse(message)).await?,
Err(e) => break e,
},
message = self.vpn_api.daemon_message() => match message{
Ok(message) => self.respond(DaemonMessage::Vpn(message)).await?,
Err(e) => break e,
},
_ = cancellation_token.cancelled() => return Ok(()),
}
};
Expand Down Expand Up @@ -473,6 +481,9 @@ impl ClientConnectionHandler {
ClientMessage::ReadyForLogs => {
self.ready_for_logs = true;
}
ClientMessage::Vpn(message) => {
self.vpn_api.layer_message(message).await?;
}
}

Ok(true)
Expand Down
4 changes: 4 additions & 0 deletions mirrord/agent/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub(crate) enum AgentError {

#[error("Timeout on accepting first client connection")]
FirstConnectionTimeout,

/// Temporary error for vpn feature
#[error("Generic error in vpn: {0}")]
VpnError(String),
}

impl From<mpsc::error::SendError<StealerCommand>> for AgentError {
Expand Down
2 changes: 2 additions & 0 deletions mirrord/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ mod steal;
#[cfg(target_os = "linux")]
mod util;
#[cfg(target_os = "linux")]
mod vpn;
#[cfg(target_os = "linux")]
mod watched_task;

#[cfg(target_os = "linux")]
Expand Down
Loading
Loading