Skip to content

Commit 50bd343

Browse files
authored
Update cexec (#157)
## Description Upgrade to Go 1.24. Use structured logging. Unmount disk device after use. Bind mount existing sources into chroot. Instead of creating new mounts from special filesystems for the chroot, we bind mount the existing locations for /dev, /sys, and/proc. Creating a new mount point using devtmpfs is not recommended as it can cause issues and conflicts with /dev. Especially when we created the devtmpfs mount point as read only. This caused the host system's /dev to change to read only as well. ## Why is this needed Fixes: # ## How Has This Been Tested? ## How are existing users impacted? What migration steps/scripts do we need? ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 6861e4a + f4eebb1 commit 50bd343

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cexec/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,24 @@ func chroot(path string) (func() error, error) {
225225

226226
// mountSpecialDirs ensures that /dev /proc /sys /etc/resolv.conf exist in the chroot.
227227
func (s settings) mountSpecialDirs(path string) error {
228+
if path == "" {
229+
return errors.New("mount path cannot be empty")
230+
}
228231
// Mount dev
229232
dev := filepath.Join(path, "dev")
230-
if err := syscall.Mount("none", dev, "devtmpfs", syscall.MS_RDONLY, ""); err != nil {
233+
if err := syscall.Mount("/dev", dev, "", syscall.MS_BIND, ""); err != nil {
231234
return fmt.Errorf("couldn't mount /dev to %v: %w", dev, err)
232235
}
233236

234237
// Mount proc
235238
proc := filepath.Join(path, "proc")
236-
if err := syscall.Mount("none", proc, "proc", syscall.MS_RDONLY, ""); err != nil {
239+
if err := syscall.Mount("/proc", proc, "", syscall.MS_BIND, ""); err != nil {
237240
return fmt.Errorf("couldn't mount /proc to %v: %w", proc, err)
238241
}
239242

240243
// Mount sys
241244
sys := filepath.Join(path, "sys")
242-
if err := syscall.Mount("none", sys, "sysfs", syscall.MS_RDONLY, ""); err != nil {
245+
if err := syscall.Mount("/sys", sys, "", syscall.MS_BIND, ""); err != nil {
243246
return fmt.Errorf("couldn't mount /sys to %v: %w", sys, err)
244247
}
245248

0 commit comments

Comments
 (0)