Iptables restrictions bugfix: #3: Restrict inter-host access
This commit is contained in:
@@ -127,12 +127,14 @@ function acceptLines({
|
|||||||
source,
|
source,
|
||||||
protocol,
|
protocol,
|
||||||
ports,
|
ports,
|
||||||
|
host_wg_ip,
|
||||||
}: {
|
}: {
|
||||||
forward_chain: string;
|
forward_chain: string;
|
||||||
input_chain: string;
|
input_chain: string;
|
||||||
source: string;
|
source: string;
|
||||||
protocol?: string;
|
protocol?: string;
|
||||||
ports: string[];
|
ports: string[];
|
||||||
|
host_wg_ip?: string;
|
||||||
}) {
|
}) {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
const protocols = protocolsForRule({
|
const protocols = protocolsForRule({
|
||||||
@@ -150,7 +152,7 @@ function acceptLines({
|
|||||||
? portMatch({ ports: chunk })
|
? portMatch({ ports: chunk })
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
// 1. FORWARD chain: Allows routed traffic (including Docker bridges/DNAT)
|
// FORWARD: Forwarded ports / Docker containers / WAN
|
||||||
lines.push(
|
lines.push(
|
||||||
joinArgs([
|
joinArgs([
|
||||||
`iptables -A ${forward_chain}`,
|
`iptables -A ${forward_chain}`,
|
||||||
@@ -161,16 +163,39 @@ function acceptLines({
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 2. INPUT chain: Allows traffic bound directly for host OS services
|
// INPUT: Only allow matching requests bound for THIS interface's host IP
|
||||||
lines.push(
|
lines.push(
|
||||||
joinArgs([
|
joinArgs([
|
||||||
`iptables -A ${input_chain}`,
|
`iptables -A ${input_chain}`,
|
||||||
`-s ${source}`,
|
`-s ${source}`,
|
||||||
|
host_wg_ip ? `-d ${host_wg_ip}` : undefined,
|
||||||
proto ? `-p ${proto}` : undefined,
|
proto ? `-p ${proto}` : undefined,
|
||||||
port_match_str,
|
port_match_str,
|
||||||
`-j ACCEPT`,
|
`-j ACCEPT`,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// // 1. FORWARD chain: Allows routed traffic (including Docker bridges/DNAT)
|
||||||
|
// lines.push(
|
||||||
|
// joinArgs([
|
||||||
|
// `iptables -A ${forward_chain}`,
|
||||||
|
// `-s ${source}`,
|
||||||
|
// proto ? `-p ${proto}` : undefined,
|
||||||
|
// port_match_str,
|
||||||
|
// `-j ACCEPT`,
|
||||||
|
// ]),
|
||||||
|
// );
|
||||||
|
|
||||||
|
// // 2. INPUT chain: Allows traffic bound directly for host OS services
|
||||||
|
// lines.push(
|
||||||
|
// joinArgs([
|
||||||
|
// `iptables -A ${input_chain}`,
|
||||||
|
// `-s ${source}`,
|
||||||
|
// proto ? `-p ${proto}` : undefined,
|
||||||
|
// port_match_str,
|
||||||
|
// `-j ACCEPT`,
|
||||||
|
// ]),
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +307,10 @@ export default function buildHostIptablesScripts({
|
|||||||
if (rule.rule_type == "all") {
|
if (rule.rule_type == "all") {
|
||||||
accept_lines.push(
|
accept_lines.push(
|
||||||
`iptables -A ${forward} -s ${source} -j ACCEPT`,
|
`iptables -A ${forward} -s ${source} -j ACCEPT`,
|
||||||
`iptables -A ${input} -s ${source} -j ACCEPT`,
|
// `iptables -A ${input} -s ${source} -j ACCEPT`,
|
||||||
|
scoped_subnet
|
||||||
|
? `iptables -A ${input} -s ${source} -d ${scoped_subnet} -j ACCEPT`
|
||||||
|
: `iptables -A ${input} -s ${source} -j ACCEPT`,
|
||||||
);
|
);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -317,6 +345,7 @@ export default function buildHostIptablesScripts({
|
|||||||
source,
|
source,
|
||||||
protocol: rule.protocol || "any",
|
protocol: rule.protocol || "any",
|
||||||
ports: parsed_ports.ports,
|
ports: parsed_ports.ports,
|
||||||
|
host_wg_ip: scoped_subnet,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user