Commit Graph

57 Commits

Author SHA1 Message Date
Tim Gross
fa40cd89dd workflow test for builds and backports (#25688)
Remove a useless comment to run a test of the build and backport workflows.

Ref: https://hashicorp.atlassian.net/browse/NET-11804
Ref: https://hashicorp.atlassian.net/browse/NET-10556
2025-04-15 16:11:17 -04:00
Charlie Voiselle
30ab8897d2 deps: Switch from mitchellh/cli to hashicorp/cli (#19321)
Co-authored-by: James Rasell <jrasell@hashicorp.com>
2024-12-19 15:41:11 +00:00
Tim Gross
df86503349 template: sandbox template rendering
The Nomad client renders templates in the same privileged process used for most
other client operations. During internal testing, we discovered that a malicious
task can create a symlink that can cause template rendering to read and write to
arbitrary files outside the allocation sandbox. Because the Nomad agent can be
restarted without restarting tasks, we can't simply check that the path is safe
at the time we write without encountering a time-of-check/time-of-use race.

To protect Nomad client hosts from this attack, we'll now read and write
templates in a subprocess:

* On Linux/Unix, this subprocess is sandboxed via chroot to the allocation
  directory. This requires that Nomad is running as a privileged process. A
  non-root Nomad agent will warn that it cannot sandbox the template renderer.

* On Windows, this process is sandboxed via a Windows AppContainer which has
  been granted access to only to the allocation directory. This does not require
  special privileges on Windows. (Creating symlinks in the first place can be
  prevented by running workloads as non-Administrator or
  non-ContainerAdministrator users.)

Both sandboxes cause encountered symlinks to be evaluated in the context of the
sandbox, which will result in a "file not found" or "access denied" error,
depending on the platform. This change will also require an update to
Consul-Template to allow callers to inject a custom `ReaderFunc` and
`RenderFunc`.

This design is intended as a workaround to allow us to fix this bug without
creating backwards compatibility issues for running tasks. A future version of
Nomad may introduce a read-only mount specifically for templates and artifacts
so that tasks cannot write into the same location that the Nomad agent is.

Fixes: https://github.com/hashicorp/nomad/issues/19888
Fixes: CVE-2024-1329
2024-02-08 10:40:24 -05:00
hashicorp-copywrite[bot]
a9d61ea3fd Update copyright file headers to BUSL-1.1 2023-08-10 17:27:29 -05:00
hashicorp-copywrite[bot]
f005448366 [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
Seth Hoenig
b21aeb8715 main: remove deprecated uses of rand.Seed (#16074)
* main: remove deprecated uses of rand.Seed

go1.20 deprecates rand.Seed, and seeds the rand package
automatically. Remove cases where we seed the random package,
and cleanup the one case where we intentionally create a
known random source.

* cl: update cl

* mod: update go mod
2023-02-07 09:19:38 -06:00
Tim Gross
6145cdcd11 cli: remove deprecated keyring and keygen commands (#16068)
These command were marked as deprecated in 1.4.0 with intent to remove in
1.5.0. Remove them and clean up the docs.
2023-02-07 09:49:52 -05:00
Seth Hoenig
cfc67c3422 client: sandbox go-getter subprocess with landlock (#15328)
* client: sandbox go-getter subprocess with landlock

This PR re-implements the getter package for artifact downloads as a subprocess.

Key changes include

On all platforms, run getter as a child process of the Nomad agent.
On Linux platforms running as root, run the child process as the nobody user.
On supporting Linux kernels, uses landlock for filesystem isolation (via go-landlock).
On all platforms, restrict environment variables of the child process to a static set.
notably TMP/TEMP now points within the allocation's task directory
kernel.landlock attribute is fingerprinted (version number or unavailable)
These changes make Nomad client more resilient against a faulty go-getter implementation that may panic, and more secure against bad actors attempting to use artifact downloads as a privilege escalation vector.

Adds new e2e/artifact suite for ensuring artifact downloading works.

TODO: Windows git test (need to modify the image, etc... followup PR)

* landlock: fixup items from cr

* cr: fixup tests and go.mod file
2022-12-07 16:02:25 -06:00
Tim Gross
b3baaa2fd2 docker_logger: reorder imports to save memory (#14875)
Nomad runs one logmon process and also one docker_logger process for each
running allocation. A naive look at memory usage shows 10-30 MB of RSS, but a
closer look shows that most of this memory (ex. all but ~2MB for logmon) is
shared (`Shared_Clean` in Linux pmap).

But a heap dump of docker_logger shows that it currently has an extra ~2500 KiB
of heap (anonymously-mapped unshared memory) used for init blocks coming from
the agent code (ex. mostly regexes from go-version, structs, and the Consul
SDK). The packages for running logmon, docker_logger, and executor have an init
block that parses `os.Args` to drop into their own logic, which prevents them
from loading all the rest of the agent code and saves on memory, so this was
unexpected.

It looks like we accidentally reordered the imports in main to undo some of the
work originally done in 404d2d4c98. This changeset
restores the ordering. A follow-up heap dump shows this saves ~2MB of unshared
RSS per docker_logger process.
2022-10-11 13:23:03 -04:00
Seth Hoenig
be7ec8de3e raw_exec: make raw exec driver work with cgroups v2
This PR adds support for the raw_exec driver on systems with only cgroups v2.

The raw exec driver is able to use cgroups to manage processes. This happens
only on Linux, when exec_driver is enabled, and the no_cgroups option is not
set. The driver uses the freezer controller to freeze processes of a task,
issue a sigkill, then unfreeze. Previously the implementation assumed cgroups
v1, and now it also supports cgroups v2.

There is a bit of refactoring in this PR, but the fundamental design remains
the same.

Closes #12351 #12348
2022-04-04 16:11:38 -05:00
Mahmood Ali
68bae12fd4 Raft Debugging Improvements (#11414) 2021-11-04 10:16:12 -04:00
Florian Apolloner
6cb36971c6 Added support for -force-color to the CLI. (#10975) 2021-10-06 10:02:42 -04:00
Mahmood Ali
1896b8f7dd add helper commands for debugging state 2020-08-31 08:45:59 -04:00
Lang Martin
b5ef217c90 nomad debug renamed to nomad operator debug (#8602)
* renamed: command/debug.go -> command/operator_debug.go
* website: rename debug -> operator debug
* website/pages/api-docs/agent: name in api docs
2020-08-11 15:39:44 -04:00
Mahmood Ali
7e69a5be21 fix comment typo 2019-09-18 09:11:08 -04:00
Nick Ethier
404d2d4c98 reduce memory required for logmon, docker_logger and executor p… (#6341)
* reduce memory required for logmon, docker_logger and executor processes

* comment early importing
2019-09-17 23:55:07 -04:00
Danielle Tomlinson
ed9818a570 ui: Support colored output on Windows
This commit uses the go-colorable library to enable support for coloured
UI output on Windows. This acts as a compatibility layer that takes
standard unix-y terminal codes and translates them into the requisite
windows calls as required.
2019-02-20 14:01:35 +01:00
Danielle Tomlinson
ccf0202ba7 cli: Hide nomad docker_logger from help output 2019-01-23 16:27:05 +01:00
Nick Ethier
5b14d24bf4 executor v2 (#4656)
* client/executor: refactor client to remove interpolation

* executor: POC libcontainer based executor

* vendor: use hashicorp libcontainer fork

* vendor: add libcontainer/nsenter dep

* executor: updated executor interface to simplify operations

* executor: implement logging pipe

* logmon: new logmon plugin to manage task logs

* driver/executor: use logmon for log management

* executor: fix tests and windows build

* executor: fix logging key names

* executor: fix test failures

* executor: add config field to toggle between using libcontainer and standard executors

* logmon: use discover utility to discover nomad executable

* executor: only call libcontainer-shim on main in linux

* logmon: use seperate path configs for stdout/stderr fifos

* executor: windows fixes

* executor: created reusable pid stats collection utility that can be used in an executor

* executor: update fifo.Open calls

* executor: fix build

* remove executor from docker driver

* executor: Shutdown func to kill and cleanup executor and its children

* executor: move linux specific universal executor funcs to seperate file

* move logmon initialization to a task runner hook

* client: doc fixes and renaming from code review


* taskrunner: use shared config struct for logmon fifo fields

* taskrunner: logmon only needs to be started once per task
2018-10-16 16:53:31 -07:00
Michael Schurter
7ff790bc7d cli: differentiate normal output vs info 2018-03-30 11:42:11 -07:00
Alex Dadgar
0360176c00 Autocomplete command aliases
This PR allows aliased commands to be autocompleted but still filters
them from the help output.
2018-03-29 12:55:25 -07:00
Chelsea Holland Komlo
7aae8ab7ab remove unused function 2018-03-23 09:51:27 -04:00
Alex Dadgar
148a9504e7 color 2018-03-21 20:27:32 -07:00
Alex Dadgar
d39b13ed58 Deprecated commands 2018-03-21 20:27:32 -07:00
Alex Dadgar
683e271069 common commands 2018-03-21 20:27:32 -07:00
Alex Dadgar
c7fc6571d8 use subcommands 2018-03-21 20:27:32 -07:00
Alex Dadgar
378c566294 node eligibility command 2018-03-21 16:51:44 -07:00
Alex Dadgar
2bdeacebff Drain cli, api, http 2018-03-21 16:51:43 -07:00
Alex Dadgar
f6fbb36054 sync 2017-10-13 14:36:02 -07:00
Alex Dadgar
a9e3a41407 Enable more linters 2017-09-26 15:26:33 -07:00
Chelsea Holland Komlo
4e3d4b1cd0 remove unneeded hidden command 2017-09-15 20:23:41 +00:00
Chelsea Holland Komlo
7941e78406 filter acl subcommands 2017-09-15 19:37:57 +00:00
Chelsea Holland Komlo
23e0acbea4 fixups from code review 2017-09-15 18:08:46 +00:00
Alex Dadgar
ed8f07f324 Hide non-user commands from autocomplete output
This PR hides non-user CLI commands from the list of autocomplete
suggestions.
2017-09-08 11:24:21 -07:00
Alex Dadgar
ac1539d5d9 Sync namespace changes 2017-09-07 17:04:21 -07:00
Alex Dadgar
c26ecb7092 Add version package
This PR adds a version package and consolidates version strings into a
Version struct.
2017-08-16 15:44:21 -07:00
Alex Dadgar
b57b9af467 Fix vet issue 2017-07-26 14:53:08 -07:00
Alex Dadgar
9c610a8862 Custom help output 2017-07-25 15:42:22 -07:00
Alex Dadgar
635395a479 Job promote command 2017-07-19 15:39:32 -07:00
Alex Dadgar
c0084dcab1 Add command autocompletion.
This PR adds command autocompletion to the CLI.
2017-07-17 15:00:40 -07:00
Alex Dadgar
b21d912277 Allow cli package to handle version.
This PR removes our custom handling of the version flag and updates job
history to use a version flag instead of `-job-version`.
2017-07-17 11:04:07 -07:00
Alex Dadgar
4ce7b62105 job deployments 2017-07-07 12:07:07 -07:00
Alex Dadgar
004a766171 deployment promote 2017-07-07 12:07:07 -07:00
Alex Dadgar
dc3d500119 deployment list 2017-07-07 12:07:07 -07:00
Alex Dadgar
fbd2b73904 job revert 2017-07-07 12:07:07 -07:00
Alex Dadgar
9220836cb4 JobVersions returns struct with optional diff 2017-07-07 12:05:57 -07:00
Alex Dadgar
24995a6749 Operator command/endpoint/documentation 2017-02-09 18:04:46 -08:00
Alex Dadgar
c1bc077d32 Vendor memberlist fixes 2017-02-08 16:07:33 -08:00
Sean Chittenden
3f9d3854dd Seed random once in main 2016-06-10 15:48:36 -04:00
Diptanu Choudhury
e0cddec857 Filtering out nomad check 2016-05-17 05:39:39 +02:00