Skip to content

Commit b9d573c

Browse files
Merge pull request #46 from agentsea/feature-support_tailscale_and_headscale_for_vpn
Feature: support tailscale and headscale for vpn
2 parents 20b1d4f + e0e102f commit b9d573c

File tree

12 files changed

+789
-176
lines changed

12 files changed

+789
-176
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nebulous"
3-
version = "0.1.89"
3+
version = "0.1.90"
44
edition = "2021"
55
description = "A globally distributed container orchestrator"
66
license = "MIT"
@@ -76,6 +76,7 @@ ed25519-dalek = "2"
7676
openai-api-rs = "6.0.3"
7777
async-ssh2-tokio = "0.8.14"
7878
tailscale-client = "0.1.5"
79+
headscale-client = { git = "https://github.com/philippschroeppel/headscale.rs.git" }
7980
http-body = "1.0.1"
8081
hickory-server = "0.25.1"
8182
warp = "0.3.7"

src/config.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,11 @@ pub struct ServerConfig {
152152
pub message_queue_type: String,
153153
pub redis: RedisConfig,
154154
pub kafka: KafkaConfig,
155-
156-
pub tailscale: Option<TailscaleConfig>,
157-
155+
pub vpn: VpnConfig,
158156
pub auth: ServerAuthConfig,
159-
160157
pub bucket_name: String,
161158
pub bucket_region: String,
162159
pub root_owner: String,
163-
164160
pub publish_url: Option<String>,
165161
}
166162

@@ -251,12 +247,6 @@ impl KafkaConfig {
251247
}
252248
}
253249

254-
#[derive(Debug, Clone)]
255-
pub struct TailscaleConfig {
256-
pub api_key: String,
257-
pub tailnet: String,
258-
}
259-
260250
#[derive(Debug, Clone)]
261251
pub struct ServerAuthConfig {
262252
pub internal: bool,
@@ -280,6 +270,33 @@ impl ServerAuthConfig {
280270
}
281271
}
282272

273+
#[derive(Debug, Clone)]
274+
pub struct VpnConfig {
275+
pub provider: String,
276+
pub api_key: Option<String>,
277+
pub tailnet: Option<String>,
278+
pub login_server: Option<String>,
279+
pub organization: Option<String>,
280+
}
281+
282+
impl VpnConfig {
283+
pub fn new() -> Self {
284+
dotenv().ok();
285+
let provider = env::var("VPN_PROVIDER").unwrap_or_else(|_| "tailscale".to_string());
286+
let api_key = env::var("TS_APIKEY").ok();
287+
let tailnet = env::var("TS_TAILNET").ok();
288+
let organization = env::var("TS_ORGANIZATION").ok();
289+
let login_server = env::var("TS_LOGIN_SERVER").ok();
290+
Self {
291+
provider,
292+
api_key,
293+
tailnet,
294+
login_server,
295+
organization,
296+
}
297+
}
298+
}
299+
283300
impl ServerConfig {
284301
pub fn new() -> Self {
285302
dotenv().ok();
@@ -307,25 +324,19 @@ impl ServerConfig {
307324
Err(_) => "redis".to_string(),
308325
};
309326

310-
311327
let redis = RedisConfig::new();
312328
let kafka = KafkaConfig::new();
313-
314-
let tailscale = match (env::var("TS_API_KEY"), env::var("TS_TAILNET")) {
315-
(Ok(api_key), Ok(tailnet)) => Some(TailscaleConfig { api_key, tailnet }),
316-
_ => None,
317-
};
318-
329+
let vpn = VpnConfig::new();
330+
319331
let auth = ServerAuthConfig::new();
320332

321333
Self {
322334
database_url,
323335
message_queue_type,
324336
redis,
325337
kafka,
326-
tailscale,
338+
vpn,
327339
auth,
328-
// TODO: Move this to dedicated config
329340
bucket_name: env::var("NEBU_BUCKET_NAME")
330341
.unwrap_or_else(|_| panic!("NEBU_BUCKET_NAME environment variable must be set")),
331342
bucket_region: env::var("NEBU_BUCKET_REGION")
@@ -339,4 +350,4 @@ impl ServerConfig {
339350
}
340351
}
341352
// Global static CONFIG instance
342-
pub static SERVER_CONFIG: Lazy<ServerConfig> = Lazy::new(ServerConfig::new);
353+
pub static SERVER_CONFIG: Lazy<ServerConfig> = Lazy::new(ServerConfig::new);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod streams;
2929
pub mod utils;
3030
pub mod validate;
3131
pub mod volumes;
32+
pub mod vpn;
3233

3334
use crate::config::SERVER_CONFIG;
3435
use crate::handlers::v1::namespaces::ensure_namespace;

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
2121
// Initialize tracing
2222
tracing_subscriber::fmt::init();
2323

24+
// Initialize VPN client
25+
if let Err(e) = nebulous::vpn::init_vpn_from_config().await {
26+
eprintln!("Failed to initialize VPN client: {}", e);
27+
}
28+
2429
// Parse command-line arguments
2530
let cli = Cli::parse();
2631

src/proxy/containers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::models::V1UserProfile;
33
use crate::proxy::authz::evaluate_authorization_rules;
44
use crate::proxy::meters::{send_request_metrics, send_response_metrics};
55
use crate::query::Query;
6-
use crate::resources::v1::containers::base::get_tailscale_device_name;
6+
use crate::resources::v1::containers::base::get_vpn_device_name;
77
use crate::AppState;
88
use axum::body::Body;
99
use axum::http::Uri;
@@ -128,7 +128,7 @@ pub async fn forward_container(
128128

129129
let hostname = match container_model.tailnet_ip {
130130
Some(ip) => ip,
131-
None => get_tailscale_device_name(&container_model).await,
131+
None => get_vpn_device_name(&container_model).await,
132132
};
133133

134134
debug!("[PROXY] Hostname: {hostname}");

0 commit comments

Comments
 (0)