aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nix/module.nix3
-rw-r--r--src/store.rs6
-rw-r--r--tests/migrations.rs7
3 files changed, 15 insertions, 1 deletions
diff --git a/nix/module.nix b/nix/module.nix
index d2f54c8..62f4222 100644
--- a/nix/module.nix
+++ b/nix/module.nix
@@ -323,6 +323,9 @@ in
environment.etc."enstate/schema.json".source = schemaFile;
environment.etc."enstate/config.json".source = settings;
+ # Root's, whatever creates it first (a deploy copying into incomingDir, say).
+ systemd.tmpfiles.rules = [ "d ${cfg.stateDir} 0700 root root -" ];
+
# At boot, and after a switch that changes the schema: the views of this
# generation, from the snapshots, and the reactions of those that changed.
systemd.services.enstate = {
diff --git a/src/store.rs b/src/store.rs
index 08d0959..9de62d3 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -14,7 +14,7 @@
//! RUN/tmp/ scratch
//! ```
//!
-//! Entries are root's (mode 0600). A new snapshot
+//! Entries are root's (mode 0600), and the state directory is 0700. A new snapshot
//! or view generation is written next to the old one and put in place by replacing
//! a symbolic link, so a reader sees one or the other, never a mix; a snapshot is
//! flushed to disk before that, so a crash leaves the old one or the new one.
@@ -77,6 +77,10 @@ impl Store {
/// Waits for, and takes, the store's lock: one receptor at a time.
pub fn lock(&self) -> Result<Lock> {
create_dir(&self.state, 0o700)?;
+ // Whatever created it (a deploy copying into incoming/, say), it is root's.
+ use std::os::unix::fs::PermissionsExt;
+ std::fs::set_permissions(&self.state, std::fs::Permissions::from_mode(0o700))
+ .with_context(|| format!("chmod {}", self.state.display()))?;
let path = self.state.join("lock");
let file = File::options()
.create(true)
diff --git a/tests/migrations.rs b/tests/migrations.rs
index 05e3099..e66895c 100644
--- a/tests/migrations.rs
+++ b/tests/migrations.rs
@@ -370,6 +370,13 @@ fn incoming_submissions() {
assert_eq!(host.view("a", "a").unwrap(), b"A");
assert!(host.snapshot("secrets").is_some());
assert!(!host.root.join("state/incoming/1").exists());
+ // The deploy created the state directory, readable by all; it is root's now.
+ use std::os::unix::fs::PermissionsExt;
+ let mode = std::fs::metadata(host.root.join("state"))
+ .unwrap()
+ .permissions()
+ .mode();
+ assert_eq!(mode & 0o777, 0o700);
// Two in order, the second building on what the first makes; then one refused,
// which refuses the switch, and is moved aside by it.