Refactor Command Run Attestation with Enhanced Tracing and Multi-Exporter Support
Overview
This issue tracks the comprehensive refactoring of the command run attestation to improve its architecture, add network tracing capabilities, support cross-platform program hashing, and implement the multi-exporter pattern for better attestation granularity.
Motivation
The current command run attestation has several limitations:
- Tracing is Linux-only with limited syscall coverage (only EXECVE and OPENAT)
- No network activity tracking
- Process trace data is embedded in the main attestation, making it bulky
- No cross-platform support for program hash calculation
- Limited visibility into script execution and interpreter usage
Goals
- Implement Multi-Exporter Pattern: Separate trace data from the main command attestation into a single trace attestation containing the complete process tree
- Enhanced Tracing: Add network syscall tracing and file write tracking
- Cross-Platform Support: Implement program hash calculation for Windows and macOS
- Improved Schema: Add timing, network operations, and process relationship data
- Clean Architecture: Create platform-agnostic interfaces with OS-specific implementations
- Performance Optimization: Make expensive operations like file hashing configurable to balance security and performance
Detailed Requirements
1. Multi-Exporter Implementation
2. Enhanced Linux Tracing
New System Calls to Trace:
Additional Process Information:
Performance Configuration:
3. Cross-Platform Program Hashing
Linux Enhancements:
Windows Support:
macOS Support:
4. Updated Schema
type ProcessInfo struct {
// Existing fields...
// New fields
StartTime time.Time `json:"starttime,omitempty"`
EndTime time.Time `json:"endtime,omitempty"`
UserTime time.Duration `json:"usertime,omitempty"`
SystemTime time.Duration `json:"systemtime,omitempty"`
NetworkActivity []NetworkOperation `json:"networkactivity,omitempty"`
FileWrites map[string]cryptoutil.DigestSet `json:"filewrites,omitempty"`
ChildProcesses []int `json:"childprocesses,omitempty"`
SignalsReceived []SignalInfo `json:"signalsreceived,omitempty"`
}
type NetworkOperation struct {
Syscall string `json:"syscall"`
Timestamp time.Time `json:"timestamp"`
LocalAddr string `json:"localaddr,omitempty"`
RemoteAddr string `json:"remoteaddr,omitempty"`
Protocol string `json:"protocol,omitempty"`
BytesSent int64 `json:"bytessent,omitempty"`
BytesRecv int64 `json:"bytesrecv,omitempty"`
SocketFD int `json:"socketfd,omitempty"`
}
5. Architecture Refactoring
Create clean abstractions:
// tracer.go
type TracerOptions struct {
EnableHashing bool // Enable file/program digest calculation
EnableNetworkTrace bool // Enable network syscall tracing
}
type Tracer interface {
Start(cmd *exec.Cmd) error
Wait() error
GetProcessTree() []ProcessInfo // Returns complete process tree
}
// Platform-specific implementations:
// - tracer_linux.go (ptrace-based)
// - tracer_windows.go (WMI/ETW-based)
// - tracer_darwin.go (dtrace/libproc-based)
Implementation Plan
Phase 1: Multi-Exporter Support
- Implement
MultiExporter interface on CommandRun
- Create
TraceAttestation type that contains the complete process tree
- Export single trace attestation per command execution
- Update attestation collection logic to exclude trace data from main attestation
- Add configuration options for tracing features
Phase 2: Enhanced Linux Tracing
- Add network syscall tracing
- Implement file write tracking
- Add timing and process relationship data
- Update process info collection
Phase 3: Cross-Platform Support
- Design and implement
Tracer interface
- Add Windows process monitoring
- Add macOS process monitoring
- Implement script detection across platforms
Phase 4: Testing and Documentation
- Comprehensive test suite
- Performance benchmarks
- Update documentation
- Migration guide for schema changes
Testing Strategy
Local Development (macOS ARM)
- Use Docker Desktop for Linux testing with
--privileged flag
- Native macOS tests for Darwin-specific code
- Cross-platform unit tests
Test Infrastructure
# Linux tracing tests
docker run --rm -it --privileged \
--platform linux/arm64 \
-v "$(pwd)":/workspace \
golang:1.21-alpine \
sh -c 'apk add gcc musl-dev linux-headers && go test -v -tags=linux ./attestation/commandrun/...'
CI/CD Pipeline
- Matrix testing across Linux/Windows/macOS
- Architecture testing (amd64/arm64)
- Performance regression tests
Success Criteria
Risks and Mitigations
-
Performance Impact: Network tracing and file hashing add significant overhead
- Mitigation: Make network tracing opt-in via configuration
- Mitigation: Make file/program hashing optional (can be disabled for performance-sensitive uses)
-
Platform Compatibility: Different OS have different APIs
- Mitigation: Graceful degradation with clear error messages
-
Security: Ptrace restrictions (Yama LSM) on Linux
- Mitigation: Detect and report restrictions clearly
-
Large Process Trees: Complex builds may spawn hundreds of processes
- Mitigation: Single trace attestation maintains context while keeping main attestation lightweight
References
- Current implementation:
/attestation/commandrun/
- Multi-exporter pattern:
/attestation/factory.go
- Example exporter:
/attestation/sbom/sbom.go
Related Issues
- #[previous issue number] - Add multi-exporter support
- #[previous issue number] - Improve attestation schema versioning
Labels: enhancement, refactoring, command-run, tracing, multi-platform
Assignees: TBD
Milestone: v0.2.0
Refactor Command Run Attestation with Enhanced Tracing and Multi-Exporter Support
Overview
This issue tracks the comprehensive refactoring of the command run attestation to improve its architecture, add network tracing capabilities, support cross-platform program hashing, and implement the multi-exporter pattern for better attestation granularity.
Motivation
The current command run attestation has several limitations:
Goals
Detailed Requirements
1. Multi-Exporter Implementation
CommandRunimplement theMultiExporterinterfaceTraceAttestationtype for trace-specific data containing the complete process treecommand-run/trace2. Enhanced Linux Tracing
New System Calls to Trace:
SYS_SOCKET- Socket creationSYS_CONNECT- Outbound connectionsSYS_BIND- Port bindingSYS_LISTEN- Server setupSYS_ACCEPT/SYS_ACCEPT4- Incoming connectionsSYS_SEND/SYS_SENDTO/SYS_SENDMSG- Data transmissionSYS_RECV/SYS_RECVFROM/SYS_RECVMSG- Data receptionSYS_WRITE/SYS_WRITEV- File write operationsAdditional Process Information:
Performance Configuration:
3. Cross-Platform Program Hashing
Linux Enhancements:
/proc/[pid]/exeapproachWindows Support:
GetModuleFileNameExorQueryFullProcessImageNamemacOS Support:
proc_pidpathorsysctlwithKERN_PROCARGS24. Updated Schema
5. Architecture Refactoring
Create clean abstractions:
Implementation Plan
Phase 1: Multi-Exporter Support
MultiExporterinterface onCommandRunTraceAttestationtype that contains the complete process treePhase 2: Enhanced Linux Tracing
Phase 3: Cross-Platform Support
TracerinterfacePhase 4: Testing and Documentation
Testing Strategy
Local Development (macOS ARM)
--privilegedflagTest Infrastructure
CI/CD Pipeline
Success Criteria
Risks and Mitigations
Performance Impact: Network tracing and file hashing add significant overhead
Platform Compatibility: Different OS have different APIs
Security: Ptrace restrictions (Yama LSM) on Linux
Large Process Trees: Complex builds may spawn hundreds of processes
References
/attestation/commandrun//attestation/factory.go/attestation/sbom/sbom.goRelated Issues
Labels: enhancement, refactoring, command-run, tracing, multi-platform
Assignees: TBD
Milestone: v0.2.0