egress: the forward chain allows each agent's declared ssh connections
This commit is contained in:
parent
934da6f31f
commit
8ece0b7e0b
1 changed files with 1110 additions and 20 deletions
|
|
@ -74,6 +74,9 @@ let
|
|||
}
|
||||
// lib.optionalAttrs (egressCfg.intercept.unrestrictedFile != null) {
|
||||
HIVE_EGRESS_UNRESTRICTED = toString egressCfg.intercept.unrestrictedFile;
|
||||
}
|
||||
// lib.optionalAttrs (egressCfg.connectionsFile != null) {
|
||||
HIVE_EGRESS_CONNECTIONS = toString egressCfg.connectionsFile;
|
||||
};
|
||||
leaseScript = pkgs.writeShellScript "hive-egress-lease" ''
|
||||
export PATH=${lib.makeBinPath [ pkgs.nftables ]}
|
||||
|
|
@ -186,6 +189,7 @@ let
|
|||
chain forward {
|
||||
type filter hook forward priority filter - 10; policy accept;
|
||||
${fromBridge} ether saddr @direct_mac accept
|
||||
${fromBridge} meta nfproto ipv4 meta l4proto tcp ether saddr . ip daddr . tcp dport @agent_allow accept
|
||||
${fromBridge} counter
|
||||
${lib.concatStringsSep "\n " (
|
||||
logRules "v4" "ip" ++ logRules "v6" "ip6" ++ unmeteredRules ++ finalRules
|
||||
|
|
@ -309,6 +313,7 @@ let
|
|||
${lib.optionalString refuseEch ''iifname "${br}" ip saddr ${relayPool} counter drop''}
|
||||
}
|
||||
set direct_mac { type ether_addr; }
|
||||
set agent_allow { type ether_addr . ipv4_addr . inet_service; }
|
||||
${lib.optionalString egressCfg.intercept.enable interceptChain}
|
||||
${lib.optionalString (egressCfg.forward != "accept") forwardChain}
|
||||
}
|
||||
|
|
@ -342,7 +347,9 @@ in
|
|||
What the `inet hive_egress` table does with traffic the host forwards
|
||||
from the agent bridge to anywhere but the bridge. In `log` and
|
||||
`reject` the traffic of the MACs in the `direct_mac` set (the unrestricted
|
||||
agents and the service containers) is accepted and never logged.
|
||||
agents and the service containers) is accepted and never logged, and so
|
||||
is TCP from an agent to an address and port in the `agent_allow` set
|
||||
(`connectionsFile`).
|
||||
|
||||
- `accept`: nothing; the table has no forward chain.
|
||||
- `log`: each new flow is logged with the prefix `hive-egress-would-drop `,
|
||||
|
|
@ -359,6 +366,22 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
options.services.hyperhive.deploy.hive-controller.egress.connectionsFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
The file hive-c0re renders with the SSH connections each agent may open,
|
||||
one `<agent> <ipv4> <port>` per line: the addresses behind the `host` of
|
||||
each connection in the permissions record of an agent whose `ssh` switch
|
||||
is on. `hive-priv egress-pin` turns each line into elements of the
|
||||
`agent_allow` set of the `inet hive_egress` table, keyed by the MAC of
|
||||
the agent's port, and the forward chain accepts TCP to an address and
|
||||
port in it before it logs or refuses. The file is read when a port is
|
||||
bound, on each pass of the 30 second timer and when the file changes.
|
||||
`null` leaves the set alone, empty: no agent has an allowance.
|
||||
'';
|
||||
};
|
||||
|
||||
options.services.hyperhive.deploy.hive-controller.egress.antiSpoof = lib.mkOption {
|
||||
type = lib.types.enum [
|
||||
"drop"
|
||||
|
|
@ -664,6 +687,17 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
# The same pass refills `agent_allow`, so a connection an operator declares
|
||||
# is allowed at once.
|
||||
systemd.paths.hive-egress-connections = lib.mkIf (egressCfg.connectionsFile != null) {
|
||||
description = "Watch the agents' allowed connections list for the egress forward chain";
|
||||
wantedBy = [ "paths.target" ];
|
||||
pathConfig = {
|
||||
PathChanged = toString egressCfg.connectionsFile;
|
||||
Unit = "hive-egress-pin.service";
|
||||
};
|
||||
};
|
||||
|
||||
# nspawn names the host end of a container's veth `vb-<machine>` when the
|
||||
# container joins a bridge.
|
||||
services.udev.extraRules = ''
|
||||
|
|
|
|||
Loading…
Reference in a new issue