git.delta.rocks / remowt / refs/commits / 11447649e1e7

difftreelog

feat remowt user identity

nulpnyxpYaroslav Bolyukin3 days agoparent: #075f103.patch.diff
in: trunk

5 files changed

modifiedCargo.lockdiffbeforeafterboth
before · Cargo.lock
330 packageslockfile v4
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,18 +3,18 @@
 resolver = "2"
 
 [workspace.package]
-version = "0.1.7"
+version = "0.1.8"
 license = "MIT"
 edition = "2021"
 repository = "https://git.delta.rocks/r/remowt"
 
 [workspace.dependencies]
-remowt-client = { version = "0.1.7", path = "crates/remowt-client" }
-remowt-polkit-shared = { version = "0.1.7", path = "crates/polkit-shared" }
-remowt-link-shared = { version = "0.1.7", path = "crates/remowt-link-shared" }
-remowt-plugin = { version = "0.1.7", path = "crates/remowt-plugin" }
-remowt-ui-prompt = { version = "0.1.7", path = "crates/remowt-ui-prompt" }
-remowt-endpoints = { version = "0.1.7", path = "crates/remowt-endpoints" }
+remowt-client = { version = "0.1.8", path = "crates/remowt-client" }
+remowt-polkit-shared = { version = "0.1.8", path = "crates/polkit-shared" }
+remowt-link-shared = { version = "0.1.8", path = "crates/remowt-link-shared" }
+remowt-plugin = { version = "0.1.8", path = "crates/remowt-plugin" }
+remowt-ui-prompt = { version = "0.1.8", path = "crates/remowt-ui-prompt" }
+remowt-endpoints = { version = "0.1.8", path = "crates/remowt-endpoints" }
 
 bifrostlink = "0.2.0"
 bifrostlink-macros = "0.2.0"
modifiedcmds/remowt-ssh/src/main.rsdiffbeforeafterboth
--- a/cmds/remowt-ssh/src/main.rs
+++ b/cmds/remowt-ssh/src/main.rs
@@ -53,8 +53,14 @@
 
 	let bundle = AgentBundle::from_dir(agents_dir()?)?;
 	let (conn, escalate) = match &opts {
-		Opts::Ssh { host, escalate } => (Remowt::connect(host, &bundle).await?, *escalate),
-		Opts::Local { escalate } => (Remowt::connect_local(&bundle).await?, *escalate),
+		Opts::Ssh { host, escalate } => (
+			Remowt::connect(host, &bundle, "remowt-ssh".to_owned()).await?,
+			*escalate,
+		),
+		Opts::Local { escalate } => (
+			Remowt::connect_local(&bundle, "remowt-ssh".to_owned()).await?,
+			*escalate,
+		),
 	};
 	let mut rpc = conn.rpc();
 
modifiedcrates/remowt-client/src/lib.rsdiffbeforeafterboth
--- a/crates/remowt-client/src/lib.rs
+++ b/crates/remowt-client/src/lib.rs
@@ -249,6 +249,7 @@
 	#[allow(dead_code)]
 	children: Mutex<Vec<tokio::process::Child>>,
 	_runtime_tmp: Option<TempDir>,
+	user: String,
 }
 
 #[derive(Clone)]
@@ -259,7 +260,7 @@
 impl Remowt {
 	/// Connect to the remote host over ssh, detect the architecture and deploy the required
 	/// agent binary.
-	pub async fn connect(host: &str, bundle: &AgentBundle) -> Result<Self> {
+	pub async fn connect(host: &str, bundle: &AgentBundle, remowt_user: String) -> Result<Self> {
 		let conf = russh_config::parse_home(host)?;
 		let port = conf.host_config.port.or(conf.port).unwrap_or(22);
 		let hostname = conf
@@ -337,11 +338,12 @@
 			elevated: tokio::sync::OnceCell::new(),
 			children: Mutex::new(Vec::new()),
 			_runtime_tmp: None,
+			user: remowt_user,
 		})))
 	}
 
 	/// "Connect" to the local machine's agent, by starting the agent binary locally.
-	pub async fn connect_local(bundle: &AgentBundle) -> Result<Self> {
+	pub async fn connect_local(bundle: &AgentBundle, user: String) -> Result<Self> {
 		let agent_path = bundle.local_binary()?;
 		let mut child = tokio::process::Command::new(&agent_path)
 			.arg("real-agent")
@@ -368,6 +370,7 @@
 			elevated: tokio::sync::OnceCell::new(),
 			children: Mutex::new(vec![child]),
 			_runtime_tmp: runtime_tmp,
+			user,
 		})))
 	}
 
@@ -431,6 +434,14 @@
 				args.push("-w".to_owned());
 				args.push(tool.to_owned());
 				args.extend(flags.iter().copied().map(str::to_owned));
+				if tool == "run0" {
+					args.push(format!(
+						"--unit={}-{}-{}.scope",
+						self.0.user,
+						std::process::id(),
+						Uuid::new_v4()
+					));
+				}
 				args.push(agent_path);
 				args.push("real-agent".to_owned());
 				args.push("--privileged".to_owned());
modifiedcrates/remowt-endpoints/Cargo.tomldiffbeforeafterboth
--- a/crates/remowt-endpoints/Cargo.toml
+++ b/crates/remowt-endpoints/Cargo.toml
@@ -11,7 +11,13 @@
 serde = { workspace = true }
 tempfile.workspace = true
 thiserror.workspace = true
-tokio = { workspace = true, features = ["net", "io-util", "rt", "process"] }
+tokio = { workspace = true, features = [
+	"net",
+	"io-util",
+	"rt",
+	"process",
+	"io-std",
+] }
 tracing.workspace = true
 nix = { workspace = true, features = ["process", "signal", "term"] }
 zbus.workspace = true