dns + keybinding consolidation
This commit is contained in:
1 parent
df46627173
commit
f8444b1549
23 files changed
+612
-109
No files matched your search
@@ -32,7 +32,14 @@ openwrt-gen firewall < config.json # prints UCI firewall rules (uci batch form
|
||||
|
||||
## Input shape (`config.rs`)
|
||||
|
||||
- `generalMappings`: `[{ ip, domains[] }]` — shared domain→IP records.
|
||||
- `generalMappings`: `[{ ip, domains[], wildcard? }]` — shared domain→IP records.
|
||||
`wildcard` defaults to `true` (omitted in existing secrets) and renders
|
||||
`address=/domain/ip` + `address=/.domain/ip`, matching every subdomain too.
|
||||
Set `false` for a plain `host-record=domain,ip` (A record + reverse PTR) —
|
||||
this is what Nix-declared `skyg.dns` records use by default.
|
||||
At deploy time this list is the **union** of the secret's entries and the
|
||||
records aggregated from every host's `skyg.dns` (see
|
||||
`modules/nixos/common/dns-records/`), merged by `jq` in `openwrt-deploy.sh`.
|
||||
- `networks`: `{ <network>: [ { mac, name, id?, domains?, justMac?, internetOnly? } ] }` —
|
||||
per-network hosts. A device with `internetOnly: true` is restricted to internet-only
|
||||
access (matched by MAC), on any network.
|
||||
|
||||
@@ -17,6 +17,16 @@ pub struct Config {
|
||||
pub struct GeneralMapping {
|
||||
pub ip: String,
|
||||
pub domains: Vec<String>,
|
||||
/// When true (the default, kept for backwards compatibility with existing
|
||||
/// router secrets), emit a wildcard `address=/domain/ip` that also matches
|
||||
/// every subdomain. When false, emit a plain `host-record=domain,ip`,
|
||||
/// which is a normal A record and also provides reverse PTR lookups.
|
||||
#[serde(default = "default_true")]
|
||||
pub wildcard: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -77,6 +87,15 @@ mod tests {
|
||||
let config: Config = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(config.general_mappings[0].ip, "192.168.1.1");
|
||||
assert_eq!(config.general_mappings[0].domains, vec!["test.local"]);
|
||||
// Existing secrets omit the flag; wildcard behaviour must be preserved.
|
||||
assert!(config.general_mappings[0].wildcard);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_general_mapping_wildcard_false() {
|
||||
let json = r#"{"generalMappings": [{"ip": "10.0.101.2", "domains": ["drawdb.app.internal"], "wildcard": false}], "networks": {}}"#;
|
||||
let config: Config = serde_json::from_str(json).unwrap();
|
||||
assert!(!config.general_mappings[0].wildcard);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -37,8 +37,13 @@ pub fn generate(config: &Config) -> String {
|
||||
|
||||
for gm in &config.general_mappings {
|
||||
for domain in &gm.domains {
|
||||
out.push_str(&format!("address=/{}/{}\n", domain, gm.ip));
|
||||
out.push_str(&format!("address=/.{}/{}\n", domain, gm.ip));
|
||||
if gm.wildcard {
|
||||
out.push_str(&format!("address=/{}/{}\n", domain, gm.ip));
|
||||
out.push_str(&format!("address=/.{}/{}\n", domain, gm.ip));
|
||||
} else {
|
||||
// Plain A record (+ reverse PTR), no subdomain wildcard.
|
||||
out.push_str(&format!("host-record={},{}\n", domain, gm.ip));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +83,7 @@ mod tests {
|
||||
general_mappings: vec![GeneralMapping {
|
||||
ip: "192.168.1.1".to_string(),
|
||||
domains: vec!["gw.local".to_string()],
|
||||
wildcard: true,
|
||||
}],
|
||||
networks: BTreeMap::new(),
|
||||
dns_resolvers: vec![],
|
||||
@@ -85,6 +91,24 @@ mod tests {
|
||||
};
|
||||
let result = generate(&config);
|
||||
assert!(result.contains("address=/gw.local/192.168.1.1\n"));
|
||||
assert!(result.contains("address=/.gw.local/192.168.1.1\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_general_mappings_host_record() {
|
||||
let config = Config {
|
||||
general_mappings: vec![GeneralMapping {
|
||||
ip: "10.0.101.2".to_string(),
|
||||
domains: vec!["drawdb.app.internal".to_string()],
|
||||
wildcard: false,
|
||||
}],
|
||||
networks: BTreeMap::new(),
|
||||
dns_resolvers: vec![],
|
||||
internet_only: vec![],
|
||||
};
|
||||
let result = generate(&config);
|
||||
assert!(result.contains("host-record=drawdb.app.internal,10.0.101.2\n"));
|
||||
assert!(!result.contains("address=/"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user