[edge] Share fixes: per-network password limit and no eviction, revocation epoch never goes down, stray share tokens stripped on every host, admin socket bound in a private directory

This commit is contained in:
2026-11-07 18:44:55 +01:00
parent fee35830d1
commit 98dad246d3
6 changed files with 151 additions and 33 deletions
+21 -1
View File
@@ -102,6 +102,8 @@ pub struct Shared {
pub paths: Paths,
credentials_dir: Option<PathBuf>,
revocations: ArcSwap<RevocationState>,
/// The highest revocation epoch seen since start; a file with a lower one is refused.
epoch_seen: std::sync::atomic::AtomicU32,
pub throttle: crate::share::Throttle,
cert_states: Mutex<HashMap<String, CertState>>,
pub acme_wake: tokio::sync::Notify,
@@ -134,6 +136,7 @@ impl Shared {
paths,
credentials_dir,
revocations: ArcSwap::from_pointee(RevocationState::default()),
epoch_seen: std::sync::atomic::AtomicU32::new(0),
throttle: crate::share::Throttle::default(),
cert_states: Mutex::new(HashMap::new()),
acme_wake: tokio::sync::Notify::new(),
@@ -323,9 +326,15 @@ impl Shared {
});
}
};
let text = std::fs::read(path).ok();
let sha = text.as_deref().map(runtime::sha256_hex);
let fail = |message: String| {
let mut old = RevocationState::clone(&self.revocations());
old.error = Some(message.clone());
// Remember this content, so the poller reports it once, not every 5 s.
if old.loaded {
old.stamp = sha.clone();
}
self.revocations.store(Arc::new(old));
EdgeError::Config {
path: path.clone(),
@@ -335,7 +344,9 @@ impl Shared {
if meta.len() > 1 << 20 {
return Err(fail("the revocation file is larger than 1 MiB".into()));
}
let text = std::fs::read_to_string(path).map_err(|e| fail(e.to_string()))?;
let text = text
.and_then(|b| String::from_utf8(b).ok())
.ok_or_else(|| fail("cannot read the revocation file as text".into()))?;
let file: RevocationFile =
serde_json::from_str(&text).map_err(|e| fail(format!("not a revocation file: {e}")))?;
if file.deny.len() > MAX_DENY {
@@ -348,6 +359,15 @@ impl Shared {
.ok_or_else(|| fail("a link id is not 32 hex digits".into()))?,
);
}
// The epoch only goes up: a lower one would bring stopped links back.
let seen = self.epoch_seen.load(Ordering::SeqCst);
if file.epoch < seen {
return Err(fail(format!(
"the revocation epoch went down from {seen} to {}; keeping the old state",
file.epoch
)));
}
self.epoch_seen.store(file.epoch, Ordering::SeqCst);
let stamp = Some(runtime::sha256_hex(text.as_bytes()));
self.revocations.store(Arc::new(RevocationState {
revocations: Revocations {