Skip to content

Commit de1e415

Browse files
authored
Merge pull request #1396 from mtravitzky/atomic-update-file-check
Add checks for atomic update compatibility
2 parents 4f6a766 + d79fe0b commit de1e415

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,20 +6,44 @@ 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",
1216
"PAMModulesCheck",
1317
"TmpFilesCheck",
1418
"SysVInitOnSystemdCheck",
1519
"SharedLibraryPolicyCheck",
20+
"AtomicUpdateCheck",
1621
]
1722

1823
# List of directory prefixes that are not allowed in packages
1924
DisallowedDirs = [
2025
"/etc/NetworkManager/dispatcher.d",
2126
]
2227

28+
# Only these directories may be used by packages compatible with
29+
# atomic updates
30+
AtomicAllowedDirs = [
31+
"/etc/",
32+
"/usr/",
33+
"/bin/",
34+
"/lib/",
35+
"/lib64/",
36+
"/sbin/",
37+
"/boot/",
38+
]
39+
40+
# List of subdirectories which are disallowed for atomic updates
41+
# despite being within otherwise allowed directories
42+
AtomicDisallowedSubdirs = [
43+
"/usr/local/",
44+
"/boot/efi/",
45+
]
46+
2347
FilterErrorTitles = [
2448
'cross-directory-hard-link',
2549
]
@@ -73,6 +97,7 @@ Filters = [
7397
'^filesystem\..*: dir-or-file-in-tmp',
7498
'^filesystem\..*: dir-or-file-in-mnt',
7599
'^filesystem\..*: dir-or-file-in-home',
100+
'^filesystem\..*: dir-or-file-outside-snapshot',
76101
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
77102
'^filesystem\..*: hidden-file-or-dir /root/.gnupg',
78103
'^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
@@ -39,3 +39,7 @@ executable-stack = 10000
3939
binary-or-shlib-defines-rpath = 10000
4040
patchable-function-entry-in-archive = 10000
4141
patch-macro-old-format = 10000
42+
43+
# Set to 10000 once affected packages have been updated
44+
# for atomic update compatibility
45+
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)