You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for scanning container images in Kubernetes manifests.
Changes:
- Add K8s manifest parser supporting Pods, Deployments, StatefulSets,
DaemonSets, Jobs, and CronJobs
- Enhance file type detection with content-based validation (checks for
apiVersion and kind fields)
- Improve diagnostic severity based on vulnerability counts instead of
policy evaluation (ERROR for Critical/High, WARNING for Medium)
- Add integration tests and comprehensive documentation
- Document development patterns and gotchas in AGENTS.md
Version: 0.7.5 -> 0.8.0
* Parse Dockerfiles to extract image references from `FROM` instructions (including multi-stage builds).
94
94
* Parse Docker Compose YAML (e.g. service `image:` fields).
95
+
* Parse Kubernetes manifests YAML (e.g. `containers[].image` and `initContainers[].image` fields).
96
+
* K8s manifests are detected by checking for both `apiVersion:` and `kind:` fields in YAML files.
97
+
* Supports all common K8s resource types: Pods, Deployments, StatefulSets, DaemonSets, Jobs, CronJobs.
95
98
* Handle complex scenarios such as build args and multi-platform images.
96
-
* Implemented via modules like `ast_parser.rs`.
99
+
* Implemented via modules like `dockerfile_ast_parser.rs`, `compose_ast_parser.rs`, and `k8s_manifest_ast_parser.rs`.
97
100
98
101
***`ScannerBinaryManager`**
99
102
* Downloads the Sysdig CLI scanner binary on demand.
@@ -165,6 +168,9 @@ The project uses `just` as a command runner to encapsulate common workflows.
165
168
Additional helpful commands:
166
169
167
170
*`cargo test -- --nocapture` – run tests with full output when debugging.
171
+
*`cargo test --lib` – run only unit tests (faster than running all tests).
172
+
173
+
**Important:** The tests `infra::sysdig_image_scanner::tests::it_scans_popular_images_correctly_test::case_*` are very slow because they scan real container images. These tests should only be run when making changes to the image scanner. For day-to-day development, skip them or run focused tests instead.
168
174
169
175
### 3.4 Pre-commit Hooks
170
176
@@ -313,7 +319,191 @@ Check the workflow file in case of doubt.
313
319
314
320
---
315
321
316
-
## 8. Commit & Pull Request Guidelines
322
+
## 8. Development Patterns & Common Gotchas
323
+
324
+
This section documents important patterns, findings, and gotchas discovered during development that are critical for maintaining consistency and avoiding common pitfalls.
325
+
326
+
### 8.1 Adding Support for New File Types
327
+
328
+
When adding support for a new file type (e.g. Kubernetes manifests, Terraform files), follow this pattern established by Docker Compose and K8s manifest implementations:
329
+
330
+
#### Step 1: Create a Parser Module
331
+
332
+
1.**Create parser in `src/infra/`**: e.g. `k8s_manifest_ast_parser.rs`
333
+
- Define an `ImageInstruction` struct with `image_name` and `range` (LSP Range)
334
+
- Create a `parse_*` function that returns `Result<Vec<ImageInstruction>, ParseError>`
335
+
- Use `marked_yaml` for YAML parsing to preserve position information for accurate LSP ranges
**Why**: File extensions alone can cause false positives. Docker Compose files, K8s manifests, and generic YAML files all use `.yaml`/`.yml` extensions. Content-based detection ensures accurate routing.
416
+
417
+
### 8.3 Diagnostic Severity Logic
418
+
419
+
The diagnostic severity shown in the editor should reflect the **actual vulnerability severity**, not just policy evaluation results.
420
+
421
+
**Current Implementation** (in `src/app/lsp_server/commands/scan_base_image.rs`):
**Gotcha**: The previous implementation used `scan_result.evaluation_result().is_passed()` which only reflected policy pass/fail. This caused High/Critical vulnerabilities to show as INFORMATION (blue) if the policy passed, which was confusing for users.
433
+
434
+
**When modifying severity logic**: Always base it on vulnerability counts/severity, not policy evaluation.
435
+
436
+
### 8.4 LSP Range Calculation
437
+
438
+
When parsing files to extract ranges for code lenses:
439
+
440
+
1.**Use position-aware parsers**: `marked_yaml` for YAML, custom parsers for Dockerfiles
441
+
2.**Account for quotes**: Image names might be quoted in YAML (`"nginx:latest"` or `'nginx:latest'`)
442
+
```rust
443
+
letmutraw_len=image_name.len();
444
+
ifletSome(c) =first_char&& (c=='"'||c=='\'') {
445
+
raw_len+=2; // Include quotes in range
446
+
}
447
+
```
448
+
3.**Test with various formats**: Unquoted, single-quoted, double-quoted values
449
+
4.**0-indexed LSP positions**: LSP uses 0-indexed line/character positions, but some parsers (like `marked_yaml`) use 1-indexed positions - convert accordingly:
450
+
```rust
451
+
letstart_line=start.line() asu32-1;
452
+
letstart_char=start.column() asu32-1;
453
+
```
454
+
455
+
### 8.5 Testing Patterns
456
+
457
+
**Unit Tests** (`#[cfg(test)]` in modules):
458
+
- Test parser logic in isolation
459
+
- Use string literals for test input
460
+
- Cover edge cases exhaustively
461
+
- Run fast (no I/O)
462
+
463
+
**Integration Tests** (`tests/general.rs`):
464
+
- Test full LSP flow: `did_open` → `code_lens` → `execute_command`
465
+
- Use fixtures from `tests/fixtures/`
466
+
- Mock external dependencies (ImageScanner) with `mockall`
0 commit comments