Add GetMode to mounter interface.
Kubelet must not call os.Lstat on raw volume paths when it runs in a container. Mounter knows where the file really is.
This commit is contained in:
parent
23d9a48e6a
commit
97b5299cd7
@ -120,6 +120,10 @@ func (mi *fakeMountInterface) GetSELinuxSupport(pathname string) (bool, error) {
|
|||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mi *fakeMountInterface) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func fakeContainerMgrMountInt() mount.Interface {
|
func fakeContainerMgrMountInt() mount.Interface {
|
||||||
return &fakeMountInterface{
|
return &fakeMountInterface{
|
||||||
[]mount.MountPoint{
|
[]mount.MountPoint{
|
||||||
|
@ -175,12 +175,6 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
|
|||||||
return nil, cleanupAction, fmt.Errorf("unable to provision SubPath `%s`: %v", mount.SubPath, err)
|
return nil, cleanupAction, fmt.Errorf("unable to provision SubPath `%s`: %v", mount.SubPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileinfo, err := os.Lstat(hostPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, cleanupAction, err
|
|
||||||
}
|
|
||||||
perm := fileinfo.Mode()
|
|
||||||
|
|
||||||
volumePath, err := filepath.EvalSymlinks(hostPath)
|
volumePath, err := filepath.EvalSymlinks(hostPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cleanupAction, err
|
return nil, cleanupAction, err
|
||||||
@ -195,6 +189,11 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
|
|||||||
// when the pod specifies an fsGroup, and if the directory is not created here, Docker will
|
// when the pod specifies an fsGroup, and if the directory is not created here, Docker will
|
||||||
// later auto-create it with the incorrect mode 0750
|
// later auto-create it with the incorrect mode 0750
|
||||||
// Make extra care not to escape the volume!
|
// Make extra care not to escape the volume!
|
||||||
|
perm, err := mounter.GetMode(volumePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, cleanupAction, err
|
||||||
|
}
|
||||||
|
|
||||||
if err := mounter.SafeMakeDir(hostPath, volumePath, perm); err != nil {
|
if err := mounter.SafeMakeDir(hostPath, volumePath, perm); err != nil {
|
||||||
glog.Errorf("failed to mkdir %q: %v", hostPath, err)
|
glog.Errorf("failed to mkdir %q: %v", hostPath, err)
|
||||||
return nil, cleanupAction, err
|
return nil, cleanupAction, err
|
||||||
|
@ -163,3 +163,7 @@ func (m *execMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (m *execMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (m *execMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return m.wrappedMounter.GetSELinuxSupport(pathname)
|
return m.wrappedMounter.GetSELinuxSupport(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *execMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return m.wrappedMounter.GetMode(pathname)
|
||||||
|
}
|
||||||
|
@ -176,3 +176,7 @@ func (fm *fakeMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (fm *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (fm *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fm *fakeMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
@ -110,3 +110,7 @@ func (mounter *execMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (mounter *execMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (mounter *execMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *execMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
@ -232,3 +232,7 @@ func (f *FakeMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (f *FakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (f *FakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return false, errors.New("GetSELinuxSupport not implemented")
|
return false, errors.New("GetSELinuxSupport not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FakeMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
@ -117,6 +117,8 @@ type Interface interface {
|
|||||||
// GetSELinuxSupport returns true if given path is on a mount that supports
|
// GetSELinuxSupport returns true if given path is on a mount that supports
|
||||||
// SELinux.
|
// SELinux.
|
||||||
GetSELinuxSupport(pathname string) (bool, error)
|
GetSELinuxSupport(pathname string) (bool, error)
|
||||||
|
// GetMode returns permissions of the path.
|
||||||
|
GetMode(pathname string) (os.FileMode, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Subpath struct {
|
type Subpath struct {
|
||||||
|
@ -982,6 +982,10 @@ func (mounter *Mounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
return getFSGroup(realpath)
|
return getFSGroup(realpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *Mounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return getMode(pathname)
|
||||||
|
}
|
||||||
|
|
||||||
// This implementation is shared between Linux and NsEnterMounter
|
// This implementation is shared between Linux and NsEnterMounter
|
||||||
func getFSGroup(pathname string) (int64, error) {
|
func getFSGroup(pathname string) (int64, error) {
|
||||||
info, err := os.Stat(pathname)
|
info, err := os.Stat(pathname)
|
||||||
@ -991,6 +995,15 @@ func getFSGroup(pathname string) (int64, error) {
|
|||||||
return int64(info.Sys().(*syscall.Stat_t).Gid), nil
|
return int64(info.Sys().(*syscall.Stat_t).Gid), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This implementation is shared between Linux and NsEnterMounter
|
||||||
|
func getMode(pathname string) (os.FileMode, error) {
|
||||||
|
info, err := os.Stat(pathname)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return info.Mode(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// This implementation is shared between Linux and NsEnterMounter
|
// This implementation is shared between Linux and NsEnterMounter
|
||||||
func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
||||||
glog.V(4).Infof("Creating directory %q within base %q", pathname, base)
|
glog.V(4).Infof("Creating directory %q within base %q", pathname, base)
|
||||||
|
@ -138,3 +138,7 @@ func (mounter *Mounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (mounter *Mounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (mounter *Mounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *Mounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
@ -461,6 +461,14 @@ func (mounter *Mounter) GetSELinuxSupport(pathname string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *Mounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
info, err := os.Stat(pathname)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return info.Mode(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// SafeMakeDir makes sure that the created directory does not escape given base directory mis-using symlinks.
|
// SafeMakeDir makes sure that the created directory does not escape given base directory mis-using symlinks.
|
||||||
func (mounter *Mounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
func (mounter *Mounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
||||||
return doSafeMakeDir(pathname, base, perm)
|
return doSafeMakeDir(pathname, base, perm)
|
||||||
|
@ -347,3 +347,11 @@ func (mounter *NsenterMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (mounter *NsenterMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (mounter *NsenterMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return getSELinuxSupport(pathname, procMountInfoPath)
|
return getSELinuxSupport(pathname, procMountInfoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *NsenterMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
kubeletpath, err := mounter.ne.KubeletPath(pathname)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return getMode(kubeletpath)
|
||||||
|
}
|
||||||
|
@ -110,3 +110,7 @@ func (*NsenterMounter) GetFSGroup(pathname string) (int64, error) {
|
|||||||
func (*NsenterMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
func (*NsenterMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*NsenterMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
@ -103,6 +103,10 @@ func (mounter *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
|
|||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *fakeMounter) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
||||||
name := path.Base(file)
|
name := path.Base(file)
|
||||||
if strings.HasPrefix(name, "mount") {
|
if strings.HasPrefix(name, "mount") {
|
||||||
|
@ -401,6 +401,10 @@ func (fftc *fakeFileTypeChecker) GetSELinuxSupport(pathname string) (bool, error
|
|||||||
return false, errors.New("not implemented")
|
return false, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fftc *fakeFileTypeChecker) GetMode(pathname string) (os.FileMode, error) {
|
||||||
|
return 0, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func setUp() error {
|
func setUp() error {
|
||||||
err := os.MkdirAll("/tmp/ExistingFolder", os.FileMode(0755))
|
err := os.MkdirAll("/tmp/ExistingFolder", os.FileMode(0755))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user