Skip to content

fix: harden log directory management for ARC/DinD and rootless Docker#5963

Merged
lpcox merged 4 commits into
mainfrom
fix/log-directory-hardening
Jul 6, 2026
Merged

fix: harden log directory management for ARC/DinD and rootless Docker#5963
lpcox merged 4 commits into
mainfrom
fix/log-directory-hardening

Conversation

@lpcox

@lpcox lpcox commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses findings from the log directory management audit (#5962). After 9 permission/ownership bug fixes landed in ~10 days for ARC/DinD support, this PR hardens the implementation and adds documentation to prevent future regressions.

Changes

Bug fix: squid-logs onAfterEnsure instead of onCreate

Previously, squid-logs only got chown(13:13) when freshly created. If the directory pre-existed from a timeout-killed run with wrong ownership (e.g., root:root from Docker daemon auto-creation), the host-side chown wouldn't fire — relying implicitly on the container entrypoint preflight.

Now uses onAfterEnsure (matching the agent-logs/session-state pattern) so ownership is repaired on every invocation. Added double-fallback: if chown fails AND chmod fails, continue silently (container Layer 2 handles it).

Bug fix: retry Docker daemon probe in topology preflight

The --network-isolation preflight runs docker info with a 5-second timeout. On GitHub-hosted runners under load (concurrent service container healthchecks + image pulls during job startup), the daemon can be temporarily unresponsive, causing spurious CI failures.

Now retries 3 times with 2-second delays between attempts, tolerating transient daemon backpressure. Total worst-case delay is ~19s, acceptable for a fail-stop preflight that previously caused hard job failures.

Feature: MCP log pruning

/tmp/gh-aw/mcp-logs lives outside workDir and was never cleaned up, growing unboundedly on persistent runners. Now removes subdirectories older than 24 hours during prepareLogDirectories().

Documentation

  • Code comments: Added TRIPLE-LAYER DEFENSE documentation block in workdir-setup.ts explaining what each layer does, which topologies it covers, and why none should be removed.
  • docs/logging_quickref.md: Added "Log Directory Layout" section covering:
    • Default vs --proxy-logs-dir directory structure
    • The squid path asymmetry (writes directly to proxyLogsDir, no subdirectory)
    • MCP gateway logs location and pruning
    • Ownership & permissions model for ARC/DinD

Tests

  • repairs squid logs ownership even when directory pre-exists
  • tolerates both chown and chmod failure on squid logs (best-effort)
  • removes subdirectories older than 24 hours (MCP pruning)
  • skips files (only prunes directories)
  • tolerates unreadable directory without throwing
  • returns without exiting when daemon becomes reachable on retry
  • exits when the Docker daemon is unreachable after all retries
  • exits when the Docker daemon probe throws on all retries

Test Results

All existing + new tests pass (29 in workdir-setup, 9 in topology, 27 in related suites).

Closes #5962

Address findings from the log directory audit (#5962):

- Switch squid-logs from onCreate to onAfterEnsure so ownership is
  repaired even when the directory pre-exists from a timeout-killed run.
  Previously only newly-created dirs got chown(13:13); now pre-existing
  dirs with wrong ownership are also fixed. The container entrypoint
  preflight remains as defense-in-depth.

- Add tolerance for chmod failure on squid-logs (double fallback: if
  chown fails AND chmod fails, continue silently — the container
  entrypoint Layer 2 will handle it).

- Add age-based pruning for /tmp/gh-aw/mcp-logs: remove subdirectories
  older than 24 hours on each AWF invocation to prevent unbounded growth
  on persistent runners.

- Document the triple-layer defense pattern for squid log permissions
  directly in the code (workdir-setup.ts) explaining what each layer
  does and why none should be removed.

- Add log directory layout documentation to docs/logging_quickref.md
  covering the proxyLogsDir path asymmetry, ownership model, and
  ARC/DinD triple-layer defense.

- Add tests: pre-existing squid-logs ownership repair, double-fallback
  tolerance, MCP log directory pruning (stale removal, file skipping,
  error tolerance).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 6, 2026 16:08
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit 2e3232d

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.82% 98.82% ➡️ +0.00%
Statements 98.75% 98.75% ➡️ +0.00%
Functions 99.72% 99.72% ➡️ +0.00%
Branches 95.17% 95.15% 📉 -0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 97.6% → 97.8% (+0.25%) 97.6% → 97.8% (+0.26%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens AWF log directory management for ARC/DinD and rootless Docker by ensuring squid log ownership repairs run even when directories pre-exist, and by preventing unbounded growth of host-level MCP gateway logs. It also documents the log directory layout and the layered permission model to reduce regression risk.

Changes:

  • Switch squid logs directory repair from onCreate to onAfterEnsure with best-effort chownchmod fallback.
  • Add best-effort pruning of stale subdirectories under /tmp/gh-aw/mcp-logs (older than 24 hours).
  • Document log directory layout and the “triple-layer defense” permission model in docs/logging_quickref.md.
Show a summary per file
File Description
src/workdir-setup.ts Repairs squid log dir ownership on every run and prunes stale MCP log subdirectories.
src/workdir-setup.test.ts Adds regression tests for squid ownership repair and MCP log pruning behavior.
docs/logging_quickref.md Documents log directory layout, squid path asymmetry, MCP log location/pruning, and layered permissions.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread src/workdir-setup.ts
Comment thread docs/logging_quickref.md Outdated
lpcox and others added 2 commits July 6, 2026 09:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@lpcox Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

PR #5963 follows the applicable CONTRIBUTING.md guidelines: clear description with issue reference, tests included for functionality, documentation updated, and files are organized appropriately.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — Service connectivity failed ⚠️

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Chroot tests failed Smoke Chroot failed - See logs for details.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) reports failed. AOAI BYOK (Entra) mode investigation needed...

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) reports failed. AOAI BYOK (api-key) mode investigation needed...

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.82% 98.82% ➡️ +0.00%
Statements 98.75% 98.75% ➡️ +0.00%
Functions 99.72% 99.72% ➡️ +0.00%
Branches 95.17% 95.15% 📉 -0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 97.6% → 97.8% (+0.25%) 97.6% → 97.8% (+0.26%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

1 similar comment
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.82% 98.82% ➡️ +0.00%
Statements 98.75% 98.75% ➡️ +0.00%
Functions 99.72% 99.72% ➡️ +0.00%
Branches 95.17% 95.15% 📉 -0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 97.6% → 97.8% (+0.25%) 97.6% → 97.8% (+0.26%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) reports failed. AOAI BYOK (Entra) mode investigation needed...

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Chroot tests failed Smoke Chroot failed - See logs for details.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) reports failed. AOAI BYOK (api-key) mode investigation needed...

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

No GitHub write action yet; preparing required smoke-test reads and build.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.82% 98.82% ➡️ +0.00%
Statements 98.75% 98.76% 📈 +0.01%
Functions 99.72% 99.72% ➡️ +0.00%
Branches 95.17% 95.15% 📉 -0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 97.6% → 97.8% (+0.25%) 97.6% → 97.8% (+0.26%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Result
API Status ✅ PASS
GH Check ✅ PASS
File Status ✅ PASS

Overall Result: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Smoke Claude for #5963 · 55.6 AIC · ⊞ 5.8K ·
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP Connectivity
GitHub.com HTTP ✅ (200)
File Write/Read ⚠️ (template vars unexpanded in workflow)

Overall: PASS

cc @lpcox

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results

  • GitHub MCP: ❌ (mcpscripts not found)
  • GitHub.com: ❌ (HTTP 000)
  • File Writing: ✅
  • Bash Tool: ✅

Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Services Connectivity

  • Redis PING: ❌ Network is unreachable
  • PostgreSQL pg_isready: ❌ No response
  • PostgreSQL SELECT 1: ❌ Network is unreachable

Result: FAILhost.docker.internal (172.17.0.1) is unreachable. GitHub Actions service containers may not be running or the network bridge is not accessible.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot PAT Auth

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ 200
File write/read ✅ Verified

Overall: PASS

@lpcox — Auth mode: PAT (COPILOT_GITHUB_TOKEN)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 PAT report filed by Smoke Copilot PAT
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🔭 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Status Detail
Module Loading otel.js loads successfully; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
Test Suite 59 tests passed, 0 failed (suites: otel.test.js, otel-fanout.test.js)
Env Var Forwarding src/services/api-proxy-env-config.ts forwards OTEL_* and GITHUB_AW_OTEL_* vars; covered by agent-environment-credentials.test.ts
Token Tracker Integration onUsage callback exists in token-tracker-http.js (lines 283, 324) as OTEL hook point
OTEL Diagnostics 1 span exported to /tmp/gh-aw/otel.jsonl (local file fallback — no OTLP endpoint configured)

Result: All scenarios pass. OTEL tracing integration is fully functional.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx all passed ✅ PASS
Node.js execa all passed ✅ PASS
Node.js p-limit all passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Notes
  • Bun: v1.3.14, both projects used built-in packages
  • C++: CMake + GCC 13.3.0, both static libraries built successfully
  • Deno: deps downloaded from deno.land
  • .NET: dotnet 8.0, NuGet packages restored successfully
  • Go: v1.22.12, all modules used local stdlib only
  • Java: Maven with custom local repo path to bypass ~/.m2/repository permissions issue
  • Node.js: node v22.23.1, all packages installed successfully
  • Rust: cargo built from source, all unit tests passed

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Build Test Suite for #5963 · 43.4 AIC · ⊞ 6.9K ·
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode)

PR: fix: harden log directory management for ARC/DinD and rootless Docker
Author: @lpcox | Assignees: none

Test Result
GitHub MCP connectivity ✅ GitHub API reachable
GitHub.com HTTP ✅ HTTP 200
File write/read ⚠️ Pre-fetched data unavailable (template vars unresolved)
BYOK inference (api-proxy → api.githubcopilot.com) ✅ Responding via direct BYOK mode

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) via api-proxy → api.githubcopilot.com

Overall: PASS (1 data warning — pre-fetch step template substitution failed)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

fix: harden log directory management for ARC/DinD and rootless Docker\nMerged PRs: fix: tolerate EROFS when chmod on pre-existing mcp-logs dir fails; fix: handle EPERM when chmod'ing pre-existing mcp-logs directory\nGitHub reads: ✅\nPlaywright: ✅\nFile write: ✅\nDiscussion comment: ✅\nBuild: ❌\nOverall: FAIL

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit: Log directory management — findings and recommendations after ARC/DinD fixes

2 participants