defense-mcp-server 0.9.3 → 0.9.4

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 (134) hide show
  1. package/package.json +2 -2
  2. package/build/core/auto-installer.d.ts +0 -102
  3. package/build/core/auto-installer.d.ts.map +0 -1
  4. package/build/core/backup-manager.d.ts +0 -63
  5. package/build/core/backup-manager.d.ts.map +0 -1
  6. package/build/core/changelog.d.ts +0 -119
  7. package/build/core/changelog.d.ts.map +0 -1
  8. package/build/core/command-allowlist.d.ts +0 -129
  9. package/build/core/command-allowlist.d.ts.map +0 -1
  10. package/build/core/config.d.ts +0 -107
  11. package/build/core/config.d.ts.map +0 -1
  12. package/build/core/dependency-validator.d.ts +0 -106
  13. package/build/core/dependency-validator.d.ts.map +0 -1
  14. package/build/core/distro-adapter.d.ts +0 -172
  15. package/build/core/distro-adapter.d.ts.map +0 -1
  16. package/build/core/distro.d.ts +0 -57
  17. package/build/core/distro.d.ts.map +0 -1
  18. package/build/core/encrypted-state.d.ts +0 -69
  19. package/build/core/encrypted-state.d.ts.map +0 -1
  20. package/build/core/executor.d.ts +0 -65
  21. package/build/core/executor.d.ts.map +0 -1
  22. package/build/core/installer.d.ts +0 -129
  23. package/build/core/installer.d.ts.map +0 -1
  24. package/build/core/logger.d.ts +0 -118
  25. package/build/core/logger.d.ts.map +0 -1
  26. package/build/core/metrics.d.ts +0 -74
  27. package/build/core/metrics.d.ts.map +0 -1
  28. package/build/core/metrics.js +0 -97
  29. package/build/core/output-redactor.d.ts +0 -26
  30. package/build/core/output-redactor.d.ts.map +0 -1
  31. package/build/core/pam-utils.d.ts +0 -356
  32. package/build/core/pam-utils.d.ts.map +0 -1
  33. package/build/core/parsers.d.ts +0 -191
  34. package/build/core/parsers.d.ts.map +0 -1
  35. package/build/core/policy-engine.d.ts +0 -170
  36. package/build/core/policy-engine.d.ts.map +0 -1
  37. package/build/core/preflight.d.ts +0 -157
  38. package/build/core/preflight.d.ts.map +0 -1
  39. package/build/core/privilege-manager.d.ts +0 -108
  40. package/build/core/privilege-manager.d.ts.map +0 -1
  41. package/build/core/progress.d.ts +0 -99
  42. package/build/core/progress.d.ts.map +0 -1
  43. package/build/core/rate-limiter.d.ts +0 -101
  44. package/build/core/rate-limiter.d.ts.map +0 -1
  45. package/build/core/rollback.d.ts +0 -73
  46. package/build/core/rollback.d.ts.map +0 -1
  47. package/build/core/run-command.d.ts +0 -14
  48. package/build/core/run-command.d.ts.map +0 -1
  49. package/build/core/safeguards.d.ts +0 -58
  50. package/build/core/safeguards.d.ts.map +0 -1
  51. package/build/core/sanitizer.d.ts +0 -118
  52. package/build/core/sanitizer.d.ts.map +0 -1
  53. package/build/core/secure-fs.d.ts +0 -67
  54. package/build/core/secure-fs.d.ts.map +0 -1
  55. package/build/core/spawn-safe.d.ts +0 -55
  56. package/build/core/spawn-safe.d.ts.map +0 -1
  57. package/build/core/sudo-guard.d.ts +0 -167
  58. package/build/core/sudo-guard.d.ts.map +0 -1
  59. package/build/core/sudo-session.d.ts +0 -143
  60. package/build/core/sudo-session.d.ts.map +0 -1
  61. package/build/core/third-party-installer.d.ts +0 -58
  62. package/build/core/third-party-installer.d.ts.map +0 -1
  63. package/build/core/third-party-manifest.d.ts +0 -48
  64. package/build/core/third-party-manifest.d.ts.map +0 -1
  65. package/build/core/tool-annotations.d.ts +0 -13
  66. package/build/core/tool-annotations.d.ts.map +0 -1
  67. package/build/core/tool-dependencies.d.ts +0 -60
  68. package/build/core/tool-dependencies.d.ts.map +0 -1
  69. package/build/core/tool-durations.d.ts +0 -71
  70. package/build/core/tool-durations.d.ts.map +0 -1
  71. package/build/core/tool-registry.d.ts +0 -112
  72. package/build/core/tool-registry.d.ts.map +0 -1
  73. package/build/core/tool-wrapper.d.ts +0 -73
  74. package/build/core/tool-wrapper.d.ts.map +0 -1
  75. package/build/index.d.ts +0 -3
  76. package/build/index.d.ts.map +0 -1
  77. package/build/tools/access-control.d.ts +0 -11
  78. package/build/tools/access-control.d.ts.map +0 -1
  79. package/build/tools/api-security.d.ts +0 -12
  80. package/build/tools/api-security.d.ts.map +0 -1
  81. package/build/tools/app-hardening.d.ts +0 -11
  82. package/build/tools/app-hardening.d.ts.map +0 -1
  83. package/build/tools/backup.d.ts +0 -8
  84. package/build/tools/backup.d.ts.map +0 -1
  85. package/build/tools/cloud-security.d.ts +0 -17
  86. package/build/tools/cloud-security.d.ts.map +0 -1
  87. package/build/tools/compliance.d.ts +0 -11
  88. package/build/tools/compliance.d.ts.map +0 -1
  89. package/build/tools/container-security.d.ts +0 -14
  90. package/build/tools/container-security.d.ts.map +0 -1
  91. package/build/tools/deception.d.ts +0 -13
  92. package/build/tools/deception.d.ts.map +0 -1
  93. package/build/tools/dns-security.d.ts +0 -93
  94. package/build/tools/dns-security.d.ts.map +0 -1
  95. package/build/tools/ebpf-security.d.ts +0 -15
  96. package/build/tools/ebpf-security.d.ts.map +0 -1
  97. package/build/tools/encryption.d.ts +0 -12
  98. package/build/tools/encryption.d.ts.map +0 -1
  99. package/build/tools/firewall.d.ts +0 -9
  100. package/build/tools/firewall.d.ts.map +0 -1
  101. package/build/tools/hardening.d.ts +0 -8
  102. package/build/tools/hardening.d.ts.map +0 -1
  103. package/build/tools/incident-response.d.ts +0 -11
  104. package/build/tools/incident-response.d.ts.map +0 -1
  105. package/build/tools/integrity.d.ts +0 -15
  106. package/build/tools/integrity.d.ts.map +0 -1
  107. package/build/tools/logging.d.ts +0 -21
  108. package/build/tools/logging.d.ts.map +0 -1
  109. package/build/tools/malware.d.ts +0 -10
  110. package/build/tools/malware.d.ts.map +0 -1
  111. package/build/tools/meta.d.ts +0 -13
  112. package/build/tools/meta.d.ts.map +0 -1
  113. package/build/tools/network-defense.d.ts +0 -11
  114. package/build/tools/network-defense.d.ts.map +0 -1
  115. package/build/tools/patch-management.d.ts +0 -3
  116. package/build/tools/patch-management.d.ts.map +0 -1
  117. package/build/tools/process-security.d.ts +0 -12
  118. package/build/tools/process-security.d.ts.map +0 -1
  119. package/build/tools/secrets.d.ts +0 -8
  120. package/build/tools/secrets.d.ts.map +0 -1
  121. package/build/tools/sudo-management.d.ts +0 -17
  122. package/build/tools/sudo-management.d.ts.map +0 -1
  123. package/build/tools/supply-chain-security.d.ts +0 -8
  124. package/build/tools/supply-chain-security.d.ts.map +0 -1
  125. package/build/tools/threat-intel.d.ts +0 -22
  126. package/build/tools/threat-intel.d.ts.map +0 -1
  127. package/build/tools/vulnerability-management.d.ts +0 -11
  128. package/build/tools/vulnerability-management.d.ts.map +0 -1
  129. package/build/tools/waf.d.ts +0 -12
  130. package/build/tools/waf.d.ts.map +0 -1
  131. package/build/tools/wireless-security.d.ts +0 -19
  132. package/build/tools/wireless-security.d.ts.map +0 -1
  133. package/build/tools/zero-trust-network.d.ts +0 -8
  134. package/build/tools/zero-trust-network.d.ts.map +0 -1
