Skip to content

Masking files/directories #2282

@flx42

Description

@flx42

The Linux section of the OCI runtime spec has an array of strings called maskedPaths:

maskedPaths (array of strings, OPTIONAL) will mask over the provided paths inside the container so that they cannot be read. The values MUST be absolute paths in the container namespace.

Here's an example from the default OCI spec generated by runc:

		"maskedPaths": [
			"/proc/kcore",
			"/proc/latency_stats",
			"/proc/timer_list",
			"/proc/timer_stats",
			"/proc/sched_debug",
			"/sys/firmware",
			"/proc/scsi"
		],

This is how runc handles it:
https://github.com/opencontainers/runc/blob/63e6708c74c1cc46091ec92ea9df5aca4d82e803/libcontainer/rootfs_linux.go#L777-L790

// For files, maskPath bind mounts /dev/null over the top of the specified path.
// For directories, maskPath mounts read-only tmpfs over the top of the specified path.

Straighforward, but in LXC I don't see a true equivalent. If you know in advance if the target is a file or directory, you can do the right lxc.mount.entry. Here, files (/proc/kcore) and directories (/sys/firmware) are in the same list, and also some paths might not exist (/proc/latency_stats for me).
The solution I've used is to add both mounts, but both optional:
brauner@c816bd8

If the target is a file, the first mount should succeed and the second one will fail.
If the target is a directory, the first mount will fail and the second one should succeed.
If the target doesn't exist, both mounts will fail.

There is a gap: if the target exists, but both mounts fail for another reason. We have no way of guaranteeing that at least one mount will succeed if the target exists.

What do you think? Should we add another configuration options to handle this case natively? Any other idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew feature, not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions