Bug 264425 - sysutils/nomad: Secure nomad data_dir
Summary: sysutils/nomad: Secure nomad data_dir
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: John Hixson
URL: https://www.nomadproject.io/docs/oper...
Keywords: needs-qa, security
Depends on:
Blocks:
 
Reported: 2022-06-03 01:56 UTC by Michael Gmelin
Modified: 2022-06-10 16:51 UTC (History)
1 user (show)

See Also:
jhixson: maintainer-feedback+
koobs: merge-quarterly?


Attachments
Patch nomad startup script to create nomad_dir using struct permissions (1.09 KB, patch)
2022-06-03 01:56 UTC, Michael Gmelin
no flags Details | Diff
Patch nomad startup script to make sure nomad data-dir has proper permissions (2.46 KB, patch)
2022-06-03 13:17 UTC, Michael Gmelin
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Gmelin freebsd_committer freebsd_triage 2022-06-03 01:56:23 UTC
Created attachment 234404 [details]
Patch nomad startup script to create nomad_dir using struct permissions

Nomad's security model depends on `data_dir` to be protected by restrictive file permissions (0700), as it writes secrets (like vault tokens) with world-readable permissions (0666) below this path.

Right now, the nomad rc script creates data_dir (which is configured using nomad_dir in /etc/rc.conf) with the default umask if it doesn't exist.

The (untested, but hopefully trivial enough) attached patch fixes this by simply running chmod 0700 on the newly created directory. It is suitable to be applied using `git am`.

See also:
- https://github.com/hashicorp/nomad/issues/11900#issuecomment-1145503292
  Discussion where I learned about this fact
- https://www.nomadproject.io/docs/operations/nomad-agent#permissions
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2022-06-03 02:18:28 UTC
Any implications for quarterly users if this was merged in terms of manual intervention on upgrade or change in functionality?
Comment 2 Michael Gmelin freebsd_committer freebsd_triage 2022-06-03 02:35:50 UTC
(In reply to Kubilay Kocak from comment #1)

The patch only makes a difference on first start of the service (when creating the directory). So no effect on update.

It might make sense to *always* correct the directory permissions on service start though (which would be a slightly different patch) or warn about it or refuse to start the service if permissions aren't strict enough- which would be more intrusive on update for existing users, but also bring them the benefit of increased security.

I guess it's up to the maintainer which approach to take - my patch is the least intrusive choice, only affecting new installations.
Comment 3 Michael Gmelin freebsd_committer freebsd_triage 2022-06-03 13:17:30 UTC
Created attachment 234420 [details]
Patch nomad startup script to make sure nomad data-dir has proper permissions

(In reply to Michael Gmelin from comment #2)

Actually, having slept over this, I think that extending the patch so it won't start nomad in case directory permissions are too lax might be a better route, as it makes sure that existing usesr correct file permissions.

The new patch does exactly this, check if permissions are correct and if not, don't start the service and output a helpful error message.

Also adds pkg-message to explain the change.

Only tested locally, no full poudriere QA done.
Comment 4 John Hixson freebsd_committer freebsd_triage 2022-06-09 22:29:02 UTC
I am currently updating the port. I should have v1.3.1 available soon with your patch applied. Thanks!
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-06-09 23:50:18 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=38014c3b12f4064e77d1b8fc9b1ac787e2ef270d

commit 38014c3b12f4064e77d1b8fc9b1ac787e2ef270d
Author:     John Hixson <jhixson@FreeBSD.org>
AuthorDate: 2022-06-09 23:43:57 +0000
Commit:     John Hixson <jhixson@FreeBSD.org>
CommitDate: 2022-06-09 23:49:10 +0000

    sysutils/nomad: update to v1.3.1

    Security fix for data_dir as discussed here:
    https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264425

    PR:     264425
    Reported by:    Michael Gmeli <grembo@FreeBSD.org>

 sysutils/nomad/Makefile          | 216 +++++++++++----------
 sysutils/nomad/distinfo          | 394 ++++++++++++++++++++++-----------------
 sysutils/nomad/files/nomad.in    |  11 +-
 sysutils/nomad/pkg-message (new) |  15 ++
 4 files changed, 365 insertions(+), 271 deletions(-)