@sentriflow/core 0.1.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.
- package/LICENSE +190 -0
- package/README.md +86 -0
- package/package.json +60 -0
- package/src/constants.ts +77 -0
- package/src/engine/RuleExecutor.ts +256 -0
- package/src/engine/Runner.ts +312 -0
- package/src/engine/SandboxedExecutor.ts +208 -0
- package/src/errors.ts +88 -0
- package/src/helpers/arista/helpers.ts +1220 -0
- package/src/helpers/arista/index.ts +12 -0
- package/src/helpers/aruba/helpers.ts +637 -0
- package/src/helpers/aruba/index.ts +13 -0
- package/src/helpers/cisco/helpers.ts +534 -0
- package/src/helpers/cisco/index.ts +11 -0
- package/src/helpers/common/helpers.ts +265 -0
- package/src/helpers/common/index.ts +5 -0
- package/src/helpers/common/validation.ts +280 -0
- package/src/helpers/cumulus/helpers.ts +676 -0
- package/src/helpers/cumulus/index.ts +12 -0
- package/src/helpers/extreme/helpers.ts +422 -0
- package/src/helpers/extreme/index.ts +12 -0
- package/src/helpers/fortinet/helpers.ts +892 -0
- package/src/helpers/fortinet/index.ts +12 -0
- package/src/helpers/huawei/helpers.ts +790 -0
- package/src/helpers/huawei/index.ts +11 -0
- package/src/helpers/index.ts +53 -0
- package/src/helpers/juniper/helpers.ts +756 -0
- package/src/helpers/juniper/index.ts +12 -0
- package/src/helpers/mikrotik/helpers.ts +722 -0
- package/src/helpers/mikrotik/index.ts +12 -0
- package/src/helpers/nokia/helpers.ts +856 -0
- package/src/helpers/nokia/index.ts +11 -0
- package/src/helpers/paloalto/helpers.ts +939 -0
- package/src/helpers/paloalto/index.ts +12 -0
- package/src/helpers/vyos/helpers.ts +429 -0
- package/src/helpers/vyos/index.ts +12 -0
- package/src/index.ts +30 -0
- package/src/json-rules/ExpressionEvaluator.ts +292 -0
- package/src/json-rules/HelperRegistry.ts +177 -0
- package/src/json-rules/JsonRuleCompiler.ts +339 -0
- package/src/json-rules/JsonRuleValidator.ts +371 -0
- package/src/json-rules/index.ts +97 -0
- package/src/json-rules/schema.json +350 -0
- package/src/json-rules/types.ts +303 -0
- package/src/pack-loader/PackLoader.ts +332 -0
- package/src/pack-loader/index.ts +17 -0
- package/src/pack-loader/types.ts +135 -0
- package/src/parser/IncrementalParser.ts +527 -0
- package/src/parser/Sanitizer.ts +104 -0
- package/src/parser/SchemaAwareParser.ts +504 -0
- package/src/parser/VendorSchema.ts +72 -0
- package/src/parser/vendors/arista-eos.ts +206 -0
- package/src/parser/vendors/aruba-aoscx.ts +123 -0
- package/src/parser/vendors/aruba-aosswitch.ts +113 -0
- package/src/parser/vendors/aruba-wlc.ts +173 -0
- package/src/parser/vendors/cisco-ios.ts +110 -0
- package/src/parser/vendors/cisco-nxos.ts +107 -0
- package/src/parser/vendors/cumulus-linux.ts +161 -0
- package/src/parser/vendors/extreme-exos.ts +154 -0
- package/src/parser/vendors/extreme-voss.ts +167 -0
- package/src/parser/vendors/fortinet-fortigate.ts +217 -0
- package/src/parser/vendors/huawei-vrp.ts +192 -0
- package/src/parser/vendors/index.ts +1521 -0
- package/src/parser/vendors/juniper-junos.ts +230 -0
- package/src/parser/vendors/mikrotik-routeros.ts +274 -0
- package/src/parser/vendors/nokia-sros.ts +251 -0
- package/src/parser/vendors/paloalto-panos.ts +264 -0
- package/src/parser/vendors/vyos-vyos.ts +454 -0
- package/src/types/ConfigNode.ts +72 -0
- package/src/types/DeclarativeRule.ts +158 -0
- package/src/types/IRule.ts +270 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// packages/core/src/types/IRule.ts
|
|
2
|
+
|
|
3
|
+
import type { ConfigNode } from "./ConfigNode";
|
|
4
|
+
import { getAvailableVendors } from '../parser/vendors';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents the outcome of a rule check.
|
|
8
|
+
*/
|
|
9
|
+
export interface RuleResult {
|
|
10
|
+
/**
|
|
11
|
+
* True if the rule passed, false if it failed.
|
|
12
|
+
*/
|
|
13
|
+
passed: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A message explaining the rule's outcome, especially on failure.
|
|
16
|
+
*/
|
|
17
|
+
message: string;
|
|
18
|
+
/**
|
|
19
|
+
* The ID of the rule that was checked.
|
|
20
|
+
*/
|
|
21
|
+
ruleId: string;
|
|
22
|
+
/**
|
|
23
|
+
* The ID of the node that was checked.
|
|
24
|
+
*/
|
|
25
|
+
nodeId: string;
|
|
26
|
+
/**
|
|
27
|
+
* The level of the result (error, warning, info).
|
|
28
|
+
*/
|
|
29
|
+
level: 'error' | 'warning' | 'info';
|
|
30
|
+
/**
|
|
31
|
+
* Optional: Remediation steps if the rule failed.
|
|
32
|
+
*/
|
|
33
|
+
remediation?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Optional: The specific lines in the configuration where the issue was found.
|
|
36
|
+
*/
|
|
37
|
+
loc?: {
|
|
38
|
+
startLine: number;
|
|
39
|
+
endLine: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Contextual information passed to a rule's check function.
|
|
45
|
+
* This might include global settings, other AST nodes, or environmental data.
|
|
46
|
+
*/
|
|
47
|
+
export interface Context {
|
|
48
|
+
/**
|
|
49
|
+
* Lazy getter for the full configuration AST. Only call this if your rule
|
|
50
|
+
* needs cross-reference validation (e.g., checking if an IP referenced in
|
|
51
|
+
* OSPF exists on an interface). Simple single-node rules should not use this.
|
|
52
|
+
*/
|
|
53
|
+
getAst?: () => ConfigNode[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Vendor identifiers that a rule can target.
|
|
58
|
+
* Use 'common' for vendor-agnostic rules that apply to all vendors.
|
|
59
|
+
*/
|
|
60
|
+
export type RuleVendor =
|
|
61
|
+
| 'common'
|
|
62
|
+
| 'cisco-ios'
|
|
63
|
+
| 'cisco-nxos'
|
|
64
|
+
| 'juniper-junos'
|
|
65
|
+
| 'aruba-aoscx'
|
|
66
|
+
| 'aruba-aosswitch'
|
|
67
|
+
| 'aruba-wlc'
|
|
68
|
+
| 'paloalto-panos'
|
|
69
|
+
| 'arista-eos'
|
|
70
|
+
| 'vyos'
|
|
71
|
+
| 'fortinet-fortigate'
|
|
72
|
+
| 'extreme-exos'
|
|
73
|
+
| 'extreme-voss'
|
|
74
|
+
| 'huawei-vrp'
|
|
75
|
+
| 'mikrotik-routeros'
|
|
76
|
+
| 'nokia-sros'
|
|
77
|
+
| 'cumulus-linux';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Canonical list of valid vendor identifiers.
|
|
81
|
+
* Dynamically derived from vendorSchemas - single source of truth.
|
|
82
|
+
* SEC-004: Centralized vendor list to prevent synchronization issues.
|
|
83
|
+
*/
|
|
84
|
+
export const VALID_VENDOR_IDS: readonly RuleVendor[] = [
|
|
85
|
+
'common',
|
|
86
|
+
...getAvailableVendors(),
|
|
87
|
+
] as readonly RuleVendor[];
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Type guard to check if a string is a valid vendor identifier.
|
|
91
|
+
* SEC-004: Provides consistent validation across CLI and VSCode.
|
|
92
|
+
*
|
|
93
|
+
* @param id The string to check
|
|
94
|
+
* @returns true if the id is a valid RuleVendor
|
|
95
|
+
*/
|
|
96
|
+
export function isValidVendorId(id: string): id is RuleVendor {
|
|
97
|
+
return VALID_VENDOR_IDS.includes(id as RuleVendor);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Specifies what to disable from the default rule pack.
|
|
102
|
+
*/
|
|
103
|
+
export interface PackDisableConfig {
|
|
104
|
+
/**
|
|
105
|
+
* Disable the entire default pack (all rules).
|
|
106
|
+
* When true, no default rules will run unless explicitly re-enabled.
|
|
107
|
+
*/
|
|
108
|
+
all?: boolean;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Disable all default rules for specific vendors.
|
|
112
|
+
* Example: ['cisco-ios', 'cisco-nxos'] disables all Cisco rules.
|
|
113
|
+
*/
|
|
114
|
+
vendors?: RuleVendor[];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Disable specific rules by ID.
|
|
118
|
+
* Example: ['NET-IP-001', 'NET-DOC-001']
|
|
119
|
+
*/
|
|
120
|
+
rules?: string[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Metadata for a rule pack.
|
|
125
|
+
*/
|
|
126
|
+
export interface RulePackMetadata {
|
|
127
|
+
/**
|
|
128
|
+
* Unique identifier for the pack (e.g., 'acme-secpack').
|
|
129
|
+
* Used for registration, unregistration, and conflict resolution.
|
|
130
|
+
*/
|
|
131
|
+
name: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Semantic version of the pack (e.g., '1.0.0').
|
|
135
|
+
*/
|
|
136
|
+
version: string;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Publisher/vendor name (e.g., 'ACME Corp').
|
|
140
|
+
*/
|
|
141
|
+
publisher: string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Brief description of the pack's purpose.
|
|
145
|
+
*/
|
|
146
|
+
description?: string;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* License type (e.g., 'Commercial', 'MIT', 'Proprietary').
|
|
150
|
+
*/
|
|
151
|
+
license?: string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Homepage or documentation URL.
|
|
155
|
+
*/
|
|
156
|
+
homepage?: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A rule pack containing multiple rules with shared metadata.
|
|
161
|
+
*/
|
|
162
|
+
export interface RulePack extends RulePackMetadata {
|
|
163
|
+
/**
|
|
164
|
+
* Priority for conflict resolution (higher wins).
|
|
165
|
+
* Default pack has priority 0.
|
|
166
|
+
* Recommended: 100+ for proprietary packs.
|
|
167
|
+
*/
|
|
168
|
+
priority: number;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Rules included in this pack.
|
|
172
|
+
*/
|
|
173
|
+
rules: IRule[];
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Configuration for disabling default pack rules.
|
|
177
|
+
* Allows disabling by: all, vendors, or specific rule IDs.
|
|
178
|
+
*/
|
|
179
|
+
disables?: PackDisableConfig;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* SEC-007: Security metadata for SARIF integration.
|
|
184
|
+
* Provides CWE mappings and CVSS scores for security-related rules.
|
|
185
|
+
*/
|
|
186
|
+
export interface SecurityMetadata {
|
|
187
|
+
/**
|
|
188
|
+
* CWE (Common Weakness Enumeration) identifiers.
|
|
189
|
+
* Example: ['CWE-798', 'CWE-259'] for hardcoded credentials.
|
|
190
|
+
*/
|
|
191
|
+
cwe?: string[];
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* CVSS v3.1 base score (0.0 - 10.0).
|
|
195
|
+
* Used by security scanners to prioritize findings.
|
|
196
|
+
*/
|
|
197
|
+
cvssScore?: number;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* CVSS v3.1 vector string.
|
|
201
|
+
* Example: 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H'
|
|
202
|
+
*/
|
|
203
|
+
cvssVector?: string;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Security-related tags for categorization.
|
|
207
|
+
* Example: ['authentication', 'hardcoded-credentials', 'encryption']
|
|
208
|
+
*/
|
|
209
|
+
tags?: string[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Extended rule metadata including optional security fields.
|
|
214
|
+
* SEC-007: Supports CWE/CVSS metadata for SARIF output.
|
|
215
|
+
*/
|
|
216
|
+
export interface RuleMetadata {
|
|
217
|
+
/** Severity level of the rule */
|
|
218
|
+
level: 'error' | 'warning' | 'info';
|
|
219
|
+
/** Organizational Business Unit responsible for this rule */
|
|
220
|
+
obu: string;
|
|
221
|
+
/** Owner of the rule logic */
|
|
222
|
+
owner: string;
|
|
223
|
+
/** Brief description of what the rule checks */
|
|
224
|
+
description?: string;
|
|
225
|
+
/** Suggested steps to fix the violation */
|
|
226
|
+
remediation?: string;
|
|
227
|
+
/** SEC-007: Optional security metadata for SARIF integration */
|
|
228
|
+
security?: SecurityMetadata;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Defines the structure of a configuration validation rule.
|
|
233
|
+
*/
|
|
234
|
+
export interface IRule {
|
|
235
|
+
/**
|
|
236
|
+
* A unique identifier for the rule (e.g., "NET-SEC-001").
|
|
237
|
+
*/
|
|
238
|
+
id: string;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* An optional selector string (e.g., "interface", "router bgp")
|
|
242
|
+
* that determines which `ConfigNode` types this rule should be applied to.
|
|
243
|
+
* This is used for optimization to avoid running rules on irrelevant nodes.
|
|
244
|
+
*/
|
|
245
|
+
selector?: string;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Optional vendor(s) this rule applies to.
|
|
249
|
+
* - Single vendor: 'cisco-ios'
|
|
250
|
+
* - Multiple vendors: ['cisco-ios', 'cisco-nxos']
|
|
251
|
+
* - All vendors: 'common' or omit this property
|
|
252
|
+
*
|
|
253
|
+
* When omitted, the rule is treated as vendor-agnostic and runs for all vendors.
|
|
254
|
+
* This is useful for proprietary rule packs that want to override or extend
|
|
255
|
+
* default rules for specific vendors only.
|
|
256
|
+
*/
|
|
257
|
+
vendor?: RuleVendor | RuleVendor[];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The function that contains the core logic of the rule.
|
|
261
|
+
* It takes a `ConfigNode` and a `Context` object, and returns a `RuleResult`.
|
|
262
|
+
*/
|
|
263
|
+
check: (node: ConfigNode, context: Context) => RuleResult;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Metadata associated with the rule, used for reporting and categorization.
|
|
267
|
+
* SEC-007: Extended to support security metadata for SARIF integration.
|
|
268
|
+
*/
|
|
269
|
+
metadata: RuleMetadata;
|
|
270
|
+
}
|