From 4b18c0bc817c06969ff8cb82717e0a0bce3b4e81 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 7 Dec 2024 09:41:50 -0800 Subject: [PATCH] Make LVM snapshots read-only. --- borgmatic/hooks/data_source/lvm.py | 2 ++ tests/end-to-end/commands/fake_lvcreate.py | 1 + tests/unit/hooks/data_source/test_lvm.py | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/borgmatic/hooks/data_source/lvm.py b/borgmatic/hooks/data_source/lvm.py index ef5a2dca..f0533f56 100644 --- a/borgmatic/hooks/data_source/lvm.py +++ b/borgmatic/hooks/data_source/lvm.py @@ -89,6 +89,8 @@ def snapshot_logical_volume( '--snapshot', ('--extents' if '%' in snapshot_size else '--size'), snapshot_size, + '--permission', + 'r', # Read-only. '--name', snapshot_name, logical_volume_device, diff --git a/tests/end-to-end/commands/fake_lvcreate.py b/tests/end-to-end/commands/fake_lvcreate.py index a389b710..4a758e6a 100644 --- a/tests/end-to-end/commands/fake_lvcreate.py +++ b/tests/end-to-end/commands/fake_lvcreate.py @@ -9,6 +9,7 @@ def parse_arguments(*unparsed_arguments): parser.add_argument('--snapshot', action='store_true', required=True) parser.add_argument('--extents') parser.add_argument('--size') + parser.add_argument('--permission', required=True) parser.add_argument('--name', dest='snapshot_name', required=True) parser.add_argument('logical_volume_device') diff --git a/tests/unit/hooks/data_source/test_lvm.py b/tests/unit/hooks/data_source/test_lvm.py index d5fe1ed2..b11bb1b9 100644 --- a/tests/unit/hooks/data_source/test_lvm.py +++ b/tests/unit/hooks/data_source/test_lvm.py @@ -99,6 +99,8 @@ def test_snapshot_logical_volume_with_percentage_snapshot_name_uses_lvcreate_ext '--snapshot', '--extents', '10%ORIGIN', + '--permission', + 'r', '--name', 'snap', '/dev/snap', @@ -116,6 +118,8 @@ def test_snapshot_logical_volume_with_non_percentage_snapshot_name_uses_lvcreate '--snapshot', '--size', '10TB', + '--permission', + 'r', '--name', 'snap', '/dev/snap',