Skip to content

Commit e73b20e

Browse files
authored
Merge pull request #4223 from ProvableHQ/fix/file-permissions
[Fix] Allow 0400 permissions for key files
2 parents e798f34 + bb99b66 commit e73b20e

5 files changed

Lines changed: 38 additions & 13 deletions

File tree

.cargo/audit.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ ignore = [
1313
"RUSTSEC-2026-0002",
1414
# TODO remove once we migrate away from bincode, or it becomes maintained again.
1515
"RUSTSEC-2025-0141",
16+
# TODO remove once termwiz/terminfo update to phf 0.13+, which drops the rand 0.8 dependency.
17+
"RUSTSEC-2026-0097",
1618
]

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/commands/start.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,14 +973,20 @@ impl Start {
973973
}
974974
}
975975

976+
/// Checks whether a file can only be read/written by the owner. It also allows more restrictive permissions, where only the owner can read it.
976977
fn check_permissions(path: &PathBuf) -> Result<(), snarkvm::prelude::Error> {
977978
#[cfg(target_family = "unix")]
978979
{
979980
use std::os::unix::fs::PermissionsExt;
980981
ensure!(path.exists(), "The file '{path:?}' does not exist");
981982
crate::check_parent_permissions(path)?;
983+
982984
let permissions = path.metadata()?.permissions().mode();
983-
ensure!(permissions & 0o777 == 0o600, "The file {path:?} must be readable only by the owner (0600)");
985+
ensure!(
986+
matches!(permissions & 0o777, 0o400 | 0o600),
987+
"The file {} must be readable and writable only by the owner (0600)",
988+
path.display()
989+
);
984990
}
985991
Ok(())
986992
}

cli/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ use std::{
3434
path::Path,
3535
};
3636

37+
/// Checks whether the parent directory of a file can only be read and modified by the owner.
3738
#[cfg(unix)]
3839
pub fn check_parent_permissions<T: AsRef<Path>>(path: T) -> Result<()> {
3940
use anyhow::{bail, ensure};
4041
use std::os::unix::fs::PermissionsExt;
4142

4243
if let Some(parent) = path.as_ref().parent() {
4344
let permissions = parent.metadata()?.permissions().mode();
44-
ensure!(permissions & 0o777 == 0o700, "The folder {parent:?} must be readable only by the owner (0700)");
45+
ensure!(
46+
permissions & 0o777 == 0o700,
47+
"The folder {} must be readable and writeable only by the owner (0700)",
48+
parent.display()
49+
);
4550
} else {
4651
let path = path.as_ref();
4752
bail!("Parent does not exist for path={}", path.display());

node/src/node.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ use anyhow::{Result, bail};
4444
use locktick::parking_lot::RwLock;
4545
#[cfg(not(feature = "locktick"))]
4646
use parking_lot::RwLock;
47-
use std::{cmp, collections::HashMap, fs, net::SocketAddr, path::{Path, PathBuf}, str::FromStr, sync::Arc, time::Duration};
47+
use std::{
48+
cmp,
49+
collections::HashMap,
50+
fs,
51+
net::SocketAddr,
52+
path::{Path, PathBuf},
53+
str::FromStr,
54+
sync::Arc,
55+
time::Duration,
56+
};
4857
use tokio::task;
4958

5059
/// The number of blocks between automatic database checkpoints.
@@ -456,7 +465,10 @@ impl<N: Network> Node<N> {
456465
#[cfg(test)]
457466
mod tests {
458467
use super::existing_startup_checkpoint_height;
459-
use std::{fs, time::{SystemTime, UNIX_EPOCH}};
468+
use std::{
469+
fs,
470+
time::{SystemTime, UNIX_EPOCH},
471+
};
460472

461473
#[test]
462474
fn seeds_last_checkpoint_height_when_startup_checkpoint_directory_exists() {

0 commit comments

Comments
 (0)