ramm 0.0.25 → 0.0.26
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 +19 -12
- package/dist/types/files.d.ts +1 -1
- package/dist/types/nft.d.ts +3 -1
- package/dist/types/ramm.d.ts +1 -1
- package/dist/types/ssh.d.ts +6 -0
- package/package.json +4 -3
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 = (
|
|
215
|
+
var createNftTable = ({ allowedIpV4 }) => {
|
|
216
216
|
const nftTable = `table inet ramm {
|
|
217
|
-
set
|
|
217
|
+
set allowed_ipv4 {
|
|
218
218
|
type ipv4_addr
|
|
219
219
|
flags dynamic
|
|
220
|
-
elements = { ${
|
|
220
|
+
elements = { ${allowedIpV4.join(`
|
|
221
|
+
`)} }
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
chain
|
|
224
|
-
iif "lo" accept
|
|
224
|
+
chain local_chain_base {
|
|
225
|
+
iif "lo" accept
|
|
225
226
|
ct state established,related accept
|
|
226
|
-
ip saddr @
|
|
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 (
|
|
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(
|
|
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
|
|
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
|
|
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,7 @@ 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
|
|
385
|
+
await addSshKeyToAuthorized(pubKey, context);
|
|
379
386
|
};
|
|
380
387
|
// src/cron.ts
|
|
381
388
|
var createCron = async ({
|
|
@@ -437,7 +444,7 @@ var passVarsServer = async () => {
|
|
|
437
444
|
};
|
|
438
445
|
export {
|
|
439
446
|
writeIfNew,
|
|
440
|
-
writeFileIfNotMatch,
|
|
447
|
+
writeIfNewCompletely as writeFileIfNotMatch,
|
|
441
448
|
writeFile,
|
|
442
449
|
setupNftable,
|
|
443
450
|
runPodmanContainerService,
|
package/dist/types/files.d.ts
CHANGED
|
@@ -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
|
|
4
|
+
export declare const writeIfNewCompletely: (pathToFile: string, str: string) => Promise<void>;
|
package/dist/types/nft.d.ts
CHANGED
package/dist/types/ramm.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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";
|
|
10
|
+
export { writeIfNew, writeFile, writeIfNewCompletely as writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
|
|
11
11
|
export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
|
|
12
12
|
export { normalizePath } from "./path.ts";
|
|
13
13
|
export { createCron } from "./cron.ts";
|
package/dist/types/ssh.d.ts
CHANGED
|
@@ -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.
|
|
4
|
+
"version": "0.0.26",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh
|
|
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
|
+
}
|