[lxc-devel] [lxd/master] lxd/profiles: Prevent rename/remove of default

stgraber on Github lxc-bot at linuxcontainers.org
Mon Jul 16 16:30:17 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180716/59e2f8a1/attachment.bin>
-------------- next part --------------
From d1d4d027da630026f6711d7490f305a71ea84576 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 16 Jul 2018 12:29:24 -0400
Subject: [PATCH] lxd/profiles: Prevent rename/remove of default
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4791

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

diff --git a/lxd/profiles.go b/lxd/profiles.go
index 5cb6bf963..a32a4a1b4 100644
--- a/lxd/profiles.go
+++ b/lxd/profiles.go
@@ -297,6 +297,10 @@ func profilePost(d *Daemon, r *http.Request) Response {
 	}
 
 	// Sanity checks
+	if name == "default" {
+		return BadRequest(fmt.Errorf("The default profile cannot be renamed"))
+	}
+
 	if req.Name == "" {
 		return BadRequest(fmt.Errorf("No name provided"))
 	}
@@ -327,6 +331,10 @@ func profilePost(d *Daemon, r *http.Request) Response {
 func profileDelete(d *Daemon, r *http.Request) Response {
 	name := mux.Vars(r)["name"]
 
+	if name == "default" {
+		return BadRequest(fmt.Errorf("The default profile cannot be removed"))
+	}
+
 	_, err := doProfileGet(d.State(), name)
 	if err != nil {
 		return SmartError(err)


More information about the lxc-devel mailing list