Skip to content

Commit 5c1dce4

Browse files
committed
Add checks for atomic update compatibility
1 parent 4f6a766 commit 5c1dce4

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

configs/openSUSE/opensuse.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CompressExtension = "gz"
55
UseVarLockSubsys = false
66
UseVersionInChangelog = false
77
BadnessThreshold = 999
8+
AtomicCheckGhosts = false
89

910
# Enabled checks for the rpmlint to be run (besides the default set)
1011
Checks = [
@@ -13,13 +14,33 @@ Checks = [
1314
"TmpFilesCheck",
1415
"SysVInitOnSystemdCheck",
1516
"SharedLibraryPolicyCheck",
17+
"AtomicUpdateCheck",
1618
]
1719

1820
# List of directory prefixes that are not allowed in packages
1921
DisallowedDirs = [
2022
"/etc/NetworkManager/dispatcher.d",
2123
]
2224

25+
# Only these directories may be used by packages compatible with
26+
# atomic updates
27+
AtomicAllowedDirs = [
28+
"/etc/",
29+
"/usr/",
30+
"/bin/",
31+
"/lib/",
32+
"/lib64/",
33+
"/sbin/",
34+
"/boot/",
35+
]
36+
37+
# List of subdirectories which are disallowed for atomic updates
38+
# despite being within otherwise allowed directories
39+
AtomicDisallowedSubdirs = [
40+
"/usr/local/",
41+
"/boot/efi/",
42+
]
43+
2344
FilterErrorTitles = [
2445
'cross-directory-hard-link',
2546
]
@@ -73,6 +94,7 @@ Filters = [
7394
'^filesystem\..*: dir-or-file-in-tmp',
7495
'^filesystem\..*: dir-or-file-in-mnt',
7596
'^filesystem\..*: dir-or-file-in-home',
97+
'^filesystem\..*: dir-or-file-outside-snapshot',
7698
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
7799
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
78100
'^filesystem\..*: hidden-file-or-dir /etc/skel/.config',

configs/openSUSE/scoring.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ executable-stack = 10000
3939
binary-or-shlib-defines-rpath = 10000
4040
patchable-function-entry-in-archive = 10000
4141
patch-macro-old-format = 10000
42+
dir-or-file-outside-snapshot = 10000
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from rpmlint.checks.AbstractCheck import AbstractCheck
2+
3+
class AtomicUpdateCheck(AbstractCheck):
4+
5+
"""
6+
Requirements for atomic updates:
7+
* All files must be stored inside the snapshot, which is in our case /etc and /usr, not /var,
8+
/opt, /srv, /usr/local or anything else.
9+
* (Re)starting daemons is not possible.
10+
* Modifying files outside of /usr and /etc is not possible.
11+
* Modifications outside the snapshot have to be done via systemd-tmpfiles and systemd services.
12+
This check currently only implements checking for files at illegal paths.
13+
"""
14+
15+
def __init__(self, config, output):
16+
super().__init__(config, output)
17+
self.check_ghosts = self.config.configuration['AtomicCheckGhosts']
18+
self.allowed_dirs = self.config.configuration['AtomicAllowedDirs']
19+
self.disallowed_subdirs = self.config.configuration['AtomicDisallowedSubdirs']
20+
21+
def check(self, pkg):
22+
if pkg.is_source:
23+
return
24+
25+
# Check for files stored outside the snapshot
26+
self._check_paths(pkg, self.check_ghosts)
27+
28+
def _check_paths(self, pkg, check_ghosts=False):
29+
for file in pkg.files.keys():
30+
if file in pkg.ghost_files:
31+
continue # Ghosts are only handled if explicitly desired
32+
if not (self._check_single_path(file)):
33+
self.output.add_info('E', pkg, 'dir-or-file-outside-snapshot', file)
34+
if check_ghosts:
35+
for ghost in pkg.ghost_files:
36+
if not (self._check_single_path(ghost)):
37+
self.output.add_info('W', pkg, 'ghost-outside-snapshot', ghost)
38+
39+
def _check_single_path(self, file):
40+
return (
41+
file.startswith(tuple(self.allowed_dirs)) and
42+
not file.startswith(tuple(self.disallowed_subdirs))
43+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dir-or-file-outside-snapshot="""
2+
The package contains files outside the snapshot, e.g. outside /etc and /usr
3+
or inside /usr/local.
4+
"""
5+
ghost-outside-snapshot="""
6+
The package contains ghosts outside the snapshot, e.g. outside /etc and /usr
7+
or inside /usr/local. This might become an issue upon removal of this
8+
package, but not during installation.
9+
"""

0 commit comments

Comments
 (0)