Skip to content

Commit

Permalink
feat: readonly paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Nov 1, 2024
1 parent 4803000 commit 1bdcc25
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [x] linux_devices
- [x] linux_masked_paths
- [x] linux_mount_label
- [x] linux_readonly_paths
- [x] linux_rootfs_propagation
- [x] linux_sysctl
- [x] mounts
Expand Down Expand Up @@ -221,7 +222,6 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [ ] linux_ns_path
- [ ] linux_ns_path_type
- [ ] linux_process_apparmor_profile
- [ ] linux_readonly_paths
- [ ] linux_seccomp
- [ ] linux_uid_mappings
- [ ] misc_props
Expand Down
10 changes: 9 additions & 1 deletion container/container_fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ func (c *Container) Fork() error {
return err
}

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

if err := filesystem.MountReadonlyPaths(
c.Spec.Linux.ReadonlyPaths,
); err != nil {
return err
}

Expand Down
30 changes: 30 additions & 0 deletions container/filesystem/readonly_paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package filesystem

import "syscall"

func MountReadonlyPaths(paths []string) error {
for _, path := range paths {
if err := mountDevice(Device{
Source: path,
Target: path,
Fstype: "",
Flags: syscall.MS_REC | syscall.MS_BIND,
Data: "",
}); err != nil {
return err
}

if err := mountDevice(Device{
Source: path,
Target: path,
Fstype: "",
Flags: syscall.MS_NOSUID | syscall.MS_NODEV | syscall.MS_NOEXEC |
syscall.MS_BIND | syscall.MS_REMOUNT | syscall.MS_RDONLY,
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 @@ -39,7 +39,7 @@ tests=(
# "linux_ns_path"
# "linux_ns_path_type"
# "linux_process_apparmor_profile" # ???
# "linux_readonly_paths"
"linux_readonly_paths"
"linux_rootfs_propagation"
# "linux_seccomp"
"linux_sysctl"
Expand Down

0 comments on commit 1bdcc25

Please sign in to comment.