@@ -1,74 +0,0 @@
1
- /**
2
- * metrics.ts — In-process metrics collection for observability.
3
- *
4
- * Collects tool invocation counts, error rates, and latency histograms
5
- * in memory. Exposes a `getMetrics()` function that returns a snapshot
6
- * for reporting via the `defense_mgmt` tool or external monitoring.
7
- *
8
- * **Design**: No external dependencies. Metrics are collected in a
9
- * simple Map structure and can be serialized to JSON. A future
10
- * Prometheus-compatible endpoint can be added without changing the
11
- * collection API.
12
- *
13
- * Environment:
14
- * DEFENSE_MCP_METRICS=true Enable metrics collection (default: true)
15
- *
16
- * @module metrics
17
- */
18
- /** Metrics snapshot for a single tool. */
19
- export interface ToolMetrics {
20
- /** Tool name (e.g., "firewall", "harden_host") */
21
- toolName: string;
22
- /** Total invocations */
23
- invocations: number;
24
- /** Total errors (non-zero exit codes) */
25
- errors: number;
26
- /** Total rate-limiter rejections */
27
- rateLimitHits: number;
28
- /** Minimum latency in ms */
29
- minLatencyMs: number;
30
- /** Maximum latency in ms */
31
- maxLatencyMs: number;
32
- /** Sum of all latencies (for computing average) */
33
- totalLatencyMs: number;
34
- /** Last invocation timestamp (ISO 8601) */
35
- lastInvoked: string | null;
36
- }
37
- /** Complete metrics snapshot. */
38
- export interface MetricsSnapshot {
39
- /** ISO 8601 timestamp when this snapshot was taken */
40
- timestamp: string;
41
- /** Server uptime in seconds */
42
- uptimeSeconds: number;
43
- /** Total tool invocations across all tools */
44
- totalInvocations: number;
45
- /** Total errors across all tools */
46
- totalErrors: number;
47
- /** Per-tool metrics */
48
- tools: ToolMetrics[];
49
- }
50
- /**
51
- * Record a tool invocation.
52
- *
53
- * @param toolName - The tool that was invoked
54
- * @param durationMs - Wall-clock duration of the invocation in milliseconds
55
- * @param isError - Whether the invocation resulted in an error
56
- */
57
- export declare function recordInvocation(toolName: string, durationMs: number, isError: boolean): void;
58
- /**
59
- * Record a rate-limiter rejection for a tool.
60
- *
61
- * @param toolName - The tool that was rate-limited
62
- */
63
- export declare function recordRateLimitHit(toolName: string): void;
64
- /**
65
- * Get a complete metrics snapshot.
66
- *
67
- * @returns MetricsSnapshot with per-tool breakdown
68
- */
69
- export declare function getMetrics(): MetricsSnapshot;
70
- /**
71
- * Reset all metrics. Primarily used in tests.
72
- */
73
- export declare function resetMetrics(): void;
74
- //# sourceMappingURL=metrics.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/core/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,iCAAiC;AACjC,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AA2BD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GACf,IAAI,CAYN;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,eAAe,CAiB5C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAEnC"}
@@ -1,97 +0,0 @@
1
- /**
2
- * metrics.ts — In-process metrics collection for observability.
3
- *
4
- * Collects tool invocation counts, error rates, and latency histograms
5
- * in memory. Exposes a `getMetrics()` function that returns a snapshot
6
- * for reporting via the `defense_mgmt` tool or external monitoring.
7
- *
8
- * **Design**: No external dependencies. Metrics are collected in a
9
- * simple Map structure and can be serialized to JSON. A future
10
- * Prometheus-compatible endpoint can be added without changing the
11
- * collection API.
12
- *
13
- * Environment:
14
- * DEFENSE_MCP_METRICS=true Enable metrics collection (default: true)
15
- *
16
- * @module metrics
17
- */
18
- // ── Metrics Collector ────────────────────────────────────────────────────────
19
- const enabled = process.env.DEFENSE_MCP_METRICS !== "false";
20
- const startTime = Date.now();
21
- const toolMetrics = new Map();
22
- /** Get or create a metrics entry for a tool. */
23
- function getOrCreate(toolName) {
24
- let entry = toolMetrics.get(toolName);
25
- if (!entry) {
26
- entry = {
27
- toolName,
28
- invocations: 0,
29
- errors: 0,
30
- rateLimitHits: 0,
31
- minLatencyMs: Infinity,
32
- maxLatencyMs: 0,
33
- totalLatencyMs: 0,
34
- lastInvoked: null,
35
- };
36
- toolMetrics.set(toolName, entry);
37
- }
38
- return entry;
39
- }
40
- /**
41
- * Record a tool invocation.
42
- *
43
- * @param toolName - The tool that was invoked
44
- * @param durationMs - Wall-clock duration of the invocation in milliseconds
45
- * @param isError - Whether the invocation resulted in an error
46
- */
47
- export function recordInvocation(toolName, durationMs, isError) {
48
- if (!enabled)
49
- return;
50
- const entry = getOrCreate(toolName);
51
- entry.invocations++;
52
- entry.totalLatencyMs += durationMs;
53
- entry.lastInvoked = new Date().toISOString();
54
- if (durationMs < entry.minLatencyMs)
55
- entry.minLatencyMs = durationMs;
56
- if (durationMs > entry.maxLatencyMs)
57
- entry.maxLatencyMs = durationMs;
58
- if (isError)
59
- entry.errors++;
60
- }
61
- /**
62
- * Record a rate-limiter rejection for a tool.
63
- *
64
- * @param toolName - The tool that was rate-limited
65
- */
66
- export function recordRateLimitHit(toolName) {
67
- if (!enabled)
68
- return;
69
- getOrCreate(toolName).rateLimitHits++;
70
- }
71
- /**
72
- * Get a complete metrics snapshot.
73
- *
74
- * @returns MetricsSnapshot with per-tool breakdown
75
- */
76
- export function getMetrics() {
77
- const tools = Array.from(toolMetrics.values()).map((t) => ({
78
- ...t,
79
- // Replace Infinity with 0 for tools that haven't been invoked
80
- minLatencyMs: t.minLatencyMs === Infinity ? 0 : t.minLatencyMs,
81
- }));
82
- const totalInvocations = tools.reduce((sum, t) => sum + t.invocations, 0);
83
- const totalErrors = tools.reduce((sum, t) => sum + t.errors, 0);
84
- return {
85
- timestamp: new Date().toISOString(),
86
- uptimeSeconds: Math.floor((Date.now() - startTime) / 1000),
87
- totalInvocations,
88
- totalErrors,
89
- tools,
90
- };
91
- }
92
- /**
93
- * Reset all metrics. Primarily used in tests.
94
- */
95
- export function resetMetrics() {
96
- toolMetrics.clear();
97
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * output-redactor.ts — Post-execution output sanitization.
3
- *
4
- * Scans command stdout/stderr for sensitive data patterns and replaces
5
- * them with [REDACTED] before returning results to the LLM.
6
- *
7
- * SECURITY: Over-redacting is preferred to under-redacting.
8
- *
9
- * @module output-redactor
10
- */
11
- export interface RedactionResult {
12
- /** The sanitized text */
13
- text: string;
14
- /** Number of redactions applied */
15
- redactionCount: number;
16
- /** Labels of patterns that matched */
17
- matchedPatterns: string[];
18
- }
19
- /**
20
- * Redact sensitive data from command output.
21
- *
22
- * @param text - Raw stdout or stderr text
23
- * @returns Sanitized text with redaction metadata
24
- */
25
- export declare function redactOutput(text: string): RedactionResult;
26
- //# sourceMappingURL=output-redactor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-redactor.d.ts","sourceRoot":"","sources":["../../src/core/output-redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAmFH,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAmB1D"}
@@ -1,356 +0,0 @@
1
- /**
2
- * PAM configuration parser, serializer, validator, and file I/O manager.
3
- *
4
- * Replaces fragile sed-based PAM manipulation with safe in-memory operations:
5
- * 1. Parse PAM config into structured records
6
- * 2. Manipulate records (insert, remove, reorder)
7
- * 3. Serialize back with correct formatting
8
- * 4. Validate before writing
9
- * 5. Write atomically with mandatory backup and auto-rollback
10
- *
11
- * @see docs/PAM-HARDENING-FIX.md for architecture details
12
- */
13
- import { type BackupEntry } from "./backup-manager.js";
14
- /** A PAM rule line: type control module [args...] */
15
- export interface PamRule {
16
- kind: "rule";
17
- /** PAM type: auth, account, password, session (optionally prefixed with -) */
18
- pamType: string;
19
- /** Control flag: required, requisite, sufficient, optional, or [value=action ...] */
20
- control: string;
21
- /** Module path/name: pam_unix.so, pam_faillock.so, etc. */
22
- module: string;
23
- /** Module arguments: nullok, silent, deny=5, etc. */
24
- args: string[];
25
- /** Original raw text (preserved for round-trip fidelity). */
26
- rawLine: string;
27
- }
28
- /** A comment line (starts with #). */
29
- export interface PamComment {
30
- kind: "comment";
31
- text: string;
32
- }
33
- /** A blank/empty line. */
34
- export interface PamBlank {
35
- kind: "blank";
36
- }
37
- /** An @include directive. */
38
- export interface PamInclude {
39
- kind: "include";
40
- target: string;
41
- rawLine: string;
42
- }
43
- /** Union of all PAM line types. */
44
- export type PamLine = PamRule | PamComment | PamBlank | PamInclude;
45
- /** Thrown when PAM config validation fails. */
46
- export declare class PamValidationError extends Error {
47
- readonly errors: string[];
48
- readonly filePath?: string | undefined;
49
- constructor(errors: string[], filePath?: string | undefined);
50
- }
51
- /** Thrown when PAM file write fails or post-write validation fails. */
52
- export declare class PamWriteError extends Error {
53
- readonly filePath: string;
54
- readonly backupId?: string | undefined;
55
- constructor(message: string, filePath: string, backupId?: string | undefined);
56
- }
57
- /**
58
- * Parse PAM config file content into structured records.
59
- *
60
- * Handles:
61
- * - Standard rules: auth required pam_unix.so nullok
62
- * - Complex controls: auth [success=1 default=ignore] pam_unix.so
63
- * - Comments: # This is a comment
64
- * - Blank lines: (preserved for formatting fidelity)
65
- * - Include directives: @include common-auth
66
- *
67
- * **Critical**: The parser is **lossless**. Every line in the input appears
68
- * in the output array. Unknown/unparseable lines are preserved as comments
69
- * to prevent silent data loss.
70
- *
71
- * @param content - Raw PAM config file text
72
- * @returns Array of PamLine records in file order
73
- */
74
- export declare function parsePamConfig(content: string): PamLine[];
75
- /**
76
- * Serialize structured PAM records back to file content.
77
- *
78
- * For PamRule records, generates lines with consistent formatting:
79
- * - Fields separated by 4-space padding
80
- * - Module args separated by single spaces
81
- *
82
- * For PamComment, PamBlank, and PamInclude records, the original
83
- * raw text is emitted unchanged (round-trip preservation).
84
- *
85
- * @param lines - Array of PamLine records
86
- * @returns PAM config file content string (with trailing newline)
87
- */
88
- export declare function serializePamConfig(lines: PamLine[]): string;
89
- /**
90
- * Validate PAM config for syntactic correctness.
91
- *
92
- * Checks:
93
- * 1. Every PamRule has a valid pamType, non-empty control, and module ending in .so
94
- * 2. At least one pam_unix.so rule exists (sanity check — PAM needs it)
95
- * 3. No lines have concatenated fields (the bug that caused the lockout)
96
- *
97
- * Does NOT check:
98
- * - Whether .so files exist on disk
99
- * - Semantic correctness of control flags
100
- *
101
- * @param lines - Parsed PamLine array
102
- * @returns Validation result with error details
103
- */
104
- export declare function validatePamConfig(lines: PamLine[]): {
105
- valid: boolean;
106
- errors: string[];
107
- };
108
- /**
109
- * Validate raw PAM config content string.
110
- *
111
- * Convenience wrapper that parses then validates.
112
- *
113
- * @param content - Raw PAM config file text
114
- * @returns Validation result
115
- */
116
- export declare function validatePamConfigContent(content: string): {
117
- valid: boolean;
118
- errors: string[];
119
- };
120
- /**
121
- * Create a new PamRule record.
122
- *
123
- * @param pamType - PAM type (auth, account, password, session)
124
- * @param control - Control flag (required, requisite, [success=1 default=ignore], etc.)
125
- * @param module - Module name (pam_faillock.so, pam_unix.so, etc.)
126
- * @param args - Module arguments
127
- * @returns New PamRule with generated rawLine
128
- */
129
- export declare function createPamRule(pamType: string, control: string, module: string, args: string[]): PamRule;
130
- /**
131
- * Remove all rules referencing a specific module.
132
- *
133
- * @param lines - Current PamLine array
134
- * @param moduleName - Module to remove (e.g., "pam_faillock.so")
135
- * @returns New array with matching rules removed
136
- */
137
- export declare function removeModuleRules(lines: PamLine[], moduleName: string): PamLine[];
138
- /**
139
- * Insert a new rule BEFORE the first rule matching targetModule.
140
- * If targetModule is not found, appends at the end.
141
- *
142
- * @param lines - Current PamLine array
143
- * @param targetModule - Module to insert before (e.g., "pam_unix.so")
144
- * @param newRule - The rule to insert
145
- * @param options - Optional filters: pamType restricts match to specific PAM type
146
- * @returns New array with the rule inserted
147
- */
148
- export declare function insertBeforeModule(lines: PamLine[], targetModule: string, newRule: PamRule, options?: {
149
- pamType?: string;
150
- }): PamLine[];
151
- /**
152
- * Insert a new rule AFTER the first rule matching targetModule.
153
- * If targetModule is not found, appends at the end.
154
- *
155
- * @param lines - Current PamLine array
156
- * @param targetModule - Module to insert after (e.g., "pam_unix.so")
157
- * @param newRule - The rule to insert
158
- * @param options - Optional filters: pamType restricts match to specific PAM type
159
- * @returns New array with the rule inserted
160
- */
161
- export declare function insertAfterModule(lines: PamLine[], targetModule: string, newRule: PamRule, options?: {
162
- pamType?: string;
163
- }): PamLine[];
164
- /**
165
- * Find all rules referencing a specific module.
166
- *
167
- * @param lines - PamLine array to search
168
- * @param moduleName - Module to find (e.g., "pam_faillock.so")
169
- * @returns Array of matching PamRule records
170
- */
171
- export declare function findModuleRules(lines: PamLine[], moduleName: string): PamRule[];
172
- /**
173
- * After inserting rules, adjust [success=N] jump counts on any rule
174
- * that uses bracket-style controls with a success=N pattern.
175
- *
176
- * For each rule with [success=N ...], count how many rules now exist
177
- * between that rule and pam_deny.so (requisite), and update N so that
178
- * success still jumps PAST pam_deny.so.
179
- *
180
- * @param lines - PamLine array (typically after insertions)
181
- * @returns New array with corrected jump counts
182
- */
183
- export declare function adjustJumpCounts(lines: PamLine[]): PamLine[];
184
- /**
185
- * Read a PAM config file via sudo.
186
- *
187
- * @param filePath - Absolute path (e.g., /etc/pam.d/common-auth)
188
- * @returns File content string
189
- * @throws If sudo cat fails
190
- */
191
- export declare function readPamFile(filePath: string): Promise<string>;
192
- /**
193
- * Write a PAM config file via sudo, with mandatory pre-write validation.
194
- *
195
- * Steps:
196
- * 1. Parse the content with parsePamConfig()
197
- * 2. Validate with validatePamConfig() — if invalid, throw (never write bad content)
198
- * 3. Write to a secure temp directory (mkdtempSync — eliminates symlink race)
199
- * 4. Use `sudo install -m 644 -o root -g root` for atomic write (eliminates partial-write state)
200
- * 5. Post-write verification
201
- *
202
- * @param filePath - Absolute path
203
- * @param content - PAM config content to write
204
- * @throws PamValidationError if pre-write validation fails
205
- * @throws PamWriteError if write or permission setting fails
206
- */
207
- export declare function writePamFile(filePath: string, content: string): Promise<void>;
208
- /**
209
- * Backup a PAM file using the project BackupManager.
210
- *
211
- * Since PAM files are root-owned, this:
212
- * 1. Reads content via sudo cat
213
- * 2. Writes to a secure temp directory (eliminates symlink race)
214
- * 3. Uses BackupManager.backupSync() to create a tracked backup
215
- * 4. Returns a new object (does NOT mutate BackupManager's internal entry)
216
- * 5. Cleans up the temp file/directory
217
- *
218
- * @param filePath - PAM file to backup
219
- * @returns BackupEntry for later restore (with corrected originalPath)
220
- */
221
- export declare function backupPamFile(filePath: string): Promise<BackupEntry>;
222
- /**
223
- * Restore a PAM file from backup.
224
- *
225
- * 1. Reads backup content from BackupManager's directory
226
- * 2. Validates the backup content (refuse to restore garbage)
227
- * 3. Writes to a secure temp file, then uses `sudo install` (eliminates tee stdout leak)
228
- *
229
- * @param backupEntry - The BackupEntry from backupPamFile()
230
- * @throws If backup file is missing, invalid, or restore fails
231
- */
232
- export declare function restorePamFile(backupEntry: BackupEntry): Promise<void>;
233
- /** A single finding from PAM policy sanity validation. */
234
- export interface PamSanityFinding {
235
- /** warning = proceed with caution; critical = blocks operation unless forced */
236
- severity: "warning" | "critical";
237
- /** Which module the finding relates to */
238
- module: "pam_faillock.so" | "pam_pwquality.so" | "general";
239
- /** The specific parameter that triggered the finding, if applicable */
240
- parameter?: string;
241
- /** The problematic value */
242
- value?: string | number;
243
- /** Human-readable description of the problem */
244
- message: string;
245
- /** What the user should do instead */
246
- recommendation: string;
247
- }
248
- /** Result of PAM policy sanity validation. */
249
- export interface PamSanityResult {
250
- /** true if no critical findings exist */
251
- safe: boolean;
252
- /** All findings, ordered by severity then module */
253
- findings: PamSanityFinding[];
254
- /** Count of critical-severity findings */
255
- criticalCount: number;
256
- /** Count of warning-severity findings */
257
- warningCount: number;
258
- }
259
- /**
260
- * Thresholds for PAM policy sanity checks.
261
- * These define what constitutes "sane" vs "dangerous" PAM policy values.
262
- * Tuned to prevent lockouts while allowing reasonable security hardening.
263
- */
264
- export declare const PAM_SANITY_THRESHOLDS: {
265
- readonly faillock: {
266
- /** deny below this triggers critical — too few attempts before lockout */
267
- readonly minDeny: 3;
268
- /** unlock_time above this triggers warning — extended lockout */
269
- readonly maxUnlockTimeWarn: 1800;
270
- /** unlock_time above this triggers critical — extreme lockout */
271
- readonly maxUnlockTimeCritical: 86400;
272
- /** fail_interval below this triggers warning — unusually short window */
273
- readonly minFailInterval: 60;
274
- };
275
- readonly pwquality: {
276
- /** minlen above this triggers warning — unusually long */
277
- readonly maxMinlenWarn: 24;
278
- /** minlen above this triggers critical — unreasonably long */
279
- readonly maxMinlenCritical: 64;
280
- /** retry below this triggers critical — no second chance */
281
- readonly minRetry: 2;
282
- /** Combined credit threshold: all credits at this or below with high minlen */
283
- readonly restrictiveCreditThreshold: -2;
284
- };
285
- };
286
- /**
287
- * Validate faillock parameters for policy sanity.
288
- *
289
- * Checks for overly restrictive settings that could cause lockouts:
290
- * - deny too low (typos cause lockout)
291
- * - unlock_time too high or zero (extended/permanent lockout)
292
- * - deny + unlock_time=0 combination (permanent lock on typos)
293
- * - fail_interval too short
294
- *
295
- * @param params - Faillock parameters to validate
296
- * @returns Array of sanity findings (empty = all sane)
297
- */
298
- export declare function validateFaillockParams(params: {
299
- deny?: number;
300
- unlock_time?: number;
301
- fail_interval?: number;
302
- }): PamSanityFinding[];
303
- /**
304
- * Validate pwquality parameters for policy sanity.
305
- *
306
- * Checks for overly restrictive settings that prevent password creation:
307
- * - minlen too high
308
- * - retry too low (no second chance)
309
- * - All character class requirements simultaneously very strict
310
- *
311
- * @param params - Pwquality parameters to validate
312
- * @returns Array of sanity findings (empty = all sane)
313
- */
314
- export declare function validatePwqualityParams(params: {
315
- minlen?: number;
316
- dcredit?: number;
317
- ucredit?: number;
318
- lcredit?: number;
319
- ocredit?: number;
320
- minclass?: number;
321
- maxrepeat?: number;
322
- retry?: number;
323
- }): PamSanityFinding[];
324
- /**
325
- * Validate a PAM config structure for dangerous patterns.
326
- *
327
- * Checks the resulting PamLine[] after manipulation for patterns
328
- * that would break authentication:
329
- * - pam_deny.so as first auth rule (blocks all auth)
330
- * - Missing pam_unix.so in auth stack
331
- * - Incomplete faillock setup (preauth without authfail or vice versa)
332
- * - Missing pam_permit.so in session stack
333
- *
334
- * @param lines - Parsed PAM config lines (after manipulation)
335
- * @returns Array of sanity findings
336
- */
337
- export declare function validatePamConfigSanity(lines: PamLine[]): PamSanityFinding[];
338
- /**
339
- * Validate PAM policy sanity — combined parameter + config check.
340
- *
341
- * This is the main entry point for sanity validation. It runs:
342
- * 1. Module-specific parameter checks (if module + params provided)
343
- * 2. Config structure checks (if lines provided)
344
- *
345
- * @param options - What to validate
346
- * @returns Combined sanity result with safe flag and all findings
347
- */
348
- export declare function validatePamPolicySanity(options: {
349
- /** Which PAM module is being configured */
350
- module?: "faillock" | "pwquality";
351
- /** Module parameters being applied */
352
- params?: Record<string, unknown>;
353
- /** Resulting PAM config lines (after manipulation) */
354
- lines?: PamLine[];
355
- }): PamSanityResult;
356
- //# sourceMappingURL=pam-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pam-utils.d.ts","sourceRoot":"","sources":["../../src/core/pam-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKtE,qDAAqD;AACrD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,sCAAsC;AACtC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,C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