Commit Graph

41 Commits

Author SHA1 Message Date
Ruslan Ermilov
85e5290d11 Allow a jail's IP alias to be created with an arbitrary netmask.
MFC after:	3 days
2008-09-24 15:18:27 +00:00
Andrew Thompson
51e1463035 Allow a jail to be started with a specific route fib.
Reviewed by:	secteam (simon)
Reviewed by:	brooks, bz
2008-09-16 20:18:25 +00:00
Doug Barton
2b9851690c As previously discussed, add the svn:executable property to all scripts 2008-07-16 19:22:48 +00:00
Simon L. B. Nielsen
ce4c63c52a Add warning about this script dealing with untrusted data.
MFC after:	1 week
2008-01-13 14:27:53 +00:00
Ralf S. Engelschall
f31380b233 Fix indentation. 2007-05-24 06:01:06 +00:00
Simon L. B. Nielsen
26d67ea70f Fix jail rc.d script privilege escalation via symlink attack against
/var/log/console.log and mount points.

Security:	FreeBSD-SA-07:01.jail
2007-01-11 18:18:57 +00:00
Florent Thoumie
eacc7cde7d Jail_ip and jail_interface local variables were renamed to _ip and _interface
in a previous commit to avoid namespace collisions, unfortunately I missed two
of them. This leads to the ip alias being incorrectly removed in some cases
when using the stop command.

Reported by:	Philipp Wuensche <cryx-freebsd@h3q.com>
2007-01-02 11:07:13 +00:00
Matteo Riondato
ce5c66f0b2 Add jail_<jname>_exec_afterstart<N> rc.conf variable, where <N> is
1,2 and so on.
It specifies the command to be run as Nth after jail startup.

sh(1)-fu by: Dario Freni
PR: 	conf/97697
MFC after: 2 weeks
Reviewed by: ru@ (man page)
2006-05-30 16:20:48 +00:00
Matteo Riondato
200ea54812 style(9) 2006-05-30 16:07:59 +00:00
Florent Thoumie
b246e9314d - Change the "jail_" prefix for internal script variables. This fixes an
issue where some global jail_* variables were overriden in the script. [1]
- Change "jid" to "jname" in rc.conf(5), since it's more a jail name than a
jail id. [1]
- Update examples and comments in defaults/rc.conf to advertise new
variables and the fact that some of the jail-specific variables may be made
jail-global. [2]

Reported by:	pjd [1], clsung [2]
Approved by:	cperciva
X-MFC after:	i got sufficient testing from people using rc.d/jail
2006-05-11 14:23:43 +00:00
Matteo Riondato
8fc80fd71f if we fail to start a jail and jail_foobar_*fs_enable or jail_foobar_mount_enable were set, umount those filesystem before exiting. If we set up an alias for jail's IP, remove that alias before exiting.
MFC after:	2 weeks
2006-05-11 13:29:01 +00:00
Matteo Riondato
8cf29c0839 if a jail fails to start, don't add its jid to /var/run and print a message with the error.
PR:	conf/97024
MFC after:	1 week
2006-05-09 17:50:16 +00:00
Florent Thoumie
656a2a8738 - Fix quoting.
Reported by:	Dirk Engling <erdgeist@erdgeist.org>
Pointyhat to:	self
2006-05-08 17:32:45 +00:00
Florent Thoumie
46d5426b1b - Check for some mandatory variables.
Approved by:	cperciva (mentor)
MFC after:	1 week
2006-05-07 23:15:39 +00:00
Florent Thoumie
69beb663f5 - Add following global jail options, used if no jail-specific options are
set:
 * jail_mount_enable
 * jail_devfs_ruleset
 * jail_devfs_enable
 * jail_fdescfs_enable
 * jail_procfs_enable
 * jail_fstab
 * jail_flags
- Add a jail_interface / jail_<jid>_interface option. An ip alias will be
created (jail_<jid>_ip) on jail_interface or jail_<jid>_interface if set.
This is not a mandatory option.
- Document all missing jail_* options in rc.conf(5).

Approved by:	cperciva (mentor)
MFC after:	2 weeks
2006-04-08 12:15:36 +00:00
Max Khon
409a60927b Fix overriding jail_list from command line.
MFC after:	3 days
2006-03-08 20:40:37 +00:00
Pawel Jakub Dawidek
5b3e518936 Skip jails which are already running and inform why.
We're checking for /var/run/jail_<name>.id file and if it exists, we don't
start the jail. It should be also safe in case of reboot(8), because
rc.d/cleanvar script is going to remove /var/run/jail_* files.

It helps to avoid potential mess when the same jail is started twice,
because of an administrator mistake (been there, done that).

