mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(storages): a pool is not made of a system directory or of another pool's
The new pool dialog took /, /etc, /var/lib/dpkg or /home as a directory pool's path, or as a share's mount point, and a path inside or around another pool's. A pool on /etc offers the host's own files as volumes, which one Delete removes; a share mounted there hides them; and a file under two pools is listed, and deleted, through both. These paths are now refused: the system directories (/var only within /var/lib/libvirt, outside libvirt's own state), /home, /mnt, /media, /opt and /srv themselves (a directory in them is fine), and a path is compared once "..", doubled and trailing slashes are resolved. A symbolic link on the host is not resolved.
This commit is contained in:
parent
2c7d7e9c3b
commit
044945bd97
6 changed files with 130 additions and 51 deletions
Binary file not shown.
|
|
@ -11,7 +11,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-13 05:44+0000\n"
|
||||
"POT-Creation-Date: 2026-11-13 07:26+0000\n"
|
||||
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
|
||||
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
|
||||
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
|
||||
|
|
@ -3489,7 +3489,7 @@ msgid "Storage pool"
|
|||
msgstr "Depolama havuzu"
|
||||
|
||||
#: instances/templates/add_instance_volume.html:41
|
||||
#: instances/templates/create_instance_w2.html:46 storages/forms.py:89
|
||||
#: instances/templates/create_instance_w2.html:46 storages/forms.py:107
|
||||
#: storages/templates/storage.html:182
|
||||
msgid "Letters, digits, dot, dash and underscore."
|
||||
msgstr "Harf, rakam, nokta, tire ve alt çizgi."
|
||||
|
|
@ -3507,8 +3507,8 @@ msgstr "Biçem"
|
|||
|
||||
#: instances/templates/add_instance_volume.html:61
|
||||
#: instances/templates/create_instance_w2.html:154
|
||||
#: instances/templates/create_instance_w2.html:220 storages/forms.py:95
|
||||
#: storages/forms.py:115 storages/templates/storage.html:197
|
||||
#: instances/templates/create_instance_w2.html:220 storages/forms.py:113
|
||||
#: storages/forms.py:133 storages/templates/storage.html:197
|
||||
msgid "Preallocate metadata (qcow2)"
|
||||
msgstr "Meta veriyi önceden ayır (qcow2)"
|
||||
|
||||
|
|
@ -3845,7 +3845,7 @@ msgstr "Seçin…"
|
|||
msgid "Custom CPU Models"
|
||||
msgstr "Özel CPU modelleri"
|
||||
|
||||
#: instances/templates/create_instance_w2.html:146 storages/forms.py:94
|
||||
#: instances/templates/create_instance_w2.html:146 storages/forms.py:112
|
||||
msgid "Size (GiB)"
|
||||
msgstr "Boyut (GiB)"
|
||||
|
||||
|
|
@ -7053,7 +7053,7 @@ msgstr "IPv4 ağ öneki /30 veya daha kısa olmalıdır"
|
|||
msgid "For libvirt, the IPv6 network prefix must be /64"
|
||||
msgstr "Libvirt için IPv6 ağ prefixi /64 olmak zorundadır"
|
||||
|
||||
#: networks/forms.py:36 storages/forms.py:27
|
||||
#: networks/forms.py:36 storages/forms.py:35
|
||||
msgid "No pool name has been entered"
|
||||
msgstr "Havuz adı girilmedi"
|
||||
|
||||
|
|
@ -7069,7 +7069,7 @@ msgstr "IPv6 alt ağı"
|
|||
msgid "Bridge or interface"
|
||||
msgstr "Köprü veya arabirim"
|
||||
|
||||
#: networks/forms.py:56 storages/forms.py:51
|
||||
#: networks/forms.py:56 storages/forms.py:59
|
||||
msgid "The pool name must not contain any special characters"
|
||||
msgstr "Havuz adı herhangi bir özel karakter içermemelidir"
|
||||
|
||||
|
|
@ -7086,7 +7086,7 @@ msgid "The pool bridge name must not contain any special characters"
|
|||
msgstr "Havuz köprü adı herhangi bir özel karakter içeremez"
|
||||
|
||||
#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
|
||||
#: storages/forms.py:82
|
||||
#: storages/forms.py:100
|
||||
msgid "This field is required."
|
||||
msgstr "Bu alan gerekli."
|
||||
|
||||
|
|
@ -8220,65 +8220,77 @@ msgstr "Worker, iş herhangi bir şeyi değiştirmeden önce durdu"
|
|||
msgid "Pool is not active"
|
||||
msgstr "Havuz etkin değil"
|
||||
|
||||
#: storages/forms.py:30 storages/templates/storage.html:102
|
||||
#: storages/forms.py:38 storages/templates/storage.html:102
|
||||
#: storages/templates/storages.html:43
|
||||
msgid "Path"
|
||||
msgstr "Yol"
|
||||
|
||||
#: storages/forms.py:31
|
||||
#: storages/forms.py:39
|
||||
msgid "Device or remote path"
|
||||
msgstr "Aygıt veya uzak yol"
|
||||
|
||||
#: storages/forms.py:32
|
||||
#: storages/forms.py:40
|
||||
msgid "Erase the device"
|
||||
msgstr "Aygıtı temizle"
|
||||
|
||||
#: storages/forms.py:33 storages/templates/create_stg_block.html:110
|
||||
#: storages/forms.py:41 storages/templates/create_stg_block.html:110
|
||||
msgid "Ceph user"
|
||||
msgstr "Ceph kullanıcısı"
|
||||
|
||||
#: storages/forms.py:34 storages/templates/create_stg_block.html:98
|
||||
#: storages/forms.py:42 storages/templates/create_stg_block.html:98
|
||||
msgid "Ceph monitor"
|
||||
msgstr "Ceph monitörü"
|
||||
|
||||
#: storages/forms.py:35 storages/templates/create_stg_block.html:104
|
||||
#: storages/forms.py:43 storages/templates/create_stg_block.html:104
|
||||
msgid "Ceph pool"
|
||||
msgstr "Ceph havuzu"
|
||||
|
||||
#: storages/forms.py:36 storages/templates/create_stg_block.html:116
|
||||
#: storages/forms.py:44 storages/templates/create_stg_block.html:116
|
||||
msgid "Ceph secret"
|
||||
msgstr "Ceph parolası"
|
||||
|
||||
#: storages/forms.py:37 storages/templates/create_stg_block.html:139
|
||||
#: storages/forms.py:45 storages/templates/create_stg_block.html:139
|
||||
msgid "Server"
|
||||
msgstr "Sunucu"
|
||||
|
||||
#: storages/forms.py:54
|
||||
#: storages/forms.py:62
|
||||
msgid "This host has a pool of that name"
|
||||
msgstr "Bu sunucuda bu adda bir havuz var"
|
||||
|
||||
#: storages/forms.py:61
|
||||
#: storages/forms.py:71
|
||||
msgid "The target must not contain any special characters"
|
||||
msgstr "Hedef herhangi bir özel karakter içeremez"
|
||||
|
||||
#: storages/forms.py:67
|
||||
#: storages/forms.py:75
|
||||
#, python-format
|
||||
msgid "%(path)s is a system directory of the host"
|
||||
msgstr "%(path)s, sunucunun bir sistem dizini"
|
||||
|
||||
#: storages/forms.py:81
|
||||
#, python-format
|
||||
msgid "Pool %(pool)s uses this path"
|
||||
msgstr "%(pool)s havuzu bu yolu kullanıyor"
|
||||
|
||||
#: storages/forms.py:74
|
||||
#: storages/forms.py:84
|
||||
#, python-format
|
||||
msgid "Pool %(pool)s uses %(path)s: one pool's directory cannot hold another's"
|
||||
msgstr ""
|
||||
"%(pool)s havuzu %(path)s yolunu kullanıyor: bir havuzun dizini başka bir "
|
||||
"havuzunkini içeremez"
|
||||
|
||||
#: storages/forms.py:92
|
||||
msgid "The disk source must not contain any special characters"
|
||||
msgstr "Disk kaynağı herhangi bir özel karakter içermemelidir"
|
||||
|
||||
#: storages/forms.py:84
|
||||
#: storages/forms.py:102
|
||||
msgid "Choose one of the host's Ceph secrets"
|
||||
msgstr "Sunucunun Ceph parolalarından birini seçin"
|
||||
|
||||
#: storages/forms.py:102 storages/forms.py:122
|
||||
#: storages/forms.py:120 storages/forms.py:140
|
||||
msgid "The image name must not contain any special characters"
|
||||
msgstr "İmaj adı herhangi bir özel karakter içeremez"
|
||||
|
||||
#: storages/forms.py:126
|
||||
#: storages/forms.py:144
|
||||
msgid "The image name must not exceed 120 characters"
|
||||
msgstr "İmaj adı 120 karakterden fazla olamaz"
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-13 05:44+0000\n"
|
||||
"POT-Creation-Date: 2026-11-13 07:26+0000\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
|
@ -3340,7 +3340,7 @@ msgid "Storage pool"
|
|||
msgstr "存储池"
|
||||
|
||||
#: instances/templates/add_instance_volume.html:41
|
||||
#: instances/templates/create_instance_w2.html:46 storages/forms.py:89
|
||||
#: instances/templates/create_instance_w2.html:46 storages/forms.py:107
|
||||
#: storages/templates/storage.html:182
|
||||
msgid "Letters, digits, dot, dash and underscore."
|
||||
msgstr "字母、数字、点、短横线和下划线。"
|
||||
|
|
@ -3358,8 +3358,8 @@ msgstr "格式"
|
|||
|
||||
#: instances/templates/add_instance_volume.html:61
|
||||
#: instances/templates/create_instance_w2.html:154
|
||||
#: instances/templates/create_instance_w2.html:220 storages/forms.py:95
|
||||
#: storages/forms.py:115 storages/templates/storage.html:197
|
||||
#: instances/templates/create_instance_w2.html:220 storages/forms.py:113
|
||||
#: storages/forms.py:133 storages/templates/storage.html:197
|
||||
msgid "Preallocate metadata (qcow2)"
|
||||
msgstr "预分配元数据(qcow2)"
|
||||
|
||||
|
|
@ -3684,7 +3684,7 @@ msgstr "请选择…"
|
|||
msgid "Custom CPU Models"
|
||||
msgstr "自定义 CPU 型号"
|
||||
|
||||
#: instances/templates/create_instance_w2.html:146 storages/forms.py:94
|
||||
#: instances/templates/create_instance_w2.html:146 storages/forms.py:112
|
||||
msgid "Size (GiB)"
|
||||
msgstr "大小(GiB)"
|
||||
|
||||
|
|
@ -6660,7 +6660,7 @@ msgstr "IPv4 网络前缀必须为 /30 或更短"
|
|||
msgid "For libvirt, the IPv6 network prefix must be /64"
|
||||
msgstr "libvirt 要求 IPv6 网络前缀为 /64"
|
||||
|
||||
#: networks/forms.py:36 storages/forms.py:27
|
||||
#: networks/forms.py:36 storages/forms.py:35
|
||||
msgid "No pool name has been entered"
|
||||
msgstr "未输入地址池名称"
|
||||
|
||||
|
|
@ -6676,7 +6676,7 @@ msgstr "IPv6 子网"
|
|||
msgid "Bridge or interface"
|
||||
msgstr "网桥或接口"
|
||||
|
||||
#: networks/forms.py:56 storages/forms.py:51
|
||||
#: networks/forms.py:56 storages/forms.py:59
|
||||
msgid "The pool name must not contain any special characters"
|
||||
msgstr "地址池名称不能包含特殊字符"
|
||||
|
||||
|
|
@ -6693,7 +6693,7 @@ msgid "The pool bridge name must not contain any special characters"
|
|||
msgstr "地址池网桥名称不能包含特殊字符"
|
||||
|
||||
#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
|
||||
#: storages/forms.py:82
|
||||
#: storages/forms.py:100
|
||||
msgid "This field is required."
|
||||
msgstr "此字段为必填项。"
|
||||
|
||||
|
|
@ -7760,65 +7760,75 @@ msgstr "工作进程在任务做出任何更改之前停止"
|
|||
msgid "Pool is not active"
|
||||
msgstr "存储池未激活"
|
||||
|
||||
#: storages/forms.py:30 storages/templates/storage.html:102
|
||||
#: storages/forms.py:38 storages/templates/storage.html:102
|
||||
#: storages/templates/storages.html:43
|
||||
msgid "Path"
|
||||
msgstr "路径"
|
||||
|
||||
#: storages/forms.py:31
|
||||
#: storages/forms.py:39
|
||||
msgid "Device or remote path"
|
||||
msgstr "设备或远程路径"
|
||||
|
||||
#: storages/forms.py:32
|
||||
#: storages/forms.py:40
|
||||
msgid "Erase the device"
|
||||
msgstr "擦除设备"
|
||||
|
||||
#: storages/forms.py:33 storages/templates/create_stg_block.html:110
|
||||
#: storages/forms.py:41 storages/templates/create_stg_block.html:110
|
||||
msgid "Ceph user"
|
||||
msgstr "Ceph 用户"
|
||||
|
||||
#: storages/forms.py:34 storages/templates/create_stg_block.html:98
|
||||
#: storages/forms.py:42 storages/templates/create_stg_block.html:98
|
||||
msgid "Ceph monitor"
|
||||
msgstr "Ceph 监视器"
|
||||
|
||||
#: storages/forms.py:35 storages/templates/create_stg_block.html:104
|
||||
#: storages/forms.py:43 storages/templates/create_stg_block.html:104
|
||||
msgid "Ceph pool"
|
||||
msgstr "Ceph 存储池"
|
||||
|
||||
#: storages/forms.py:36 storages/templates/create_stg_block.html:116
|
||||
#: storages/forms.py:44 storages/templates/create_stg_block.html:116
|
||||
msgid "Ceph secret"
|
||||
msgstr "Ceph 机密"
|
||||
|
||||
#: storages/forms.py:37 storages/templates/create_stg_block.html:139
|
||||
#: storages/forms.py:45 storages/templates/create_stg_block.html:139
|
||||
msgid "Server"
|
||||
msgstr "服务器"
|
||||
|
||||
#: storages/forms.py:54
|
||||
#: storages/forms.py:62
|
||||
msgid "This host has a pool of that name"
|
||||
msgstr "此主机已有同名存储池"
|
||||
|
||||
#: storages/forms.py:61
|
||||
#: storages/forms.py:71
|
||||
msgid "The target must not contain any special characters"
|
||||
msgstr "目标不能包含特殊字符"
|
||||
|
||||
#: storages/forms.py:67
|
||||
#: storages/forms.py:75
|
||||
#, python-format
|
||||
msgid "%(path)s is a system directory of the host"
|
||||
msgstr "%(path)s 是主机的系统目录"
|
||||
|
||||
#: storages/forms.py:81
|
||||
#, python-format
|
||||
msgid "Pool %(pool)s uses this path"
|
||||
msgstr "存储池 %(pool)s 正在使用此路径"
|
||||
|
||||
#: storages/forms.py:74
|
||||
#: storages/forms.py:84
|
||||
#, python-format
|
||||
msgid "Pool %(pool)s uses %(path)s: one pool's directory cannot hold another's"
|
||||
msgstr "存储池 %(pool)s 正在使用 %(path)s:一个存储池的目录不能包含另一个存储池的目录"
|
||||
|
||||
#: storages/forms.py:92
|
||||
msgid "The disk source must not contain any special characters"
|
||||
msgstr "磁盘源不能包含特殊字符"
|
||||
|
||||
#: storages/forms.py:84
|
||||
#: storages/forms.py:102
|
||||
msgid "Choose one of the host's Ceph secrets"
|
||||
msgstr "请选择此主机上的一个 Ceph 机密"
|
||||
|
||||
#: storages/forms.py:102 storages/forms.py:122
|
||||
#: storages/forms.py:120 storages/forms.py:140
|
||||
msgid "The image name must not contain any special characters"
|
||||
msgstr "镜像名称不能包含特殊字符"
|
||||
|
||||
#: storages/forms.py:126
|
||||
#: storages/forms.py:144
|
||||
msgid "The image name must not exceed 120 characters"
|
||||
msgstr "镜像名称不能超过 120 个字符"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import posixpath
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
|
|
@ -8,6 +9,25 @@ from django.utils.translation import gettext_lazy as _
|
|||
# after "/". Written without nested repetition, which backtracked
|
||||
# exponentially on crafted input.
|
||||
POOL_PATH = re.compile(r"(?!-)(?:[/0-9a-zA-Z_.:]|(?<!/)-)+")
|
||||
# the host's own directories: a pool there offers its files as volumes to
|
||||
# delete, and a share mounted there hides them
|
||||
SYSTEM_DIRS = ("/bin", "/boot", "/dev", "/etc", "/lib", "/lib64", "/proc", "/root", "/run", "/sbin", "/sys", "/tmp",
|
||||
"/usr", "/var")
|
||||
# inside /var, libvirt's directory holds images and ISOs beside these of its own
|
||||
LIBVIRT_STATE = ("/var/lib/libvirt/dnsmasq", "/var/lib/libvirt/filesystems", "/var/lib/libvirt/lockd", "/var/lib/libvirt/lxc", "/var/lib/libvirt/network",
|
||||
"/var/lib/libvirt/qemu", "/var/lib/libvirt/swtpm")
|
||||
# directories whose subdirectories are a pool's place, not they themselves
|
||||
PARENT_DIRS = ("/home", "/media", "/mnt", "/opt", "/srv")
|
||||
|
||||
|
||||
def inside(path, other):
|
||||
return path == other or path.startswith(other.rstrip("/") + "/")
|
||||
|
||||
|
||||
def system_dir(path):
|
||||
if path.startswith("/var/lib/libvirt/"):
|
||||
return any(inside(path, state) for state in LIBVIRT_STATE)
|
||||
return path == "/" or path in PARENT_DIRS or any(inside(path, system) for system in SYSTEM_DIRS)
|
||||
|
||||
|
||||
class AddStgPool(forms.Form):
|
||||
|
|
@ -56,15 +76,25 @@ class AddStgPool(forms.Form):
|
|||
|
||||
def clean_target(self):
|
||||
target = self.cleaned_data["target"]
|
||||
if target and not POOL_PATH.fullmatch(target):
|
||||
if not target:
|
||||
return target
|
||||
if not POOL_PATH.fullmatch(target):
|
||||
raise forms.ValidationError(
|
||||
_("The target must not contain any special characters")
|
||||
)
|
||||
target = posixpath.normpath(re.sub("/+", "/", target)) # "/srv/../etc/" is /etc
|
||||
if system_dir(target):
|
||||
raise forms.ValidationError(_("%(path)s is a system directory of the host") % {"path": target})
|
||||
# an RBD pool's path is its Ceph pool, not a directory
|
||||
used = next((pool["name"] for pool in self.pools
|
||||
if pool["type"] != "rbd" and pool["path"] and pool["path"].rstrip("/") == target.rstrip("/")), None)
|
||||
if target and used:
|
||||
raise forms.ValidationError(_("Pool %(pool)s uses this path") % {"pool": used})
|
||||
for pool in self.pools:
|
||||
if pool["type"] == "rbd" or not pool["path"]:
|
||||
continue
|
||||
if pool["path"].rstrip("/") == target:
|
||||
raise forms.ValidationError(_("Pool %(pool)s uses this path") % {"pool": pool["name"]})
|
||||
# its volumes would be listed, and deleted, through both pools
|
||||
if inside(target, pool["path"]) or inside(pool["path"], target):
|
||||
raise forms.ValidationError(_("Pool %(pool)s uses %(path)s: one pool's directory cannot hold another's") % {
|
||||
"pool": pool["name"], "path": pool["path"]})
|
||||
return target
|
||||
|
||||
def clean_source(self):
|
||||
|
|
|
|||
|
|
@ -39,6 +39,33 @@ class PoolTargetTests(SimpleTestCase):
|
|||
with self.subTest(target=target):
|
||||
self.assertEqual(target_error(target), refused)
|
||||
|
||||
def test_a_system_directory_is_refused(self):
|
||||
# a pool there offers the host's own files as volumes to delete
|
||||
for target, refused in (("/", True), ("/etc", True), ("//etc/", True), ("/srv/../etc", True), ("/usr/lib", True),
|
||||
("/var", True), ("/var/lib", True), ("/var/lib/dpkg", True), ("/var/lib/libvirt", True),
|
||||
("/var/lib/libvirt/qemu", True), ("/tmp/x", True), ("/home", True), ("/srv", True),
|
||||
("/mnt", True), ("/etc-images", False), ("/srv/etc", False), ("/home/vms", False),
|
||||
("/mnt/share", False), ("/var/lib/libvirt/images", False),
|
||||
("/var/lib/libvirt/images/iso", False), ("/var/lib/libvirt/isos", False)):
|
||||
with self.subTest(target=target):
|
||||
self.assertEqual(target_error(target), refused)
|
||||
|
||||
def test_a_path_inside_or_around_another_pools_is_refused(self):
|
||||
# a file in both would be listed, and deleted, through either pool
|
||||
pools = [{"name": "default", "type": "dir", "path": "/srv/vms/images"},
|
||||
{"name": "ceph", "type": "rbd", "path": "rbd-pool"}]
|
||||
for target, error in (
|
||||
("/srv/vms/images/", "Pool default uses this path"),
|
||||
("/srv/vms/images/iso", "Pool default uses /srv/vms/images: one pool's directory cannot hold another's"),
|
||||
("/srv/vms", "Pool default uses /srv/vms/images: one pool's directory cannot hold another's"),
|
||||
("/srv/vms/images-2", None),
|
||||
("rbd-pool", None),
|
||||
):
|
||||
with self.subTest(target=target):
|
||||
form = AddStgPool({"name": "pool1", "stg_type": "dir", "target": target}, pools=pools)
|
||||
form.is_valid()
|
||||
self.assertEqual(form.errors.get("target"), [error] if error else None)
|
||||
|
||||
def test_accepted_and_refused_sources(self):
|
||||
for source, refused in (
|
||||
("/dev/vdb", False),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue