Skip to content

Commit c2c5126

Browse files
mtravitzkydanigm
authored andcommitted
Add checks for atomic update compatibility
1 parent c3b438a commit c2c5126

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

configs/openSUSE/opensuse.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ UseVarLockSubsys = false
66
UseVersionInChangelog = false
77
BadnessThreshold = 999
88

9+
# Set to true to issue a warning for ghost entries outside snapshots
10+
# when checking for atomic update compatibility
11+
AtomicCheckGhosts = false
12+
913
# Enabled checks for the rpmlint to be run (besides the default set)
1014
Checks = [
1115
"BashismsCheck",
@@ -24,13 +28,33 @@ Checks = [
2428
"SystemdTmpfilesCheck",
2529
"SUIDPermissionsCheck",
2630
"WorldWritableCheck",
31+
"AtomicUpdateCheck",
2732
]
2833

2934
# List of directory prefixes that are not allowed in packages
3035
DisallowedDirs = [
3136
"/etc/NetworkManager/dispatcher.d",
3237
]
3338

39+
# Only these directories may be used by packages compatible with
40+
# atomic updates
41+
AtomicAllowedDirs = [
42+
"/etc/",
43+
"/usr/",
44+
"/bin/",
45+
"/lib/",
46+
"/lib64/",
47+
"/sbin/",
48+
"/boot/",
49+
]
50+
51+
# List of subdirectories which are disallowed for atomic updates
52+
# despite being within otherwise allowed directories
53+
AtomicDisallowedSubdirs = [
54+
"/usr/local/",
55+
"/boot/efi/",
56+
]
57+
3458
FilterErrorTitles = [
3559
'cross-directory-hard-link',
3660
]
@@ -83,6 +107,7 @@ Filters = [
83107
'^filesystem\..*: dir-or-file-in-tmp',
84108
'^filesystem\..*: dir-or-file-in-mnt',
85109
'^filesystem\..*: dir-or-file-in-home',
110+
'^filesystem\..*: dir-or-file-outside-snapshot',
86111
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
87112
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
88113
'^filesystem\..*: hidden-file-or-dir /etc/skel/.config',

configs/openSUSE/scoring.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ zypperplugin-file-unauthorized = 10
102102
patch-macro-old-format = 10000
103103
# TODO: raise to 10,000 after we surveyed affected packages
104104
logrotate-user-writable-log-dir = 100
105+
106+
# Set to 10000 once affected packages have been updated
107+
# for atomic update compatibility
108+
dir-or-file-outside-snapshot = 100
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)