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
This commit is contained in:
1 parent
6e74d3d99b
commit
97c81f899c
6 files changed
+54
-5
No files matched your search
@@ -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 <service user> slinuxm token create consolidator-<host>`), 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:
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
+22
-2
@@ -141,6 +141,17 @@ pub struct PeersConfig {
|
||||
pub peer: Vec<PeerConfig>,
|
||||
}
|
||||
|
||||
/// 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]
|
||||
|
||||
@@ -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 = []
|
||||
"#;
|
||||
|
||||
Reference in new issue
Block a user