@vibelord/lanes 1.9.6 → 1.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/payload/lanes/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.7
|
package/payload/lanes/bin/lanes
CHANGED
|
@@ -5764,6 +5764,9 @@ def cmd_doctor(_args):
|
|
|
5764
5764
|
print(f'{mark or " "} {text}')
|
|
5765
5765
|
else:
|
|
5766
5766
|
check(mark == '✓', text)
|
|
5767
|
+
# FLE-413 (27 Nov 2026): the site hooks this host loads and each one the loader refused; nothing without one.
|
|
5768
|
+
for mark, text in site_hooks.doctor_lines():
|
|
5769
|
+
check(mark == '✓', text)
|
|
5767
5770
|
# Lanes 2.0 runtime signals (RT 16.3, lanes2 R2-DOCTOR): the snapshot a Lanes 2.0 host exports; nothing until one does.
|
|
5768
5771
|
import doctor_lanes2
|
|
5769
5772
|
for mark, text in doctor_lanes2.doctor_lines(L.STATE):
|
|
@@ -1,59 +1,267 @@
|
|
|
1
|
-
"""External site-hook loader (FLE-388, BEY-6912 durable federation).
|
|
2
|
-
|
|
3
|
-
A host declares `LANES_SITE_HOOK=<dir>` in site.conf (or the env). Each `.py`
|
|
4
|
-
module in that dir may define any of install_library / install_status /
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"""External site-hook loader (FLE-388, BEY-6912 durable federation; hardened FLE-413, 27 Nov 2026).
|
|
2
|
+
|
|
3
|
+
A host declares `LANES_SITE_HOOK=<absolute dir>` in `$HOME/.config/lanes/site.conf` (or the env). Each `.py`
|
|
4
|
+
module in that dir may define any of install_library / install_status / install_cli / install_docs /
|
|
5
|
+
install_actions. At each entrypoint the matching one is called, so a host's federation hook lives OUTSIDE the
|
|
6
|
+
package tree and survives every update. No declaration (or `=refuse`) -> a no-op. Values are read from site.conf,
|
|
7
|
+
never executed.
|
|
8
|
+
|
|
9
|
+
The hooks run inside every host process that imports `lanes_lib`, so the loader takes only what the host account
|
|
10
|
+
controls (FLE-413):
|
|
11
|
+
|
|
12
|
+
* The declared path is absolute, and without HOME no site.conf is read: nothing resolves against the working
|
|
13
|
+
directory.
|
|
14
|
+
* site.conf is read first only to learn whether it declares a hook (a regular file, O_NOFOLLOW | O_NONBLOCK, at
|
|
15
|
+
most MAX_BYTES; a value there is never executed). A declaration loads code, so then site.conf's directories and
|
|
16
|
+
the hook directory are checked component by component with lstat (no symlink; owner root or this account; not
|
|
17
|
+
writable by group or others, except a root-owned sticky directory above, such as /tmp), and the last is opened
|
|
18
|
+
O_NOFOLLOW and compared by device and inode.
|
|
19
|
+
* site.conf and each hook are opened O_NOFOLLOW | O_NONBLOCK, checked with fstat on that fd (a regular file, owned
|
|
20
|
+
by root or this account, not writable by group or others, at most MAX_BYTES) and read from that fd, so a FIFO
|
|
21
|
+
never blocks and the bytes executed are the bytes checked.
|
|
22
|
+
* A hidden file and a file whose stem is not a module name are refused. A stem that names a Lanes module (any
|
|
23
|
+
module of this package's libexec) is refused, and every hook is loaded as `lanes_site_hook_<stem>`, never under
|
|
24
|
+
its bare stem, so no hook can become another module.
|
|
25
|
+
|
|
26
|
+
A refused directory loads nothing; a refused file is skipped and the others load. `doctor_lines()` reports what
|
|
27
|
+
was loaded and what was refused, and `lanes doctor` prints it; the loader itself writes nothing to stderr, so a
|
|
28
|
+
program's output never depends on it. A host with no site.conf and no LANES_SITE_HOOK opens nothing (one lstat).
|
|
9
29
|
"""
|
|
10
|
-
import
|
|
30
|
+
import errno
|
|
11
31
|
import os
|
|
32
|
+
import stat
|
|
12
33
|
import sys
|
|
34
|
+
import types
|
|
13
35
|
from pathlib import Path
|
|
14
36
|
|
|
15
37
|
_STAGES = ('library', 'status', 'cli', 'docs', 'actions')
|
|
38
|
+
MAX_BYTES = 1 << 20 # a site.conf or hook larger than this is refused
|
|
39
|
+
MODULE_PREFIX = 'lanes_site_hook_'
|
|
16
40
|
_modules = None
|
|
41
|
+
_report = None # {'dir': str | None, 'loaded': [stem], 'refused': [(name, why)], 'error': str | None}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Refused(Exception):
|
|
45
|
+
"""A path the loader does not take; the message says why, without the file's content."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _owners():
|
|
49
|
+
"""The accounts whose files the loader takes: root and the account this process runs as."""
|
|
50
|
+
return {0, os.geteuid()}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _check(st, what, owners, sticky_ok=False):
|
|
54
|
+
if st.st_uid not in owners:
|
|
55
|
+
raise Refused(f'{what} is owned by uid {st.st_uid}, not by root or this account')
|
|
56
|
+
if st.st_mode & 0o022:
|
|
57
|
+
if sticky_ok and st.st_uid == 0 and stat.S_ISDIR(st.st_mode) and st.st_mode & stat.S_ISVTX:
|
|
58
|
+
return
|
|
59
|
+
raise Refused(f'{what} is writable by group or others ({oct(st.st_mode & 0o777)})')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _open_dir(path, owners):
|
|
63
|
+
"""A directory fd for the absolute `path`. Every component is checked with lstat first (no open, so nothing
|
|
64
|
+
outside the path is read): not a symlink, a directory, owned by root or this account and not writable by group or
|
|
65
|
+
others, except a root-owned sticky directory above the last. Then the last is opened with O_NOFOLLOW and must be the
|
|
66
|
+
directory that was checked. No account but root and this one can change a component in between, because no
|
|
67
|
+
component is writable by another (a sticky root directory lets nobody else rename what this account owns)."""
|
|
68
|
+
if not isinstance(path, str) or not path.startswith('/'):
|
|
69
|
+
raise Refused('the path is not absolute')
|
|
70
|
+
parts = [part for part in path.split('/') if part]
|
|
71
|
+
if any(part in ('.', '..') for part in parts):
|
|
72
|
+
raise Refused('the path holds . or ..')
|
|
73
|
+
current, st = '/', os.lstat('/')
|
|
74
|
+
_check(st, '/', owners, sticky_ok=bool(parts))
|
|
75
|
+
for index, part in enumerate(parts):
|
|
76
|
+
current = os.path.join(current, part)
|
|
77
|
+
st = os.lstat(current)
|
|
78
|
+
if stat.S_ISLNK(st.st_mode):
|
|
79
|
+
raise Refused(f'{part} is a symlink')
|
|
80
|
+
if not stat.S_ISDIR(st.st_mode):
|
|
81
|
+
raise Refused(f'{part} is not a directory')
|
|
82
|
+
_check(st, part, owners, sticky_ok=index < len(parts) - 1)
|
|
83
|
+
try:
|
|
84
|
+
fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC)
|
|
85
|
+
except OSError as error:
|
|
86
|
+
if error.errno in (errno.ELOOP, errno.ENOTDIR):
|
|
87
|
+
raise Refused(f'{parts[-1] if parts else "/"} changed while it was checked') from None
|
|
88
|
+
raise
|
|
89
|
+
opened = os.fstat(fd)
|
|
90
|
+
if (opened.st_dev, opened.st_ino) != (st.st_dev, st.st_ino):
|
|
91
|
+
os.close(fd)
|
|
92
|
+
raise Refused(f'{parts[-1] if parts else "/"} changed while it was checked')
|
|
93
|
+
return fd
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
_FILE_FLAGS = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_CLOEXEC
|
|
97
|
+
|
|
17
98
|
|
|
99
|
+
def _read(dir_fd, name, owners):
|
|
100
|
+
"""The bytes of regular file `name` in `dir_fd`, read from the fd that was checked (`_read_fd`)."""
|
|
101
|
+
try:
|
|
102
|
+
fd = os.open(name, _FILE_FLAGS, dir_fd=dir_fd)
|
|
103
|
+
except OSError as error:
|
|
104
|
+
if error.errno == errno.ELOOP:
|
|
105
|
+
raise Refused(f'{name} is a symlink') from None
|
|
106
|
+
raise
|
|
107
|
+
return _read_fd(fd, name, owners)
|
|
18
108
|
|
|
19
|
-
|
|
109
|
+
|
|
110
|
+
def _read_fd(fd, name, owners):
|
|
111
|
+
"""The bytes of the open fd `fd` (closed here): a regular file by fstat, at most MAX_BYTES, and, unless `owners` is
|
|
112
|
+
None, owned by one of `owners` and not writable by group or others."""
|
|
113
|
+
try:
|
|
114
|
+
st = os.fstat(fd)
|
|
115
|
+
if not stat.S_ISREG(st.st_mode):
|
|
116
|
+
raise Refused(f'{name} is not a regular file')
|
|
117
|
+
if owners is not None:
|
|
118
|
+
_check(st, name, owners)
|
|
119
|
+
if st.st_size > MAX_BYTES:
|
|
120
|
+
raise Refused(f'{name} is larger than {MAX_BYTES} bytes')
|
|
121
|
+
chunks, total = [], 0
|
|
122
|
+
while True:
|
|
123
|
+
chunk = os.read(fd, 65536)
|
|
124
|
+
if not chunk:
|
|
125
|
+
break
|
|
126
|
+
total += len(chunk)
|
|
127
|
+
if total > MAX_BYTES:
|
|
128
|
+
raise Refused(f'{name} is larger than {MAX_BYTES} bytes')
|
|
129
|
+
chunks.append(chunk)
|
|
130
|
+
return b''.join(chunks)
|
|
131
|
+
finally:
|
|
132
|
+
os.close(fd)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _declared(data):
|
|
136
|
+
val = None
|
|
137
|
+
for line in data.decode('utf-8', 'replace').splitlines():
|
|
138
|
+
s = line.strip()
|
|
139
|
+
if s.startswith('LANES_SITE_HOOK='):
|
|
140
|
+
val = s.split('=', 1)[1].strip()
|
|
141
|
+
return val
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _hook_dir(owners):
|
|
145
|
+
"""The declared hook directory (an absolute path), or None when none is declared. Refused raises.
|
|
146
|
+
|
|
147
|
+
site.conf is read once only to learn whether it declares a hook: opened O_NOFOLLOW | O_NONBLOCK, a regular file of
|
|
148
|
+
at most MAX_BYTES (a value there is never executed). Only a declaration loads code, so only then must site.conf and
|
|
149
|
+
its directories be the host account's: it is read again through `_open_dir` and `_read`, and the checked bytes
|
|
150
|
+
decide. A site.conf that declares no hook is never judged by its owner."""
|
|
20
151
|
val = os.environ.get('LANES_SITE_HOOK')
|
|
21
152
|
if val is None:
|
|
22
|
-
|
|
153
|
+
home = os.environ.get('HOME', '')
|
|
154
|
+
if not home.startswith('/'):
|
|
155
|
+
return None # no HOME: never a site.conf relative to the working directory
|
|
156
|
+
directory = os.path.join(home, '.config', 'lanes')
|
|
23
157
|
try:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
158
|
+
os.lstat(os.path.join(directory, 'site.conf'))
|
|
159
|
+
except (FileNotFoundError, NotADirectoryError):
|
|
160
|
+
return None # none declared: nothing is opened (a host without hooks reads nothing more)
|
|
161
|
+
try:
|
|
162
|
+
fd = os.open(os.path.join(directory, 'site.conf'), _FILE_FLAGS)
|
|
163
|
+
except OSError as error:
|
|
164
|
+
if error.errno == errno.ELOOP:
|
|
165
|
+
raise Refused('site.conf is a symlink') from None
|
|
29
166
|
return None
|
|
167
|
+
try:
|
|
168
|
+
val = _declared(_read_fd(fd, 'site.conf', None))
|
|
169
|
+
except Refused as refused:
|
|
170
|
+
raise Refused(f'site.conf: {refused}') from None
|
|
171
|
+
if not val or val == 'refuse':
|
|
172
|
+
return None
|
|
173
|
+
try:
|
|
174
|
+
fd = _open_dir(directory, owners)
|
|
175
|
+
try:
|
|
176
|
+
val = _declared(_read(fd, 'site.conf', owners))
|
|
177
|
+
finally:
|
|
178
|
+
os.close(fd)
|
|
179
|
+
except Refused as refused:
|
|
180
|
+
raise Refused(f'site.conf declares a hook directory, but {refused}') from None
|
|
30
181
|
if not val or val == 'refuse':
|
|
31
182
|
return None
|
|
32
|
-
|
|
33
|
-
|
|
183
|
+
if not val.startswith('/'):
|
|
184
|
+
raise Refused('LANES_SITE_HOOK is not an absolute path')
|
|
185
|
+
return val
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _reserved():
|
|
189
|
+
"""Stems a hook may not take: every module of this package's libexec, and the loader's own name."""
|
|
190
|
+
here = Path(__file__).resolve().parent
|
|
191
|
+
return {p.stem for p in here.glob('*.py')} | {'lanes', 'site_hooks'}
|
|
34
192
|
|
|
35
193
|
|
|
36
194
|
def _load():
|
|
37
|
-
global _modules
|
|
195
|
+
global _modules, _report
|
|
38
196
|
if _modules is not None:
|
|
39
197
|
return _modules
|
|
40
198
|
_modules = []
|
|
41
|
-
|
|
42
|
-
|
|
199
|
+
_report = {'dir': None, 'loaded': [], 'refused': [], 'error': None}
|
|
200
|
+
owners = _owners()
|
|
201
|
+
try:
|
|
202
|
+
path = _hook_dir(owners)
|
|
203
|
+
if path is None:
|
|
204
|
+
return _modules
|
|
205
|
+
_report['dir'] = path
|
|
206
|
+
dir_fd = _open_dir(path, owners)
|
|
207
|
+
except Refused as refused:
|
|
208
|
+
_report['error'] = str(refused)
|
|
43
209
|
return _modules
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
210
|
+
except OSError as error:
|
|
211
|
+
_report['error'] = f'the hook directory cannot be opened ({error.strerror})'
|
|
212
|
+
return _modules
|
|
213
|
+
try:
|
|
214
|
+
reserved = _reserved()
|
|
215
|
+
for name in sorted(os.listdir(dir_fd)):
|
|
216
|
+
if not name.endswith('.py') or name.startswith('_'):
|
|
217
|
+
continue
|
|
218
|
+
stem = name[:-3]
|
|
219
|
+
try:
|
|
220
|
+
if name.startswith('.'):
|
|
221
|
+
raise Refused('a hidden file')
|
|
222
|
+
if not stem.isidentifier():
|
|
223
|
+
raise Refused('not a module name')
|
|
224
|
+
if stem in reserved:
|
|
225
|
+
raise Refused('it names a Lanes module')
|
|
226
|
+
source = _read(dir_fd, name, owners)
|
|
227
|
+
except Refused as refused:
|
|
228
|
+
_report['refused'].append((name, str(refused)))
|
|
229
|
+
continue
|
|
230
|
+
except OSError as error:
|
|
231
|
+
_report['refused'].append((name, error.strerror))
|
|
232
|
+
continue
|
|
233
|
+
module_name = MODULE_PREFIX + stem
|
|
234
|
+
module = types.ModuleType(module_name)
|
|
235
|
+
module.__file__ = os.path.join(path, name)
|
|
236
|
+
code = compile(source, module.__file__, 'exec')
|
|
237
|
+
sys.modules[module_name] = module
|
|
238
|
+
try:
|
|
239
|
+
exec(code, module.__dict__)
|
|
240
|
+
except BaseException:
|
|
241
|
+
sys.modules.pop(module_name, None)
|
|
242
|
+
raise
|
|
243
|
+
_modules.append(module)
|
|
244
|
+
_report['loaded'].append(stem)
|
|
245
|
+
finally:
|
|
246
|
+
os.close(dir_fd)
|
|
54
247
|
return _modules
|
|
55
248
|
|
|
56
249
|
|
|
250
|
+
def doctor_lines():
|
|
251
|
+
"""(mark, text) lines for `lanes doctor`: the loaded hooks (✓) and each refusal (✗). None declared -> []."""
|
|
252
|
+
_load()
|
|
253
|
+
report = _report or {}
|
|
254
|
+
lines = []
|
|
255
|
+
if report.get('error'):
|
|
256
|
+
lines.append(('✗', f'site hooks: refused, so none is loaded: {report["error"]}'))
|
|
257
|
+
elif report.get('dir'):
|
|
258
|
+
names = ', '.join(report['loaded']) or 'none'
|
|
259
|
+
lines.append(('✓', f'site hooks loaded from {report["dir"]}: {names}'))
|
|
260
|
+
for name, why in report.get('refused', []):
|
|
261
|
+
lines.append(('✗', f'site hook {name} refused: {why}'))
|
|
262
|
+
return lines
|
|
263
|
+
|
|
264
|
+
|
|
57
265
|
def apply(stage, *args):
|
|
58
266
|
"""Call install_<stage>(*args) on every declared site-hook module that defines it."""
|
|
59
267
|
if stage not in _STAGES:
|
package/payload/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibelord/lanes",
|
|
3
|
-
"version": "1.9.
|
|
4
|
-
"commit": "
|
|
5
|
-
"digest": "sha256:
|
|
3
|
+
"version": "1.9.7",
|
|
4
|
+
"commit": "d35621513d447b393f04013c74735b2a2c010b8e",
|
|
5
|
+
"digest": "sha256:e026906f4c0e60c1acbdd1c3f34f70c5c7f208b7373d272f93086c43c2877f8d",
|
|
6
6
|
"executables": [
|
|
7
7
|
"bin/lanes",
|
|
8
8
|
"bin/lanes-site-serve",
|