Skip to content
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

Windows EmptyDir volumes are not created with 0777 #75049

Closed
benmoss opened this issue Mar 6, 2019 · 13 comments
Closed

Windows EmptyDir volumes are not created with 0777 #75049

benmoss opened this issue Mar 6, 2019 · 13 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/windows Categorizes an issue or PR as relevant to SIG Windows.

Comments

@benmoss
Copy link
Member

benmoss commented Mar 6, 2019

What happened:
Running a Windows pod with an EmptyDir volume attached should allow a non-Administrator user to read, write, and execute files inside that directory. Instead, it appears that this currently only works if the host's filesystem has ACLs set on a parent directory that set these permissions on all subdirectories. Basically the equivalent of setting 0777 on all of /var/lib/kubelet or something like that.

What you expected to happen:
EmptyDir directories should be created with 0777 permissions, just like on Linux.

How to reproduce it (as minimally and precisely as possible):

/sig windows

@benmoss benmoss added the kind/bug Categorizes issue or PR as related to a bug. label Mar 6, 2019
@k8s-ci-robot k8s-ci-robot added the sig/windows Categorizes an issue or PR as relevant to SIG Windows. label Mar 6, 2019
@benmoss
Copy link
Member Author

benmoss commented Mar 6, 2019

@benmoss
Copy link
Member Author

benmoss commented Mar 6, 2019

Seems like at least part of the problem is that Mkdir on Windows ignores the file mode, since Windows permissions are a bit different: https://github.com/golang/sys/blob/70f52985063808f21fd6dd197895cdb9729443a5/windows/syscall_windows.go#L433-L439

@michmike michmike added this to Backlog (v.1.15) in SIG-Windows Mar 6, 2019
@yujuhong
Copy link
Contributor

yujuhong commented Mar 6, 2019

Seems like at least part of the problem is that Mkdir on Windows ignores the file mode, since Windows permissions are a bit different: https://github.com/golang/sys/blob/70f52985063808f21fd6dd197895cdb9729443a5/windows/syscall_windows.go#L433-L439

:-(

Ref: code to set permission to 777 in emptydir

const perm os.FileMode = 0777

/cc @jingxu97, who ran into similar problems writing tests.

@yujuhong yujuhong added the sig/storage Categorizes an issue or PR as relevant to SIG Storage. label Mar 6, 2019
@benmoss
Copy link
Member Author

benmoss commented Mar 7, 2019

Started looking at this today, it's more difficult than I imagined. What I mean by "are not created with 0777" is that on Linux 0777 means all users have read/write/execute access. The code in

func (ed *emptyDir) setupDir(dir string) error {
// Create the directory if it doesn't already exist.
if err := os.MkdirAll(dir, perm); err != nil {
return err
}
// stat the directory to read permission bits
fileinfo, err := os.Lstat(dir)
if err != nil {
return err
}
if fileinfo.Mode().Perm() != perm.Perm() {
// If the permissions on the created directory are wrong, the
// kubelet is probably running with a umask set. In order to
// avoid clearing the umask for the entire process or locking
// the thread, clearing the umask, creating the dir, restoring
// the umask, and unlocking the thread, we do a chmod to set
// the specific bits we need.
err := os.Chmod(dir, perm)
if err != nil {
return err
}
fileinfo, err = os.Lstat(dir)
if err != nil {
return err
}
if fileinfo.Mode().Perm() != perm.Perm() {
klog.Errorf("Expected directory %q permissions to be: %s; got: %s", dir, perm.Perm(), fileinfo.Mode().Perm())
}
}
return nil
}
is running on Windows and isn't erroring, but the problem is that Go's attempt to map Unix permissions to Windows ends up not really matching the intention of this code.

I don't know that there is a super straightforward way to translate something like 0777 to Windows, except maybe putting ACLs on the directory giving BUILTIN\Users the windows.GENERIC_ALL permission.

@yujuhong
Copy link
Contributor

yujuhong commented Mar 7, 2019

I don't know that there is a super straightforward way to translate something like 0777 to Windows, except maybe putting ACLs on the directory giving BUILTIN\Users the windows.GENERIC_ALL permission.

This is what was done in the stackoverflow answer: https://stackoverflow.com/questions/33445727/how-to-control-file-access-in-windows

@jingxu97
Copy link
Contributor

cc @andyzhangx

Could we fix this issue this the package mentioned by @yujuhong? https://github.com/hectane/go-acl

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 11, 2019
@yujuhong yujuhong removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 11, 2019
@yujuhong
Copy link
Contributor

@benmoss @PatrickLang do you know of a better way to handle this, or would we have to change the ACLs as the comments above suggest?

@benmoss
Copy link
Member Author

benmoss commented Jun 11, 2019

@PatrickLang PatrickLang moved this from Backlog (v.1.15) to Backlog (v1.16) in SIG-Windows Jun 18, 2019
@PatrickLang PatrickLang moved this from Backlog (v1.16) to Backlog in SIG-Windows Aug 29, 2019
@liyanhui1228
Copy link
Contributor

Tried reproducing this by deploying that pod using the yaml file, and this seems like already been fixed in someway. We could mark this as fixed if it cannot be reproduced any more. cc @yujuhong

Path Owner                       Access
---- -----                       ------
C:\  NT SERVICE\TrustedInstaller CREATOR OWNER Allow  268435456
                                NT AUTHORITY\SYSTEM Allow  FullControl
                                BUILTIN\Administrators Allow  FullControl
                                BUILTIN\Users Allow  AppendData
                                BUILTIN\Users Allow  CreateFiles
                                BUILTIN\Users Allow  ReadAndExecute, Synchronize
PS C:\busybox> get-acl /cache | format-table -wrap

Path  Owner                  Access
----  -----                  ------
cache BUILTIN\Administrators NT AUTHORITY\SYSTEM Allow  FullControl
                             BUILTIN\Administrators Allow  FullControl
                             BUILTIN\Users Allow  ReadAndExecute, Synchronize
                             BUILTIN\Users Allow  AppendData
                             BUILTIN\Users Allow  CreateFiles
                             CREATOR OWNER Allow  268435456

@yujuhong
Copy link
Contributor

yujuhong commented Sep 4, 2019

@benmoss could you still reproduce the issue?

@benmoss
Copy link
Member Author

benmoss commented Sep 5, 2019

No, I'm not sure this is still an issue
/close

@k8s-ci-robot
Copy link
Contributor

@benmoss: Closing this issue.

In response to this:

No, I'm not sure this is still an issue
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

SIG-Windows automation moved this from Backlog to Done (v1.16) Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/windows Categorizes an issue or PR as relevant to SIG Windows.
Projects
None yet
Development

No branches or pull requests

6 participants