ramm 0.0.9 → 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 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 add chain inet ramm forward '{ type filter hook forward priority 0 ; }'");
217
- await execCommand(`nft add rule inet ramm forward iifname != @podman_interfaces jump ${localNftChainName}`);
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";
@@ -271,11 +292,11 @@ var writeIfNew = async (rawFilePath, str) => {
271
292
  };
272
293
  // src/ssh.ts
273
294
  import { debug } from "console";
274
- var addKeyToHostConfig = async (address, pathToKey) => {
295
+ var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
275
296
  const text = `Host ${address}
276
297
  IdentityFile ${pathToKey}
277
298
  `;
278
- await writeIfNew(pathToKey, text);
299
+ await writeIfNew(pathToHost, text);
279
300
  };
280
301
  var getServerFingerprintBySsh = async (context) => {
281
302
  const { output } = await execBySsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
@@ -1,4 +1,4 @@
1
1
  import type { Context } from "./context.ts";
2
- export declare const addKeyToHostConfig: (address: string, pathToKey: string) => Promise<void>;
2
+ export declare const addKeyToHostConfig: (pathToHost: string, address: string, pathToKey: string) => Promise<void>;
3
3
  export declare const getServerFingerprintBySsh: (context: Context) => Promise<string>;
4
4
  export declare const createAndAddSshKey: (pathToKey: string, comment: string, context: Context) => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "scripts": {
6
6
  "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
7
7
  "types": "tsc --project tsconfig.types.json"