Commit Graph

55 Commits

Author SHA1 Message Date
Stéphane Graber
4c8139f9cf
Remove autotools
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-06-08 00:46:59 -04:00
Stéphane Graber
faa4ae06ef
meson: Add lxcmntent to unmount-namespace hook
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-06-07 17:18:14 -04:00
Stéphane Graber
8d77f43f5c
meson: Cleanup and fix includes
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-06-07 17:18:04 -04:00
Stéphane Graber
eba7f7a6bc
meson: Rework configuration variables
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-06-02 16:50:00 -04:00
Stéphane Graber
31985a040d
meson: Fix hook install locations
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-05-01 10:24:35 +02:00
Stéphane Graber
20b03401be
meson: Cleanup build configs
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-04-28 22:17:01 -04:00
Simon Deziel
af0ab1854c Replace last occurence of 'which' with 'command -v'
The later is builtin and POSIX compliant.

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
2021-10-28 17:10:05 -04:00
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
7af71c9416
hooks: fix quoting
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-27 12:51:18 +02:00
Christian Brauner
659611a36d
build: add hooks
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-27 11:39:52 +02:00
Christian Brauner
db4af8c57e
build: improve meson build
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-23 14:05:24 +02:00
Christian Brauner
bfcece94b6
hooks: use cloexec everywhere
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-16 14:45:39 +02:00
Christian Brauner
26a6b71917
build: fix hook program build
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-16 14:45:36 +02:00
Christian Brauner
58db1a61c8
build: add src/include to build and simplify header inclusions
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-03 09:25:56 +02: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
Felix Abecassis
52e1d4cb49 hooks/nvidia: handle spaces in NVIDIA_REQUIRE variables
Previously, environment variables with a space where splitted.

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2019-04-16 13:59:37 -07:00
Josh Soref
71cce97fc2 spelling: passphrase
Signed-off-by: Josh Soref <jsoref@gmail.com>
2018-10-30 07:45:15 +00:00
Josh Soref
768f183c1c spelling: override
Signed-off-by: Josh Soref <jsoref@gmail.com>
2018-10-30 07:44:56 +00:00
Felix Abecassis
d23c6cc996 Fix license of the nvidia hook
Fixes: #2494

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-07-28 18:06:58 -07:00
Felix Abecassis
41be52e8ab hooks: fix dhclient hook when an AppArmor profile is active
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-03-23 10:47:35 -07:00
Felix Abecassis
89f1ef110e hooks: implement passthrough for latest features of libnvidia-container
The "display" driver capability will expose /dev/nvidia-modeset:
9398d41d9f

The "--ldcache" argument allows overriding the location of the DSO cache:
41656bf9ed

The "--root" argument allows nvidia-container-cli to execute in a different rootfs:
019fdc14e3

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-03-19 15:38:53 -07:00
Felix Abecassis
4a0a5e89e1 hooks: fix nvidia hook when running under the lxc-start AppArmor profile
For a reason that I don't understand, the profile transition needs to
be done on the current process. Changing the attributes for a
subsequent execve(2) (with /proc/self/attr/exec) will cause the kernel
to set AT_SECURE in the auxiliary vector and thus secure_getenv(3)
inside libnvidia-container will return NULL.

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-03-19 15:34:49 -07:00
Felix Abecassis
b87243830e hooks: change the semantic of NVIDIA_VISIBLE_DEVICES=""
With LXC, you can override the value of an environment variable to
null, but you can't unset an existing variable.

The NVIDIA hook was previously activated when NVIDIA_VISIBLE_DEVICES
was set to null. As a result, it was not possible to disable the hook
by overriding the environment variable in the configuration.

The hook can now be disabled by setting NVIDIA_VISIBLE_DEVICES to
null or to the new special value "void".

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-02-02 06:19:13 -08:00
Jonathan Calmels
84bf5645ed hooks: dhclient hook improvements
- Merge dhclient-start and dhclient-stop into a single hook.
- Wait for a lease before returning from the hook.
- Generate a logfile when LXC log level is either DEBUG or TRACE.
- Rely on namespace file descriptors for the stop hook.
- Use settings from /<sysconf>/lxc/dhclient.conf if available.
- Attempt to cleanup if dhclient fails to shutdown properly.

Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-12-19 15:18:28 -08:00
Felix Abecassis
58e29e9bf1 hooks: add mount hook to configure access to NVIDIA GPUs
This hook requires the nvidia-container-cli tool provided by libnvidia-container:
https://github.com/nvidia/libnvidia-container

