[edge] Share fixes: revocation epoch floor kept in edge's own state across restarts, every share=ish1. parameter stripped (also encoded)

This commit is contained in:
2026-11-07 19:22:03 +01:00
parent 7d3af00720
commit 60fb4b63ee
4 changed files with 111 additions and 25 deletions
+37 -2
View File
@@ -122,6 +122,7 @@ fn same_listeners(a: &Runtime, b: &Runtime) -> Result<(), EdgeError> {
impl Shared {
pub fn new(rt: Runtime, paths: Paths, credentials_dir: Option<PathBuf>) -> Arc<Shared> {
let floor = read_epoch_floor(&rt);
let certs = Arc::new(CertStore::default());
certs.replace_files(rt.file_certs.clone());
let (changed, _) = tokio::sync::watch::channel(1);
@@ -136,7 +137,7 @@ impl Shared {
paths,
credentials_dir,
revocations: ArcSwap::from_pointee(RevocationState::default()),
epoch_seen: std::sync::atomic::AtomicU32::new(0),
epoch_seen: std::sync::atomic::AtomicU32::new(floor),
throttle: crate::share::Throttle::default(),
cert_states: Mutex::new(HashMap::new()),
acme_wake: tokio::sync::Notify::new(),
@@ -367,7 +368,13 @@ impl Shared {
file.epoch
)));
}
self.epoch_seen.store(file.epoch, Ordering::SeqCst);
if file.epoch > seen {
self.epoch_seen.store(file.epoch, Ordering::SeqCst);
if let Err(e) = write_epoch_floor(&self.current(), file.epoch) {
// Still refused within this process; only a restart could forget it.
log::error!(target: "ianitor::share", "cannot save the revocation epoch floor: {e}");
}
}
let stamp = Some(runtime::sha256_hex(text.as_bytes()));
self.revocations.store(Arc::new(RevocationState {
revocations: Revocations {
@@ -414,6 +421,34 @@ impl Shared {
}
}
/// Edge's own record of the highest revocation epoch it has accepted, in its state
/// directory: a restart (even after control's files were rolled back) still refuses lower.
fn epoch_floor_path(rt: &Runtime) -> PathBuf {
Path::new(&rt.cfg.state_dir).join("share-epoch-floor")
}
fn read_epoch_floor(rt: &Runtime) -> u32 {
std::fs::read_to_string(epoch_floor_path(rt))
.ok()
.and_then(|s| s.trim().parse().ok())
.unwrap_or(0)
}
fn write_epoch_floor(rt: &Runtime, epoch: u32) -> std::io::Result<()> {
let path = epoch_floor_path(rt);
if let Some(dir) = path.parent() {
std::fs::create_dir_all(dir)?;
}
let tmp = path.with_extension("tmp");
{
use std::io::Write;
let mut f = std::fs::File::create(&tmp)?;
f.write_all(format!("{epoch}\n").as_bytes())?;
f.sync_all()?;
}
std::fs::rename(&tmp, &path)
}
fn poisoned() -> AdminError {
AdminError::Conflict("internal state is unavailable".into())
}