From 7587284ae48fb59c59da33af928322e8a621f4b0 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 17:43:25 +0000 Subject: =?UTF-8?q?pipeline,=20db:=20the=20correctness=20minors=20?= =?UTF-8?q?=E2=80=94=20fsync,=20withdrawal,=20orphans,=20retry=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m-7. `fsync_file` and `fsync_dir` opened, ignored every error, and returned Ok, in the module whose entire guarantee is "fsync, then rename". A filesystem that refused the sync — full, read-only, a network mount that had dropped — still produced a successful publish whose database might not be on disk. They propagate now, with the path and the cause. m-10. `withdraw_release_in` set `state='withdrawn'` unconditionally, so withdrawing twice reported success the second time while changing nothing, and withdrawing a release that had never been live did the same. The write is a compare-and-swap on `state='published'`, and a refusal names the state that was actually there ("release 1 is withdrawn, not published: nothing to withdraw"). m-16. Artifacts are copied into the served tree before the DB commit, and when the commit refused they stayed: files no index names, sitting in the directory consumers download from. `publish` now tracks which files it created (a file that already existed belongs to the release still being served and is never touched) and removes them if the publish does not land. m-14. `is_transient` treated every `Error::Io` as retryable, which made ENOSPC and EACCES — plain `Io` — into three identical failures and a silent build. Only the kinds that mean "ask again in a moment" retry now. This turned a test that had been asserting the bug: it simulated a transient failure by pointing `makechrootpkg` at a nonexistent path, which is a missing binary, not a flaky network. That test now asserts the opposite (one attempt, no retries), and a new one produces a genuinely transient failure the way production does — a `SKIP` source whose bytes go unreachable after detection, cache dropped, so the `sources` step fails over the fetch path and retries to the cap. m-13. `random_hex` read `/dev/urandom` into a zeroed buffer, ignored every error, and hashed it anyway. Since C-1 the session id is the whole credential, so a failed read is now a refusal: `new_session()` returns `Option`, and the two call sites answer 500 rather than mint a token derivable from the clock and a counter. m-9. The row-error policy is decided and applied: a row that cannot be read fails the query instead of vanishing from the result (six `filter_map(|r| r.ok())` sites, including the reaper's and the claimer's), and `setting_i64` documents its own policy — absent means default, nonsense means default *and a complaint*, because a typo that silently does nothing is worse than a knob that refuses to apply. --- src/http/auth.rs | 28 +++++++++++++++++----------- src/http/mod.rs | 7 ++++++- src/http/routes.rs | 5 ++++- 3 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src/http') diff --git a/src/http/auth.rs b/src/http/auth.rs index 3d05cab..8c56c1f 100644 --- a/src/http/auth.rs +++ b/src/http/auth.rs @@ -27,20 +27,26 @@ fn sessions() -> &'static Mutex> { SESSIONS.get_or_init(|| Mutex::new(HashMap::new())) } -/// Random hex token from the system RNG (`/dev/urandom` through our hash). -fn random_hex() -> String { +/// Random hex token from the system RNG, or `None` when there is no usable one. +/// +/// The old version read `/dev/urandom` into a zeroed buffer, ignored every +/// error, and hashed the result anyway (§6 m-13): a failed read produced a +/// session id derived from a buffer of zeros plus the clock and a counter, +/// which is guessable by anyone who can guess roughly when the process started +/// — and nothing anywhere said the RNG had failed. A session id is the whole +/// credential now (C-1), so "no RNG" is a refusal, not a weaker token. +fn random_hex() -> Option { + use std::io::Read; let mut buf = [0u8; 32]; - if let Ok(mut f) = std::fs::File::open("/dev/urandom") { - use std::io::Read; - let _ = f.read_exact(&mut buf); - } - // Mix in a counter and the clock so two calls in the same instant differ. + let mut f = std::fs::File::open("/dev/urandom").ok()?; + f.read_exact(&mut buf).ok()?; + // Mixed in regardless, so two calls in the same instant still differ. let nanos = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map(|d| d.as_nanos()) .unwrap_or(0); let salt = format!("{:?}", (buf, nanos, std::process::id(), counter())); - hash::hex(salt.as_bytes()) + Some(hash::hex(salt.as_bytes())) } fn counter() -> u64 { @@ -50,12 +56,12 @@ fn counter() -> u64 { /// Mint an anonymous session: enough for a CSRF token, not enough to see a /// single page when a password is set. -pub fn new_session() -> String { - let sid = random_hex(); +pub fn new_session() -> Option { + let sid = random_hex()?; if let Ok(mut s) = sessions().lock() { s.insert(sid.clone(), false); } - sid + Some(sid) } pub fn is_valid_session(sid: &str) -> bool { diff --git a/src/http/mod.rs b/src/http/mod.rs index 07024d8..24da43f 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -238,7 +238,12 @@ fn dispatch(state: &State, req: &Req) -> Res { // through a sid that a successful login marked authenticated. let (sid, new_session) = match req.cookie("sid") { Some(s) if auth::is_valid_session(&s) => (s, false), - _ => (auth::new_session(), true), + _ => match auth::new_session() { + Some(s) => (s, true), + // No system RNG means no unguessable session id. Refuse rather than + // hand out a token someone else could compute. + None => return Res::text(500, "500: could not mint a session\n".into()), + }, }; let gated = routes::gate(state, req, &sid); if let Some(mut res) = gated { diff --git a/src/http/routes.rs b/src/http/routes.rs index 288f002..f475d3a 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -52,7 +52,10 @@ pub fn login(state: &State, req: &Req) -> Res { if let Some(old) = req.cookie("sid") { auth::drop_session(&old); } - let sid = auth::new_session(); + let sid = match auth::new_session() { + Some(sid) => sid, + None => return page_to_res(Login { page, error: "server: no entropy for a session".into() }, 500), + }; auth::authenticate(&sid); let mut res = Res::redirect("/"); // `serve` turns this into the `Set-Cookie: sid=…` header. -- cgit v1.2.3