aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 05:28:26 +0100
committertv <tv@krebsco.de>2026-10-31 05:28:26 +0100
commit9c45cb3e478a519182a7d9bf48af1529b2ccc457 (patch)
tree89b88ebc310f243c95441e953f04e6842604bb45 /src/swarm
parent6823476285a846efc96147c1e727987da7939e1f (diff)
move warn_if_readable_by_others to files module
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/auth.rs23
1 files changed, 1 insertions, 22 deletions
diff --git a/src/swarm/auth.rs b/src/swarm/auth.rs
index 50e2fae..534a64d 100644
--- a/src/swarm/auth.rs
+++ b/src/swarm/auth.rs
@@ -40,27 +40,6 @@ struct Rejections {
suppressed: u64,
}
-/// A key is a secret: a file others may read is worth a warning (not an error: a
-/// group may be deliberate, e.g. shared with a deployment tool). `what`: which key.
-pub(crate) fn warn_if_readable_by_others(path: &Path, what: &str) {
- #[cfg(unix)]
- {
- use std::os::unix::fs::PermissionsExt;
- if let Ok(metadata) = std::fs::metadata(path) {
- let mode = metadata.permissions().mode();
- if mode & 0o077 != 0 {
- tracing::warn!(
- path = %path.display(),
- mode = format!("{:o}", mode & 0o777),
- "The {what} file is readable by others than its owner; chmod 600 it"
- );
- }
- }
- }
- #[cfg(not(unix))]
- let _ = (path, what);
-}
-
/// At most one rejection log line per this interval.
const REJECTION_LOG_INTERVAL: Duration = Duration::from_secs(10);
@@ -70,7 +49,7 @@ impl SwarmKey {
pub(crate) fn from_file(path: &Path) -> Result<Self> {
let key = std::fs::read(path)
.with_context(|| format!("Reading the swarm key from {}", path.display()))?;
- warn_if_readable_by_others(path, "swarm key");
+ crate::files::warn_if_readable_by_others(path, "swarm key");
if key.len() < 16 {
bail!(
"The swarm key in {} has {} bytes; use at least 16 (32 random bytes recommended)",