ramm 0.0.10 → 0.0.11
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 +45 -24
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -155,28 +155,6 @@ var createSystemdService = async (context, serviceName, pathToServiceFile) => {
|
|
|
155
155
|
await execCommand(formatUserspace(context, `sysyemctl start ${serviceName}`));
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
// src/nft.ts
|
|
159
|
-
var localNftChainName = "local_chain";
|
|
160
|
-
var setupNftable = async (allowedIpSsh) => {
|
|
161
|
-
const listTable = await execCommandSilent("nft list table inet ramm");
|
|
162
|
-
if (listTable.spawnResult.exitCode === 0) {
|
|
163
|
-
await execCommand("nft delete table inet ramm");
|
|
164
|
-
}
|
|
165
|
-
await execCommand("nft add table inet ramm");
|
|
166
|
-
await execCommand("nft add chain inet ramm input '{ type filter hook input priority 0 ; }'");
|
|
167
|
-
await execCommand(`nft add set inet ramm allowed_ssh_ipv4 '{ type ipv4_addr; flags dynamic; elements = { ${allowedIpSsh} } }'`);
|
|
168
|
-
await execCommand(`nft add chain inet ramm ${localNftChainName}`);
|
|
169
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} iif lo accept`);
|
|
170
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} ct state established,related accept`);
|
|
171
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} ip saddr @allowed_ssh_ipv4 tcp dport 22 accept`);
|
|
172
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} tcp dport 22 ct state new limit rate over 3/minute drop`);
|
|
173
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} tcp dport 22 accept`);
|
|
174
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} tcp dport 80 accept`);
|
|
175
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} tcp dport 443 accept`);
|
|
176
|
-
await execCommand(`nft add rule inet ramm ${localNftChainName} drop`);
|
|
177
|
-
await execCommand("nft add rule inet ramm input fib daddr type local jump local_chain ");
|
|
178
|
-
};
|
|
179
|
-
|
|
180
158
|
// src/podman.ts
|
|
181
159
|
var installPodman = async () => {
|
|
182
160
|
if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
|
|
@@ -185,6 +163,10 @@ var installPodman = async () => {
|
|
|
185
163
|
await createNetwork();
|
|
186
164
|
};
|
|
187
165
|
var createNetwork = async () => {
|
|
166
|
+
const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
167
|
+
if (netwroks.output.includes("podman_ramm")) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
188
170
|
await execCommand("podman network create --interface-name=podman_ramm ramm");
|
|
189
171
|
};
|
|
190
172
|
var getCreateCommand = async (name) => {
|
|
@@ -213,8 +195,47 @@ var addNftPodmanRule = async () => {
|
|
|
213
195
|
const podmanNetworks = podmanNetworksResult.output.trim().split(`
|
|
214
196
|
`);
|
|
215
197
|
await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
|
|
216
|
-
await execCommand("nft
|
|
217
|
-
|
|
198
|
+
await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
|
|
199
|
+
};
|
|
200
|
+
// src/nft.ts
|
|
201
|
+
var createNftTable = (allowed_ssh_ipv4) => {
|
|
202
|
+
const nftTable = `table inet ramm {
|
|
203
|
+
set allowed_ssh_ipv4 {
|
|
204
|
+
type ipv4_addr
|
|
205
|
+
flags dynamic
|
|
206
|
+
elements = { ${allowed_ssh_ipv4} }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
chain local_chain {
|
|
210
|
+
iif "lo" accept
|
|
211
|
+
ct state established,related accept
|
|
212
|
+
ip saddr @allowed_ssh_ipv4 tcp dport 22 accept
|
|
213
|
+
tcp dport 22 ct state new limit rate over 3/minute burst 5 packets drop
|
|
214
|
+
tcp dport 22 accept
|
|
215
|
+
tcp dport 80 accept
|
|
216
|
+
tcp dport 443 accept
|
|
217
|
+
drop
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
chain prerouting {
|
|
221
|
+
type filter hook prerouting priority mangle; policy accept;
|
|
222
|
+
fib daddr type local jump local_chain
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
`;
|
|
226
|
+
return nftTable;
|
|
227
|
+
};
|
|
228
|
+
var setupNftable = async (allowedIpSsh) => {
|
|
229
|
+
const listTable = await execCommandSilent("nft list table inet ramm");
|
|
230
|
+
if (listTable.spawnResult.exitCode === 0) {
|
|
231
|
+
await execCommand("nft delete table inet ramm");
|
|
232
|
+
}
|
|
233
|
+
const nftTable = createNftTable(allowedIpSsh);
|
|
234
|
+
await execCommand(`nft -f - <<EOF
|
|
235
|
+
${nftTable}
|
|
236
|
+
EOF`);
|
|
237
|
+
await execCommand("nft list ruleset > /etc/nftables.conf");
|
|
238
|
+
await execCommand("systemctl enable nftables");
|
|
218
239
|
};
|
|
219
240
|
// src/files.ts
|
|
220
241
|
import { appendFile, exists } from "fs/promises";
|
package/package.json
CHANGED