difftreelog
fix privileged agent plugins
in: trunk
4 files changed
cmds/remowt-agent/src/main.rsdiffbeforeafterboth15use remowt_link_shared::{Address, BifConfig, Fs, Pty, Systemd};15use remowt_link_shared::{Address, BifConfig, Fs, Pty, Systemd};16use remowt_polkit_shared::{emphasize, BackendRequest, Identity, PidDisplay};16use remowt_polkit_shared::{emphasize, BackendRequest, Identity, PidDisplay};17use remowt_ui_prompt::bifrost::PromptEndpointsClient;17use remowt_ui_prompt::bifrost::PromptEndpointsClient;18use remowt_ui_prompt::rofi::RofiPrompter;18use remowt_ui_prompt::{PrependSourcePrompter, Prompter, Source};19use remowt_ui_prompt::{PrependSourcePrompter, Prompter, Source};19use tokio::fs;20use tokio::fs;20use tokio::net::UnixStream;21use tokio::net::UnixStream;21use tokio::runtime::Builder;22use tokio::runtime::Builder;22use tokio::task::AbortHandle;23use tokio::task::AbortHandle;23use tracing::{info, trace};24use tracing::{debug, info, trace};24use zbus::fdo;25use zbus::fdo;25use zbus::zvariant::{OwnedValue, Str};26use zbus::zvariant::{OwnedValue, Str};26use zbus::{interface, proxy, Connection};27use zbus::{interface, proxy, Connection};39}40}40impl Drop for CancelTaskOnDrop {41impl Drop for CancelTaskOnDrop {41 fn drop(&mut self) {42 fn drop(&mut self) {42 info!("cancel on drop");43 debug!("cancel on drop");43 if let Some(task) = self44 if let Some(task) = self44 .tasks45 .tasks45 .lock()46 .lock()121 identities.iter().map(|v| v.to_string()).collect();122 identities.iter().map(|v| v.to_string()).collect();122 let identity_displays: Vec<&str> =123 let identity_displays: Vec<&str> =123 identity_displays.iter().map(|v| v.as_str()).collect();124 identity_displays.iter().map(|v| v.as_str()).collect();124 info!("choose identity");125 debug!("choose identity");125 let choosen_identity = match identity_displays.len() {126 let choosen_identity = match identity_displays.len() {126 0 => {127 0 => {127 return Err(fdo::Error::AuthFailed(128 return Err(fdo::Error::AuthFailed(140 .await?141 .await?141 }142 }142 };143 };143 info!("identity chosen");144 debug!("identity chosen");144145145 let _ = write!(146 let _ = write!(146 description,147 description,169 .lock()170 .lock()170 .unwrap()171 .unwrap()171 .insert(cookie.clone(), task.abort_handle());172 .insert(cookie.clone(), task.abort_handle());172 info!("abort handle stored");173 debug!("abort handle stored");173 let _ = _cancel_guard.set(CancelTaskOnDrop {174 let _ = _cancel_guard.set(CancelTaskOnDrop {174 tasks: self.tasks.clone(),175 tasks: self.tasks.clone(),175 handle: cookie.clone(),176 handle: cookie.clone(),182183183 /// CancelAuthentication method184 /// CancelAuthentication method184 async fn cancel_authentication(&self, cookie: &str) -> zbus::fdo::Result<()> {185 async fn cancel_authentication(&self, cookie: &str) -> zbus::fdo::Result<()> {185 info!("auth cancelled");186 debug!("auth cancelled");186 if let Some(abort) = self.tasks.lock().unwrap().remove(cookie) {187 if let Some(abort) = self.tasks.lock().unwrap().remove(cookie) {187 info!("abort handle found");188 debug!("abort handle found");188 abort.abort();189 abort.abort();189 }190 }190 // debug!("Authentication cancled ! {cookie}");191 // debug!("Authentication cancled ! {cookie}");220 #[arg(long)]221 #[arg(long)]221 privileged: bool,222 privileged: bool,222 },223 },224 LocalAgent,223}225}224226225fn main() -> anyhow::Result<()> {227fn main() -> anyhow::Result<()> {226 // Log to stderr: `privileged-agent` uses stdout as the bifrost transport,228 // Log to stderr: `privileged-agent` uses stdout as the bifrost transport,227 // so anything written there would corrupt the stream.229 // so anything written there would corrupt the stream.228 tracing_subscriber::fmt()230 tracing_subscriber::fmt()229 .with_writer(std::io::stderr)231 .with_writer(std::io::stderr)232 .without_time()230 .init();233 .init();231 let opts = Opts::parse();234 let opts = Opts::parse();232235237 prompt,240 prompt,238 description,241 description,239 } => runtime.block_on(askpass::ask(&prompt, description)),242 } => runtime.block_on(askpass::ask(&prompt, description)),243 Opts::LocalAgent => runtime.block_on(main_real()),240 Opts::Editor { path } => runtime.block_on(editor::edit(path)),244 Opts::Editor { path } => runtime.block_on(editor::edit(path)),241 Opts::RealAgent { path, privileged } => runtime.block_on(main_real_agent(path, privileged)),245 Opts::RealAgent { path, privileged } => runtime.block_on(main_real_agent(path, privileged)),242 }246 }243}247}248async fn main_real() -> anyhow::Result<()> {249 let conn = Connection::system().await?;250 let helper = SocketHelper {251 fallback: SuidHelper,252 };253 register_auth_agent(&conn, Agent::new(helper, RofiPrompter)).await?;254255 let _conn = conn;256 pending().await257}244async fn main_real_agent(path: Option<PathBuf>, privileged: bool) -> anyhow::Result<()> {258async fn main_real_agent(path: Option<PathBuf>, privileged: bool) -> anyhow::Result<()> {245 let address = if privileged {259 let address = if privileged {246 Address::AgentPrivileged260 Address::AgentPrivileged330 proxy344 proxy331 .register_authentication_agent(&subject, "C", OBJ_PATH)345 .register_authentication_agent(&subject, "C", OBJ_PATH)332 .await?;346 .await?;333 info!(kind = subject.subject_kind, "registered polkit agent");347 debug!(kind = subject.subject_kind, "registered polkit agent");334 Ok(())348 Ok(())335}349}336350crates/remowt-plugin/Cargo.tomldiffbeforeafterboth--- a/crates/remowt-plugin/Cargo.toml
+++ b/crates/remowt-plugin/Cargo.toml
@@ -11,6 +11,7 @@
bifrostlink-ports.workspace = true
bytes.workspace = true
remowt-link-shared.workspace = true
+serde_json.workspace = true
tokio = { workspace = true, features = [
"rt",
"net",
crates/remowt-plugin/src/host.rsdiffbeforeafterboth--- a/crates/remowt-plugin/src/host.rs
+++ b/crates/remowt-plugin/src/host.rs
@@ -13,6 +13,7 @@
pub fn serve(rpc: &mut Rpc<BifConfig>) {
let host = Host {
+ me: rpc.me(),
rpc: rpc.clone().downgrade(),
children: Mutex::new(Vec::new()),
};
@@ -20,6 +21,7 @@
}
struct Host {
+ me: Address,
rpc: WeakRpc<BifConfig>,
children: Mutex<Vec<Child>>,
}
@@ -30,6 +32,7 @@
let mut child = Command::new(path)
.arg(id.to_string())
+ .arg(serde_json::to_string(&self.me).expect("address serializes"))
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.kill_on_drop(true)
crates/remowt-plugin/src/lib.rsdiffbeforeafterboth--- a/crates/remowt-plugin/src/lib.rs
+++ b/crates/remowt-plugin/src/lib.rs
@@ -18,6 +18,13 @@
.map_err(|e| anyhow::anyhow!("invalid plugin index {arg:?}: {e}"))
}
+pub fn host_address() -> Result<Address> {
+ let arg = std::env::args()
+ .nth(2)
+ .ok_or_else(|| anyhow::anyhow!("missing host address argument"))?;
+ serde_json::from_str(&arg).map_err(|e| anyhow::anyhow!("invalid host address {arg:?}: {e}"))
+}
+
pub fn run<F>(register: F) -> Result<()>
where
F: FnOnce(&mut Rpc<BifConfig>),
@@ -27,10 +34,11 @@
.init();
let index = plugin_index()?;
+ let host = host_address()?;
let runtime = Builder::new_current_thread().enable_all().build()?;
runtime.block_on(async move {
let mut rpc = Rpc::<BifConfig>::new(Address::Plugin(index));
- rpc.add_direct(Address::Agent, from_stdio(), Rtt(0));
+ rpc.add_direct(host, from_stdio(), Rtt(0));
register(&mut rpc);
let _rpc = rpc;
pending::<Result<()>>().await