max_open_files is accepted everywhere but never applied
max_open_files is accepted by the builder, the CLI, the C ABI, Python and Go — and never applied. RLIMIT_NOFILE appears nowhere under crates/.
Reproduction
Verified on main (0.8.5, x86-64).
$ sandlock run -r /usr -r /lib -r /lib64 -r /bin -- /bin/sh -c 'ulimit -n'
524288
$ sandlock run -r /usr -r /lib -r /lib64 -r /bin --max-open-files 10 -- /bin/sh -c 'ulimit -n'
524288
$ ulimit -n # the host, for comparison
524288
The flag is accepted without complaint and changes nothing. Going further — asking for two hundred descriptors under a stated cap of ten:
$ sandlock run -r /usr -r /lib -r /lib64 -r /bin -r /etc --max-open-files 10 -- \
/usr/bin/python3 -c "
import resource
print('RLIMIT_NOFILE inside the sandbox:', resource.getrlimit(resource.RLIMIT_NOFILE))
fds = [open('/etc/hostname') for _ in range(200)]
print('descriptors opened:', len(fds))
"
RLIMIT_NOFILE inside the sandbox: (524288, 524288)
descriptors opened: 200
Trace
The value flows all the way through and then stops:
crates/sandlock-core/src/sandbox/builder.rs:112— fieldcrates/sandlock-core/src/sandbox/builder.rs:482— settercrates/sandlock-core/src/sandbox/builder.rs:869— copied into the sandboxcrates/sandlock-core/src/sandbox.rs:443,:579— carriedcrates/sandlock-core/src/profile.rs:286— settable from a profile
$ rg -n 'RLIMIT_NOFILE|NOFILE' crates/
(no matches)
Every other limit in the group reaches an enforcement point; this one has none.
Why it matters more than a no-op usually would
The Go SDK documents it as enforced, go/sandbox.go:243:
MaxOpenFiles uint32 // RLIMIT_NOFILE; 0 = inherit system default
A caller who sets it believes a descriptor limit is in place. Since max_open_files reads as a hardening control, a silent no-op is worse than an absent field: the sandbox looks more constrained than it is.
Why the tests do not catch it
Nothing asserts the limit takes effect — the same shape as the restrict_max_processes and restrict_max_memory gaps closed in #104 by adding tests that verify enforcement rather than acceptance. A test in that style (open descriptors past the cap, expect EMFILE) would have caught this; the reproduction above is essentially that test.
Options
- Implement it —
setrlimit(RLIMIT_NOFILE)in the child before exec, next to where the other limits land. - Remove the field and the flag, and note it in the release notes.
- Keep it and document it as accepted-but-unenforced.
I would go with (1), and would rather not leave (3) standing for something that reads as a hardening control. Either way the Go doc comment needs correcting.
Happy to take this if you want it implemented.
Yes, please implement it. Thank you.