-
Notifications
You must be signed in to change notification settings - Fork 10
feat(docker): Add docker-compose parser with security queries #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Owner
Author
Merged
2 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #419 +/- ##
==========================================
+ Coverage 81.10% 81.44% +0.34%
==========================================
Files 81 83 +2
Lines 8172 8393 +221
==========================================
+ Hits 6628 6836 +208
- Misses 1287 1294 +7
- Partials 257 263 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
This was referenced Dec 9, 2025
Owner
Author
Merge activity
|
Implements comprehensive docker-compose.yml parsing support: **YAML Parser Infrastructure:** - YAMLGraph and YAMLNode structures for generic YAML parsing - Support for scalar, mapping, and sequence node types - ParseYAML() and ParseYAMLString() entry points - Helper methods: Query(), HasChild(), GetChild(), ListValues(), StringValue() **ComposeGraph Wrapper:** - Service, volume, and network indexing for fast lookups - Version detection and metadata tracking - Thin wrapper over YAMLGraph with compose-specific methods **Security Query Methods:** - GetPrivilegedServices() - Detects privileged: true containers - ServicesWithDockerSocket() - Finds Docker socket mounts (/var/run/docker.sock) - ServiceHasSecurityOpt() - Checks security_opt values (e.g., seccomp:unconfined) - ServiceHasCapability() - Validates cap_add/cap_drop settings - ServicesWithHostNetwork() - Identifies network_mode: host usage - ServicesWithoutReadOnly() - Finds writable containers - ServiceExposesPort() - Port mapping validation - ServiceHasEnvVar() - Environment variable checks (array and map formats) **Test Coverage:** - 20 comprehensive test cases covering all query methods - Edge case handling (empty compose, missing sections, both env formats) - 100% coverage on all new code Files added: - sast-engine/graph/parser_yaml.go (YAML infrastructure) - sast-engine/graph/parser_compose.go (ComposeGraph wrapper) - sast-engine/graph/parser_compose_test.go (comprehensive tests) Part of: Dockerfile & Docker Compose Support Stacked on: docker/03-instruction-converters (#418) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Improves test coverage from 71% to 100% by adding:
**parser_yaml_test.go (NEW):**
- Tests for ParseYAML() file reading and error handling
- Tests for ParseYAMLString() with valid/invalid YAML
- Tests for convertToYAMLNode() with all data types:
- Scalars (string, int, bool, nil)
- map[string]interface{} mappings
- map[interface{}]interface{} mappings (YAML v3)
- Sequences (arrays)
- Nested structures
- Tests for YAMLGraph.Query() with various scenarios
- Tests for YAMLNode methods: HasChild, GetChild, ListValues, StringValue, BoolValue
- Edge case testing: nil nodes, missing children, invalid types
**parser_compose_test.go (expanded):**
- Tests for ParseDockerCompose() file reading
- Error handling tests for all security query methods
- Edge case testing:
- Non-existent services
- Missing volumes/capabilities/security_opt
- Invalid port formats
- Non-string volume entries
- Both environment variable formats (array and map)
- Tests for ServiceGet() with different value types (string, int, bool)
- Tests for network and volume indexing
- cap_drop testing (in addition to cap_add)
**Coverage improvements:**
- parser_yaml.go: 56% → 100%
- parser_compose.go: 78.76% → 100%
- Total patch coverage: 71% → 100%
All 50+ new test cases pass with 0 linting issues.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
07646b5 to
c99803c
Compare
shivasurya
added a commit
that referenced
this pull request
Dec 10, 2025
## Summary
Implements the core Python DSL for writing Dockerfile and docker-compose security rules.
## Changes
**Decorators:**
- `@dockerfile_rule` - Register Dockerfile security rules
- `@compose_rule` - Register docker-compose security rules
**Dockerfile Matchers:**
- `instruction()` - Match instructions with 30+ parameters (FROM, USER, EXPOSE, ARG, etc.)
- `missing()` - Detect missing instructions
**Docker Compose Matchers:**
- `service_has()` - Match service properties with various operators
- `service_missing()` - Detect missing service properties
**IR Compilation:**
- `compile_all_rules()` - Convert rules to JSON IR for Go executor
- `compile_to_json()` - Export to JSON string
- `write_ir_file()` - Write to file
## Example Usage
```python
from rules import dockerfile_rule, instruction, missing
@dockerfile_rule(id="DOCKER-001", severity="HIGH", cwe="CWE-250")
def container_runs_as_root():
return missing(instruction="USER")
@dockerfile_rule(id="DOCKER-002", severity="MEDIUM")
def uses_latest_tag():
return instruction(type="FROM", image_tag="latest")
```
## Testing
- 41 tests with 100% coverage
- All linting checks pass
## Stack
- Depends on: #419 (Docker Compose Parser)
- Part of: Dockerfile & Docker Compose Support
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Summary
Adds docker-compose.yml parsing support with security-focused query methods for detecting misconfigurations.
Stacked on: docker/03-instruction-converters (#418)
Changes
Checklist
gradle testGo)gradle lintGo)