shadow.enabled in housecarl.yaml loads Housecarl's ruleset so that it blocks, rejects and translates nothing: drops and rejects count and accept (an accept only ends Housecarl's chain), policies accept and log what they would drop, NAT only counts, MSS clamping and the flowtable are left out, and raw rules that do more than accept, drop or reject are left out with a warning. Comments mark what would happen ([would drop]). Filter chains run after the other firewall's (+10) or before (-10); NAT chains always first. Every change is checked by nftables in both forms. No probation; takeovers and closing connections are refused. The boot fallback filters nothing. internal/tablewatch puts the table back after a flush ruleset. Mode in status, healthz, whoami, the web UI, the log and the tracer; hc ruleset --enforcing. docs/shadow.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"housecarl/internal/trace"
|
|
)
|
|
|
|
// otherTables lists the tables in an `nft -j list ruleset` other than
|
|
// Housecarl's ("inet main").
|
|
// inputFilters lists the tables other than Housecarl's with a filter
|
|
// chain on the input hook: what filters the machine in shadow mode.
|
|
func inputFilters(data []byte) []string {
|
|
var doc struct {
|
|
Nftables []map[string]json.RawMessage `json:"nftables"`
|
|
}
|
|
out := []string{}
|
|
if json.Unmarshal(data, &doc) != nil {
|
|
return out
|
|
}
|
|
for _, item := range doc.Nftables {
|
|
raw, ok := item["chain"]
|
|
if !ok {
|
|
continue
|
|
}
|
|
var c struct{ Family, Table, Type, Hook string }
|
|
if json.Unmarshal(raw, &c) == nil && c.Type == "filter" && c.Hook == "input" && !(c.Family == "inet" && (c.Table == "housecarl" || c.Table == trace.Table)) {
|
|
out = append(out, c.Family+" "+c.Table)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func otherTables(data []byte) []string {
|
|
var doc struct {
|
|
Nftables []map[string]json.RawMessage `json:"nftables"`
|
|
}
|
|
out := []string{}
|
|
if json.Unmarshal(data, &doc) != nil {
|
|
return out
|
|
}
|
|
for _, item := range doc.Nftables {
|
|
raw, ok := item["table"]
|
|
if !ok {
|
|
continue
|
|
}
|
|
var t struct{ Family, Name string }
|
|
if json.Unmarshal(raw, &t) == nil && !(t.Family == "inet" && (t.Name == "housecarl" || t.Name == trace.Table)) {
|
|
out = append(out, t.Family+" "+t.Name)
|
|
}
|
|
}
|
|
return out
|
|
}
|