vouchington-tooling 0.68.0 → 0.70.0

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.
Files changed (41) hide show
  1. package/README.md +50 -0
  2. package/dist/cli/commands/docker-image-mirror.d.mts +13 -0
  3. package/dist/cli/commands/docker-image-mirror.mjs +53 -0
  4. package/dist/cli/commands/trivy-policy.d.mts +12 -0
  5. package/dist/cli/commands/trivy-policy.mjs +76 -0
  6. package/dist/cli/index.mjs +4 -0
  7. package/dist/cli/parse-forwarded-commands.d.mts +7 -72
  8. package/dist/cli/parse-forwarded-commands.mjs +30 -49
  9. package/dist/cli/parse.d.mts +6 -0
  10. package/dist/cli/usage-text-policy.d.mts +2 -0
  11. package/dist/cli/usage-text-policy.mjs +28 -0
  12. package/dist/cli/usage-text.d.mts +1 -1
  13. package/dist/cli/usage-text.mjs +3 -6
  14. package/dist/docker-image-mirror/images.d.mts +25 -0
  15. package/dist/docker-image-mirror/images.mjs +97 -0
  16. package/dist/docker-image-mirror/index.d.mts +19 -0
  17. package/dist/docker-image-mirror/index.mjs +44 -0
  18. package/dist/docker-image-mirror/policy.d.mts +10 -0
  19. package/dist/docker-image-mirror/policy.mjs +53 -0
  20. package/dist/index.d.mts +4 -0
  21. package/dist/index.mjs +2 -0
  22. package/dist/postgres-test-faults/index.d.mts +9 -0
  23. package/dist/postgres-test-faults/index.mjs +9 -0
  24. package/dist/trivy-policy/background.d.mts +1 -0
  25. package/dist/trivy-policy/background.mjs +24 -0
  26. package/dist/trivy-policy/gate.d.mts +5 -0
  27. package/dist/trivy-policy/gate.mjs +92 -0
  28. package/dist/trivy-policy/index.d.mts +15 -0
  29. package/dist/trivy-policy/index.mjs +48 -0
  30. package/dist/trivy-policy/invocations.d.mts +4 -0
  31. package/dist/trivy-policy/invocations.mjs +76 -0
  32. package/dist/trivy-policy/options.d.mts +26 -0
  33. package/dist/trivy-policy/options.mjs +17 -0
  34. package/dist/trivy-policy/registry.d.mts +7 -0
  35. package/dist/trivy-policy/registry.mjs +48 -0
  36. package/dist/trivy-policy/scan.d.mts +5 -0
  37. package/dist/trivy-policy/scan.mjs +59 -0
  38. package/dist/trivy-policy/shell.d.mts +2 -0
  39. package/dist/trivy-policy/shell.mjs +62 -0
  40. package/package.json +11 -1
  41. package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
