Skip to content

Replace tmpfs with bind mounts for .thvignore directory overlays to fix tmpcopyup - #1765

Merged
JAORMX merged 1 commit into
mainfrom
fix-thvignore-tmpcopyup
Sep 8, 2025
Merged

JAORMX merged 1 commit into
mainfrom
fix-thvignore-tmpcopyup

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

Problem

When using .thvignore to exclude sensitive directories (like .ssh/) from MCP server containers, the current implementation uses tmpfs mounts with the tmpcopyup option. This causes a critical security issue where the original directory contents are copied into the tmpfs overlay, defeating the purpose of ignoring these paths and potentially exposing secrets to MCP servers.

Root Cause

The tmpcopyup behavior in Docker/Podman automatically copies the contents of the original directory into the tmpfs mount when it's created. This means that even though we're trying to hide .ssh/ by overlaying it with tmpfs, the SSH keys and other sensitive files are still accessible inside the container.

Solution

This PR replaces tmpfs-based directory overlays with bind-mounted empty directories:

Key Changes:

  1. Modified pkg/ignore/processor.go:

    • Changed directory overlays from Type: "tmpfs" to Type: "bind"
    • Added createEmptyDirectory() method to create unique empty directories for each overlay
    • Implemented lifecycle management with artifact tracking and cleanup
    • Added workload-specific artifact directory under XDG runtime or temp directory
    • Fixed directory permissions to use 0750 for security
  2. Updated pkg/container/docker/client.go:

    • Removed tmpfs handling in addIgnoreOverlays() and convertMounts()
    • All overlays now consistently use bind mounts
  3. Enhanced tests:

    • Added TestGetOverlayMounts to verify all mounts are bind type
    • Added TestProcessorCleanup to verify artifact cleanup
    • Updated E2E tests to check for bind mounts instead of tmpfs

Benefits

  • Fixes security issue: No more tmpcopyup copying sensitive files into overlays
  • Consistent approach: Both files and directories now use bind mounts
  • Proper cleanup: Lifecycle management ensures temporary artifacts are cleaned up
  • SELinux compatible: Bind-mounting empty directories works well under SELinux
  • Thread-safe: Mutex protection for concurrent access

Testing

  • ✅ All unit tests pass
  • ✅ Linting issues resolved
  • ✅ E2E tests updated and passing
  • ✅ Verified no tmpfs mounts are created for overlays

Backward Compatibility

No changes to CLI flags or user-facing behavior. The implementation change is transparent to users while fixing the underlying security issue.

@JAORMX
JAORMX requested review from dmjb and yrobla September 8, 2025 08:22
@codecov

codecov Bot commented Sep 8, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.72840% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.70%. Comparing base (c1dfe18) to head (afd3ac4).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ignore/processor.go 71.42% 13 Missing and 7 partials ⚠️
pkg/container/docker/client.go 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1765      +/-   ##
==========================================
+ Coverage   40.55%   40.70%   +0.14%     
==========================================
  Files         184      184              
  Lines       21309    21420     +111     
==========================================
+ Hits         8642     8718      +76     
- Misses      12018    12042      +24     
- Partials      649      660      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls

coveralls commented Sep 8, 2025 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 38.454% (+0.1%) from 38.322%
when pulling afd3ac4 on fix-thvignore-tmpcopyup
into 02c003c on main.

@JAORMX
JAORMX force-pushed the fix-thvignore-tmpcopyup branch from c611147 to afd3ac4 Compare September 8, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants