github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/drivers/exec.mdx (about) 1 --- 2 layout: docs 3 page_title: 'Drivers: Exec' 4 description: The Exec task driver is used to run binaries using OS isolation primitives. 5 --- 6 7 # Isolated Fork/Exec Driver 8 9 Name: `exec` 10 11 The `exec` driver is used to simply execute a particular command for a task. 12 However, unlike [`raw_exec`](/docs/drivers/raw_exec) it uses the underlying isolation 13 primitives of the operating system to limit the task's access to resources. While 14 simple, since the `exec` driver can invoke any command, it can be used to call 15 scripts or other wrappers which provide higher level features. 16 17 ## Task Configuration 18 19 ```hcl 20 task "webservice" { 21 driver = "exec" 22 23 config { 24 command = "my-binary" 25 args = ["-flag", "1"] 26 } 27 } 28 ``` 29 30 The `exec` driver supports the following configuration in the job spec: 31 32 - `command` - The command to execute. Must be provided. If executing a binary 33 that exists on the host, the path must be absolute and within the task's 34 [chroot](#chroot) or in a [host volume][] mounted with a 35 [`volume_mount`][volume_mount] block. The driver will make the binary 36 executable and will search, in order: 37 38 - The `local` directory with the task directory. 39 - The task directory. 40 - Any mounts, in the order listed in the job specification. 41 - The `usr/local/bin`, `usr/bin` and `bin` directories inside the task 42 directory. 43 44 If executing a binary that is downloaded 45 from an [`artifact`](/docs/job-specification/artifact), the path can be 46 relative from the allocation's root directory. 47 48 - `args` - (Optional) A list of arguments to the `command`. References 49 to environment variables or any [interpretable Nomad 50 variables](/docs/runtime/interpolation) will be interpreted before 51 launching the task. 52 53 - `pid_mode` - (Optional) Set to `"private"` to enable PID namespace isolation for 54 this task, or `"host"` to disable isolation. If left unset, the behavior is 55 determined from the [`default_pid_mode`][default_pid_mode] in plugin configuration. 56 57 !> **Warning:** If set to `"host"`, other processes running as the same user will 58 be able to access sensitive process information like environment variables. 59 60 - `ipc_mode` - (Optional) Set to `"private"` to enable IPC namespace isolation for 61 this task, or `"host"` to disable isolation. If left unset, the behavior is 62 determined from the [`default_ipc_mode`][default_ipc_mode] in plugin configuration. 63 64 !> **Warning:** If set to `"host"`, other processes running as the same user will be 65 able to make use of IPC features, like sending unexpected POSIX signals. 66 67 - `cap_add` - (Optional) A list of Linux capabilities to enable for the task. 68 Effective capabilities (computed from `cap_add` and `cap_drop`) must be a subset 69 of the allowed capabilities configured with [`allow_caps`][allow_caps]. 70 71 ```hcl 72 config { 73 cap_add = ["net_raw", "sys_time"] 74 } 75 ``` 76 77 - `cap_drop` - (Optional) A list of Linux capabilities to disable for the task. 78 Effective capabilities (computed from `cap_add` and `cap_drop`) must be a subset 79 of the allowed capabilities configured with [`allow_caps`][allow_caps]. 80 81 ```hcl 82 config { 83 cap_drop = ["all"] 84 cap_add = ["chown", "sys_chroot", "mknod"] 85 } 86 ``` 87 88 ## Examples 89 90 To run a binary present on the Node: 91 92 ```hcl 93 task "example" { 94 driver = "exec" 95 96 config { 97 # When running a binary that exists on the host, the path must be absolute. 98 command = "/bin/sleep" 99 args = ["1"] 100 } 101 } 102 ``` 103 104 To execute a binary downloaded from an 105 [`artifact`](/docs/job-specification/artifact): 106 107 ```hcl 108 task "example" { 109 driver = "exec" 110 111 config { 112 command = "name-of-my-binary" 113 } 114 115 artifact { 116 source = "https://internal.file.server/name-of-my-binary" 117 options { 118 checksum = "sha256:abd123445ds4555555555" 119 } 120 } 121 } 122 ``` 123 124 ## Capabilities 125 126 The `exec` driver implements the following [capabilities](/docs/concepts/plugins/task-drivers#capabilities-capabilities-error). 127 128 | Feature | Implementation | 129 | -------------------- | -------------- | 130 | `nomad alloc signal` | true | 131 | `nomad alloc exec` | true | 132 | filesystem isolation | chroot | 133 | network isolation | host, group | 134 | volume mounting | all | 135 136 ## Client Requirements 137 138 The `exec` driver can only be run when on Linux and running Nomad as root. 139 `exec` is limited to this configuration because currently isolation of resources 140 is only guaranteed on Linux. Further, the host must have cgroups mounted properly 141 in order for the driver to work. 142 143 If you are receiving the error: 144 145 ``` 146 * Constraint "missing drivers" filtered <> nodes 147 ``` 148 149 and using the exec driver, check to ensure that you are running Nomad as root. 150 This also applies for running Nomad in -dev mode. 151 152 ## Plugin Options 153 154 - `default_pid_mode` `(string: optional)` - Defaults to `"private"`. Set to 155 `"private"` to enable PID namespace isolation for tasks by default, or `"host"` to 156 disable isolation. 157 158 !> **Warning:** If set to `"host"`, other processes running as the same user will 159 be able to access sensitive process information like environment variables. 160 161 - `default_ipc_mode` `(string: optional)` - Defaults to `"private"`. Set to 162 `"private"` to enable IPC namespace isolation for tasks by default, 163 or `"host"` to disable isolation. 164 165 !> **Warning:** If set to `"host"`, other processes running as the same user will be 166 able to make use of IPC features, like sending unexpected POSIX signals. 167 168 - `no_pivot_root` `(bool: optional)` - Defaults to `false`. When `true`, the driver uses `chroot` 169 for file system isolation without `pivot_root`. This is useful for systems 170 where the root is on a ramdisk. 171 172 - `allow_caps` - A list of allowed Linux capabilities. Defaults to 173 174 ```hcl 175 ["audit_write", "chown", "dac_override", "fowner", "fsetid", "kill", "mknod", 176 "net_bind_service", "setfcap", "setgid", "setpcap", "setuid", "sys_chroot"] 177 ``` 178 179 which is modeled after the capabilities allowed by [docker by default][docker_caps] 180 (without [`NET_RAW`][no_net_raw]). Allows the operator to control which capabilities 181 can be obtained by tasks using [`cap_add`][cap_add] and [`cap_drop`][cap_drop] options. 182 Supports the value `"all"` as a shortcut for allow-listing all capabilities supported 183 by the operating system. 184 185 !> **Warning:** Allowing more capabilities beyond the default may lead to 186 undesirable consequences, including untrusted tasks being able to compromise the 187 host system. 188 189 ## Client Attributes 190 191 The `exec` driver will set the following client attributes: 192 193 - `driver.exec` - This will be set to "1", indicating the driver is available. 194 195 ## Resource Isolation 196 197 The resource isolation provided varies by the operating system of 198 the client and the configuration. 199 200 On Linux, Nomad will use cgroups, and a chroot to isolate the resources of a 201 process and as such the Nomad agent must be run as root. Some Linux 202 distributions do not boot with all required cgroups enabled by default. You 203 can see which cgroups are enabled by reading `/proc/cgroups`, and verifying 204 that all the following cgroups are enabled: 205 206 ``` 207 $ awk '{print $1 " " $4}' /proc/cgroups 208 #subsys_name enabled 209 cpuset 1 210 cpu 1 211 cpuacct 1 212 blkio 1 213 memory 1 214 devices 1 215 freezer 1 216 net_cls 1 217 perf_event 1 218 net_prio 1 219 hugetlb 1 220 pids 1 221 ``` 222 223 ### Chroot 224 225 The chroot is populated with data in the following directories from the host 226 machine: 227 228 ``` 229 [ 230 "/bin", 231 "/etc", 232 "/lib", 233 "/lib32", 234 "/lib64", 235 "/run/resolvconf", 236 "/sbin", 237 "/usr", 238 ] 239 ``` 240 241 The task's chroot is populated by linking or copying the data from the host into 242 the chroot. Note that this can take considerable disk space. Since Nomad v0.5.3, 243 the client manages garbage collection locally which mitigates any issue this may 244 create. 245 246 This list is configurable through the agent client 247 [configuration file](/docs/configuration/client#chroot_env). 248 249 [default_pid_mode]: /docs/drivers/exec#default_pid_mode 250 [default_ipc_mode]: /docs/drivers/exec#default_ipc_mode 251 [cap_add]: /docs/drivers/exec#cap_add 252 [cap_drop]: /docs/drivers/exec#cap_drop 253 [no_net_raw]: /docs/upgrade/upgrade-specific#nomad-1-1-0-rc1-1-0-5-0-12-12 254 [allow_caps]: /docs/drivers/exec#allow_caps 255 [docker_caps]: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities 256 [host volume]: /docs/configuration/client#host_volume-stanza 257 [volume_mount]: /docs/job-specification/volume_mount