Repository navigation
fix(update): give staged plugin dir the plugin home's permissions - #833
Conversation
The update path staged the plugin in an os.MkdirTemp directory (mode 0700) and moved it into place without touching the mode, so the updated plugin ended up unreadable and unexecutable for every other user sharing the VFOX_HOME. The add path already chmods the staged directory to the plugin home's mode; factor that out and apply it on update too. Fixes version-fox#829
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #833 +/- ##
==========================================
+ Coverage 61.98% 63.16% +1.18%
==========================================
Files 125 125
Lines 9810 9910 +100
==========================================
+ Hits 6081 6260 +179
+ Misses 3207 3119 -88
- Partials 522 531 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
linghengqian
left a comment
There was a problem hiding this comment.
Not ready to merge at d096934.
matchPluginsDirMode sets the mode on the staging directory before util.MovePath runs. That only holds when the move is a rename. When the staging directory and VFOX_HOME are on different filesystems, MovePath falls back to copyDir (internal/shared/util/file.go:194), and copyDir creates the top-level directory with os.MkdirAll(dst, info.Mode().Perm()) (file.go:199). The umask applies to that call, so the mode the helper set is lost.
Reproduced with VFOX_HOME on a different filesystem from $HOME and umask 077: after vfox update tool, the plugin directory is 700 while the plugin home is 755. The same update with umask 022, or with both directories on one filesystem, leaves the directory at 755.
Suggested fix: apply the mode to the installed path after the move has succeeded, in Update (internal/manager.go:355-357) and in Add (internal/manager.go:719-721). That covers the rename and the copy path. The new test puts both directories under one t.TempDir(), so it only exercises the rename path. A case that goes through the copy path would keep this from coming back.
The staging chmod only held when the move was a rename. On a cross-filesystem move, MovePath falls back to copyDir, which creates the top-level directory through os.MkdirAll, and the umask masks the mode back down: with umask 077 the updated plugin ended at 0700 while the plugin home was 0755. Apply the mode to the installed path after the move in Update and Add so both the rename and the copy path keep it. The new test stages on /dev/shm, a filesystem separate from the plugin home, under umask 077, so the copy path stays covered.
|
Thanks for the careful review, @linghengqian. You were right about the copy path: the staging chmod only survived a rename, and a cross-filesystem move lost the mode to the umask in copyDir's os.MkdirAll. Reworked in 6479de8:
|
Summary
Fixes #829.
installPluginToTempstages plugins in anos.MkdirTempdirectory, which is always created with mode0700.Updatethen moves that directory intoShared.Pluginsviautil.MovePathwithout changing its mode, so avfox updateleaves the plugin directory at0700and every other user sharing theVFOX_HOMEloses read and execute access to it.Addalready chmods the staged directory to the plugin home's mode before the move. This change factors that logic intoManager.matchPluginsDirModeand calls it on the update path too, so both paths normalize the staged directory's permissions the same way.Testing
TestUpdatePluginDirTakesPluginHomePermissions, which installs a plugin, updates it through the registry path, and asserts the resulting plugin directory has the plugin home's permission bits. It failed before the fix (mode = 700, want 755) and passes after.go test ./internal/passes.