mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
feat(gitprotect): on Linux, warn at each launch and report .git hooks and config that changed (#20)
Linux hosts have no unprivileged immutable flag, so devvm can't lock .git there. It now warns at every launch of a VM that mounts a folder with a .git (git_unprotected), unless it's a --clone VM or the user chose devvm git-protect off (git.chosen), and it names, after the fact, the hooks and config that changed (git_changed). It sums what a lock would cover, .git/commondir, include.path targets and the folder core.hooksPath names, never through a symlink out of the project folder and within bounds (git_watch_blind names what it can't fully watch), at each launch that finds the VM stopped and at devvm stop. A check on such a host runs protect's reports without locking: git_replaced, git_commondir, stray worktrees, git dirs that appeared, core.hooksPath and delegations into the project folder, and a submodule's folder that isn't a git dir (git_gitdir_not_git), in which nothing is created and which the watch doesn't sum as a git dir. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
30 files changed
+1261
-97
No files matched your search
Vendored
+3
-1
@@ -10,7 +10,9 @@ vm_name WEB web
|
||||
stub_reset
|
||||
exec devvm
|
||||
! stdout 'starting|creating'
|
||||
! stderr .
|
||||
# Each launch on Linux says .git is unprotected (git_watch.txtar).
|
||||
[!linux] ! stderr .
|
||||
[linux] stderr '\Adevvm: git_unprotected vm=devvm-web-[0-9a-f]{14}\n\z'
|
||||
stub_calls
|
||||
! stdout 'limactl (start|stop|clone|create|edit|delete)'
|
||||
stdout '^limactl shell --workdir / devvm-web-[0-9a-f]{14} sh -c .*tar -xf - '
|
||||
|
||||
Vendored
+1
-1
@@ -22,7 +22,7 @@ exec devvm git-protect
|
||||
[darwin] stdout '\Aon\n\z'
|
||||
[linux] stdout '\Aoff\n\z'
|
||||
[linux] exec devvm git-protect off
|
||||
[linux] stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
|
||||
[linux] stdout '^==> git_unprotected_quiet vm=devvm-web-[0-9a-f]{14}$'
|
||||
[linux] ! exec devvm git-protect strict
|
||||
[linux] stderr '^devvm: git_protect_on_needs_macos$'
|
||||
[linux] stop 'no locks off macOS'
|
||||
|
||||
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
# On a host without .git locks (Linux), each launch warns that the VM can
|
||||
# change the hooks and config in .git, until devvm git-protect off says
|
||||
# the user knows. Each launch that finds the VM stopped, and devvm stop,
|
||||
# name what changed of what a lock would cover since the last check: the
|
||||
# new VM's first sums are recorded when it's made, and a VM with none
|
||||
# recorded (an older devvm's) records its first without naming anything.
|
||||
# A --clone VM mounts no .git, so neither applies.
|
||||
[!linux] skip 'macOS locks .git: git_protect.txtar'
|
||||
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
|
||||
|
||||
# A new VM: warned, its first sums recorded, nothing named.
|
||||
project web git
|
||||
exec devvm --network open
|
||||
vm_name WEB web
|
||||
stderr '^devvm: git_unprotected vm=devvm-web-[0-9a-f]{14}$'
|
||||
! stderr git_changed
|
||||
vm_state $WEB_dir/vm.json
|
||||
stdout '^git.watched.scanned=true$'
|
||||
stdout '^git.watched.sums..git/config=sha256 [0-9a-f]{64}$'
|
||||
! stdout 'git.chosen'
|
||||
|
||||
# While it runs, a launch warns again and checks nothing.
|
||||
exec git config core.fsmonitor ./evil
|
||||
cp $WORK/hook .git/hooks/pre-commit
|
||||
exec devvm
|
||||
stderr '^devvm: git_unprotected vm=devvm-web-[0-9a-f]{14}$'
|
||||
! stderr git_changed
|
||||
|
||||
# devvm stop names what changed, once.
|
||||
exec devvm stop
|
||||
stderr '^devvm: git_changed paths=\.git/config, \.git/hooks/pre-commit vm=devvm-web-[0-9a-f]{14}$'
|
||||
! stderr git_unprotected
|
||||
exec devvm stop
|
||||
! stderr git_changed
|
||||
|
||||
# So does a launch that finds it stopped, before it starts.
|
||||
exec limactl stop $WEB
|
||||
rm .git/hooks/pre-commit
|
||||
exec devvm
|
||||
stderr '^devvm: git_changed paths=\.git/hooks/pre-commit vm=devvm-web-[0-9a-f]{14}$'
|
||||
|
||||
# devvm git-protect off is the user's choice: the warning stops, the watch
|
||||
# goes on.
|
||||
exec devvm git-protect off
|
||||
stdout '^==> git_unprotected_quiet vm=devvm-web-[0-9a-f]{14}$'
|
||||
vm_state $WEB_dir/vm.json
|
||||
stdout '^git.chosen=true$'
|
||||
exec devvm
|
||||
! stderr git_unprotected
|
||||
exec git config core.sshCommand ./evil
|
||||
exec devvm stop
|
||||
stderr '^devvm: git_changed paths=\.git/config vm=devvm-web-[0-9a-f]{14}$'
|
||||
|
||||
# A VM an older devvm made has no sums: its first check records them and
|
||||
# names nothing.
|
||||
json_set $WEB_dir/vm.json git.watched:=null
|
||||
exec git config core.pager ./evil
|
||||
exec devvm stop
|
||||
! stderr git_changed
|
||||
vm_state $WEB_dir/vm.json
|
||||
stdout '^git.watched.scanned=true$'
|
||||
|
||||
# --no-git-protect is the user's choice too.
|
||||
project quiet git
|
||||
exec devvm --no-git-protect --network open
|
||||
! stderr git_unprotected
|
||||
|
||||
# A --clone VM: neither.
|
||||
project cloned
|
||||
exec git init -q -b main
|
||||
exec git commit -q --allow-empty -m one
|
||||
exec devvm --clone --network open
|
||||
! stderr git_unprotected
|
||||
exec git config core.fsmonitor ./evil
|
||||
exec devvm stop
|
||||
! stderr git_changed
|
||||
|
||||
-- hook --
|
||||
#!/bin/sh
|
||||
Vendored
+3
-3
@@ -23,8 +23,8 @@ stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
|
||||
# None of devvm's own files written out: they stay in the binary.
|
||||
! exists $XDG_DATA_HOME/devvm/assets
|
||||
# .git unprotected off macOS, and devvm says so.
|
||||
[darwin] ! stderr git_protect_needs_macos_new
|
||||
[linux] stderr '^devvm: git_protect_needs_macos_new$'
|
||||
[darwin] ! stderr git_unprotected
|
||||
[linux] stderr '^devvm: git_unprotected vm=devvm-web-[0-9a-f]{14}$'
|
||||
stub_calls
|
||||
stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"[^"]*/web","writable":true\},\{"location":"[^"]*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\] --set \.ssh\.forwardAgent=false --set \.ssh\.localPort=[1-9][0-9]+ --set \.portForwards = \[\{"guestIP":"127\.0\.0\.1","guestPortRange":\[1,65535\],"proto":"any","ignore":true\},\{"guestIP":"0\.0\.0\.0","guestPortRange":\[1,65535\],"proto":"any","ignore":true\},\{"guestIP":"::","guestPortRange":\[1,65535\],"proto":"any","ignore":true\}\] --set \.propagateProxyEnv=true --set \.env = \{"NODE_EXTRA_CA_CERTS":.*\}$'
|
||||
# Its first start's one edit: its proxy in its environment (the
|
||||
@@ -98,7 +98,7 @@ stub_reset
|
||||
exec devvm --network open --no-git-protect
|
||||
! stdout building_image
|
||||
stderr '^devvm: ssh_remote_hint vm=devvm-api-[0-9a-f]{14}$'
|
||||
! stderr git_protect_needs_macos_new
|
||||
! stderr git_unprotected
|
||||
stub_calls
|
||||
! stdout chflags
|
||||
vm_name API api
|
||||
|
||||
Reference in new issue
Block a user