Commit Graph

26 Commits

Author SHA1 Message Date
Ryan Moeller
66005c453d jail: Add exec.prepare and exec.release command hooks
This change introduces new jail command hooks that run before and after any
other actions.

The exec.prepare hook can be used for example to invoke a script that checks
if the jail's root exists, creating it if it does not. Since arbitrary
variables in jail.conf can be passed to the command, it can be pretty useful
for templating jails.

An example use case for exec.release would be to remove the filesystem of an
ephemeral jail.

The names "prepare" and "release" are borrowed from the names of similar hooks
in libvirt.

Reviewed by:	jamie, manpages, mmacy
Approved by:	mmacy (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D24829
2020-05-14 23:38:11 +00:00
Eugene Grosbein
1e1a4743ba jail(8): introduce new command option -e to exhibit
a list of configured non-wildcard jails with their parameters,
no matter running or not.

The option -e takes separator argument that is used
to separate printed parameters. It will be used with following
additions to system periodic scripts to differentiate parts
of directory tree belonging jails as opposed to host's.

MFC after:	1 month
2018-11-10 12:03:57 +00:00
Jamie Gritton
07ebf3dd69 security.jail.enforce_statfs is handled by jail_set(2), so handling it in
userspace jail(8) is redundant.

Differential Revision:	D14791
2018-08-16 18:30:49 +00:00
Alexander Leidinger
f6c0e63bf7 - Add exec hook "exec.created". This is called when the jail is
created and before exec.start is called.			[1]
- Bump __FreeBSD_version.

This allows to attach ZFS datasets and various other things to be
done before any command/service/rc-script is started in the new
jail.

PR:			228066					[1]
Reviewed by:		jamie					[1]
Submitted by:		Stefan Grönke <stefan@gronke.net>	[1]
Differential Revision:	https://reviews.freebsd.org/D15330	[1]
2018-08-15 18:35:42 +00:00
Pedro F. Giffuni
1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:37:16 +00:00
Jamie Gritton
4c86c0fa98 Fix up the order in which jail creation processes are run, to preserve
the config file's order in the non-parallel-start case.

PR:		209112
MFC after:	3 days
2016-07-14 20:15:55 +00:00
Eitan Adler
463a577b27 Fix a ton of speelling errors
arc lint is helpful

Reviewed By: allanjude, wblock, #manpages, chris@bsdjunk.com
Differential Revision: https://reviews.freebsd.org/D3337
2015-10-21 05:37:09 +00:00
Hiroki Sato
64bb8a3881 Implement PF_IMMUTABLE flag and apply it to "name" and "jid" in
jail.conf parameters.  This flag disallows redefinition of the parameter.

"name" and/or "jid" are automatically defined in jail.conf by using
the jail names at the front of jail parameter definitions.  However,
one could override them by using a variable with the same name like
$name = "foo".  This confused the parser and could end up with SIGSEGV.

Note that this change also affects a case when all of parameters are
defined in the command line arguments, not in jail.conf.  Specifically,
"jail -c name=j1 name=j2" no longer works.  This should be harmless.

PR:		196574
Reviewed by:	jamie
Differential Revision:	https://reviews.freebsd.org/D3017
2015-07-08 16:37:48 +00:00
Jamie Gritton
07a7869fb2 Add mount.procfs jail parameter, so procfs can be mounted when a prison's
root is in its fstab.

Also fix a typo while I'm at it.

PR:		197237 197066
MFC after:	3 days
2015-02-06 17:54:53 +00:00
Hiroki Sato
fbd868c9d8 - Add mount.fdescfs parameter to jail(8). This is similar to
mount.devfs but mounts fdescfs.  The mount happens just after
  mount.devfs.

- rc.d/jail now displays whole error message from jail(8) when a jail
  fails to start.

Approved by:	re (gjb)
2013-10-12 17:27:59 +00:00
Jamie Gritton
bea2eefca4 Reverse the order of some implicit commands (FS mounts and ifconfigs)
when stopping jails.  This matters particularly for nested filesystem
mounts.

PR:		kern/177325
Submitted by:	Harald Schmalzbauer
MFC after:	3 days
2013-03-28 21:02:49 +00:00
Jamie Gritton
a6486f6008 When writing the jid via the -i flag, do it right when the jail is created,
before any commands run.  /etc/rc.d/jail depends on this.
2012-05-28 20:44:11 +00:00
Baptiste Daroussin
5e2a209a27 Fix world after byacc import:
- old yacc(1) use to magicially append stdlib.h, while new one don't
- new yacc(1) do declare yyparse by itself, fix redundant declaration of
  'yyparse'

Approved by:	des (mentor)
2012-05-22 16:33:10 +00:00
Jamie Gritton
6fcbac3cd5 Add a meta-parameter IP__NULL to enum intparam, instead of mixing
enum values and zeroes.  This keeps clang happy (and is just good form).

Submitted by:	dim
2012-05-03 21:39:23 +00:00
Jamie Gritton
0c4d49e94a Use the defvs_ruleset paramater when mounting a jail's /dev,
instead of a mount.devfs.ruleset pseudo-parameter.
2012-02-27 22:37:35 +00:00
Jamie Gritton
1ca35de448 Improvements in error messages:
Some errors printed the jail name for unnamed (command line) jails.

Attempting to create an already-existing jail from the command line
returned with no error (even for non-root) due to bad logic in
start_state.

Ignore kvm_proc errors, which are typically caused by permission
problems.  Instead, stop ignoring permission errors when removing
a jail (but continue to silently ignore other errors, i.e. the
jail no longer existing).  This makes non-root attempts at removing
a jail give a clearer error message.
2012-02-08 23:51:46 +00:00
Jamie Gritton
5fb611c2bf Following r222465:
Check for IPv4 or IPv6 to be available by the kernel to not
  provoke errors trying to query options not available.
  Make it possible to compile out INET or INET6 only parts.
2011-06-20 23:04:13 +00:00
Jamie Gritton
2b00f7ba65 Move the actual create/remove (IP__OP) handling into run_command,
and the cost of an ugly single-use global variable.
2011-06-18 15:23:08 +00:00
Jamie Gritton
d8352076b1 Update copyright dates and other whitespacey stuff. 2011-06-17 16:21:03 +00:00
Jamie Gritton
3b40332c44 Split run_command up into an outer function (next_command) that chooses
a single command string to run, and an inner function (run_command) that
 runs that single string.
Move the list of start/stop commands to run from a switch statement into
 an array, with a new placeholder parameter IP__OP for actually creating
 or removing the jail.
When jail creation fails, revert all non-exec commands in reverse order.
2011-06-17 16:18:44 +00:00
Jamie Gritton
2a194551a7 Change cfstrings from an STAILQ into a TAILQ to allow commands to be
traversed in reverse order.
2011-06-17 16:06:13 +00:00
Jamie Gritton
aa02af5404 run_command (mostly) cleanup:
Make the parallelism limit a global instead of always passing it
 to run_command and finish_command.
In the case of an empty command string, try to run any other strings
 the command may have.
Replace JF_BACKGROUND with its sort-of opposite JF_SLEEPQ.
Change j->comstring earlier to render JF_RUNQ unncessary.
Change the if-else series to a more readable switch statement.
Treat IP_STOP_TIMEOUT like a command, calling run_command which then
 calls term_procs.
When the IP_STOP_TIMEOUT "command" finishes, it shouldn't mess with
 the parallelism limit.
Make sufficient checks in finish_command and run_command so that
 the nonintuitive j->comstring null check isn't necessary to run them.
Rename the "waiting" queue to "depend", because the "sleeping" and
 "runnable" queues are also used to wait for something.
2010-12-10 23:57:55 +00:00
Jamie Gritton
52a4962202 Reads the mount.fstab file, and put its lines separately into the
IP__MOUNT_FROM_FSTAB internal parameter.
2010-11-04 17:01:21 +00:00
Jamie Gritton
e3c69673a6 Combine check_intparams() and ip_params(), JF_CHECKINT and JF_IPPARAMS. 2010-11-01 21:37:28 +00:00
Jamie Gritton
5553043801 Keep all internal/known parameter names in one place, and use
enum constants everywhere else.
2010-10-27 16:22:54 +00:00
Jamie Gritton
2671ee736f Initial work on the new jail(8). There are more features to add, and some
cleaning up to do on existing features, but this is pretty much what the
final product will look like.
2010-10-20 20:42:33 +00:00