open-nomad/website/content/docs/drivers/exec.mdx

246 lines
7.6 KiB
Plaintext
Raw Normal View History

2015-09-20 22:31:33 +00:00
---
2020-02-06 23:45:31 +00:00
layout: docs
page_title: 'Drivers: Exec'
description: The Exec task driver is used to run binaries using OS isolation primitives.
2015-09-20 22:31:33 +00:00
---
2015-10-08 18:36:22 +00:00
# Isolated Fork/Exec Driver
2015-09-20 22:31:33 +00:00
Name: `exec`
2015-09-20 22:42:33 +00:00
The `exec` driver is used to simply execute a particular command for a task.
2020-02-10 19:20:59 +00:00
However, unlike [`raw_exec`](/docs/drivers/raw_exec) it uses the underlying isolation
2016-08-27 12:56:39 +00:00
primitives of the operating system to limit the task's access to resources. While
2020-02-06 23:45:31 +00:00
simple, since the `exec` driver can invoke any command, it can be used to call
2015-10-08 19:18:44 +00:00
scripts or other wrappers which provide higher level features.
2015-09-20 22:42:33 +00:00
## Task Configuration
```hcl
task "webservice" {
driver = "exec"
config {
command = "my-binary"
args = ["-flag", "1"]
}
}
```
2015-09-20 22:42:33 +00:00
The `exec` driver supports the following configuration in the job spec:
2020-02-06 23:45:31 +00:00
- `command` - The command to execute. Must be provided. If executing a binary
that exists on the host, the path must be absolute and within the task's
2020-02-10 19:20:59 +00:00
[chroot](#chroot). If executing a binary that is downloaded from
2020-02-06 23:45:31 +00:00
an [`artifact`](/docs/job-specification/artifact), the path can be
relative from the allocations's root directory.
2020-02-06 23:45:31 +00:00
- `args` - (Optional) A list of arguments to the `command`. References
to environment variables or any [interpretable Nomad
2020-02-06 23:45:31 +00:00
variables](/docs/runtime/interpolation) will be interpreted before
launching the task.
2015-09-20 22:42:33 +00:00
- `pid_mode` - (Optional) Set to `"private"` to enable PID namespace isolation for
this task, or `"host"` to disable isolation. If left unset, the behavior is
determined from the [`default_pid_mode`][default_pid_mode] in plugin configuration.
!> **Warning:** If set to `"host"`, other processes running as the same user will
be able to access sensitive process information like environment variables.
- `ipc_mode` - (Optional) Set to `"private"` to enable IPC namespace isolation for
this task, or `"host"` to disable isolation. If left unset, the behavior is
determined from the [`default_ipc_mode`][default_ipc_mode] in plugin configuration.
!> **Warning:** If set to `"host"`, other processes running as the same user will be
able to make use of IPC features, like sending unexpected POSIX signals.
- `cap_add` - (Optional) A list of Linux capabilities to enable for the task.
Effective capabilities (computed from `cap_add` and `cap_drop`) must be a subset
of the allowed capabilities configured with [`allow_caps`][allow_caps].
```hcl
config {
cap_add = ["net_raw", "sys_time"]
}
```
- `cap_drop` - (Optional) A list of Linux capabilities to disable for the task.
Effective capabilities (computed from `cap_add` and `cap_drop`) must be a subset
of the allowed capabilities configured with [`allow_caps`][allow_caps].
```hcl
config {
cap_drop = ["all"]
cap_add = ["chown", "sys_chroot", "mknod"]
}
```
## Examples
To run a binary present on the Node:
```hcl
task "example" {
driver = "exec"
2016-03-16 16:56:04 +00:00
config {
# When running a binary that exists on the host, the path must be absolute.
command = "/bin/sleep"
args = ["1"]
}
}
```
To execute a binary downloaded from an
2020-02-06 23:45:31 +00:00
[`artifact`](/docs/job-specification/artifact):
```hcl
task "example" {
driver = "exec"
2016-03-16 16:56:04 +00:00
config {
command = "name-of-my-binary"
}
2016-03-16 16:56:04 +00:00
artifact {
source = "https://internal.file.server/name-of-my-binary"
options {
checksum = "sha256:abd123445ds4555555555"
2016-03-16 16:56:04 +00:00
}
}
}
```
## Capabilities
The `exec` driver implements the following [capabilities](/docs/internals/plugins/task-drivers#capabilities-capabilities-error).
2020-09-30 13:48:40 +00:00
| Feature | Implementation |
| -------------------- | -------------- |
| `nomad alloc signal` | true |
| `nomad alloc exec` | true |
| filesystem isolation | chroot |
| network isolation | host, group |
| volume mounting | all |
2016-03-16 16:56:04 +00:00
## Client Requirements
The `exec` driver can only be run when on Linux and running Nomad as root.
`exec` is limited to this configuration because currently isolation of resources
2016-08-27 12:56:39 +00:00
is only guaranteed on Linux. Further, the host must have cgroups mounted properly
2016-03-16 16:56:04 +00:00
in order for the driver to work.
If you are receiving the error:
```
* Constraint "missing drivers" filtered <> nodes
```
and using the exec driver, check to ensure that you are running Nomad as root.
This also applies for running Nomad in -dev mode.
2016-03-16 16:56:04 +00:00
## Plugin Options
- `default_pid_mode` `(string: optional)` - Defaults to `"private"`. Set to
`"private"` to enable PID namespace isolation for tasks by default, or `"host"` to
disable isolation.
!> **Warning:** If set to `"host"`, other processes running as the same user will
be able to access sensitive process information like environment variables.
- `default_ipc_mode` `(string: optional)` - Defaults to `"private"`. Set to
`"private"` to enable IPC namespace isolation for tasks by default,
or `"host"` to disable isolation.
!> **Warning:** If set to `"host"`, other processes running as the same user will be
able to make use of IPC features, like sending unexpected POSIX signals.
- `no_pivot_root` `(bool: optional)` - Defaults to `false`. When `true`, the driver uses `chroot`
for file system isolation without `pivot_root`. This is useful for systems
where the root is on a ramdisk.
- `allow_caps` - A list of allowed Linux capabilities. Defaults to
```hcl
["audit_write", "chown", "dac_override", "fowner", "fsetid", "kill", "mknod",
"net_bind_service", "setfcap", "setgid", "setpcap", "setuid", "sys_chroot"]
```
which is modeled after the capabilities allowed by [docker by default][docker_caps]
2021-05-17 18:52:52 +00:00
(without [`NET_RAW`][no_net_raw]). Allows the operator to control which capabilities
can be obtained by tasks using [`cap_add`][cap_add] and [`cap_drop`][cap_drop] options.
Supports the value `"all"` as a shortcut for allow-listing all capabilities supported
by the operating system.
!> **Warning:** Allowing more capabilities beyond the default may lead to
undesirable consequences, including untrusted tasks being able to compromise the
host system.
2015-09-20 22:42:33 +00:00
## Client Attributes
The `exec` driver will set the following client attributes:
2020-02-06 23:45:31 +00:00
- `driver.exec` - This will be set to "1", indicating the driver is available.
2015-09-20 22:42:33 +00:00
## Resource Isolation
The resource isolation provided varies by the operating system of
the client and the configuration.
On Linux, Nomad will use cgroups, and a chroot to isolate the resources of a
process and as such the Nomad agent must be run as root. Some Linux
distributions do not boot with all required cgroups enabled by default. You
can see which cgroups are enabled by reading `/proc/cgroups`, and verifying
that all the following cgroups are enabled:
```
$ awk '{print $1 " " $4}' /proc/cgroups
#subsys_name enabled
cpuset 1
cpu 1
cpuacct 1
blkio 1
memory 1
devices 1
freezer 1
net_cls 1
perf_event 1
net_prio 1
hugetlb 1
pids 1
```
2016-01-21 23:02:51 +00:00
2020-03-26 20:21:24 +00:00
### Chroot
2020-02-06 23:45:31 +00:00
2016-08-27 12:56:39 +00:00
The chroot is populated with data in the following directories from the host
2016-01-21 23:02:51 +00:00
machine:
```
[
"/bin",
"/etc",
"/lib",
"/lib32",
"/lib64",
"/run/resolvconf",
"/sbin",
"/usr",
]
```
2017-01-23 18:51:57 +00:00
The task's chroot is populated by linking or copying the data from the host into
the chroot. Note that this can take considerable disk space. Since Nomad v0.5.3,
the client manages garbage collection locally which mitigates any issue this may
create.
This list is configurable through the agent client
2020-02-06 23:45:31 +00:00
[configuration file](/docs/configuration/client#chroot_env).
[default_pid_mode]: /docs/drivers/exec#default_pid_mode
[default_ipc_mode]: /docs/drivers/exec#default_ipc_mode
[cap_add]: /docs/drivers/exec#cap_add
[cap_drop]: /docs/drivers/exec#cap_drop
[no_net_raw]: /docs/upgrade/upgrade-specific#nomad-1-1-0-rc1-1-0-5-0-12-12
[allow_caps]: /docs/drivers/exec#allow_caps
[docker_caps]: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities