Commit Graph

76 Commits

Author SHA1 Message Date
Diederik de Haas
ac46b35693
Replace deprecated backticks with $() construct
See https://github.com/koalaman/shellcheck/wiki/SC2006 for details.
Not only uses this the recommended construct, it also makes the code
more uniform as in many other places the $() construct was already used.

Signed-off-by: Diederik de Haas <didi.debian@cknow.org>
2021-10-28 20:15:29 +02:00
Diederik de Haas
7a7671655a
Replace 'which' with 'command -v'
The 'which' command is deprecated on Debian Sid as it is not POSIX
compliant and it's behavior is therefor not consistent, so replace it
with 'command -v' which is POSIX compliant.
See https://stackoverflow.com/a/677212 for details.

Also replaced a use of backticks (`) as that is deprecated as well.
See https://github.com/koalaman/shellcheck/wiki/SC2006 for details.

Signed-off-by: Diederik de Haas <didi.debian@cknow.org>
2021-10-28 17:27:08 +02:00
Christian Brauner
7172b98c77
build: add templates
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-27 12:39:10 +02:00
Christian Brauner
b081cb55e4
busybox: simplify
Start relying on autodev for busybox template and wipe all the device
creation.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-08-17 13:50:58 +02:00
Christian Brauner
8829829deb
busybox: mount sys:ro
There's no udev so sys doesn't need to be read-write.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-08-17 13:49:56 +02:00
Christian Ratzenhofer
655d10ed7f templates/*.in: fixed PATH handling with spaces
if $PATH already contains a path with a space the append of the
default directories in all template scripts fails with an error
like the following:

/usr/share/lxc/templates/lxc-download: 69: export: (x86)/NVIDIA: bad
variable name

Signed-off-by: Christian Ratzenhofer <christian.ratzenhofer@cdnm.at>
2021-04-06 14:43:11 +02:00
Stéphane Graber
bff9399765
busybox: Mark mqueue optional
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2020-03-16 21:49:55 -04:00
Rachid Koucha
1f76a6a777
Auto-create /dev/shm and /dev/mqueue
Mount fs on /dev/shm and /dev/mqueue to experiment IPC in namespaces

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2020-03-16 21:19:15 +01:00
Stéphane Graber
83e280f649
busybox: Fix bad lxc.mount.entry
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2020-03-16 15:48:32 -04:00
Rachid Koucha
078c676f4d
Trigger the mounting of shm file system
shm file system was not mounted because of the "/" in :
lxc.mount.entry = shm /dev/shm tmpfs defaults 0 0

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2020-03-16 19:10:00 +01:00
Rachid Koucha
eeea2ef1b1
Suppress useless udhcpc directory
The udhcpc directory is created with "mkdir -p" at the place dynamically specified by "busybox udhcpc --help".

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2020-01-03 10:48:41 +01:00
Rachid Koucha
e76e315c11
Adaptation to latest busybox
In busybox 1.30, the help of udhcpc for "-s" option changed:
--> busybox v1.27.2: -s,--script PROG	Run PROG at DHCP events (default /usr/share/udhcpc/default.script)
--> busybox v1.30.1: -s PROG		Run PROG at DHCP events (default /etc/udhcpc/default.script)
So, I changed the command line which extracts the script name to make it work for both versions

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-12-27 08:49:00 +01:00
Lukas Pirl
16a312e118
suppress false-negative error in templates and nvidia hook
``/proc`` might be mounted with ``hidepid=2``.
This makes ``/proc/1/…`` appear absent for non-root users.
When using the templates or the nvidia hook as a non-root user
(e.g., when creating unprivileged containers) the error
"/proc/1/uid_map: No such file or directory" is printed.
Since the script works correctly despite the error, this error
message might be confusing for users.

Signed-off-by: Lukas Pirl <git@lukas-pirl.de>
2019-07-22 14:39:23 +02:00
Rachid Koucha
a725bbc4b7
Make /tmp accessible to any user
/tmp created with "rwxrwxrwt" mode

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-06-05 13:04:11 +02:00
Rachid Koucha
5f0fb855f8
Option --busybox-path instead of --bbpath
As suggested during the review.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-05-10 21:28:35 +02:00
Rachid Koucha
e796239406
New --bbpath option and unecessary --rootfs checks
. Add the "--bbpath" option to pass an alternate busybox pathname instead of the one found from ${PATH}.
. Take this opportunity to add some formatting in the usage display
. As a try is done to pick rootfs from the config file and set it to ${path}/rootfs, it is unnecessary to make it mandatory

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-05-10 17:01:13 +02:00
Rachid Koucha
634ad9358e
Redirect error messages to stderr
Some error messages were not redirected to stderr.
Moreover, do "exit 0" instead of "exit 1" when "help" option is passed.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-05-10 07:39:03 +02:00
Rachid Koucha
28eb86bd43
Devices created in rootfs instead of rootfs/dev
Added /dev in the mknod commands.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-05-07 16:03:02 +02:00
Rachid Koucha
567f891596
/etc/resolv.conf grows indefinitely
This file grows indefinitely : upon each DHCP lease renew,
the "nameserver ..dns..." line is added at the end of the file.
Make a "grep" in the file to make sure that the same line
does not already exist.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-01-27 13:46:48 +01:00
Rachid Koucha
c65973ad89
Create /var/run
Some programs like "who" need this directory
to work (this permits the of /var/run/utmp file).

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-01-27 12:23:58 +01:00
Rachid Koucha
4765b926b1
Use BUSYBOX_EXE variable in configure_busybox()
As "which busybox" is stored in BUSYBOX_EXE 
global variable at startup, use it wherever it is
needed.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-01-27 11:51:57 +01:00
Rachid Koucha
1c9bca6b88
Installation of default.script for udhcpc
The busybox template installs default.script in /usr/share/udhcpc/.
But the pathname of "default.script" may vary from one busybox
build to another. As the pathname is displayed in udhcpc's help,
grab it from it.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-01-27 03:38:36 +01:00
Christian Brauner
46a6646a83
templates: avoid endless loop
Closes #2512.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-06 16:43:35 +02:00
Thomas Hipp
8b7681f354
templates: Fix busybox template
Use `busybox --list`, and exclude the `busybox` applet if necessary.

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
2018-06-20 16:56:04 +02:00
Christian Brauner
b62671d849
lxc-busybox: make shellcheck clean
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-02-28 10:05:34 +01:00
Christian Brauner
fd99824155
templates: remove legacy key from busybox
lxc.rebootsignal -> lxc.signal.reboot

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-08-22 00:02:28 +02:00
Long Wang
a1d5fdfd9b doc: s/aa_profile/apparmor.profile/g
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-12 09:53:58 +08:00
Christian Brauner
232763d645
confile: lxc.pts --> lxc.pty.max
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:07 +02:00
Christian Brauner
fe1c588797
confile: lxc.tty --> lxc.tty.max
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:07 +02:00
Christian Brauner
7a96a068f8
confile: lxc.rootfs --> lxc.rootfs.path
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:06 +02:00
0x0916
b67771bc26 confile: rename lxc.utsname to lxc.uts.name
the legacy keys will be kept around until LXC 3.0 and then will be
removed.

Signed-off-by: 0x0916 <w@laoqinren.net>
2017-06-30 09:43:53 +08:00
0x0916
55c84efcba confile: namespace lxc.signal keys
* rename lxc.haltsignal to lxc.signal.halt
* rename lxc.rebootsignal to lxc.signal.reboot
* rename lxc.stopsignal to lxc.signal.stop

the legacy keys will be kept around until LXC 3.0 and then will be
removed.

Signed-off-by: 0x0916 <w@laoqinren.net>
2017-06-30 09:41:25 +08:00
Evgeni Golov
37fbf44812 do not set insecure passwords
Signed-off-by: Evgeni Golov <evgeni@debian.org>
2016-12-15 20:04:15 +01:00
Bogdan Purcareata
07e4c41f29 lxc-busybox: Remove warning for dynamically linked Busybox
The warning has been present since commit 32b37181ea (with no purpose stated).
Support for dynamically linked Busybox has been added since commit bf6cc73696.
Haven't encountered any issues with dynamically linked Busybox in my last
2 years' testing.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2016-03-24 12:46:32 -04:00
Bogdan Purcareata
6ab1ca0375 lxc-busybox: Touch /etc/fstab in the container rootfs
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
2016-03-24 07:09:15 +01:00
Bogdan Purcareata
88e3899351 lxc-busybox: Prevent copying binaries from /usr/local to container
On certain systems, some binaries needed by the container features (dropbear,
openssh), may be placed in non-standard (aka non-distribution-managed
locations), such as /usr/local/*, /opt/local/*, etc. Don't copy the respective
binaries in the container and return a clear error why.

The user should only use these binaries if they are installed at system-wide
locations on the host, such as /{s,}bin or /usr/{s,}bin.

v2:
- check that binary paths adhere to /{,usr/}{,s}bin only

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-05-26 13:04:43 -04:00
Bogdan Purcareata
4432b512a2 lxc-busybox: make some OpenSSH tools optional
Currently, when installing OpenSSH in a Busybox container, the template searches
for all the OpenSSH client binaries available in the Debian distro package. The
included tools might differ from distro to distro, so make part of the tools
optional. The mandatory tools, without which installing OpenSSH fails, are
"sshd" for the server and "ssh" and "scp" for the client.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-05-26 13:04:41 -04:00
Bogdan Purcareata
ed52814c77 lxc-busybox: add OpenSSH support
Add an additional template parameter for SSH support in the container. Currently
this can be implemented using the Dropbear or OpenSSH utility. The respective
tool needs to be available on the host Linux.

If the parameter is omitted, the template will look for the Dropbear utility on
the host and install it if it is available (legacy behavior).

Adding OpenSSH support has been done following the model in the lxc-sshd
template.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-04-22 12:34:19 -04:00
Bogdan Purcareata
22fb28a946 lxc-busybox: use lxc.rebootsignal = SIGTERM
Otherwise lxc-stop -r has no effect on the container.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-02-18 09:42:40 -08:00
Stéphane Graber
f24a52d5f5 Use consistent /proc, /sys and /sys/fs/cgroup (v2)
- Implements mixed mode for /sys where it's mounted read-only but with
   /sys/devices/virtual/net/ writable.

 - Sets lxc.mount.auto to "cgroup:mixed proc:mixed sys:mixed" for all
   templates.

 - Drop any template-specific mount for /proc, /sys or /sys/fs/cgroup.

 - Get rid of the fstab file by default, using lxc.mount.entry instead.

 - Set sys:mixed as the default for "sys". sys:mixed is slightly more
   permissive than sys:ro so this shouldn't be a problem.

The read-only bind mount of /sys on top of itself is there so that
mountall and other init systems don't attempt to remount /sys
read-write.

v2 changes:
 - Fix the mount list, don't specify a source for the remount.
 - Update the documentation.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-01-29 11:44:02 +01:00
Serge Hallyn
cfe615f031 fix busybox unpriv
1. tty5 is not needed
2. the devices should be optional in case they didn't exist in the
host / parent-container
3. switch from 'touch $rootfs/dev/$dev' to using create=file in the
mount entry.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-01-27 10:30:29 +01:00
Bogdan Purcareata
12c3b43fbe busybox template: mount fstab when available
When running unprivileged, lxc-create will touch a fstab file, with bind-mounts
for the ttys and other devices. Add this entry in the container config.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 09:18:14 -05:00
Bogdan Purcareata
a542dd3c1a busybox template: support for unprivileged containers
Apply the changes found in templates/lxc-download to the busybox template as
well. Change ownership of the config and fstab files to the unprivileged user,
and the ownership of the rootfs to root in the new user namespace.

Eliminate the "unsupported for userns" flag.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 09:18:05 -05:00
Bogdan Purcareata
50dbb8209b lxc-busybox: follow symlinks when inspecting busybox binary
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-24 14:19:27 -05:00
Stéphane Graber
96283b5460
templates: Fix bashisms in common code
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-02-19 10:45:14 -05:00
Stéphane Graber
207bf0e475 templates: Make sure usual locations are in PATH
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-02-06 17:14:03 -05:00
TAMUKI Shoichi
c63c04fcaf templates: improve refusing to run unprivileged
For all templates except lxc-ubuntu-cloud and lxc-download, detect not
only --mapped-uid but also --mapped-gid and error out.  Detecting will
not be done after -- parameter because of non-option parameters.

Also, change the mode of lxc-archlinux.in 100755 to 100644.

Signed-off-by: TAMUKI Shoichi <tamuki@linet.gr.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-02-06 11:05:20 -05:00
Stéphane Graber
8ec981fc8b templates: Refuse to run unprivileged
Only the download and ubuntu-cloud templates work with unprivileged
containers, for all others, detect --mapped-uid and error out as early
as possible, recommending the use of the download template.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-02-04 14:30:51 -05:00
Elan Ruusamäe
17abf2784d handle simple bashisms:
- [[ ]] -> [ ]
- == -> =
- source -> .
- redirect of fd 200 is error in mksh, use fd 9
- &> /dev/null -> > /dev/null 2>&1
- useless function keyword
- echo -e -> printf

still left bash shebang which did not validate with checkbashism, mostly
due 'type' being reported as bashism

Signed-Off-By: Elan Ruusamäe <glen@delfi.ee>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-01-14 16:16:00 -05:00
Dwight Engen
f0f1d8c076 add lxc.haltsignal for soft shutdown
- use this in the busybox template since busybox's init expects
  to receive SIGUSR1 to halt

- fix lxc.stopsignal to be output by write_config so lxcapi_clone()
  and lxcapi_save_config() will output it

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-01-06 12:49:44 -05:00