egress: the forward chain allows each agent's declared ssh connections
This commit is contained in:
parent
934da6f31f
commit
8ece0b7e0b
3 changed files with 1110 additions and 20 deletions
|
|
@ -298,6 +298,14 @@ in
|
|||
HIVE_SQUID_PROXY = config.services.hyperhive.deploy.hive-controller.squid.listen;
|
||||
HIVE_EGRESS_NO_PROXY = lib.concatStringsSep "," egressDirectHosts;
|
||||
}
|
||||
//
|
||||
lib.optionalAttrs (config.services.hyperhive.deploy.hive-controller.egress.connectionsFile != null)
|
||||
{
|
||||
# Where `workers::egress_connections` renders the SSH connections each agent
|
||||
# may open, for the egress forward chain.
|
||||
HIVE_EGRESS_CONNECTIONS_FILE =
|
||||
config.services.hyperhive.deploy.hive-controller.egress.connectionsFile;
|
||||
}
|
||||
// lib.optionalAttrs (haveBaoClientIdentity && baoDeploy.serverCaFile != null) {
|
||||
# Absent means the system trust store — right for a deployment with a real
|
||||
# CA, wrong for the self-signed one ../glue-bao-tls.nix mints, which is why
|
||||
|
|
|
|||
|
|
@ -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 = ''
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ let
|
|||
proxyUrl = "http://${netCfg.bridgeIp}:${toString port}";
|
||||
exporterListen = "127.0.0.1:9301";
|
||||
interceptCfg = hyperhiveCfg.deploy.hive-controller.egress.intercept;
|
||||
egressCfg = hyperhiveCfg.deploy.hive-controller.egress;
|
||||
# The path every platform container's unit runs hive-priv by (hive-priv.nix
|
||||
# points it at the current build). Squid runs `egress-whois` through it.
|
||||
hivePriv = (import ./lib/container-rootfs-check.nix { inherit config; }).hivePriv;
|
||||
|
|
@ -555,6 +556,11 @@ in
|
|||
enable = lib.mkDefault true;
|
||||
inherit (cfg) unrestrictedFile agentAllowFile;
|
||||
};
|
||||
# The file `hive-c0re` renders with the SSH connections each agent may open,
|
||||
# which the egress forward chain reads (`workers::egress_connections`). It
|
||||
# sits in the directory hive-c0re may write.
|
||||
services.hyperhive.deploy.hive-controller.egress.connectionsFile =
|
||||
lib.mkDefault "${usersDir}/ssh-connections";
|
||||
services.hyperhive.network.enable = lib.mkDefault true;
|
||||
|
||||
services.hyperhive.otel.scrapeTargets.squid = exporterListen;
|
||||
|
|
@ -591,7 +597,10 @@ in
|
|||
"C ${cfg.allowedFile} 0640 hive-core squid - ${seedFile}"
|
||||
"f ${cfg.agentAllowFile} 0640 hive-core squid - -"
|
||||
"f ${cfg.denyFile} 0640 hive-core squid - -"
|
||||
];
|
||||
]
|
||||
++ lib.optional (
|
||||
egressCfg.connectionsFile != null
|
||||
) "f ${egressCfg.connectionsFile} 0640 hive-core squid - -";
|
||||
|
||||
# Squid reads the unrestricted list, the allow-list and the per-agent include
|
||||
# when it parses its configuration, not when they change. hive-c0re writes
|
||||
|
|
|
|||
Loading…
Reference in a new issue