@@ -0,0 +1,48 @@
1
+ import { parse } from 'yaml';
2
+ import { resolveOptions } from "./options.mjs";
3
+ const PART = String.raw `(?:[A-Za-z0-9._~+-]|%[0-9A-Fa-f]{2})+`;
4
+ const VALUE = String.raw `(?:[A-Za-z0-9._~+:-]|%[0-9A-Fa-f]{2})+`;
5
+ const QUALIFIER = String.raw `${PART}=${VALUE}`;
6
+ const OS_PURL = new RegExp(String.raw `^pkg:(deb|apk|rpm)\/${PART}\/${PART}@${VALUE}(?:\?${QUALIFIER}(?:&${QUALIFIER})*)?$`);
7
+ // The registry's fields are all re-validated below with an explicit `typeof` check plus a regex,
8
+ // so the default YAML core schema is safe: a value it coerces to a non-string still fails.
9
+ export function parseIgnoreRegistry(source) {
10
+ return parse(source);
11
+ }
12
+ function isCalendarDate(value) {
13
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
14
+ return false;
15
+ const date = new Date(`${value}T00:00:00Z`);
16
+ return !Number.isNaN(date.valueOf()) && date.toISOString().slice(0, 10) === value;
17
+ }
18
+ function validateExpiry(expiredAt, prefix, options) {
19
+ const { now, maxExpiryDays } = resolveOptions(options);
20
+ if (typeof expiredAt !== 'string' || !isCalendarDate(expiredAt))
21
+ throw new Error(`${prefix}.expired_at must be a UTC calendar date`);
22
+ const today = now.toISOString().slice(0, 10);
23
+ if (expiredAt <= today)
24
+ throw new Error(`${prefix}.expired_at must be after today`);
25
+ const latest = new Date(`${today}T00:00:00Z`);
26
+ latest.setUTCDate(latest.getUTCDate() + maxExpiryDays);
27
+ if (expiredAt > latest.toISOString().slice(0, 10))
28
+ throw new Error(`${prefix}.expired_at must be no more than ${maxExpiryDays} days away`);
29
+ }
30
+ export function validateIgnoreRegistry(registry, options = {}) {
31
+ const vulnerabilities = registry?.vulnerabilities;
32
+ if (!Array.isArray(vulnerabilities))
33
+ throw new Error('vulnerabilities must be an array');
34
+ const { cleanupUrlPattern } = resolveOptions(options);
35
+ const statement = new RegExp(String.raw `^Not exploitable:\s*(?=\S).+?\.\s*Cleanup:\s*${cleanupUrlPattern}[1-9]\d*$`, 'i');
36
+ for (const [index, ignore] of vulnerabilities.entries()) {
37
+ const prefix = `vulnerabilities[${index}]`;
38
+ if (typeof ignore.id !== 'string' || ignore.id.trim() === '')
39
+ throw new Error(`${prefix}.id must be a vulnerability identifier`);
40
+ if (!Array.isArray(ignore.purls) ||
41
+ ignore.purls.length === 0 ||
42
+ ignore.purls.some((purl) => typeof purl !== 'string' || !OS_PURL.test(purl)))
43
+ throw new Error(`${prefix}.purls must contain exact versioned package purls`);
44
+ if (typeof ignore.statement !== 'string' || !statement.test(ignore.statement))
45
+ throw new Error(`${prefix}.statement must give exploitability rationale and cleanup issue URL`);
46
+ validateExpiry(ignore.expired_at, prefix, options);
47
+ }
48
+ }
@@ -0,0 +1,5 @@
1
+ export declare function isShellPolicySource(path: string): boolean;
2
+ export declare function assertNoUnsupportedTrivyAction(uses: unknown, path?: string): void;
3
+ export declare function assertNoUnsupportedTrivyShellSource(source: string, path?: string): void;
4
+ /** Every Trivy package-scan command in tracked workflows and composite actions. */
5
+ export declare function trivyPackageScanCommands(repositoryFiles: readonly string[], root: string): string[];
@@ -0,0 +1,59 @@
1
+ import { existsSync, readFileSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { parse } from 'yaml';
4
+ import { isDownloadDatabaseOnly } from "./gate.mjs";
5
+ import { trivyPackageScanCommandSegments } from "./invocations.mjs";
6
+ export function isShellPolicySource(path) {
7
+ if (/\.(bash|sh|zsh)$/.test(path))
8
+ return true;
9
+ try {
10
+ if ((statSync(path).mode & 0o111) === 0)
11
+ return false;
12
+ const firstLine = readFileSync(path, 'utf8').split('\n', 1)[0];
13
+ return /^#!\s*(?:\/usr\/bin\/env(?:\s+-S)?\s+|\/(?:usr\/)?bin\/)(?:ba|z)?sh(?:\s|$)/.test(firstLine);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ function workflowSteps(path) {
20
+ const document = parse(readFileSync(path, 'utf8'));
21
+ return [
22
+ ...Object.values(document?.jobs ?? {}).flatMap((job) => job.steps ?? []),
23
+ ...(document?.runs?.steps ?? []),
24
+ ];
25
+ }
26
+ export function assertNoUnsupportedTrivyAction(uses, path = 'fixture') {
27
+ if (typeof uses === 'string' && /trivy/i.test(uses)) {
28
+ throw new Error(`${path}: unsupported Trivy action ${uses}; use an auditable CLI run block`);
29
+ }
30
+ }
31
+ function assertSupportedWorkflowSteps(paths) {
32
+ const commands = [];
33
+ for (const path of paths) {
34
+ for (const step of workflowSteps(path)) {
35
+ assertNoUnsupportedTrivyAction(step.uses, path);
36
+ if (typeof step.run !== 'string')
37
+ continue;
38
+ commands.push(...trivyPackageScanCommandSegments(step.run));
39
+ }
40
+ }
41
+ return commands;
42
+ }
43
+ export function assertNoUnsupportedTrivyShellSource(source, path = 'fixture') {
44
+ if (trivyPackageScanCommandSegments(source).some((command) => !isDownloadDatabaseOnly(command))) {
45
+ throw new Error(`${path}: unsupported Trivy shell-script scan; use an auditable workflow run block`);
46
+ }
47
+ }
48
+ /** Every Trivy package-scan command in tracked workflows and composite actions. */
49
+ export function trivyPackageScanCommands(repositoryFiles, root) {
50
+ const present = repositoryFiles.filter((path) => existsSync(join(root, path)));
51
+ for (const path of present.filter((path) => isShellPolicySource(join(root, path)))) {
52
+ assertNoUnsupportedTrivyShellSource(readFileSync(join(root, path), 'utf8'), path);
53
+ }
54
+ const yamlPaths = [
55
+ ...present.filter((path) => /^\.github\/workflows\/[^/]+\.ya?ml$/.test(path)),
56
+ ...present.filter((path) => /^\.github\/actions\/.+\.ya?ml$/.test(path)),
57
+ ];
58
+ return assertSupportedWorkflowSteps(yamlPaths.map((path) => join(root, path)));
59
+ }
@@ -0,0 +1,2 @@
1
+ export declare function withoutShellComment(command: string): string;
2
+ export declare function shellSegments(command: string): string[];
@@ -0,0 +1,62 @@
1
+ export function withoutShellComment(command) {
2
+ return command
3
+ .replace(/\\\r?\n/g, '')
4
+ .split('\n')
5
+ .map(withoutShellCommentLine)
6
+ .join('\n');
7
+ }
8
+ function withoutShellCommentLine(command) {
9
+ let quote = '';
10
+ for (let index = 0; index < command.length; index++) {
11
+ const character = command[index];
12
+ if (character === '\\' && quote !== "'") {
13
+ index++;
14
+ continue;
15
+ }
16
+ if (quote !== '') {
17
+ if (character === quote)
18
+ quote = '';
19
+ }
20
+ else if (character === '"' || character === "'")
21
+ quote = character;
22
+ else if (character === '#' && (index === 0 || /\s/.test(command[index - 1])))
23
+ return command.slice(0, index);
24
+ }
25
+ return command;
26
+ }
27
+ export function shellSegments(command) {
28
+ const segments = [];
29
+ let quote = '';
30
+ let start = 0;
31
+ for (let index = 0; index < command.length; index++) {
32
+ const character = command[index];
33
+ if (character === '\\' && quote !== "'") {
34
+ index++;
35
+ continue;
36
+ }
37
+ if (quote !== '') {
38
+ if (character === quote)
39
+ quote = '';
40
+ continue;
41
+ }
42
+ if (character === '"' || character === "'") {
43
+ quote = character;
44
+ continue;
45
+ }
46
+ const operatorLength = character === ';' ||
47
+ character === '\n' ||
48
+ character === '|' ||
49
+ (character === '&' && command[index + 1] === '&')
50
+ ? command[index + 1] === character && character !== ';'
51
+ ? 2
52
+ : 1
53
+ : 0;
54
+ if (operatorLength === 0)
55
+ continue;
56
+ segments.push(command.slice(start, index));
57
+ index += operatorLength - 1;
58
+ start = index + 1;
59
+ }
60
+ segments.push(command.slice(start));
61
+ return segments;
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vouchington-tooling",
3
- "version": "0.68.0",
3
+ "version": "0.70.0",
4
4
  "description": "Vouchington CLI and extractable tooling libraries.",
5
5
  "homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
6
6
  "bugs": {
@@ -321,6 +321,16 @@
321
321
  "import": "./dist/dead-code/index.mjs",
322
322
  "default": "./dist/dead-code/index.mjs"
323
323
  },
324
+ "./trivy-policy": {
325
+ "types": "./dist/trivy-policy/index.d.mts",
326
+ "import": "./dist/trivy-policy/index.mjs",
327
+ "default": "./dist/trivy-policy/index.mjs"
328
+ },
329
+ "./docker-image-mirror": {
330
+ "types": "./dist/docker-image-mirror/index.d.mts",
331
+ "import": "./dist/docker-image-mirror/index.mjs",
332
+ "default": "./dist/docker-image-mirror/index.mjs"
333
+ },
324
334
  "./cloc": {
325
335
  "types": "./dist/cloc/index.d.mts",
326
336
  "import": "./dist/cloc/index.mjs",