MFC after:	1 week
2005-08-07 23:19:02 +00:00
Pawel Jakub Dawidek
4558bd977d Allow to give more than one jail's name, eg.:
# /etc/rc.d/jail start www mail

MFC after:	3 days
2005-08-07 22:38:41 +00:00
Pawel Jakub Dawidek
7db9a6fcd1 Introduce new per-jail variable jail_<name>_flags, which allows to specify
jail(8) flags (before the change we had hardcoded "-l -U root").

Submitted by:	Frank Behrens <frank@pinky.sax.de>
PR:		conf/80244
Approved by:	re (scottl)
MFC after:	1 week
2005-06-26 16:30:20 +00:00
Christian S.J. Peron
115005468b Do not unconditionally mount devfs to ${jail_devdir}/dev. First check
to see if a prior devfs has been mounted. If no devfs is mounted on
${jail_devdir}/dev then proceed. This will prevent the stack up of
multiple devfs mounts on the same mount point.

Discussed with:	pjd
MFC after:	1 week
2005-04-30 00:16:00 +00:00
David E. O'Brien
835e0fa318 "REQUIRE: cleanvar" for all RC's writing into /var/run. 2005-01-16 03:12:03 +00:00
Ralf S. Engelschall
62bb1d78fe Improve the RC framework for the clean booting/shutdown of Jails:
1. Feature: for flexibility reasons and as a prerequisite to clean
   shutdowns, allow the configuration of a stop/shutdown command
   via rc.conf variable "jail_<name>_exec_stop" in addition to the
   start/boot command (rc.conf variable "jail_<name>_exec_start"). For
   backward compatibility reasons, rc.conf variable "jail_<name>_exec"
   is still supported, too.

2. Debug: Add the used boot/shutdown commands to the debug output of
   the /etc/rc.d/jail script, too.

3. Security: Run the Jail start/boot command in a cleaned environment
   to not leak information from the host to the Jail during startup.

4. Feature: Run the Jail stop/shutdown command "jail_<name>_exec_stop" on
   "/etc/rc.d/jail stop <name>" to allow a graceful shutdown of the Jail
   before its processes are just killed.

5. Bugfix: When killing the remaining Jail processes give the processes
   time to actually perform their termination sequence. Without this the
   subsequent umount(8) operations usually fail because the resources
   are still in use. Additionally, if after trying to TERM-inate the
   processes there are still processes hanging around, finally just KILL
   them.

