A: A1 peers config section, env overrides and print-config redaction
This commit is contained in:
1 parent
12c3a40708
commit
40d18c2253
3 files changed
+211
No files matched your search
@@ -54,3 +54,29 @@ journal_namespace = "" # journal namespace, empty = default jo
|
|||||||
max_lines = 1000 # max journal lines per request; SKYG_LIMITS__MAX_LINES
|
max_lines = 1000 # max journal lines per request; SKYG_LIMITS__MAX_LINES
|
||||||
max_tail = 1000 # max container log lines per request; SKYG_LIMITS__MAX_TAIL
|
max_tail = 1000 # max container log lines per request; SKYG_LIMITS__MAX_TAIL
|
||||||
max_follow_secs = 60 # max duration of a bounded follow (MCP tail_journal); SKYG_LIMITS__MAX_FOLLOW_SECS
|
max_follow_secs = 60 # max duration of a bounded follow (MCP tail_journal); SKYG_LIMITS__MAX_FOLLOW_SECS
|
||||||
|
|
||||||
|
# Other slinuxm instances this process can health-check and proxy.
|
||||||
|
# Off by default: no peer routes, tools, background tasks or metrics.
|
||||||
|
# Scalar keys accept SKYG_PEERS__* (SKYG_PEERS__ENABLED, SKYG_PEERS__TCP_INTERVAL_SECS, ...).
|
||||||
|
# [[peers.peer]] entries are file-only. token_file is a path; the file is read
|
||||||
|
# into memory and never written back, logged, or shown by --print-config.
|
||||||
|
[peers]
|
||||||
|
enabled = false # SKYG_PEERS__ENABLED
|
||||||
|
tcp_interval_secs = 10 # SKYG_PEERS__TCP_INTERVAL_SECS
|
||||||
|
tcp_timeout_secs = 3 # must be below tcp_interval_secs; SKYG_PEERS__TCP_TIMEOUT_SECS
|
||||||
|
api_interval_secs = 30 # SKYG_PEERS__API_INTERVAL_SECS
|
||||||
|
api_timeout_secs = 5 # must be below api_interval_secs; SKYG_PEERS__API_TIMEOUT_SECS
|
||||||
|
fail_threshold = 2 # consecutive failures before a check flips down; SKYG_PEERS__FAIL_THRESHOLD
|
||||||
|
request_timeout_secs = 10 # SKYG_PEERS__REQUEST_TIMEOUT_SECS
|
||||||
|
max_response_bytes = 8388608 # SKYG_PEERS__MAX_RESPONSE_BYTES
|
||||||
|
max_concurrent_per_peer = 4 # SKYG_PEERS__MAX_CONCURRENT_PER_PEER
|
||||||
|
max_concurrent_total = 16 # SKYG_PEERS__MAX_CONCURRENT_TOTAL
|
||||||
|
deny_cidrs = ["169.254.0.0/16", "0.0.0.0/8"] # resolved peer addresses in these ranges are refused; SKYG_PEERS__DENY_CIDRS
|
||||||
|
|
||||||
|
# [[peers.peer]]
|
||||||
|
# name = "minipc1" # ^[a-z0-9][a-z0-9_-]{0,31}$, unique, at most 64
|
||||||
|
# url = "https://minipc1:1984" # http or https, no userinfo, query or fragment
|
||||||
|
# token_file = "/run/credentials/skyg-linux-tracker.service/peer-minipc1" # absolute path
|
||||||
|
# ca_file = "/etc/ssl/private-ca.pem" # optional extra trust anchor
|
||||||
|
# allow_plain_http = false # required for http:// to a host that is not loopback
|
||||||
|
# enabled = true
|
||||||
@@ -491,4 +491,90 @@ mod tests {
|
|||||||
assert!(!s.contains("secret"));
|
assert!(!s.contains("secret"));
|
||||||
assert!(s.contains("port = 1984"));
|
assert!(s.contains("port = 1984"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn peerless_print_config_adds_only_the_peers_block() {
|
||||||
|
let s = Config::default().to_toml_redacted().unwrap();
|
||||||
|
assert!(s.contains("[peers]\n"));
|
||||||
|
assert!(s.contains("enabled = false\n"));
|
||||||
|
assert!(s.contains("tcp_interval_secs = 10\n"));
|
||||||
|
assert!(s.contains("tcp_timeout_secs = 3\n"));
|
||||||
|
assert!(s.contains("api_interval_secs = 30\n"));
|
||||||
|
assert!(s.contains("api_timeout_secs = 5\n"));
|
||||||
|
assert!(s.contains("fail_threshold = 2\n"));
|
||||||
|
assert!(s.contains("request_timeout_secs = 10\n"));
|
||||||
|
assert!(s.contains("max_response_bytes = 8388608\n"));
|
||||||
|
assert!(s.contains("max_concurrent_per_peer = 4\n"));
|
||||||
|
assert!(s.contains("max_concurrent_total = 16\n"));
|
||||||
|
assert!(s.contains("deny_cidrs = ["));
|
||||||
|
assert!(s.contains("169.254.0.0/16"));
|
||||||
|
assert!(s.contains("0.0.0.0/8"));
|
||||||
|
assert!(s.contains("peer = []\n"));
|
||||||
|
// The rest of the default document is unchanged.
|
||||||
|
assert!(s.contains("port = 1984\n"));
|
||||||
|
assert!(s.contains("[server.tls]\n"));
|
||||||
|
assert!(s.contains("[auth]\n"));
|
||||||
|
assert!(s.contains("db_path = \"/var/lib/skyg-linux-tracker/db.sqlite\"\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn peers_env_overrides_scalars_and_keeps_file_entries() {
|
||||||
|
Jail::expect_with(|jail| {
|
||||||
|
let token = jail.directory().join("peer.token");
|
||||||
|
write_private_token(&token, "slinuxm_PEER_TOKEN_SHOULD_NOT_LEAK");
|
||||||
|
let file = format!(
|
||||||
|
"\
|
||||||
|
[peers]\n\
|
||||||
|
enabled = false\n\
|
||||||
|
tcp_interval_secs = 10\n\
|
||||||
|
\n\
|
||||||
|
[[peers.peer]]\n\
|
||||||
|
name = \"beta\"\n\
|
||||||
|
url = \"http://127.0.0.1:1984\"\n\
|
||||||
|
token_file = \"{}\"\n\
|
||||||
|
",
|
||||||
|
token.display()
|
||||||
|
);
|
||||||
|
jail.create_file("c.toml", &file)?;
|
||||||
|
jail.set_env("SKYG_PEERS__ENABLED", "true");
|
||||||
|
jail.set_env("SKYG_PEERS__TCP_INTERVAL_SECS", "20");
|
||||||
|
jail.set_env("SKYG_PEERS__TCP_TIMEOUT_SECS", "4");
|
||||||
|
jail.set_env("SKYG_PEERS__API_INTERVAL_SECS", "40");
|
||||||
|
jail.set_env("SKYG_PEERS__API_TIMEOUT_SECS", "6");
|
||||||
|
jail.set_env("SKYG_PEERS__FAIL_THRESHOLD", "3");
|
||||||
|
jail.set_env("SKYG_PEERS__REQUEST_TIMEOUT_SECS", "12");
|
||||||
|
jail.set_env("SKYG_PEERS__MAX_RESPONSE_BYTES", "1000");
|
||||||
|
jail.set_env("SKYG_PEERS__MAX_CONCURRENT_PER_PEER", "2");
|
||||||
|
jail.set_env("SKYG_PEERS__MAX_CONCURRENT_TOTAL", "8");
|
||||||
|
jail.set_env("SKYG_PEERS__DENY_CIDRS", r#"["10.0.0.0/8"]"#);
|
||||||
|
let c = load(Some("c.toml"), &CliOverrides::default()).unwrap();
|
||||||
|
assert!(c.peers.enabled);
|
||||||
|
assert_eq!(c.peers.tcp_interval_secs, 20);
|
||||||
|
assert_eq!(c.peers.tcp_timeout_secs, 4);
|
||||||
|
assert_eq!(c.peers.api_interval_secs, 40);
|
||||||
|
assert_eq!(c.peers.api_timeout_secs, 6);
|
||||||
|
assert_eq!(c.peers.fail_threshold, 3);
|
||||||
|
assert_eq!(c.peers.request_timeout_secs, 12);
|
||||||
|
assert_eq!(c.peers.max_response_bytes, 1000);
|
||||||
|
assert_eq!(c.peers.max_concurrent_per_peer, 2);
|
||||||
|
assert_eq!(c.peers.max_concurrent_total, 8);
|
||||||
|
assert_eq!(c.peers.deny_cidrs, vec!["10.0.0.0/8".to_string()]);
|
||||||
|
assert_eq!(c.peers.peer.len(), 1);
|
||||||
|
assert_eq!(c.peers.peer[0].name.as_str(), "beta");
|
||||||
|
assert_eq!(c.peers.peer[0].token_file, token);
|
||||||
|
let printed = c.to_toml_redacted().unwrap();
|
||||||
|
assert!(printed.contains(&token.display().to_string()));
|
||||||
|
assert!(!printed.contains("SHOULD_NOT_LEAK"));
|
||||||
|
assert!(!format!("{c:?}").contains("SHOULD_NOT_LEAK"));
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 0600 so a later permission check accepts the file. The contents are a
|
||||||
|
/// stand-in secret and must never show up in printed config.
|
||||||
|
fn write_private_token(path: &std::path::Path, contents: &str) {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
std::fs::write(path, contents).unwrap();
|
||||||
|
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600)).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
//! sources: the peer-less default, the ping route, and registry reads.
|
//! sources: the peer-less default, the ping route, and registry reads.
|
||||||
|
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::Command;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use axum::body::{to_bytes, Body};
|
use axum::body::{to_bytes, Body};
|
||||||
@@ -41,6 +43,103 @@ fn status(name: &str, up: bool) -> PeerStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SECRET: &str = "slinuxm_PEER_TOKEN_SHOULD_NOT_LEAK";
|
||||||
|
|
||||||
|
struct TempDir(PathBuf);
|
||||||
|
|
||||||
|
impl TempDir {
|
||||||
|
fn new() -> Self {
|
||||||
|
let nanos = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.subsec_nanos();
|
||||||
|
let dir =
|
||||||
|
std::env::temp_dir().join(format!("slinuxm-peers-{}-{nanos}", std::process::id()));
|
||||||
|
std::fs::create_dir(&dir).unwrap();
|
||||||
|
Self(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path(&self) -> &Path {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for TempDir {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = std::fs::remove_dir_all(&self.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_private_token(path: &Path, contents: &str) {
|
||||||
|
std::fs::write(path, contents).unwrap();
|
||||||
|
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn slinuxm(config: &Path, args: &[&str]) -> std::process::Output {
|
||||||
|
Command::new(env!("CARGO_BIN_EXE_slinuxm"))
|
||||||
|
.arg("--config")
|
||||||
|
.arg(config)
|
||||||
|
.args(args)
|
||||||
|
.env_clear()
|
||||||
|
.env("PATH", std::env::var_os("PATH").unwrap_or_default())
|
||||||
|
.output()
|
||||||
|
.expect("run slinuxm")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_config_shows_peer_paths_and_not_token_contents() {
|
||||||
|
let dir = TempDir::new();
|
||||||
|
let token = dir.path().join("peer.token");
|
||||||
|
write_private_token(&token, SECRET);
|
||||||
|
let cfg = dir.path().join("config.toml");
|
||||||
|
std::fs::write(
|
||||||
|
&cfg,
|
||||||
|
format!(
|
||||||
|
"\
|
||||||
|
[peers]\n\
|
||||||
|
enabled = true\n\
|
||||||
|
tcp_interval_secs = 20\n\
|
||||||
|
tcp_timeout_secs = 4\n\
|
||||||
|
\n\
|
||||||
|
[[peers.peer]]\n\
|
||||||
|
name = \"beta\"\n\
|
||||||
|
url = \"http://127.0.0.1:1984\"\n\
|
||||||
|
token_file = \"{}\"\n\
|
||||||
|
",
|
||||||
|
token.display()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let out = slinuxm(&cfg, &["--print-config"]);
|
||||||
|
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||||
|
let stderr = String::from_utf8(out.stderr).unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"print-config failed: {stderr}\n{stdout}"
|
||||||
|
);
|
||||||
|
assert!(stdout.contains("[peers]"));
|
||||||
|
assert!(stdout.contains("enabled = true"));
|
||||||
|
assert!(stdout.contains(&token.display().to_string()));
|
||||||
|
assert!(!stdout.contains("SHOULD_NOT_LEAK"), "{stdout}");
|
||||||
|
assert!(!stderr.contains("SHOULD_NOT_LEAK"), "{stderr}");
|
||||||
|
|
||||||
|
let bare = dir.path().join("empty.toml");
|
||||||
|
std::fs::write(&bare, "").unwrap();
|
||||||
|
let out = slinuxm(&bare, &["--print-config"]);
|
||||||
|
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
assert!(stdout.contains("[peers]\n"));
|
||||||
|
assert!(stdout.contains("enabled = false\n"));
|
||||||
|
assert!(stdout.contains("port = 1984\n"));
|
||||||
|
assert!(stdout.contains("peer = []\n"));
|
||||||
|
assert!(!stdout.contains("SHOULD_NOT_LEAK"));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn peerless_default_is_off_and_unchanged() {
|
async fn peerless_default_is_off_and_unchanged() {
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
|
|||||||
Reference in new issue
Block a user