Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions 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 @@ -13,6 +13,7 @@ chacha20poly1305 = "0.10"
chrono = { version = "0.4", features = ["serde"] }
hex = "0.4"
futures-util = "0.3"
hkdf = "0.12"
hickory-resolver = { version = "0.25", default-features = false, features = ["tokio"] }
hmac = "0.12"
jsonwebtoken = "9"
Expand Down
37 changes: 37 additions & 0 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ pub async fn run() -> Result<()> {
http: crate::system_http_client(),
devices,
};
// Seed sessiond's E2E history recipient set in the background, retrying
// until sessiond is up. Without this, sessiond starts with no recipients
// and (correctly) refuses to persist history until a device mutation pushes
// the set. Re-pushed on every later enroll/revoke from their handlers.
{
let seed_state = state.clone();
tokio::spawn(async move {
for _ in 0..60 {
if push_history_recipients(&seed_state).await.is_ok() {
return;
}
tokio::time::sleep(Duration::from_secs(2)).await;
}
eprintln!("agent: gave up seeding sessiond history recipients after retries");
});
}

let api_state = state.clone();
let api_ng_state = ng_state.clone();

Expand Down Expand Up @@ -1022,6 +1039,9 @@ async fn create_device(
.upsert(device.clone())
.await
.map_err(|e| Error::Internal(format!("devices upsert: {e}")))?;
if let Err(e) = push_history_recipients(&s).await {
eprintln!("agent: failed to push history recipients after enroll: {e}");
}
Ok((axum::http::StatusCode::CREATED, Json(device)))
}

Expand All @@ -1043,6 +1063,9 @@ async fn revoke_device(
if !ok {
return Err(Error::NotFound);
}
if let Err(e) = push_history_recipients(&s).await {
eprintln!("agent: failed to push history recipients after revoke: {e}");
}
Ok(Json(serde_json::json!({
"revoked": pubkey,
"at_ms": now,
Expand Down Expand Up @@ -1196,6 +1219,20 @@ async fn attach_to_sessiond(
Ok(())
}

/// Push the current non-revoked device pubkey set to `dd-sessiond` so it seals
/// persisted history to exactly those recipients. Called at startup (with retry,
/// since sessiond may still be coming up) and after every device mutation.
async fn push_history_recipients(s: &St) -> Result<()> {
let pubkeys = s.devices.live_pubkeys().await;
sessiond_post_empty_json(
s,
"/api/recipients",
&serde_json::json!({ "pubkeys": pubkeys }),
)
.await
.map(|_| ())
}

async fn sessiond_get<T: DeserializeOwned>(s: &St, path: &str) -> Result<T> {
let url = format!("{}{}", s.sessiond_http_url.trim_end_matches('/'), path);
let resp = s.http.get(url).send().await?;
Expand Down
13 changes: 13 additions & 0 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ impl Store {
self.inner.read().await.values().cloned().collect()
}

/// Hex pubkeys of all non-revoked devices — the recipient set that
/// `dd-sessiond` seals persisted history to. Mirrors the membership of the
/// noise-gateway [`TrustHandle`], but as hex strings ready to POST.
pub async fn live_pubkeys(&self) -> Vec<String> {
self.inner
.read()
.await
.values()
.filter(|d| d.revoked_at_ms.is_none())
.map(|d| d.pubkey.clone())
.collect()
}

pub async fn upsert(&self, device: Device) -> anyhow::Result<()> {
{
let mut w = self.inner.write().await;
Expand Down
Loading
Loading