From 97c81f899c71da4557e02dccaa5135ce4447f6af Mon Sep 17 00:00:00 2001 From: ari Date: Tue, 20 Oct 2026 16:13:25 -0400 Subject: [PATCH] H: deny IPv6 link-local and metadata addresses by default Add fe80::/10, ::/128 and fd00:ec2::254/128 to the default deny_cidrs and sync config.example.toml, README and docs/consolidator.md --- README.md | 2 ++ config.example.toml | 2 +- docs/consolidator.md | 4 ++-- src/peers/config.rs | 24 ++++++++++++++++++++++++ src/peers/types.rs | 24 ++++++++++++++++++++++-- tests/peers_config.rs | 3 +++ 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a69caf5..6fc24c6 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ token_file = "/etc/skyg/peer-nas.token" # 0600, owned by the service user allow_plain_http = true ``` +Peers are only ever declared in configuration, and every address a peer's name resolves to is checked against `deny_cidrs` before a connection is made; the defaults refuse link-local and cloud-metadata addresses in both families (`169.254.0.0/16`, `fe80::/10`, `fd00:ec2::254/128`) and the unspecified address (`0.0.0.0/8`, `::/128`), while private LAN ranges stay allowed. + `token_file` holds a path, never the token. A consolidator has to replay the peer's plaintext bearer token, so the token lives in a file managed outside `slinuxm` (agenix on NixOS), is read into memory on every check and request, and never appears in the config, `--print-config`, the database or the logs. Mint **one token per consolidator on every peer** and use it only there (`sudo -u slinuxm token create consolidator-`), so a single `token revoke` on a peer cuts that consolidator off and nothing else. Replacing the file is enough to rotate: the next check reads the new value, and no restart is needed. On NixOS also run `systemctl reload skyg-linux-tracker` so systemd re-copies the credential the unit holds (`RefreshOnReload=credentials`). Two checks per peer, kept in memory and reset on restart: diff --git a/config.example.toml b/config.example.toml index 5b27380..af8512f 100644 --- a/config.example.toml +++ b/config.example.toml @@ -76,7 +76,7 @@ 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 +deny_cidrs = ["169.254.0.0/16", "0.0.0.0/8", "fe80::/10", "::/128", "fd00:ec2::254/128"] # resolved peer addresses in these ranges are refused (link-local, metadata, unspecified); SKYG_PEERS__DENY_CIDRS # [[peers.peer]] # name = "minipc1" # ^[a-z0-9][a-z0-9_-]{0,31}$, unique, at most 64 diff --git a/docs/consolidator.md b/docs/consolidator.md index aecc71c..d378d4b 100644 --- a/docs/consolidator.md +++ b/docs/consolidator.md @@ -43,7 +43,7 @@ request_timeout_secs = 10 # one proxied request, connect to body max_response_bytes = 8388608 # buffered bodies above this are refused max_concurrent_per_peer = 4 # proxied requests in flight per peer max_concurrent_total = 16 # ... across all peers -deny_cidrs = ["169.254.0.0/16", "0.0.0.0/8"] # resolved peer addresses in these ranges are refused +deny_cidrs = ["169.254.0.0/16", "0.0.0.0/8", "fe80::/10", "::/128", "fd00:ec2::254/128"] # resolved peer addresses in these ranges are refused [[peers.peer]] name = "minipc1" # ^[a-z0-9][a-z0-9_-]{0,31}$, unique, at most 64 @@ -56,7 +56,7 @@ enabled = true # false keeps the declaration without contacting Scalar keys accept environment overrides (`SKYG_PEERS__ENABLED`, `SKYG_PEERS__API_INTERVAL_SECS`, ...); `[[peers.peer]]` entries are file-only. `slinuxm --print-config` prints `token_file` paths, never their contents. Validation refuses: a timeout that is not below its interval, more than 64 peers, duplicate names, a bad name, a relative `token_file` or `ca_file`, a non-http(s) URL, userinfo/query/fragment in a URL, an IP literal in `deny_cidrs`, and plain `http` to a non-loopback host without `allow_plain_http = true` (which also logs a warning: the bearer token travels in cleartext). `enabled = true` with no peers logs a warning. -`deny_cidrs` is checked against every **resolved** address at connect time, so a name where any address lands in a denied range is refused as `unreachable`. Private LAN ranges are deliberately allowed; the default denies only link-local/metadata and the unspecified range. +`deny_cidrs` is checked against every **resolved** address at connect time, so a name where any address lands in a denied range is refused as `unreachable`. IPv4-mapped addresses are compared in their IPv4 form, so `::ffff:169.254.169.254` is caught by `169.254.0.0/16`. Private LAN ranges are deliberately allowed; the defaults deny only link-local and cloud-metadata addresses in both families (`169.254.0.0/16`, `fe80::/10`, `fd00:ec2::254/128`) and the unspecified address (`0.0.0.0/8`, `::/128`). ## REST and MCP diff --git a/src/peers/config.rs b/src/peers/config.rs index 0fba74c..34a55ed 100644 --- a/src/peers/config.rs +++ b/src/peers/config.rs @@ -516,6 +516,30 @@ mod tests { assert!(!url_is_loopback(&Url::parse("http://beta:1984").unwrap())); } + #[test] + fn the_default_deny_list_covers_metadata_in_both_families_but_allows_lans() { + let deny = deny_networks(&PeersConfig::default().deny_cidrs).unwrap(); + for refused in [ + "169.254.169.254", + "0.0.0.0", + "fe80::1", + "::", + "fd00:ec2::254", + "::ffff:169.254.169.254", + ] { + assert!(denied(refused.parse().unwrap(), &deny), "{refused}"); + } + for allowed in [ + "10.1.2.3", + "192.168.1.10", + "::1", + "fd00:1::5", + "2001:db8::1", + ] { + assert!(!denied(allowed.parse().unwrap(), &deny), "{allowed}"); + } + } + #[test] fn deny_networks_rejects_a_bad_cidr_once_for_every_caller() { assert!(deny_networks(&["10.0.0.0/8".into()]).is_ok()); diff --git a/src/peers/types.rs b/src/peers/types.rs index 0005c5a..e858acf 100644 --- a/src/peers/types.rs +++ b/src/peers/types.rs @@ -141,6 +141,17 @@ pub struct PeersConfig { pub peer: Vec, } +/// Refused by default: link-local and cloud metadata addresses in both +/// families, plus the unspecified address. Private LAN ranges stay allowed, +/// since that is where peers live. +pub const DEFAULT_DENY_CIDRS: [&str; 5] = [ + "169.254.0.0/16", + "0.0.0.0/8", + "fe80::/10", + "::/128", + "fd00:ec2::254/128", +]; + impl Default for PeersConfig { fn default() -> Self { Self { @@ -154,7 +165,7 @@ impl Default for PeersConfig { max_response_bytes: 8 * 1024 * 1024, max_concurrent_per_peer: 4, max_concurrent_total: 16, - deny_cidrs: vec!["169.254.0.0/16".into(), "0.0.0.0/8".into()], + deny_cidrs: DEFAULT_DENY_CIDRS.iter().map(|c| c.to_string()).collect(), peer: Vec::new(), } } @@ -290,7 +301,16 @@ mod tests { assert_eq!(c.tcp_interval_secs, 10); assert_eq!(c.request_timeout_secs, 10); assert_eq!(c.max_response_bytes, 8 * 1024 * 1024); - assert_eq!(c.deny_cidrs, vec!["169.254.0.0/16", "0.0.0.0/8"]); + assert_eq!( + c.deny_cidrs, + vec![ + "169.254.0.0/16", + "0.0.0.0/8", + "fe80::/10", + "::/128", + "fd00:ec2::254/128", + ] + ); } #[test] diff --git a/tests/peers_config.rs b/tests/peers_config.rs index 4dd2835..fe220fc 100644 --- a/tests/peers_config.rs +++ b/tests/peers_config.rs @@ -164,6 +164,9 @@ max_concurrent_total = 16 deny_cidrs = [ "169.254.0.0/16", "0.0.0.0/8", + "fe80::/10", + "::/128", + "fd00:ec2::254/128", ] peer = [] "#;