Skip to content

Commit b885709

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

4 files changed

Lines changed: 76 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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from rpmlint.checks.AbstractCheck import AbstractCheck
2+
3+
4+
class AtomicUpdateCheck(AbstractCheck):
5+
6+
"""
7+
Requirements for atomic updates:
8+
* All files must be stored inside the snapshot, which is in our case /etc and /usr, not /var,
9+
/opt, /srv, /usr/local or anything else.
10+
* (Re)starting daemons is not possible.
11+
* Modifying files outside of /usr and /etc is not possible.
12+
* Modifications outside the snapshot have to be done via systemd-tmpfiles and systemd services.
13+
This check currently only implements checking for files at illegal paths.
14+
"""
15+
16+
def __init__(self, config, output):
17+
super().__init__(config, output)
18+
self.check_ghosts = self.config.configuration['AtomicCheckGhosts']
19+
self.allowed_dirs = self.config.configuration['AtomicAllowedDirs']
20+
self.disallowed_subdirs = self.config.configuration['AtomicDisallowedSubdirs']
21+
22+
def check(self, pkg):
23+
if pkg.is_source:
24+
return
25+
26+
# Check for files stored outside the snapshot
27+
self._check_paths(pkg, self.check_ghosts)
28+
29+
def _check_paths(self, pkg, check_ghosts=False):
30+
for file in pkg.files.keys():
31+
if file in pkg.ghost_files:
32+
continue # Ghosts are only handled if explicitly desired
33+
if not (self._check_single_path(file)):
34+
self.output.add_info('E', pkg, 'dir-or-file-outside-snapshot', file)
35+
if check_ghosts:
36+
for ghost in pkg.ghost_files:
37+
if not (self._check_single_path(ghost)):
38+
self.output.add_info('W', pkg, 'ghost-outside-snapshot', ghost)
39+
40+
def _check_single_path(self, file):
41+
return (
42+
file.startswith(tuple(self.allowed_dirs)) and
43+
not file.startswith(tuple(self.disallowed_subdirs))
44+
)
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)