-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client: enable specifying user/group permissions in the template stanza #13755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
There's one piece missing to fully pipe the values from the job file all the way to the task runner, which is to set the uid
and gid
values in ApiTaskToStructsTask
. This is the function that transforms an api.Task
(external representation used by the api
package and SDK) into a structs.Task
(internal representation).
More over though, there's a fundamental challenge here related to how Nomad creates the task file system.
To illustrate the problem, after updating ApiTaskToStructsTask
, run a Docker task with a template using the new fields:
job "example" {
datacenters = ["dc1"]
group "cache" {
network {
port "db" {
to = 6379
}
}
task "redis" {
driver = "docker"
template {
data = <<EOF
hello
EOF
destination = "local/test"
uid = 1000
gid = 1000
}
config {
image = "redis:7"
ports = ["db"]
auth_soft_fail = true
}
resources {
cpu = 500
memory = 256
}
}
}
}
Then exec into the task and take a look at the file ownership:
$ nomad job allocs example
ID Node ID Task Group Version Desired Status Created Modified
0d067f1a 6322f391 cache 0 run running 33s ago 22s ago
$ nomad alloc exec 0d /bin/bash
root@2c548b828bf9:/data# ls -l /local/test
-rw-r--r-- 1 root root 6 Jul 14 21:58 /local/test
And then look at the file on your machine (you can grab the path from Nomad's logs, there will be a message like 2022-07-14T17:58:45.402-0400 [DEBUG] agent: (runner) final config: {"Consul":...
with the full template config, one of the values is the rendered file path):
$ ls -l /private/tmp/NomadClient1242048785/0d067f1a-515a-506a-9848-716952d5ffd0/redis/local/test
-rw-r--r-- 1 1000 6 Jul 14 17:58 /private/tmp/NomadClient1242048785/0d067f1a-515a-506a-9848-716952d5ffd0/redis/local/test
So consul-template
operates at the host level and does the right thing: in my machine the file owner ID is 1000
, but inside the container the owner is still root
. We do this because Nomad doesn't know which user is running within the container, so permissions for the task directory are set broadly.
We'll need to figure out how to go around this 😅
Done, thanks for catching this 👍
So this is somewhat tricky. Nomad does a
I set uid and gid to 33, which corresponds to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments, and it also needs a changelog entry but LGTM!
Co-authored-by: Luiz Aoqui <[email protected]>
Co-authored-by: Luiz Aoqui <[email protected]>
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR adds support for specifying uid and gid of the template file. Resolves #5020.