-
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
Chown files when copying into chroot #2553
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.
Thanks for addressing this so quickly, today was my first day reading go so please bear with me!
client/allocdir/alloc_dir.go
Outdated
return fmt.Errorf("Couldn't copy %q to %q: %v", src, dst, err) | ||
} | ||
|
||
if uid >= 0 && gid >= 0 { |
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.
Do we want to say ||
here in case the perms are like root:bob
?
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.
I want to make sure they're both both valid IDs. Even if it's root:bob
that's uid=0, gid>0 which will pass this conditional.
client/allocdir/fs_unix.go
Outdated
if err := os.Link(src, dst); err == nil { | ||
return nil | ||
} | ||
//if err := os.Link(src, dst); err == nil { |
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.
Were you maybe just doing this for testing / can we keep hardlinking?
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.
Wow! Huge goof on my part. Thanks for the review! Fixing.
client/allocdir/fs_linux.go
Outdated
@@ -88,3 +88,11 @@ func removeSecretDir(dir string) error { | |||
} | |||
return os.RemoveAll(dir) | |||
} | |||
|
|||
func getOwner(fi os.FileInfo) (int, int) { | |||
stat, ok := fi.Sys().(*syscall.Stat_t) |
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.
Is syscall.Stat_t
not implemented on the other platforms we chroot in? We shouldn't leave the bug open on other platforms we chroot in
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.
We tried a build with the existing patch, but even when hardlinking files, the code is creating the directories to contain these hardlinks, without honoring the ownership (you can't hardlink directories). I think we need to check the ownership of the source directory somehwere around here: https://github.com/hashicorp/nomad/blob/master/client/allocdir/task_dir.go#L176 |
With this change, this allows ownership of directories to be preserved.
|
This looks good except for the use of the |
Fixes #2552 Not needed when hardlinking. Only adds Linux support but other OS's may be easy.
e4e7a4c
to
cabe9a6
Compare
Also support getOwner on all Unixes as they all have `Stat_t.{U,G}id`
cabe9a6
to
17471bf
Compare
@dadgar Fixed! A quick peek reveals all Unixes we support have @jshuping Great catch. Fixed! @sean- The only place we use |
LGTM |
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. |
Fixes #2552
Not needed when hardlinking. Only adds Linux support but other Unixes may
be easy.