ramm 0.0.25 → 0.0.27

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
@@ -212,22 +212,27 @@ var addNftPodmanRule = async () => {
212
212
  await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
213
213
  };
214
214
  // src/nft.ts
215
- var createNftTable = (allowed_ssh_ipv4) => {
215
+ var createNftTable = ({ allowedIpV4 }) => {
216
216
  const nftTable = `table inet ramm {
217
- set allowed_ssh_ipv4 {
217
+ set allowed_ipv4 {
218
218
  type ipv4_addr
219
219
  flags dynamic
220
- elements = { ${allowed_ssh_ipv4} }
220
+ elements = { ${allowedIpV4.join(`
221
+ `)} }
221
222
  }
222
223
 
223
- chain local_chain {
224
- iif "lo" accept
224
+ chain local_chain_base {
225
+ iif "lo" accept
225
226
  ct state established,related accept
226
- ip saddr @allowed_ssh_ipv4 tcp dport 22 accept
227
+ ip saddr @allowed_ipv4 tcp dport 22 accept
227
228
  tcp dport 22 ct state new limit rate over 700/minute burst 5 packets drop
228
229
  tcp dport 22 accept
229
230
  tcp dport 80 accept
230
231
  tcp dport 443 accept
232
+ }
233
+
234
+ chain local_chain {
235
+ jump local_chain_base
231
236
  drop
232
237
  }
233
238
 
@@ -239,12 +244,14 @@ var createNftTable = (allowed_ssh_ipv4) => {
239
244
  `;
240
245
  return nftTable;
241
246
  };
242
- var setupNftable = async (allowedIpSsh) => {
247
+ var setupNftable = async ({
248
+ allowedIpV4
249
+ }) => {
243
250
  const listTable = await execCommand("nft list table inet ramm");
244
251
  if (listTable.spawnResult.exitCode === 0) {
245
252
  await execCommand("nft delete table inet ramm");
246
253
  }
247
- const nftTable = createNftTable(allowedIpSsh);
254
+ const nftTable = createNftTable({ allowedIpV4 });
248
255
  await execCommand(`nft -f - <<EOF
249
256
  ${nftTable}
250
257
  EOF`);
@@ -323,7 +330,7 @@ var writeFile = async (pathToFile, str) => {
323
330
  debugApiCall(`write(${normalizedPath})`);
324
331
  await write(normalizedPath, str);
325
332
  };
326
- var writeFileIfNotMatch = async (pathToFile, str) => {
333
+ var writeIfNewCompletely = async (pathToFile, str) => {
327
334
  const normalizedPath = normalizePath(pathToFile);
328
335
  await createFileIfNeed(normalizedPath);
329
336
  debugApiCall(`file(${normalizedPath}).text()`);
@@ -365,7 +372,7 @@ async function createSshKey(pathToKey, comment) {
365
372
  const pubKey = await Bun.file(pathToKeyPub).text();
366
373
  return pubKey;
367
374
  }
368
- var addSshKey = async (pubKey, context) => {
375
+ var addSshKeyToAuthorized = async (pubKey, context) => {
369
376
  const { output: keys } = await execBySsh("cat .ssh/authorized_keys", context);
370
377
  if (keys.includes(pubKey)) {
371
378
  return;
@@ -375,7 +382,18 @@ var addSshKey = async (pubKey, context) => {
375
382
  var createAndAddSshKey = async (pathToKey, comment, context) => {
376
383
  const pubKey = await createSshKey(pathToKey, comment);
377
384
  debug(`Key is: ${pubKey}`);
378
- await addSshKey(pubKey, context);
385
+ await addSshKeyToAuthorized(pubKey, context);
386
+ };
387
+ var setupSshKey = async ({
388
+ key,
389
+ fingerprint,
390
+ pathToFile,
391
+ server
392
+ }) => {
393
+ await writeIfNewCompletely(pathToFile, key);
394
+ await execCommand(`chmod 0600 ${pathToFile}`);
395
+ await writeIfNew("~/.ssh/known_hosts", fingerprint);
396
+ await addKeyToHostConfig("~/.ssh/config", server, pathToFile);
379
397
  };
380
398
  // src/cron.ts
381
399
  var createCron = async ({
@@ -437,8 +455,9 @@ var passVarsServer = async () => {
437
455
  };
438
456
  export {
439
457
  writeIfNew,
440
- writeFileIfNotMatch,
458
+ writeIfNewCompletely as writeFileIfNotMatch,
441
459
  writeFile,
460
+ setupSshKey,
442
461
  setupNftable,
443
462
  runPodmanContainerService,
444
463
  runPodmanContainer,
@@ -1,4 +1,4 @@
1
1
  export declare const normalizeFileContent: (str: string) => string;
2
2
  export declare const writeIfNew: (rawFilePath: string, str: string) => Promise<void>;
3
3
  export declare const writeFile: (pathToFile: string, str: string) => Promise<void>;
4
- export declare const writeFileIfNotMatch: (pathToFile: string, str: string) => Promise<void>;
4
+ export declare const writeIfNewCompletely: (pathToFile: string, str: string) => Promise<void>;
@@ -1,2 +1,4 @@
1
1
  export declare const localNftChainName = "local_chain";
2
- export declare const setupNftable: (allowedIpSsh: string) => Promise<void>;
2
+ export declare const setupNftable: ({ allowedIpV4, }: {
3
+ allowedIpV4: string[];
4
+ }) => Promise<void>;
@@ -7,8 +7,8 @@ export { restartSystemdService } from "./systemd.ts";
7
7
  export { installSystemPackage } from "./packages.ts";
8
8
  export { debugBlock } from "./debug.ts";
9
9
  export { setupNftable } from "./nft.ts";
10
- export { writeIfNew, writeFile, writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
- export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
10
+ export { writeIfNew, writeFile, writeIfNewCompletely as writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
+ export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, setupSshKey, } from "./ssh.ts";
12
12
  export { normalizePath } from "./path.ts";
13
13
  export { createCron } from "./cron.ts";
14
14
  export { buildAndRunOverSsh, passVarsClient, passVarsServer } from "./build.ts";
@@ -2,3 +2,9 @@ import type { Context } from "./context.ts";
2
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>;
5
+ export declare const setupSshKey: ({ key, fingerprint, pathToFile, server, }: {
6
+ key: string;
7
+ fingerprint: string;
8
+ pathToFile: string;
9
+ server: string;
10
+ }) => Promise<void>;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.25",
4
+ "version": "0.0.27",
5
5
  "scripts": {
6
- "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
6
+ "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh",
7
7
  "types": "tsc --project tsconfig.types.json"
8
8
  },
9
9
  "main": "dist/ramm.js",
@@ -19,6 +19,7 @@
19
19
  "typescript": "^5.8.2"
20
20
  },
21
21
  "dependencies": {
22
+ "dapes": "^0.0.26",
22
23
  "desy": "^0.0.14"
23
24
  }
24
- }
25
+ }