@samitouri / QOSAMI-WSL / commits / 39b4cd88

Various fixes in validate-modern.py (#13405)

* Various fixes in validate-modern.py * Update distributions/validate-modern.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix copilot diff * Fix copilot diff --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Blue committed Aug 18, 2025 at 14:07 UTC 39b4cd8873020a9a3b1c71e891fa7a845d91469d
1 file changed +31 -7
distributions/validate-modern.py
+31 -7
@@ -37,6 +37,27 @@ DISCOURAGED_SYSTEM_UNITS = ['systemd-resolved.service',
37
38 WSL1_UNSUPPORTED_XATTRS = ['security.selinux', 'security.ima', 'security.evm']
39
40 +WSL_CONF_KEYS = ['automount.enabled',
41 + 'automount.ldconfig',
42 + 'automount.mountfstab',
43 + 'automount.options',
44 + 'automount.root',
45 + 'boot.command',
46 + 'boot.protectbinfmt',
47 + 'boot.systemd',
48 + 'fileserver.enabled',
49 + 'filesystem.umask',
50 + 'general.hostname',
51 + 'gpu.appendlibpath',
52 + 'gpu.enabled',
53 + 'interop.appendwindowspath',
54 + 'interop.enabled',
55 + 'network.generatehosts',
56 + 'network.generateresolvconf',
57 + 'network.hostname',
58 + 'time.usewindowstimezone',
59 + 'user.default']
60 +
61 errors = {}
62 warnings = {}
63
@@ -200,7 +221,7 @@ def read_passwd(node, default_uid: int, fd):
221 entries[uid] = fields
222
223 if 0 not in entries:
203 - error(flavor, name, f'No root (uid=0) found in /etc/passwd')
224 + error(node, f'No root (uid=0) found in /etc/passwd')
225 elif entries[0][0] != 'root':
226 error(node, f'/etc/passwd has a uid=0, but it is not root: {entries[0][0]}')
227
@@ -352,7 +373,7 @@ def read_tar(node, file, elf_magic: str):
373
374 if info is None:
375 if not optional:
355 - error(flavor, name, f'File "{path}" not found in tar')
376 + error(node, f'File "{path}" not found in tar')
377 return False
378
379 permissions = oct(info.mode)
@@ -395,7 +416,7 @@ def read_tar(node, file, elf_magic: str):
416
417 keys = read_config_keys(config)
418
398 - unexpected_keys = [e for e in keys if e.lower() not in valid_keys]
419 + unexpected_keys = [e for e in keys if e.casefold() not in valid_keys]
420 if unexpected_keys:
421 error(node, f'Found unexpected_keys in "{path}": {unexpected_keys}')
422 else:
@@ -434,14 +455,17 @@ def read_tar(node, file, elf_magic: str):
455 warning(node, f'value for windowsterminal.profileTemplate is not under {USR_LIB_WSL}: "{terminal_profile}"')
456
457 if validate_mode('/etc/wsl.conf', [oct(0o664), oct(0o644)], 0, 0, optional=True, follow_symlink=True):
437 - config = validate_config('/etc/wsl.conf', ['boot.systemd'])
458 + config = validate_config('/etc/wsl.conf', WSL_CONF_KEYS)
459 if config.get('boot.systemd', False):
439 - validate_mode('/sbin/init', [oct(0o775), oct(0o755)], 0, 0, magic=elf_magic, follow_symlink=True)
460 + validate_mode('/sbin/init', [oct(0o775), oct(0o755), oct(0o555)], 0, 0, magic=elf_magic, follow_symlink=True)
461 +
462 + if (default_user := config.get('user.default')) is not None:
463 + warning(node, f'Found discouraged wsl.conf key: user.default={default_user}')
464
465 validate_mode('/etc/passwd', [oct(0o664), oct(0o644)], 0, 0, parse_method = lambda fd: read_passwd(node, defaultUid, fd))
466 validate_mode('/etc/shadow', [oct(0o640), oct(0o600), oct(0)], 0, None)
443 - validate_mode('/bin/bash', [oct(0o755), oct(0o775)], 0, 0, magic=elf_magic, follow_symlink=True)
444 - validate_mode('/bin/sh', [oct(0o755), oct(0o775)], 0, 0, magic=elf_magic, follow_symlink=True)
467 + validate_mode('/bin/bash', [oct(0o755), oct(0o775), oct(0o555)], 0, 0, magic=elf_magic, follow_symlink=True, optional=True)
468 + validate_mode('/bin/sh', [oct(0o755), oct(0o775), oct(0o555)], 0, 0, magic=elf_magic, follow_symlink=True)
469
470 enabled_systemd_units = read_systemd_enabled_units(node, tar)
471 for unit, path in enabled_systemd_units.items():