Vagrant Synced Folder Permission Mismatch Between Local Development and CI Production Environments
0 reputation · 22 Jul 2022, 16:09 UTC
0 reputation · 22 Jul 2022, 16:09 UTC
In a Vagrant setup, the shared folder is mounted using rsync on Linux and SMB on Windows, which relies on matching user IDs between the host and the guest.
When the host's effective user ID differs from the guest's UID—common in CI pipelines or after OS upgrades—the mounted files become inaccessible, causing build failures despite working locally.
The configuration must guarantee consistent file access regardless of host UID variations, yet the current Vagrantfile lacks a mechanism to enforce a stable ownership model across environments.
Can the Vagrantfile be adjusted to preserve file permissions across differing host UIDs, can provisioner settings enforce UID consistency, and does using a dedicated guest user mitigate the issue?
Yes. Make ownership a property of the guest, not the host. Use a dedicated guest build account with a fixed UID/GID and set explicit ownership on the synced folder. Do not try to make every CI host match your laptop UID; that is the fragile part.
Likely explanation: your CI runner has a different effective UID/GID than your local host. With Linux shared-folder or rsync workflows, the guest then sees files as an unexpected numeric owner, so the build user cannot read or write. CI image changes or OS upgrades can shift the runner UID while your local machine stays the same.
Confirmed behavior to rely on: Vagrant synced folders support explicit ownership configuration; rsync is one-way by default; Windows SMB does not map a Windows account to a Linux UID by equality; SELinux or AppArmor can still deny access even when POSIX ownership looks correct.
groupadd -g 1050 build
useradd -m -u 1050 -g 1050 buildconfig.vm.synced_folder ".", "/vagrant",
type: "virtualbox",
owner: "build",
group: "build",
mount_options: ["uid=1050", "gid=1050", "dmode=775", "fmode=664"]Use either owner/group or numeric mount_options consistently for your provider; do not assume every provider honors the same options.rsync --help | grep -E 'chmod|chown|usermap|groupmap'Then use only documented options, for example permission and time flags. Do not rely on a --chown option unless your rsync version documents it.A provisioner can create the fixed guest user or chown the mounted path after it appears, but it cannot change the host's UID. If the host identity is known at runtime, you can align the guest user to that UID, but that reintroduces variability across machines. Prefer a fixed guest identity. If you must change an existing user's UID/GID, be careful: usermod and groupmod can orphan ownership on existing files.
| Mechanism | Best use | Ownership control | Main caveat |
|---|---|---|---|
| Linux shared folder | Two-way local and CI edits | Explicit owner/group or uid/gid mount options | Provider option support varies |
| rsync | One-way host-to-guest sync | Permission flags during transfer | Guest changes do not flow back by default |
| Windows SMB | Windows hosts needing shared access | Guest mount uid/gid and modes | Windows identity does not map to POSIX UID by equality |
Reload or re-sync the folder, then check numeric ownership and write access inside the guest:
ls -ln /vagrant
id build
stat -c '%u %g %a %n' /vagrant
touch /vagrant/.write-test && rm /vagrant/.write-testOne detail would change the recommendation: does CI need files written inside the guest to persist back to the host? If yes, rsync alone is the wrong default because it is one-way; use a shared-folder or SMB mount with explicit ownership, or add an explicit reverse sync step.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.