Page MenuHomeFreeBSD

Add ".include" directive to jail.conf
ClosedPublic

Authored by jamie on May 21 2023, 12:14 AM.
Tags
Referenced Files
Unknown Object (File)
Fri, Mar 1, 10:35 AM
Unknown Object (File)
Wed, Feb 28, 4:59 PM
Unknown Object (File)
Feb 18 2024, 8:28 AM
Unknown Object (File)
Jan 10 2024, 10:49 PM
Unknown Object (File)
Jan 3 2024, 5:45 AM
Unknown Object (File)
Dec 20 2023, 5:26 AM
Unknown Object (File)
Dec 17 2023, 1:45 AM
Unknown Object (File)
Dec 10 2023, 8:01 PM

Details

Summary

Allow jail config files to include other files, via the ".include" directive (the leading dot is to ensure it doesn't clash with jail or parameter names). The include filename may be a glob, which allowed for config dirfectories such as /etc/jail.conf.d.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

@jamie please re-generate the diff with -U9999 and re-upload it. This is necessary to have context available. (Annoying Phab limitation when diffs are uploaded manually)

Example:

git diff -U99999 | wl-copy

I like this approach.
It blurs the line between UCL and jail format (IMHO making future transition to UCL smoother), and makes include more explicit (and less magical comparing to D40188)

The I have not read the code thoughtfully yet, will do so over the next day or two.

I you use git format-patch -1 -U9999 and apply it with git am <patch>, you get the whole commit with the message. Not strictly needed, but makes life easier.

usr.sbin/jail/config.c
274

Initialize all glob_t vars to zero/NULL.

Haven't looked closely yet, but: are circular includes handled correctly?

In D40188#915159, @otis wrote:

Haven't looked closely yet, but: are circular includes handled correctly?

This is what I came here to ask.

In D40188#915660, @dvl wrote:
In D40188#915159, @otis wrote:

Haven't looked closely yet, but: are circular includes handled correctly?

This is what I came here to ask.

Theoretically this is easy to handle. All it takes is a map/list of absolute file paths that the parser has already seen. If a new path encountered - include, if a known one encountered - skip.

It doesn't look like the patch in it's current state handles this circular includes.

usr.sbin/jail/config.c
295

Checking if the file was already included would need to happen somewhere here.

True, they're not handled. I took my include inspiration from newsyslog (which has includes that also support globbing), and there it's also just a simple matter or running whatever it's told to include. It's kind of a footgun situation, where it's generally good enough to trust the administrator not to make such a loop. I did it for depend loops, but only because that's kind of elemental in building an acyclic directed graph.

I imagine it wouldn't be incredibly hard to handle, though it's a bit more than just tracking filenames, since I do at least a cursory job of resolving relative names, and because the same file may be included in different contexts (within different jails). But hashing a jail/dev/inode tuple might do the trick.

Simple include-loop prevention with via a maximum depth counter.

Just a small nitpick: I would prefer a macro #define MAX_INCLUDE_DEPTH 32 or constant static const unsigned int max_include_depth = 32; somewhere above the include_config() in config.c instead of the literal to improve readability.

Just a small nitpick: I would prefer a macro #define MAX_INCLUDE_DEPTH 32

True, let's not let bad habits creep in.

I've committed the "jails can include jails" and "use the recursive parser" bits separately. This new diff is just the part that handles the includes.

jamie marked an inline comment as done.Jun 4 2023, 4:29 AM

Commited in eb5bfdd06565. I forgot to add the review to the commit message :-/

Commited in eb5bfdd06565. I forgot to add the review to the commit message :-/

In that case, I guess we have to mark it as "Accept Revision"?

This revision is now accepted and ready to land.Oct 16 2023, 12:28 PM

Oh and we also have to close it, because it did land! ugh Phabricator is very Project-Management-y :)

Commited in eb5bfdd06565. I forgot to add the review to the commit message :-/

eb5bfdd06565 is tcp: Add and update cubic module variable names

This should be e82a62943529d1a7c1fcec39aec13eba69c671d6 I think?