6. Bugfix: In rc.shutdown, if running inside a Jail, skip the /etc/rc.d/*
   scripts which are flagged with the KEYWORD "nojail" to allow the
   correct operation of rc.shutdown under jail_<name>_exec_stop="/bin/sh
   /etc/rc.shutdown". This is analogous to what /etc/rc does inside a Jail.

Now the following typical host-configuration for two Jails works as
expected and correctly boots and shutdowns the Jails:

-----------------------------------------------------------
#  /etc/rc.conf:
jail_enable="YES"
jail_list="foo bar"
jail_foo_rootdir="/j/foo"
jail_foo_hostname="foo.example.com"
jail_foo_ip="192.168.0.1"
jail_foo_devfs_enable="YES"
jail_foo_mount_enable="YES"
jail_foo_exec_start="/bin/sh /etc/rc"
jail_foo_exec_stop="/bin/sh /etc/rc.shutdown"
jail_bar_rootdir="/j/bar"
jail_bar_hostname="bar.example.com"
jail_bar_ip="192.168.0.2"
jail_bar_devfs_enable="YES"
jail_bar_mount_enable="YES"
jail_bar_exec_start="/path/to/kjailer -v"
jail_bar_exec_stop="/bin/sh -c 'killall kjailer && sleep 60'"
-----------------------------------------------------------
#  /etc/fstab.foo
/v/foo /j/foo/v/foo nullfs rw 0 0
-----------------------------------------------------------
#  /etc/fstab.bar
/v/bar /j/bar/v/bar nullfs rw 0 0
-----------------------------------------------------------

Reviewed by:	freebsd-hackers
MFC after:	2 weeks
2004-12-14 14:36:35 +00:00
Maxime Henrion
f89336da41 Fix a typo in an error message.
Spotted by:	ceri
2004-11-24 10:44:39 +00:00
Maxime Henrion
d4d8b79704 Implement per-jail fstab(5) files. Here's a rc.conf sample using
this feature for a jail named foo :

jail_foo_mount_enable="YES"
jail_foo_fstab="/etc/fstab.foo"

The second line is actually useless, since the code defaults to
using "/etc/fstab.$jailname" as the fstab file if none is specified.

MFC after:	3 days
Submitted by:	Jeremie Le Hen <jeremie@le-hen.org>
2004-11-23 20:09:58 +00:00
Mike Makonnen
337338ee00 Remove the requirement for the FreeBSD keyword as it no longer
makes any sense.

Discussed with: dougb, brooks
MFC after: 3 days
2004-10-07 13:55:26 +00:00
Dag-Erling Smørgrav
da5d8b9395 Always quote variables in tests, to ensure correct evaluation even when
they are empty or undefined.

MFC after:	3 days
2004-08-19 08:55:24 +00:00
Jacques Vidrine
fc94eecc8f Create temporary files safely.
Submitted by:	Jon Passki <cykyc@yahoo.com>
2004-08-16 16:37:06 +00:00
Pawel Jakub Dawidek
bd57d5b0f5 Mark scripts as not usable inside a jail by adding keyword 'nojail'.
Some suggestions from:	rwatson, Ruben de Groot <mail25@bzerk.org>
2004-03-08 12:25:05 +00:00
Mike Makonnen
33dc111393 o Unbreak the individual jail starting patch that I broke when
I committed it. Apologies to Juergen Unger <j.unger@addict.de>.
o When stopping jails output the hostname of the jails that
  were stopped.
o Refactor
o Remove extraneous empty line
o Correct spelling error
2004-02-03 12:59:30 +00:00
Mike Makonnen
2104ae4ea4 Configure a jail sysctl value only if it is different than
what the rc.conf(5) knob specifies. Also, correct a minor
capitalization error.
2004-02-03 07:15:32 +00:00
Mike Makonnen
5d2885f928 Support starting/stoping of jails individually.
This commit also removes the support for the sysutils/jailer port. This
is inline with the general policy to keep ports related knobs out
of the base system's configuration mechanism.

Submitted by: Juergen Unger <j.unger@addict.de>
2004-02-02 13:25:28 +00:00
Mike Makonnen
ed0bd3657c o Rename devfs_link() to make_symlink() and turn it into a generic
symlinking routine.
o Modify rc.d/jail to create its own symlink relative to the jail's
  filesystem
2003-12-09 08:51:11 +00:00
Mike Makonnen
16805414e4 If fdescfs(5) is mounted in a jail unmount it before devfs(5).
Submitted by:	"Scot W. Hetzel" <hetzelsw@westbend.net>
2003-12-09 08:32:43 +00:00
Mike Makonnen
7645a316db Redirect rc(8) output to a file in the jail's /var/log directory.
Previously it was redirected to /dev/null.

Submitted by: phk
2003-12-09 08:09:04 +00:00
Doug Barton
76f9428757 Remove trailing whitespace 2003-10-13 08:20:55 +00:00
Mike Makonnen
66338db9e9 Enhance the jail start/stop script.
o The following additional configuration attributes of a jail can be
  controlled from rc.conf:
	- mounting devfs(5)
	- mounting fdescfs(5)
	- mounting procfs(5)
	- custom devfs(8) ruleset
	  If no ruleset is specified, the default jail ruleset is used.

o The output of executing /etc/rc in the jail is now redirected
  to /dev/null. Instead, the hostname of the jail is echoed if
  the jail(8) command exited successfully. If the output is wanted
  it can probably be redirected to a file (/var/run/$jail maybe)
  instead of /dev/null.

Submitted by:	Scot W. Hetzel <hetzels@westbend.net>
		with modifications by Jens Rehsack <rehsack@liwing.de>
		and me.
2003-08-24 06:29:32 +00:00
Jun Kuriyama
7a79a9d713 Quote $jail_exec with double-quote to avoid "[: unexpected operator". 2003-08-19 03:49:30 +00:00
Mike Makonnen
575716147b Move securelevel further back in the boot order.
Approved by:	markm (mentor)(implicit)
Reviewed by:	dougb
2003-05-05 15:38:41 +00:00
Mike Makonnen
cd3b264dfd Spell ${_jail} correctly
Submitted by: Shizuka Kudo <shizukakudo_99@yahoo.com>
Approved by:	markm (mentor) (implicit)
2003-04-19 07:50:32 +00:00
Mike Makonnen
61c79e443b Fix typo (and make it more explicit/self-documenting).
Noticed by:	gshapiro
2003-04-16 16:44:00 +00:00
Mike Makonnen
676f8a41dd o Add a script to start jails on boot.
o Hook it up to the build

Approved by:	markm (mentor)
Submitted by:	Clement Laforet <sheepkiller@cultdeadsheep.org> (modified)
Prodded by:	mike
2003-04-16 16:27:23 +00:00