|
7 | 7 | - [Policy Definition and Verification](#policy-definition-and-verification) |
8 | 8 | - [Usage](#usage) |
9 | 9 | - [Policy Examples](#policy-examples) |
10 | | -- [Creating Rules for Violation Detection](#creating-rules-for-violation-detection) |
| 10 | +- [Creating Rules for Findings](#creating-rules-for-findings) |
11 | 11 | - [Understanding the `deny` Rule](#understanding-the-deny-rule) |
12 | 12 | - [Key Concepts for Rule Development](#key-concepts-for-rule-development) |
13 | 13 | - [Step-by-Step Guide to Creating a New Rule](#step-by-step-guide-to-creating-a-new-rule) |
@@ -61,8 +61,8 @@ by the Weaver tool during various phases of the development process. |
61 | 61 |
|
62 | 62 | The policy verification process involves: |
63 | 63 | - Reading the semconv files of both the new and previous versions. |
64 | | -- Applying Rego policies to these files to identify violations. |
65 | | -- Displaying any detected policy violations, aiding in the resolution before |
| 64 | +- Applying Rego policies to these files to identify findings (can be `violation`, `informational` or `warning`). |
| 65 | +- Displaying any detected policy findings, aiding in the resolution before |
66 | 66 | publication. |
67 | 67 |
|
68 | 68 | The following diagram illustrates the policy verification process: |
@@ -255,88 +255,98 @@ groups: |
255 | 255 | deprecated: true |
256 | 256 | ``` |
257 | 257 |
|
258 | | -... will generate the following violations. |
| 258 | +... will generate the following findings. |
259 | 259 |
|
260 | 260 | ```json |
261 | 261 | [ |
262 | 262 | { |
263 | 263 | "type": "semconv_attribute", |
264 | | - "id": "attr_stability_deprecated", |
265 | | - "category": "attribute", |
266 | | - "group": "registry.network1", |
267 | | - "attr": "protocol.name" |
| 264 | + "context": { |
| 265 | + "id": "attr_stability_deprecated", |
| 266 | + "category": "attribute", |
| 267 | + "group": "registry.network1", |
| 268 | + "attr": "protocol.name", |
| 269 | + }, |
| 270 | + "message": "...", |
| 271 | + "level": "violation", |
268 | 272 | }, |
269 | 273 | { |
270 | | - "type": "semconv_attribute", |
271 | | - "id": "attr_removed", |
272 | | - "category": "schema_evolution", |
273 | | - "group": "registry.network1", |
274 | | - "attr": "protocol.name.3" |
| 274 | + "id": "semconv_attribute", |
| 275 | + "context": { |
| 276 | + "id": "attr_stability_deprecated", |
| 277 | + "category": "attribute", |
| 278 | + "group": "registry.network1", |
| 279 | + "attr": "protocol.name", |
| 280 | + }, |
| 281 | + "message": "...", |
| 282 | + "level": "violation", |
275 | 283 | }, |
276 | 284 | { |
277 | | - "type": "semconv_attribute", |
278 | | - "id": "registry_with_ref_attr", |
279 | | - "category": "attribute_registry", |
280 | | - "group": "registry.network1", |
281 | | - "attr": "protocol.port" |
| 285 | + "id": "semconv_attribute", |
| 286 | + "context": { |
| 287 | + "id": "attr_stability_deprecated", |
| 288 | + "category": "attribute", |
| 289 | + "group": "registry.network1", |
| 290 | + "attr": "protocol.name", |
| 291 | + }, |
| 292 | + "message": "...", |
| 293 | + "level": "violation", |
282 | 294 | } |
283 | 295 | ] |
284 | 296 | ``` |
285 | 297 |
|
286 | | -## Creating Rules for Violation Detection |
| 298 | +## Creating Rules for Findings |
287 | 299 |
|
288 | 300 | The Weaver Policy Engine allows for the dynamic creation and enforcement of |
289 | 301 | rules to maintain the integrity and consistency of semantic conventions and |
290 | 302 | telemetry schemas. By leveraging the Rego language, developers can specify |
291 | | -policies that define what constitutes a violation within these domains. This |
292 | | -section explains how to craft rules for detecting new violations, enhancing the |
| 303 | +policies that define what constitutes a finding within these domains. This |
| 304 | +section explains how to craft rules for detecting new finding, enhancing the |
293 | 305 | engine's capability to safeguard the quality and coherence of semantic |
294 | 306 | conventions and application telemetry schemas. |
295 | 307 |
|
296 | 308 | ### Understanding the `deny` Rule |
297 | 309 |
|
298 | | -The `deny` rule serves as the cornerstone for defining policy violations. When |
| 310 | +The `deny` rule serves as the cornerstone for defining policy finding. When |
299 | 311 | the conditions specified within a `deny` rule are met, it indicates a policy |
300 | | -violation. Each `deny` rule must uniquely identify the violation it detects by |
| 312 | +finding. Each `deny` rule must uniquely identify the finding it detects by |
301 | 313 | producing a descriptive message or a structured object that outlines the nature |
302 | | -of the violation. |
| 314 | +of the finding. |
303 | 315 |
|
304 | 316 | ### Key Concepts for Rule Development |
305 | 317 |
|
306 | | -- **Rule Name**: Rules detecting violations must be named `deny`. This is a |
307 | | - convention chosen by the Weaver project to facilitate the use and management of |
308 | | - these policy files. |
309 | | -- **Violation Conditions**: The body of a `deny` rule contains one or more |
310 | | - conditions that, when true, signal a violation. These conditions can range from |
| 318 | +- **Rule Name**: Rules detecting a finding (e.g. detecting issues or violations) |
| 319 | + must be named `deny`. This is a convention chosen by the Weaver project to |
| 320 | + facilitate the use and management of these policy files. |
| 321 | +- **Finding Conditions**: The body of a `deny` rule contains one or more |
| 322 | + conditions that, when true, signal a finding. These conditions can range from |
311 | 323 | simple checks, like the presence of a deprecated attribute, to complex validations |
312 | 324 | involving multiple components of the semantic conventions or telemetry schemas. |
313 | | -- **Violation Message**: Upon detecting a violation, the rule should generate a |
314 | | - message or an object that provides detailed information about the violation, |
315 | | - including the type of violation, relevant identifiers (e.g., attribute or group |
316 | | - ID), and a brief description of the issue. |
| 325 | +- **Finding Message**: Upon detecting a finding, the rule should generate a |
| 326 | + message or an object that provides detailed information about the finding, |
| 327 | + including an id, the severity level, a human readable description, and |
| 328 | + any other relevant context you would like to attach. |
317 | 329 |
|
318 | 330 | ### Step-by-Step Guide to Creating a New Rule |
319 | 331 |
|
320 | | -1. **Identify the Violation**: Determine the specific condition or practice that |
321 | | - should be flagged as a violation. This could be a new policy requirement, a best |
| 332 | +1. **Identify the Finding**: Determine the specific condition or practice that |
| 333 | + should be flagged as a finding. This could be a new policy requirement, a best |
322 | 334 | practice, or an identified gap in the current policy enforcement. |
323 | 335 |
|
324 | 336 | 2. **Define the Rule Conditions**: Craft a set of conditions that accurately |
325 | | - capture the criteria for the violation. Utilize the Rego language to express |
| 337 | + capture the criteria for the finding. Utilize the Rego language to express |
326 | 338 | these conditions, making use of variables, functions, and operators as necessary. |
327 | 339 |
|
328 | | -3. **Construct the Violation Output**: For defining the structure of the violation |
329 | | - object, you can either reuse one of the already defined categories (i.e., |
330 | | - attr_registry_violation, attr_violation, schema_evolution_violation), or define |
331 | | - a new one if the category of this violation has not already been defined. |
| 340 | +3. **Construct the Finding Output**: For defining the structure of the finding |
| 341 | + object. |
332 | 342 |
|
333 | 343 | 4. **Implement the Rule in Rego**: Write the `deny` rule in Rego, encapsulating |
334 | | - the conditions and violation output you've defined. Ensure the rule is clearly |
| 344 | + the conditions and finding output you've defined. Ensure the rule is clearly |
335 | 345 | commented and documented to facilitate understanding and maintenance. |
336 | 346 |
|
337 | 347 | 5. **Test the Rule**: Before integrating the new rule into the Weaver Policy |
338 | 348 | Engine, test it with various input scenarios to ensure it accurately detects |
339 | | - violations without producing false positives or negatives. A unit test |
| 349 | + finding without producing false positives or negatives. A unit test |
340 | 350 | framework will be provided to facilitate this process in a future PR. |
341 | 351 |
|
342 | 352 | ## Links |
|
0 commit comments