For containers that do not have CUDA_VERSION or NVIDIA_VISIBLE_DEVICES
set in the environment, the hook will be a no-op.

To enable in the configuration file:
lxc.hook.mount = /usr/local/share/lxc/hooks/nvidia

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-18 16:17:23 -08:00
Jonathan Calmels
27234deb3a hooks: add dhclient hooks
Add new hooks leveraging dhclient from the host to automatically
configure the container interfaces. This is especially useful for
application containers which rely on an IPAM driver for network
configuration (e.g. Docker).

Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-11-20 16:54:16 -08:00
Matt Keeler
cd85f31e26 Use LXC_ROOTFS_MOUNT in clonehostname hook
Previously this hook did not work when cloning containers using an overlayfs snapshot as the LXC_ROOTFS_PATH didn't point to the actual filesystem that the container would see. LXC_ROOTFS_MOUNT should be used instead and in fact lxc.container.conf man page says that you usually would want to use the _MOUNT variant.

Signed-off-by: Matt Keeler <mjkeeler7@gmail.com>
2017-02-23 10:13:16 -05:00
Wolfgang Bumiller
16d08ae7e3 hooks: put binary hooks into $libexecdir/lxc/hooks
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Serge Hallyn
e963273a77 coverity: free mounts on error path
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-10-17 21:16:22 -05:00
Stéphane Graber
2d9ec00d61
Tell gcc about lxcmntent for the unmount hook
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 15:44:38 -07:00
Stéphane Graber
36dd8426cb
Don't include mntent when lxcmntent is used
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 14:36:51 -07:00
Stéphane Graber
97272aec0f
Attempt to fix bionic builds of unmount-namespace
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 13:07:52 -04:00
Wolfgang Bumiller
b73f115f41 added the unmount-namespace hook
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:24 +01:00
Scott Moser
5d066f24e6 lxc-ubuntu-cloud: support passing vendor-data
vendor-data is supported in Ubuntu cloud images in trusty and later.
This allows the user to pass it in on create or clone.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
2015-07-21 10:30:19 -04:00
Serge Hallyn
cd6b3e37a6 remove mountcgroup hook entirely
Also fix the comment in lxc-cirros template (which I overlooked last time).

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-07-17 17:33:45 -05:00
Stéphane Graber
5b99af0079 Reduce duplication in new style configs
This is a rather massive cleanup of config/templates/*

As new templates were added, I've noticed that we pretty much all share
the tty/pts configs, some capabilities being dropped and most of the
cgroup configuration. All the userns configs were also almost identical.

As a result, this change introduces two new files:
 - common.conf.in
 - userns.conf.in

Each is included by the relevant <template>.<type>.conf.in templates,
this means that the individual per-template configs are now overlays on
top of the default config.

Once we see a specific key becoming popular, we ought to check whether
it should also be applied to the other templates and if more than 50% of
the templates have it set to the same value, that value ought to be
moved to the master config file and then overriden for the templates
that do not use it.

This change while pretty big and scary, shouldn't be very visible from a
user point of view, the actual changes can be summarized as:
 - Extend clonehostname to work with Debian based distros and use it for
   all containers.
 - lxc.pivotdir is now set to lxc_putold for all templates, this means
   that instead of using /mnt in the container, lxc will create and use
   /lxc_putold instead. The reason for this is to avoid failures when the
   user bind-mounts something else on top of /mnt.
 - Some minor cgroup limit changes, the main one I remember is
   /dev/console now being writable by all of the redhat based containers.
   The rest of the set should be identical with additions in the per-distro
   ones.
 - Drop binfmtmisc and efivars bind-mounts for non-mountall based
   unpriivileged containers as I assumed they got those from copy/paste
   from Ubuntu and not because they actually need those entries. (If I'm
   wrong, we probably should move those to userns.conf then).

Additional investigation and changes to reduce the config delta between
distros would be appreciated. In practice, I only expect lxc.cap.drop
and lxc.mount.entry to really vary between distros (depending on the
init system, the rest should be mostly common.

Diff from the RFC:
 - Add archlinux to the mix
 - Drop /etc/hostname from the clone hook

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-06-24 16:40:48 -04:00
Chris Glass
959dd8f250 Fix small mistake with squid-deb-proxy hook
I unfortunately realized that I did not push the latest version of the
file. This fixes an issue in the case where we want to create the proxy
file in the container (not nested).

Signed-off-by: Chris Glass <tribaal@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-01-15 10:41:16 -05:00
Chris Glass
4213a747e8 Make ubuntu templates squid-deb-proxy-client aware
This makes the ubuntu and ubuntu-cloud templates automatically aware of apt
proxy settings when the LXC host has "squid-deb-proxy-client" installed. This
makes installations *much* faster when a suitable squid-deb-proxy is
found on the network (or installed on the host).

Signed-off-by: Chris Glass <tribaal@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-01-14 16:20:52 -05:00
S.Çağlar Onur
fa7fced878 make mountcgroups hook to lxc.include aware (v2)
[resending the patch from correct branch]

commit 09ad624693 introduced lxc.include option
to include other config files. This patch uses it in mountcgroups hook otherwise
lxc-start fails with following error message for the nested containers;

root@oOo:/var/lib/lxc/raring# lxc-start -l debug -o l -n raring -d
lxc-start: command get_cgroup failed to receive response

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-12-16 08:44:32 -06:00
Serge Hallyn
1e0f62acaa ubuntu-cloud-prep hook: fix debug helper to not inappropriately fail
Bug found by Vincent Ladeuil <vila+ci@canonical.com>
Fix suggested by Scott Moser <smoser@ubuntu.com>

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-09 13:03:56 -05:00
Stéphane Graber
250b1eec71
licensing: Add missing headers and FSF address
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-03 14:33:03 -04:00
Scott Moser
cb0c6c0203 hooks/ubuntu-cloud-prep: add hostname to meta-data
prior to my enabling of the clone hook, the setting of the hostname
was being done by writing to /etc/hostname.  Instead of relying on that
we're now writing 'local-hostname' into the metadata for the instance.

cloud-init then reads this and sets the hostname properly.

We are also writing /etc/hostname with the new hostname explicitly.  This is
useful/necessary because on network bringup of eth0, dhclient will submit its
hosname.  The updating done by cloud-init occurs to late, and thus
the dhcp request goes out with the un-configured hostname and dns doens't
work correctly.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-22 15:29:06 -05:00
Scott Moser
fb760f7054 ubuntu-cloud-prep: improve overlayfs workaround
the previous 'patch_start' can be vastly simplified now that I better
understand what the bug was.  Instead of wrapping 'start', we only
need to ensure that /etc/init exists inside the overlayfs, so that the
directory that upstart watches is guaranteed to be in the overlay, not
the underlay.

The problem is described under bug 1213925.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 12:36:38 -05:00
Scott Moser
d24d56d7ee ubuntu-cloud-prep: patch /sbin/start for overlayfs
upstart depends on inotify, and overlayfs does not support inotify.

That means that the following results in 'tgt' not running. tgt is simply
used here as an example of a service that installs an upstart job and
starts it on package install.
 lxc-clone -s -B overlayfs -o source-precise-amd64 -n test1
 lxc-start -n test1
 ..
 apt-get install tgt

The change here is to modify /sbin/start inside the container so that when
something explicitly tries 'start', it results in an explicit call to
'initctl reload-configuration' so that upstart is aware of the newly
placed job.

Should overlayfs ever gain inotify support, this should still not cause
any harm.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-16 16:05:40 -05:00
Serge Hallyn
3fb18be957 hooks/Makefile.am: add ubuntu-cloud-prep
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-14 09:57:12 -05:00
Serge Hallyn
8bb17b7791 mountcgroups: use the right configuration file!
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-13 00:06:32 -05:00
Scott Moser
79159a86dd ubuntu-cloud-prep: cleanup, fix bug with userdata
--userdata was broken, completely missing an implementation.
This adds that implementation back in, makes 'debug' logic
correct, and then also improves the doc at the top.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-12 08:07:58 -05:00
Scott Moser
54e339f917 ubuntu-cloud-prep: fix bad declare of VERBOSITY
Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-09 09:59:41 -05:00
Scott Moser
65d8ae9c4a add a clone hook for ubuntu-cloud images
This allows ability to now specify '--userdata' arguments to 'create' or
to 'clone'. So now, the following means very fast start of instances with
different user-data.

$ sudo lxc-create -t ubuntu-cloud -n precise -- \
   -r precise --arch amd64

$ sudo lxc-clone -B overlayfs -o precise -s -n ephem1 \
   --userdata="my.userdata1"
$ sudo lxc-clone -B overlayfs -o precise -s -n ephem2 \
   --userdata="my.userdata2"

Also present here is
 * an improvement to the static list of Ubuntu releases. It uses
   ubuntu-distro-info if available degrades back to a static list on failure.
 * moving of the replacement variables to the top of the create template This
   is just to make it more obvious what is being replaced and put them in a
   single location.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
2013-08-09 08:40:25 -05:00