Repository navigation
feat(build_stream): add log query API with response-time redaction - #5803
Rajeshkumar-s2 merged 2 commits into
Conversation
Implements a read-only log query API for Build Stream that allows authenticated clients to retrieve stage log content with response-time redaction of sensitive data. The API enforces job ownership, path traversal protection, rate limiting, and concurrency limits. Existing job detail endpoint is extended with log metadata fields. Related: dell#5733
24350c6 to
62ee38f
Compare
FVT code has not been validated in a lab environment yet and will be included in a follow-up PR.
abhishek-sa1
left a comment
There was a problem hiding this comment.
Based on my analysis of PR #5803 against ER-BSM-003 and Story ER-BSM-003-log-query-api-and-redaction , here's the
alignment assessment:
✅ Aligned Components
The PR correctly implements:
- FR-2.1: Log Query Endpoint ✅
• GET /api/v1/jobs/{job_id}/logs endpoint with tail_lines , stage , full parameters
• Job ownership enforcement (404 for non-owned jobs)
• Path traversal protection (409 + security event logging)
• Rate limiting (60 req/min, 429 response)
• Concurrency limiting (5 concurrent, 503 response)
• Response-size bounding (10 MiB default, truncated flag) - FR-2.2: Stage Enumeration ✅
• Extended GET /api/v1/jobs/{job_id} with has_log and log_lines per stage
• Host-to-container path translation implemented
• In-progress stage handling (404 for logs not yet available) - FR-3.2: API-Response-Time Redaction ✅
• Tier 1 redaction patterns (secrets, tokens, passwords)
• Tier 2 patterns (IPs, emails) - though story says "audit only"
• RedactionService with tiered application
• Fail-closed behavior (lines suppressed on redaction error) - Security Controls ✅
• Binary file detection (NUL byte rejection)
• Private key block handling (multi-line PEM tracking)
• Bounded quantifiers in regex patterns (prevents catastrophic backtracking)
• Audit logging for all queries - Configuration ✅
• All required config parameters in build_stream.ini
• Safe defaults provided
• Range validation implemented
❌ Missing Components
FR-3.1: Write-Time Log Sanitization - NOT IMPLEMENTED
The story requires:
• Remove ANSIBLE_LOG_PATH from subprocess environment
• Capture output via Popen(stdout=PIPE, stderr=STDOUT)
• Apply Tier 1 redaction line-by-line before disk write
• Handle encoding errors, partial lines, timeout drain
PR status: The PR does NOT modify playbook_watcher_service.py to implement write-time redaction. This is a significant
gap because:
• Defense-in-depth is incomplete (only API-layer redaction exists)
• If logs are leaked from disk before API query, they contain unredacted secrets
• The story explicitly states "No unsanitized byte reaches any log file on disk"
- FVT Exclusion
• FVTs were removed in commit d6414f0 because they haven't been validated in a lab
• Story requires FVT validation for ER closure
• This defers integration testing to a follow-up PR - Tier 2 Redaction Scope
• Story says Tier 2 (PII: IPs, emails) is "audit only"
• PR implements Tier 2 as a selectable tier in the API
• This may be intentional but should be clarified - Story Status
• Story metadata shows status: "draft"
• Story should be in_progress or done for implementation PRs
Recommendation
Do NOT approve this PR as-is for Story completion because:
- FR-3.1 (write-time redaction) is completely missing - this is a critical security requirement
- FVT validation is deferred - ER closure requires passing tests on a single build
Suggested path forward:
- Option A: Request that the author add write-time redaction implementation before merge
- Option B: Split the PR into two parts:
• Part 1: API query + response-time redaction (current PR)
• Part 2: Write-time redaction + watcher modification
• Update Story to reflect this split - Option C: Update the Story to remove FR-3.1 from scope if defense-in-depth is no longer required (needs architect
approval)
The code quality is excellent, but the implementation is incomplete relative to the Story specification.
Approving PR now. Please take care of this in next PR
I left write time redaction intentionally considering the nature of changes in watcher service which will also require a change for the image for the monday's demo purpose. I had this plan post the demo. |
067e03c
into
dell:release_2.3.0.0-rc2.1
PR Title
feat(build_stream): add log query API with response-time redaction
Description of the Solution
Implements a read-only log query API for Build Stream that allows authenticated clients to retrieve stage log content with response-time redaction of sensitive data. The API enforces job ownership, path traversal protection, rate limiting, and concurrency limits. Existing job detail endpoint is extended with log metadata fields.
Related Issue
Changes
Component (
src/build_stream/app/api/logs/)/api/v1/jobs/{job_id}/logsendpointComponent (
src/build_stream/app/core/logs/)Component (
src/build_stream/app/infra/logs/)Component (
src/build_stream/app/orchestrator/logs/)Component (
src/build_stream/app/api/jobs/)GET /jobs/{id}withhas_logandlog_linesfields per stageComponent (
src/build_stream/app/api/router.py)Component (
src/build_stream/app/build_stream.ini)[log_query]configuration section with safe defaultsComponent (
src/build_stream/app/common/config.py)Component (
test/build_stream/)Files Changed
src/build_stream/app/api/logs/__init__.pysrc/build_stream/app/api/logs/dependencies.pysrc/build_stream/app/api/logs/limiter.pysrc/build_stream/app/api/logs/routes.pysrc/build_stream/app/api/logs/schemas.pysrc/build_stream/app/api/router.pysrc/build_stream/app/api/jobs/routes.pysrc/build_stream/app/api/jobs/schemas.pysrc/build_stream/app/core/logs/__init__.pysrc/build_stream/app/core/logs/exceptions.pysrc/build_stream/app/core/logs/redaction.pysrc/build_stream/app/core/logs/redaction_patterns.pysrc/build_stream/app/core/logs/services.pysrc/build_stream/app/infra/logs/__init__.pysrc/build_stream/app/infra/logs/filesystem_adapter.pysrc/build_stream/app/orchestrator/logs/__init__.pysrc/build_stream/app/orchestrator/logs/use_cases/__init__.pysrc/build_stream/app/orchestrator/logs/use_cases/query_logs.pysrc/build_stream/app/orchestrator/logs/use_cases/stage_log_metadata.pysrc/build_stream/app/build_stream.inisrc/build_stream/app/common/config.pytest/build_stream/nft/unit/api/logs/test/build_stream/nft/unit/core/logs/test/build_stream/nft/unit/infra/logs/test/build_stream/nft/unit/orchestrator/logs/test/build_stream/nft/unit/common/test_log_query_config.pytest/build_stream/fvt/log_query/test/build_stream/library/functions/log_query_func.pytest/build_stream/_run.pytest/build_stream/library/functions/validation_func.pytest/build_stream/library/vars/domain_vars.pytest/build_stream/library/vars/test_case_vars.pytest/build_stream/test_config.ymlTesting
Unit Tests:
Functional Verification Tests (FVT):
run_validation.shSecurity:
Backward Compatibility
No breaking changes.
GET /api/v1/jobs/{job_id}/logs)GET /jobs/{id}endpoint extended with new fields (backward compatible)Suggested Reviewers