H: name the token mode check after what it rejects

This commit is contained in:
ari committed 2026-10-20 16:16:30 -04:00
1 parent fea6a52bb0
commit 5ba6e820ca
1 file changed
+4 -3
+4 -3
View File
@@ -21,7 +21,8 @@ fn header_safe(text: &str) -> bool {
&& axum::http::HeaderValue::from_str(&format!("Bearer {text}")).is_ok() && axum::http::HeaderValue::from_str(&format!("Bearer {text}")).is_ok()
} }
/// Read `peer.token_file`, trimming one trailing newline. /// Read `peer.token_file`, trimming one trailing newline. The value must be
/// usable as a bearer header verbatim, so control characters are refused.
/// ///
/// Group- and world-accessible files are rejected unless the path is inside /// Group- and world-accessible files are rejected unless the path is inside
/// `$CREDENTIALS_DIRECTORY` (systemd's credential dir is not mode 0600; the /// `$CREDENTIALS_DIRECTORY` (systemd's credential dir is not mode 0600; the
@@ -49,7 +50,7 @@ pub fn load_token_at(
return Err(PeerError::TokenFile("not a file".into())); return Err(PeerError::TokenFile("not a file".into()));
} }
if !under_credentials(path, credentials_dir) { if !under_credentials(path, credentials_dir) {
reject_group_or_world_readable(&meta)?; reject_group_or_world_accessible(&meta)?;
} }
if meta.len() > MAX_TOKEN_BYTES as u64 { if meta.len() > MAX_TOKEN_BYTES as u64 {
return Err(oversize()); return Err(oversize());
@@ -76,7 +77,7 @@ fn oversize() -> PeerError {
PeerError::TokenFile(format!("larger than {MAX_TOKEN_BYTES} bytes")) PeerError::TokenFile(format!("larger than {MAX_TOKEN_BYTES} bytes"))
} }
fn reject_group_or_world_readable(meta: &std::fs::Metadata) -> Result<(), PeerError> { fn reject_group_or_world_accessible(meta: &std::fs::Metadata) -> Result<(), PeerError> {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
// Other users who can reach the file can call the peer as this // Other users who can reach the file can call the peer as this
// consolidator, and one who can write it can swap the token. // consolidator, and one who can write it can swap the token.