e2e: setup nomad permissions correctly (client vs. server) (#16399)

This PR configures

- server nodes with a systemd unit running the agent as the nomad service user
- client nodes with a root owned nomad data directory
This commit is contained in:
Seth Hoenig 2023-03-08 14:41:08 -06:00 committed by GitHub
parent b0124ee683
commit 2b5efeac04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -1,11 +1,12 @@
[Unit]
Description=Nomad Agent
Description=Nomad Client Agent
Requires=network-online.target
After=network-online.target
StartLimitIntervalSec=0
StartLimitBurst=3
[Service]
User=root
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad.d
EnvironmentFile=-/etc/nomad.d/.environment

View File

@ -1,11 +1,12 @@
[Unit]
Description=Nomad Agent
Description=Nomad Server Agent
Requires=network-online.target
After=network-online.target
StartLimitIntervalSec=0
StartLimitBurst=3
[Service]
User=nomad
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad.d
EnvironmentFile=-/etc/nomad.d/.environment

View File

@ -58,6 +58,10 @@ resource "null_resource" "install_consul_configs_linux" {
}
}
locals {
data_owner = var.role == "client" ? "root" : "nomad"
}
resource "null_resource" "install_nomad_configs_linux" {
count = var.platform == "linux" ? 1 : 0
@ -79,6 +83,7 @@ resource "null_resource" "install_nomad_configs_linux" {
"mkdir -p /etc/nomad.d",
"mkdir -p /opt/nomad/data",
"sudo chmod 0700 /opt/nomad/data",
"sudo chown ${local.data_owner}:${local.data_owner} /opt/nomad/data",
"sudo rm -rf /etc/nomad.d/*",
"sudo mv /tmp/consul.hcl /etc/nomad.d/consul.hcl",
"sudo mv /tmp/vault.hcl /etc/nomad.d/vault.hcl",