Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/config/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ func lockFile(file string) {
run("chflags", "uchg", file)
default:
run("chattr", "+i", file)
_ = os.Chmod(file, 0o400)
// 0o500, not 0o400: protectedTargets() includes the guard binary, and
// chattr commonly fails without CAP_LINUX_IMMUTABLE (containers,
// rootless), so this chmod is the fallback that actually runs. Keeping
// the execute bit matches the windows ACL above (grants RX) and the
// directory mode in protectpaths.go's LockPath.
_ = os.Chmod(file, 0o500)
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/core/config/protect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestLockFileThenUnlockFileRoundTrip(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm() != 0o400 {
t.Errorf("after lockFile, perm = %v, want 0400", info.Mode().Perm())
if info.Mode().Perm() != 0o500 {
t.Errorf("after lockFile, perm = %v, want 0500", info.Mode().Perm())
}

unlockFile(file)
Expand Down Expand Up @@ -90,8 +90,8 @@ func TestWriteProtectedFileOverLockedFileUnlocksRewritesAndRelocks(t *testing.T)
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm() != 0o400 {
t.Errorf("perm after relock = %v, want 0400", info.Mode().Perm())
if info.Mode().Perm() != 0o500 {
t.Errorf("perm after relock = %v, want 0500", info.Mode().Perm())
}
}

Expand Down
Loading