Skip to content

Commit

Permalink
feat: linux masked paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Nov 1, 2024
1 parent 42ddd8e commit 4803000
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [x] kill
- [x] kill_no_effect
- [x] linux_devices
- [x] linux_masked_paths
- [x] linux_mount_label
- [x] linux_rootfs_propagation
- [x] linux_sysctl
Expand Down Expand Up @@ -215,7 +216,6 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [ ] linux_cgroups_relative_memory
- [ ] linux_cgroups_relative_network
- [ ] linux_cgroups_relative_pids
- [ ] linux_masked_paths
- [ ] linux_ns_itype
- [ ] linux_ns_nopath
- [ ] linux_ns_path
Expand Down
4 changes: 4 additions & 0 deletions container/container_fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (c *Container) Fork() error {
return err
}

if err := filesystem.MountMaskedPaths(c.Spec.Linux.MaskedPaths); err != nil {
return err
}

if c.Spec.Linux.RootfsPropagation != "" {
if err := syscall.Mount("", "/", "", filesystem.MountOptions[c.Spec.Linux.RootfsPropagation].Flag, ""); err != nil {
return err
Expand Down
40 changes: 40 additions & 0 deletions container/filesystem/masked_paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package filesystem

import (
"os"
"syscall"
)

func MountMaskedPaths(paths []string) error {
for _, path := range paths {
f, err := os.Stat(path)
if err != nil {
continue
}

if f.IsDir() {
if err := mountDevice(Device{
Source: "tmpfs",
Target: path,
Fstype: "tmpfs",
Flags: syscall.MS_RDONLY,
Data: "",
}); err != nil {
return err
}
} else {
if err := mountDevice(Device{
Source: "/dev/null",
Target: path,
Fstype: "bind",
Flags: syscall.MS_BIND,
Data: "",
}); err != nil {
return err
}
}

}

return nil
}
2 changes: 1 addition & 1 deletion oci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tests=(
# "linux_cgroups_relative_network"
# "linux_cgroups_relative_pids"
"linux_devices"
# "linux_masked_paths"
"linux_masked_paths"
"linux_mount_label"
# "linux_ns_itype" # ???
# "linux_ns_nopath"
Expand Down

0 comments on commit 4803000

Please sign in to comment.