瀏覽代碼

We need to fix labels if the user requests on volumes

Currently local volumes and other volumes that support SELinux do
not get labeled correctly.  This patch will allow a user to specify
:Z or :z when  mounting a volume and have it fix the label of the newly
created volume.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
Dan Walsh 8 年之前
父節點
當前提交
0c791c8e9f
共有 1 個文件被更改,包括 14 次插入6 次删除
  1. 14 6
      volume/volume.go

+ 14 - 6
volume/volume.go

@@ -124,7 +124,20 @@ type MountPoint struct {
 
 
 // Setup sets up a mount point by either mounting the volume if it is
 // Setup sets up a mount point by either mounting the volume if it is
 // configured, or creating the source directory if supplied.
 // configured, or creating the source directory if supplied.
-func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (string, error) {
+func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (path string, err error) {
+	defer func() {
+		if err == nil {
+			if label.RelabelNeeded(m.Mode) {
+				if err = label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode)); err != nil {
+					path = ""
+					err = errors.Wrapf(err, "error setting label on mount source '%s'", m.Source)
+					return
+				}
+			}
+		}
+		return
+	}()
+
 	if m.Volume != nil {
 	if m.Volume != nil {
 		id := m.ID
 		id := m.ID
 		if id == "" {
 		if id == "" {
@@ -152,11 +165,6 @@ func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (string, err
 			}
 			}
 		}
 		}
 	}
 	}
-	if label.RelabelNeeded(m.Mode) {
-		if err := label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode)); err != nil {
-			return "", errors.Wrapf(err, "error setting label on mount source '%s'", m.Source)
-		}
-	}
 	return m.Source, nil
 	return m.Source, nil
 }
 }