Skip to content

Commit eba2637

Browse files
Mossakaclaude
andcommitted
fix: mount ~/.cargo read-only in chroot, hide only credentials file
The previous approach hid the entire ~/.cargo directory via tmpfs AND skipped mounting it unless --allow-full-filesystem-access was set. This broke Rust toolchain access in chroot mode (rustc not found). Now ~/.cargo is always mounted read-only in chroot mode for toolchain access, and only ~/.cargo/credentials is hidden via tmpfs to protect crates.io tokens. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 91d998a commit eba2637

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/docker-manager.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ describe('docker-manager', () => {
655655
expect(volumes).not.toContain(`${homeDir}:/host${homeDir}:rw`);
656656
});
657657

658-
it('should not mount .cargo when enableChroot is true and allowFullFilesystemAccess is false', () => {
658+
it('should mount .cargo read-only and hide only credentials when enableChroot is true and allowFullFilesystemAccess is false', () => {
659659
const configWithChroot = {
660660
...mockConfig,
661661
enableChroot: true,
@@ -666,14 +666,14 @@ describe('docker-manager', () => {
666666
const volumes = agent.volumes as string[];
667667
const tmpfs = agent.tmpfs as string[];
668668

669-
// Should NOT mount .cargo as volume (it's hidden via tmpfs)
669+
// Should mount .cargo as volume (read-only) so toolchain binaries are accessible
670670
const homeDir = process.env.HOME || '/root';
671671
const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
672-
const cargoVolumePattern = new RegExp(`${escapeRegExp(homeDir)}.*\\.cargo.*:/host.*\\.cargo`);
673-
expect(volumes.some((v: string) => cargoVolumePattern.test(v))).toBe(false);
672+
const cargoVolumePattern = new RegExp(`${escapeRegExp(homeDir)}/\\.cargo:/host.*\\.cargo:ro`);
673+
expect(volumes.some((v: string) => cargoVolumePattern.test(v))).toBe(true);
674674

675-
// Should have .cargo hidden via tmpfs
676-
expect(tmpfs.some((t: string) => t.includes('.cargo'))).toBe(true);
675+
// Should hide only .cargo/credentials via tmpfs (not the entire directory)
676+
expect(tmpfs.some((t: string) => t.includes('.cargo/credentials'))).toBe(true);
677677
});
678678

679679
it('should mount .cargo when enableChroot is true and allowFullFilesystemAccess is true', () => {

src/docker-manager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ export function generateDockerCompose(
503503
}
504504

505505
// Mount ~/.cargo for Rust binaries (read-only) if it exists
506-
// SKIP if allowFullFilesystemAccess is false (credentials will be hidden via tmpfs)
506+
// Credentials in ~/.cargo/credentials are hidden separately via tmpfs
507507
const hostCargoDir = path.join(userHome, '.cargo');
508-
if (fs.existsSync(hostCargoDir) && config.allowFullFilesystemAccess) {
508+
if (fs.existsSync(hostCargoDir)) {
509509
agentVolumes.push(`${hostCargoDir}:/host${hostCargoDir}:ro`);
510510
}
511511

@@ -705,7 +705,7 @@ export function generateDockerCompose(
705705
`${effectiveHome}/.azure`, // Azure credentials
706706
`${effectiveHome}/.config/gcloud`, // Google Cloud credentials
707707
`${effectiveHome}/.config/gh`, // GitHub CLI OAuth tokens
708-
`${effectiveHome}/.cargo`, // Rust crates.io tokens (credentials file)
708+
`${effectiveHome}/.cargo/credentials`, // Rust crates.io tokens
709709
`${effectiveHome}/.composer`, // PHP Composer tokens (auth.json)
710710
];
711711

@@ -739,7 +739,7 @@ export function generateDockerCompose(
739739
`${userHome}/.azure`, // Azure credentials
740740
`${userHome}/.config/gcloud`, // Google Cloud credentials
741741
`${userHome}/.config/gh`, // GitHub CLI OAuth tokens
742-
`${userHome}/.cargo`, // Rust crates.io tokens (credentials file)
742+
`${userHome}/.cargo/credentials`, // Rust crates.io tokens
743743
`${userHome}/.composer`, // PHP Composer tokens (auth.json)
744744
];
745745

0 commit comments

Comments
 (0)