[lxc-devel] [lxd/master] Rsync version detection and various small fixes

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jul 3 15:26:41 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200703/e8f56793/attachment.bin>
-------------- next part --------------
From f0bd85c884f018ca006852da1099f507ebcec0c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 10:28:00 -0400
Subject: [PATCH 1/7] lxd/network: Validate ipv4/ipv6 routes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #7612

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/networks_config.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/networks_config.go b/lxd/networks_config.go
index 66b2ef5101..f4e32f4263 100644
--- a/lxd/networks_config.go
+++ b/lxd/networks_config.go
@@ -73,7 +73,7 @@ var networkConfigKeys = map[string]func(value string) error{
 	"ipv4.dhcp.gateway": device.NetworkValidAddressV4,
 	"ipv4.dhcp.expiry":  shared.IsAny,
 	"ipv4.dhcp.ranges":  shared.IsAny,
-	"ipv4.routes":       shared.IsAny,
+	"ipv4.routes":       device.NetworkValidNetworkV4List,
 	"ipv4.routing":      shared.IsBool,
 
 	"ipv6.address": func(value string) error {
@@ -93,7 +93,7 @@ var networkConfigKeys = map[string]func(value string) error{
 	"ipv6.dhcp.expiry":   shared.IsAny,
 	"ipv6.dhcp.stateful": shared.IsBool,
 	"ipv6.dhcp.ranges":   shared.IsAny,
-	"ipv6.routes":        shared.IsAny,
+	"ipv6.routes":        device.NetworkValidNetworkV6List,
 	"ipv6.routing":       shared.IsBool,
 
 	"dns.domain": shared.IsAny,

From c0d41c495fa0cfe7436422590afa4e3ed4388dab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 10:51:15 -0400
Subject: [PATCH 2/7] lxd/proxy: Fix govet
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/device/proxy.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/device/proxy.go b/lxd/device/proxy.go
index c86f04e17b..39958f4891 100644
--- a/lxd/device/proxy.go
+++ b/lxd/device/proxy.go
@@ -439,7 +439,7 @@ func (d *proxy) setupProxyProcInfo() (*proxyProcInfo, error) {
 
 	containerPidFd := -1
 	lxdPidFd := -1
-	var inheritFd []*os.File = nil
+	var inheritFd []*os.File
 	if d.state.OS.PidFds {
 		cPidFd, err := cc.InitPidFd()
 		if err == nil {

From 8af8d2d4028632684cd0b3a191648f8bb69fd502 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 11:05:45 -0400
Subject: [PATCH 3/7] lxd/rsync: Add AtLeast
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/rsync/rsync.go | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/lxd/rsync/rsync.go b/lxd/rsync/rsync.go
index b5b70a58ce..b6893a1860 100644
--- a/lxd/rsync/rsync.go
+++ b/lxd/rsync/rsync.go
@@ -7,6 +7,7 @@ import (
 	"net"
 	"os"
 	"os/exec"
+	"strings"
 	"time"
 
 	"github.com/pborman/uuid"
@@ -15,6 +16,7 @@ import (
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/ioprogress"
 	"github.com/lxc/lxd/shared/logger"
+	"github.com/lxc/lxd/shared/version"
 )
 
 // LocalCopy copies a directory using rsync (with the --devices option).
@@ -369,3 +371,32 @@ func rsyncFeatureArgs(features []string) []string {
 
 	return args
 }
+
+// AtLeast compares the local version to a minimum version.
+func AtLeast(min string) bool {
+	// Parse the current version.
+	out, err := shared.RunCommand("rsync", "--version")
+	if err != nil {
+		return false
+	}
+
+	fields := strings.Split(strings.Split(out, "\n")[0], "  ")
+	if len(fields) < 3 {
+		return false
+	}
+
+	versionStr := strings.TrimPrefix(fields[1], "version ")
+
+	ver, err := version.NewDottedVersion(versionStr)
+	if err != nil {
+		return false
+	}
+
+	// Load minium version.
+	minVer, err := version.NewDottedVersion(min)
+	if err != nil {
+		return false
+	}
+
+	return ver.Compare(minVer) >= 0
+}

From 39d6e23d027b1113ea5b85c8a146fa8648628cc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 11:06:08 -0400
Subject: [PATCH 4/7] lxd/rsync: Filter out security.selinux
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #7607

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/rsync/rsync.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lxd/rsync/rsync.go b/lxd/rsync/rsync.go
index b6893a1860..7a7f1a118b 100644
--- a/lxd/rsync/rsync.go
+++ b/lxd/rsync/rsync.go
@@ -47,6 +47,9 @@ func LocalCopy(source string, dest string, bwlimit string, xattrs bool, rsyncArg
 
 	if xattrs {
 		args = append(args, "--xattrs")
+		if AtLeast("3.1.3") {
+			args = append(args, "--filter=-x security.selinux")
+		}
 	}
 
 	if bwlimit != "" {
@@ -358,6 +361,9 @@ func rsyncFeatureArgs(features []string) []string {
 	args := []string{}
 	if shared.StringInSlice("xattrs", features) {
 		args = append(args, "--xattrs")
+		if AtLeast("3.1.3") {
+			args = append(args, "--filter=-x security.selinux")
+		}
 	}
 
 	if shared.StringInSlice("delete", features) {

From 716912a697250b081dff855e662952c31f42a4a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 11:06:17 -0400
Subject: [PATCH 5/7] lxd-p2c: Filter out security.selinux
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd-p2c/transfer.go | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/lxd-p2c/transfer.go b/lxd-p2c/transfer.go
index 9679212ae2..329c2754f4 100644
--- a/lxd-p2c/transfer.go
+++ b/lxd-p2c/transfer.go
@@ -13,8 +13,8 @@ import (
 	"github.com/pborman/uuid"
 
 	"github.com/lxc/lxd/lxd/migration"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/shared"
-	"github.com/lxc/lxd/shared/version"
 )
 
 // Send an rsync stream of a path over a websocket
@@ -83,28 +83,11 @@ func rsyncSendSetup(path string, rsyncArgs string) (*exec.Cmd, net.Conn, io.Read
 		"--compress-level=2",
 	}
 
-	// Ignore deletions (requires 3.1 or higher)
-	rsyncCheckVersion := func(min string) bool {
-		out, err := shared.RunCommand("rsync", "--version")
-		if err != nil {
-			return false
-		}
-
-		fields := strings.Split(out, " ")
-		curVer, err := version.Parse(fields[3])
-		if err != nil {
-			return false
-		}
-
-		minVer, err := version.Parse(min)
-		if err != nil {
-			return false
-		}
-
-		return curVer.Compare(minVer) >= 0
+	if rsync.AtLeast("3.1.3") {
+		args = append(args, "--filter=-x security.selinux")
 	}
 
-	if rsyncCheckVersion("3.1.0") {
+	if rsync.AtLeast("3.1.0") {
 		args = append(args, "--ignore-missing-args")
 	}
 

From 5e7dc62615e2e432b04093bef533f351c43c1fae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 11:12:32 -0400
Subject: [PATCH 6/7] lxc-to-lxd: Filter out security.selinux
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc-to-lxd/transfer.go | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/lxc-to-lxd/transfer.go b/lxc-to-lxd/transfer.go
index 57c85fbcb9..abcae89bc4 100644
--- a/lxc-to-lxd/transfer.go
+++ b/lxc-to-lxd/transfer.go
@@ -13,8 +13,8 @@ import (
 	"github.com/pborman/uuid"
 
 	"github.com/lxc/lxd/lxd/migration"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/shared"
-	"github.com/lxc/lxd/shared/version"
 )
 
 // Send an rsync stream of a path over a websocket
@@ -79,28 +79,11 @@ func rsyncSendSetup(path string, rsyncArgs string) (*exec.Cmd, net.Conn, io.Read
 		"--compress-level=2",
 	}
 
-	// Ignore deletions (requires 3.1 or higher)
-	rsyncCheckVersion := func(min string) bool {
-		out, err := shared.RunCommand("rsync", "--version")
-		if err != nil {
-			return false
-		}
-
-		fields := strings.Split(out, " ")
-		curVer, err := version.Parse(fields[3])
-		if err != nil {
-			return false
-		}
-
-		minVer, err := version.Parse(min)
-		if err != nil {
-			return false
-		}
-
-		return curVer.Compare(minVer) >= 0
+	if rsync.AtLeast("3.1.3") {
+		args = append(args, "--filter=-x security.selinux")
 	}
 
-	if rsyncCheckVersion("3.1.0") {
+	if rsync.AtLeast("3.1.0") {
 		args = append(args, "--ignore-missing-args")
 	}
 

From 869c6c34c7d5666383a9d1b92df69717f5346a56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jul 2020 11:25:36 -0400
Subject: [PATCH 7/7] lxc/launch: Add --console
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/launch.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lxc/launch.go b/lxc/launch.go
index adab111d43..019a02ed4f 100644
--- a/lxc/launch.go
+++ b/lxc/launch.go
@@ -14,6 +14,8 @@ import (
 type cmdLaunch struct {
 	global *cmdGlobal
 	init   *cmdInit
+
+	flagConsole bool
 }
 
 func (c *cmdLaunch) Command() *cobra.Command {
@@ -31,6 +33,8 @@ lxc launch ubuntu:18.04 u1 < config.yaml
 
 	cmd.RunE = c.Run
 
+	cmd.Flags().BoolVar(&c.flagConsole, "console", false, i18n.G("Immediately attach to the console"))
+
 	return cmd
 }
 
@@ -98,7 +102,14 @@ func (c *cmdLaunch) Run(cmd *cobra.Command, args []string) error {
 
 		return fmt.Errorf("%s\n"+i18n.G("Try `lxc info --show-log %s` for more info"), err, prettyName)
 	}
-
 	progress.Done("")
+
+	// Handle console attach
+	if c.flagConsole {
+		console := cmdConsole{}
+		console.global = c.global
+		return console.Console(d, name)
+	}
+
 	return nil
 }


More information about the lxc-devel mailing list