ramm 0.0.33 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ramm.js +58 -44
- package/dist/types/nft.d.ts +3 -1
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -175,6 +175,63 @@ var createSystemdService = async (context, serviceName, pathToServiceFile) => {
|
|
|
175
175
|
await execCommand(formatUserspace(context, `sysyemctl start ${serviceName}`));
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
+
// src/nft.ts
|
|
179
|
+
var createNftTable = ({
|
|
180
|
+
allowedIpV4,
|
|
181
|
+
allowedPorts
|
|
182
|
+
}) => {
|
|
183
|
+
const nftTable = `table inet ramm {
|
|
184
|
+
set allowed_ipv4 {
|
|
185
|
+
type ipv4_addr
|
|
186
|
+
flags dynamic
|
|
187
|
+
elements = { ${allowedIpV4.join(`
|
|
188
|
+
`)} }
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
chain local_chain_base {
|
|
192
|
+
iif "lo" accept
|
|
193
|
+
ct state established,related accept
|
|
194
|
+
ip saddr @allowed_ipv4 tcp dport 22 accept
|
|
195
|
+
tcp dport 22 ct state new limit rate over 700/minute burst 5 packets drop
|
|
196
|
+
tcp dport 22 accept
|
|
197
|
+
${allowedPorts.map((port) => {
|
|
198
|
+
return `tcp dport ${port} accept`;
|
|
199
|
+
}).join(`
|
|
200
|
+
`)}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
chain local_chain {
|
|
204
|
+
jump local_chain_base
|
|
205
|
+
drop
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
chain prerouting {
|
|
209
|
+
type filter hook prerouting priority mangle; policy accept;
|
|
210
|
+
fib daddr type local jump local_chain
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
`;
|
|
214
|
+
return nftTable;
|
|
215
|
+
};
|
|
216
|
+
var setupNftable = async ({
|
|
217
|
+
allowedIpV4,
|
|
218
|
+
allowedPorts
|
|
219
|
+
}) => {
|
|
220
|
+
const listTable = await execCommand("nft list table inet ramm");
|
|
221
|
+
if (listTable.spawnResult.exitCode === 0) {
|
|
222
|
+
await execCommand("nft delete table inet ramm");
|
|
223
|
+
}
|
|
224
|
+
const nftTable = createNftTable({ allowedIpV4, allowedPorts });
|
|
225
|
+
await execCommand(`nft -f - <<EOF
|
|
226
|
+
${nftTable}
|
|
227
|
+
EOF`);
|
|
228
|
+
await safeNftTable();
|
|
229
|
+
};
|
|
230
|
+
var safeNftTable = async () => {
|
|
231
|
+
await execCommand("nft list ruleset > /etc/nftables.conf");
|
|
232
|
+
await execCommand("systemctl enable nftables");
|
|
233
|
+
};
|
|
234
|
+
|
|
178
235
|
// src/podman.ts
|
|
179
236
|
var installPodman = async () => {
|
|
180
237
|
if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
|
|
@@ -223,50 +280,7 @@ var addNftPodmanRule = async () => {
|
|
|
223
280
|
`);
|
|
224
281
|
await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
|
|
225
282
|
await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
|
|
226
|
-
|
|
227
|
-
// src/nft.ts
|
|
228
|
-
var createNftTable = ({ allowedIpV4 }) => {
|
|
229
|
-
const nftTable = `table inet ramm {
|
|
230
|
-
set allowed_ipv4 {
|
|
231
|
-
type ipv4_addr
|
|
232
|
-
flags dynamic
|
|
233
|
-
elements = { ${allowedIpV4.join(`
|
|
234
|
-
`)} }
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
chain local_chain_base {
|
|
238
|
-
iif "lo" accept
|
|
239
|
-
ct state established,related accept
|
|
240
|
-
ip saddr @allowed_ipv4 tcp dport 22 accept
|
|
241
|
-
tcp dport 22 ct state new limit rate over 700/minute burst 5 packets drop
|
|
242
|
-
tcp dport 22 accept
|
|
243
|
-
tcp dport 80 accept
|
|
244
|
-
tcp dport 443 accept
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
chain local_chain {
|
|
248
|
-
jump local_chain_base
|
|
249
|
-
drop
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
chain prerouting {
|
|
253
|
-
type filter hook prerouting priority mangle; policy accept;
|
|
254
|
-
fib daddr type local jump local_chain
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
`;
|
|
258
|
-
return nftTable;
|
|
259
|
-
};
|
|
260
|
-
var setupNftable = async ({
|
|
261
|
-
allowedIpV4
|
|
262
|
-
}) => {
|
|
263
|
-
await execCommand("nft flush ruleset");
|
|
264
|
-
const nftTable = createNftTable({ allowedIpV4 });
|
|
265
|
-
await execCommand(`nft -f - <<EOF
|
|
266
|
-
${nftTable}
|
|
267
|
-
EOF`);
|
|
268
|
-
await execCommand("nft list ruleset > /etc/nftables.conf");
|
|
269
|
-
await execCommand("systemctl enable nftables");
|
|
283
|
+
await safeNftTable();
|
|
270
284
|
};
|
|
271
285
|
// src/files.ts
|
|
272
286
|
import { appendFile, exists } from "fs/promises";
|
package/dist/types/nft.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const localNftChainName = "local_chain";
|
|
2
|
-
export declare const setupNftable: ({ allowedIpV4, }: {
|
|
2
|
+
export declare const setupNftable: ({ allowedIpV4, allowedPorts, }: {
|
|
3
3
|
allowedIpV4: string[];
|
|
4
|
+
allowedPorts: string[];
|
|
4
5
|
}) => Promise<void>;
|
|
6
|
+
export declare const safeNftTable: () => Promise<void>;
|
package/package.json
CHANGED