@yahyahammad/venastine 0.3.8 → 0.3.10
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/.env.example +19 -19
- package/CONFIG_ARCHITECTURE.md +2139 -2002
- package/LICENSE +201 -201
- package/README.md +1043 -1034
- package/agents/builtin/compactor.md +75 -75
- package/agents/builtin/explore.md +77 -77
- package/agents/builtin/pipeline-reviewer.md +100 -100
- package/agents/builtin/plan.md +106 -106
- package/agents/builtin/review.md +74 -74
- package/agents/manager.py +261 -261
- package/agents/subagent_tool.py +472 -472
- package/agents/tui_commands.py +238 -146
- package/bin/venastine.mjs +584 -528
- package/bin/venastine.py +73 -71
- package/cli_commands.py +848 -835
- package/config.yaml +64 -0
- package/config_edit.py +1301 -1301
- package/config_schema.py +987 -966
- package/config_update.py +749 -749
- package/core/agent_activity.py +256 -256
- package/core/ansi.py +452 -452
- package/core/approval.py +137 -137
- package/core/call_view.py +364 -364
- package/core/cancel.py +121 -121
- package/core/chatgpt_auth.py +747 -747
- package/core/claims_view.py +107 -107
- package/core/client.py +2756 -2715
- package/core/commands.py +464 -454
- package/core/compaction.py +1735 -1735
- package/core/config_loader.py +1982 -1982
- package/core/connect.py +686 -686
- package/core/events.py +123 -123
- package/core/file_mentions.py +280 -280
- package/core/interaction.py +411 -411
- package/core/loop.py +2566 -2566
- package/core/memory.py +482 -482
- package/core/pipeline_models.py +190 -190
- package/core/provider_errors.py +274 -234
- package/core/reasoning/authorization.py +130 -130
- package/core/reasoning/base.py +219 -219
- package/core/reasoning/confidence_scoring.py +484 -484
- package/core/reasoning/events.py +149 -149
- package/core/reasoning/orchestrator.py +1561 -1561
- package/core/reasoning/output_writer.py +345 -345
- package/core/reasoning/payload_validation.py +524 -524
- package/core/reasoning/pipeline_storage.py +427 -427
- package/core/reasoning/scholar.py +467 -458
- package/core/reasoning/source_corpus.py +433 -433
- package/core/reasoning/source_scoring.py +855 -855
- package/core/replay.py +315 -315
- package/core/shell_sessions.py +1553 -1553
- package/credentials.py +307 -307
- package/database.py +333 -333
- package/docs/PRIVACY.md +78 -78
- package/docs/SECURITY.md +114 -108
- package/docs/THIRD_PARTY_NOTICES.md +148 -148
- package/env_secrets.py +118 -118
- package/json_store.py +343 -343
- package/logging_setup.py +295 -295
- package/main.py +3433 -3433
- package/mcp_client/client.py +780 -733
- package/mcp_client/config.py +484 -484
- package/mcp_client/registration.py +343 -343
- package/memories/manager.py +147 -147
- package/memories/tui_commands.py +319 -239
- package/package.json +303 -303
- package/project_init/config_files.py +282 -282
- package/project_init/generator.py +728 -728
- package/project_init/manifest.py +418 -418
- package/project_init/tui_commands.py +147 -147
- package/prompts/critic_pass.md +24 -24
- package/prompts/revalidate.md +25 -25
- package/prompts/revise.md +17 -17
- package/prompts/source_grounding.md +66 -66
- package/prompts/system_prompts.py +316 -316
- package/providers.json.example +94 -94
- package/pyproject.toml +149 -149
- package/requirements.txt +314 -295
- package/safety/policy_enforcement.py +1082 -1082
- package/security/askpass.py +419 -419
- package/security/capability.py +207 -207
- package/security/confine.py +484 -484
- package/security/hosted.py +182 -182
- package/security/permissions.py +237 -237
- package/security/protected_paths.py +501 -501
- package/security/sandbox.py +4108 -4108
- package/skills/builtin/math/formal-specification.md +67 -67
- package/skills/builtin/math/numerical-methods.md +66 -66
- package/skills/builtin/research/experiment-design.md +62 -62
- package/skills/builtin/research/reproducibility.md +55 -55
- package/skills/builtin/research/source-evaluation.md +70 -70
- package/skills/builtin/research/statistical-inference.md +63 -63
- package/skills/builtin/research/technical-writing.md +59 -59
- package/skills/builtin/software/code-review.md +61 -61
- package/skills/builtin/software/debugging.md +61 -61
- package/skills/builtin/software/test-design.md +67 -67
- package/skills/tui_commands.py +110 -110
- package/storage.py +1338 -1338
- package/tools/base.py +465 -465
- package/tools/builtin/_math_common.py +667 -667
- package/tools/builtin/_net_common.py +1145 -267
- package/tools/builtin/_page_text.py +490 -0
- package/tools/builtin/_pdf_text.py +113 -0
- package/tools/builtin/arxiv.py +685 -681
- package/tools/builtin/fetch_url.py +639 -371
- package/tools/builtin/file_ops.py +720 -720
- package/tools/builtin/geometry.py +184 -184
- package/tools/builtin/load_skill.py +76 -76
- package/tools/builtin/pin.py +227 -227
- package/tools/builtin/probability_stats.py +224 -224
- package/tools/builtin/project_docs.py +464 -464
- package/tools/builtin/remember.py +175 -175
- package/tools/builtin/shell.py +980 -980
- package/tools/builtin/todo.py +149 -149
- package/tools/builtin/web_search.py +402 -328
- package/tools/context.py +159 -159
- package/tools/isolation.py +387 -387
- package/tools/registry.py +1252 -1242
- package/tui/app.py +8372 -8307
- package/tui/app.tcss +754 -739
- package/tui/commands.py +26 -26
- package/tui/diffs.py +286 -286
- package/tui/history.py +128 -128
- package/tui/hosted_driver.py +102 -102
- package/tui/markdown.py +1329 -1329
- package/tui/meters.py +364 -364
- package/tui/ravens.py +146 -146
- package/tui/screens.py +1255 -1197
- package/tui/themes.py +599 -599
- package/tui/widgets.py +3861 -3796
package/security/hosted.py
CHANGED
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
"""
|
|
2
|
-
security/hosted.py
|
|
3
|
-
|
|
4
|
-
ROADMAP_v3 §79 (HD4, HD6, HD13). What a hosted deployment changes inside the
|
|
5
|
-
harness, and nothing else: the mode it runs in, the tools a shared deployment
|
|
6
|
-
refuses whatever `config.yaml` says, the sign-ins its bridge completes, and
|
|
7
|
-
the hardening calls a hosted process makes about itself.
|
|
8
|
-
|
|
9
|
-
THE MODE COMES FROM THE REAL ENVIRONMENT, ONCE, AT IMPORT. The web bridge
|
|
10
|
-
(`deploy/hosted/`) starts every session's process with `VENASTINE_HOSTED`
|
|
11
|
-
set, and nothing else does. A `.env` cannot supply it (A70: `VENASTINE_*`
|
|
12
|
-
names are never taken from that file, and the file is never loaded into the
|
|
13
|
-
environment at all). It is bound at import for `security/posture.py`'s
|
|
14
|
-
reason: a value read at call time follows a mutation, and this one decides
|
|
15
|
-
what a visitor may do.
|
|
16
|
-
|
|
17
|
-
AN ENVIRONMENT VARIABLE CAN ONLY TAKE CAPABILITY AWAY HERE, which is why
|
|
18
|
-
having one does not contradict `posture.py`'s "there is none, by design".
|
|
19
|
-
Unset is a local install. `single-user` is a local install that says it is
|
|
20
|
-
hosted. `shared` removes things. And anything the parser does not recognise
|
|
21
|
-
is `shared`: a typo must land on the restrictive side, because the bridge
|
|
22
|
-
that sets this is the only thing standing between a visitor and the
|
|
23
|
-
container.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
import ctypes
|
|
27
|
-
import os
|
|
28
|
-
import signal
|
|
29
|
-
import sys
|
|
30
|
-
|
|
31
|
-
OFF = ""
|
|
32
|
-
SHARED = "shared"
|
|
33
|
-
SINGLE_USER = "single-user"
|
|
34
|
-
|
|
35
|
-
# HD4. The tools that reach the container itself -- its files and its
|
|
36
|
-
# processes. A shared deployment runs every visitor in one container as one
|
|
37
|
-
# Unix user, so any of these would let one visitor read another's session.
|
|
38
|
-
# They ship disabled anyway; this is the second layer, for the deployment
|
|
39
|
-
# whose config.yaml says otherwise.
|
|
40
|
-
SHARED_REFUSED_TOOLS = frozenset({
|
|
41
|
-
"read", "write", "edit",
|
|
42
|
-
# Batch 174: an image file, read under `read`'s rules (§81, IM1).
|
|
43
|
-
"view_image",
|
|
44
|
-
"shell", "shell_background", "shell_monitor", "shell_interactive",
|
|
45
|
-
"shell_input", "shell_sessions", "shell_output", "shell_kill",
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# HD11. The tools whose child evaluates what the model sent: SymPy's parser
|
|
50
|
-
# ends in `eval`. A shared deployment runs them only inside the walls
|
|
51
|
-
# security/confine.py puts up, and only once the bridge's self-test has
|
|
52
|
-
# shown those walls standing on this host -- `VENASTINE_CONFINEMENT` is set
|
|
53
|
-
# to `verified` by the bridge after a clean pass, and by nothing else.
|
|
54
|
-
# Unset, they are refused like the tools above. (These are exactly the
|
|
55
|
-
# registry's BUDGET_COMPUTE tools; a test pins that.)
|
|
56
|
-
CONFINED_TOOLS = frozenset({
|
|
57
|
-
"symbolic_math", "linear_algebra", "probability_stats",
|
|
58
|
-
"discrete_math", "logic", "geometry",
|
|
59
|
-
})
|
|
60
|
-
CONFINEMENT_VERIFIED = "verified"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _mode_from_env() -> str:
|
|
64
|
-
raw = os.environ.get("VENASTINE_HOSTED", "").strip().lower()
|
|
65
|
-
if not raw:
|
|
66
|
-
return OFF
|
|
67
|
-
if raw == SINGLE_USER:
|
|
68
|
-
return SINGLE_USER
|
|
69
|
-
return SHARED
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
MODE = _mode_from_env()
|
|
73
|
-
# Bound at import for MODE's reason. Only a value the bridge set counts.
|
|
74
|
-
CONFINEMENT = os.environ.get("VENASTINE_CONFINEMENT", "").strip()
|
|
75
|
-
|
|
76
|
-
# HD13. The sign-ins the BRIDGE completes for this session -- ModelScope's,
|
|
77
|
-
# on modelscope.ai and on modelscope.cn (batch 176), whose apps each need a
|
|
78
|
-
# client secret that only the bridge holds. The names are
|
|
79
|
-
# deploy/hosted/sign_in.py's SITES, which this layer does not import;
|
|
80
|
-
# test_hosted_mode.py holds the two together. Bound at import for MODE's
|
|
81
|
-
# reason, and honoured only in a hosted session: the bridge sets it when it
|
|
82
|
-
# can finish the sign-in, and a local install has no bridge to finish it,
|
|
83
|
-
# however this variable reads.
|
|
84
|
-
BRIDGE_SIGN_IN_NAMES = frozenset({"modelscope", "modelscope-cn"})
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def _bridge_sign_ins_from_env() -> frozenset:
|
|
88
|
-
if MODE == OFF:
|
|
89
|
-
return frozenset()
|
|
90
|
-
raw = os.environ.get("VENASTINE_BRIDGE_SIGN_IN", "")
|
|
91
|
-
return frozenset(name.strip().lower() for name in raw.split(",")) \
|
|
92
|
-
& BRIDGE_SIGN_IN_NAMES
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
BRIDGE_SIGN_INS = _bridge_sign_ins_from_env()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def mode() -> str:
|
|
99
|
-
return MODE
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def refused_tools() -> frozenset:
|
|
103
|
-
"""What this deployment refuses whatever config.yaml says: nothing
|
|
104
|
-
unless it is shared; then the container tools always, and the math
|
|
105
|
-
tools unless their confinement was verified on this host (HD4, HD11)."""
|
|
106
|
-
if MODE != SHARED:
|
|
107
|
-
return frozenset()
|
|
108
|
-
if CONFINEMENT == CONFINEMENT_VERIFIED:
|
|
109
|
-
return SHARED_REFUSED_TOOLS
|
|
110
|
-
return SHARED_REFUSED_TOOLS | CONFINED_TOOLS
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def is_hosted() -> bool:
|
|
114
|
-
return MODE != OFF
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def is_shared() -> bool:
|
|
118
|
-
return MODE == SHARED
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def bridge_signs_in(name: str) -> bool:
|
|
122
|
-
"""Whether this session's bridge completes `name`'s sign-in (HD13)."""
|
|
123
|
-
return name in BRIDGE_SIGN_INS
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
def make_undumpable() -> bool:
|
|
127
|
-
"""Mark this process non-dumpable, so other processes of the same user
|
|
128
|
-
cannot read its memory or environment (HD6). True when it took effect.
|
|
129
|
-
|
|
130
|
-
`prctl(PR_SET_DUMPABLE, 0)`: the kernel then hands `/proc/<pid>/mem`,
|
|
131
|
-
`/proc/<pid>/environ` and the rest to root and refuses a debugger
|
|
132
|
-
attach without CAP_SYS_PTRACE. Measured under WSL before it was relied
|
|
133
|
-
on: a sibling process read an ordinary process's environ, secret
|
|
134
|
-
included, and was refused the same read once the target had made this
|
|
135
|
-
call. It is per PROCESS and an exec resets it, which is why the session
|
|
136
|
-
makes it itself, first thing, rather than the bridge making it for the
|
|
137
|
-
child.
|
|
138
|
-
|
|
139
|
-
Linux only, and never raises: off Linux there is no shared container to
|
|
140
|
-
protect, and a hosted session that cannot harden itself still runs --
|
|
141
|
-
the bridge's own isolation is the first line, and this is the second.
|
|
142
|
-
"""
|
|
143
|
-
if not sys.platform.startswith("linux"):
|
|
144
|
-
return False
|
|
145
|
-
try:
|
|
146
|
-
libc = ctypes.CDLL(None, use_errno=True)
|
|
147
|
-
return libc.prctl(4, 0, 0, 0, 0) == 0 # PR_SET_DUMPABLE == 4
|
|
148
|
-
except (OSError, AttributeError):
|
|
149
|
-
return False
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def die_with_parent() -> bool:
|
|
153
|
-
"""Ask the kernel for SIGTERM when the bridge that started this session
|
|
154
|
-
goes away (HD8). True when it took effect.
|
|
155
|
-
|
|
156
|
-
The bridge starts every session in a NEW process group, so that stopping
|
|
157
|
-
one reaches what it started; the cost is that a signal to the bridge
|
|
158
|
-
reaches no session. Measured 2026-10-20 under WSL: a SIGTERM to the
|
|
159
|
-
bridge left the open session running, orphaned, with its directory, and
|
|
160
|
-
nothing would ever have stopped it -- it holds a visitor's key in memory
|
|
161
|
-
and counts against the container's. `prctl(PR_SET_PDEATHSIG)` closes
|
|
162
|
-
that, in the session, because like PR_SET_DUMPABLE it does not survive
|
|
163
|
-
the exec that starts one.
|
|
164
|
-
|
|
165
|
-
The signal comes when the THREAD that forked this process exits; the
|
|
166
|
-
bridge spawns from its event loop's thread, which lives as long as the
|
|
167
|
-
server does. If the bridge died before this call, the signal is already
|
|
168
|
-
missed, so a changed parent pid ends the session here instead.
|
|
169
|
-
|
|
170
|
-
Linux only, and never raises, for make_undumpable's reasons.
|
|
171
|
-
"""
|
|
172
|
-
if not sys.platform.startswith("linux"):
|
|
173
|
-
return False
|
|
174
|
-
parent = os.getppid()
|
|
175
|
-
try:
|
|
176
|
-
libc = ctypes.CDLL(None, use_errno=True)
|
|
177
|
-
ok = libc.prctl(1, int(signal.SIGTERM), 0, 0, 0) == 0 # PR_SET_PDEATHSIG == 1
|
|
178
|
-
except (OSError, AttributeError):
|
|
179
|
-
return False
|
|
180
|
-
if ok and os.getppid() != parent:
|
|
181
|
-
os.kill(os.getpid(), signal.SIGTERM)
|
|
182
|
-
return ok
|
|
1
|
+
"""
|
|
2
|
+
security/hosted.py
|
|
3
|
+
|
|
4
|
+
ROADMAP_v3 §79 (HD4, HD6, HD13). What a hosted deployment changes inside the
|
|
5
|
+
harness, and nothing else: the mode it runs in, the tools a shared deployment
|
|
6
|
+
refuses whatever `config.yaml` says, the sign-ins its bridge completes, and
|
|
7
|
+
the hardening calls a hosted process makes about itself.
|
|
8
|
+
|
|
9
|
+
THE MODE COMES FROM THE REAL ENVIRONMENT, ONCE, AT IMPORT. The web bridge
|
|
10
|
+
(`deploy/hosted/`) starts every session's process with `VENASTINE_HOSTED`
|
|
11
|
+
set, and nothing else does. A `.env` cannot supply it (A70: `VENASTINE_*`
|
|
12
|
+
names are never taken from that file, and the file is never loaded into the
|
|
13
|
+
environment at all). It is bound at import for `security/posture.py`'s
|
|
14
|
+
reason: a value read at call time follows a mutation, and this one decides
|
|
15
|
+
what a visitor may do.
|
|
16
|
+
|
|
17
|
+
AN ENVIRONMENT VARIABLE CAN ONLY TAKE CAPABILITY AWAY HERE, which is why
|
|
18
|
+
having one does not contradict `posture.py`'s "there is none, by design".
|
|
19
|
+
Unset is a local install. `single-user` is a local install that says it is
|
|
20
|
+
hosted. `shared` removes things. And anything the parser does not recognise
|
|
21
|
+
is `shared`: a typo must land on the restrictive side, because the bridge
|
|
22
|
+
that sets this is the only thing standing between a visitor and the
|
|
23
|
+
container.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import ctypes
|
|
27
|
+
import os
|
|
28
|
+
import signal
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
OFF = ""
|
|
32
|
+
SHARED = "shared"
|
|
33
|
+
SINGLE_USER = "single-user"
|
|
34
|
+
|
|
35
|
+
# HD4. The tools that reach the container itself -- its files and its
|
|
36
|
+
# processes. A shared deployment runs every visitor in one container as one
|
|
37
|
+
# Unix user, so any of these would let one visitor read another's session.
|
|
38
|
+
# They ship disabled anyway; this is the second layer, for the deployment
|
|
39
|
+
# whose config.yaml says otherwise.
|
|
40
|
+
SHARED_REFUSED_TOOLS = frozenset({
|
|
41
|
+
"read", "write", "edit",
|
|
42
|
+
# Batch 174: an image file, read under `read`'s rules (§81, IM1).
|
|
43
|
+
"view_image",
|
|
44
|
+
"shell", "shell_background", "shell_monitor", "shell_interactive",
|
|
45
|
+
"shell_input", "shell_sessions", "shell_output", "shell_kill",
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# HD11. The tools whose child evaluates what the model sent: SymPy's parser
|
|
50
|
+
# ends in `eval`. A shared deployment runs them only inside the walls
|
|
51
|
+
# security/confine.py puts up, and only once the bridge's self-test has
|
|
52
|
+
# shown those walls standing on this host -- `VENASTINE_CONFINEMENT` is set
|
|
53
|
+
# to `verified` by the bridge after a clean pass, and by nothing else.
|
|
54
|
+
# Unset, they are refused like the tools above. (These are exactly the
|
|
55
|
+
# registry's BUDGET_COMPUTE tools; a test pins that.)
|
|
56
|
+
CONFINED_TOOLS = frozenset({
|
|
57
|
+
"symbolic_math", "linear_algebra", "probability_stats",
|
|
58
|
+
"discrete_math", "logic", "geometry",
|
|
59
|
+
})
|
|
60
|
+
CONFINEMENT_VERIFIED = "verified"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _mode_from_env() -> str:
|
|
64
|
+
raw = os.environ.get("VENASTINE_HOSTED", "").strip().lower()
|
|
65
|
+
if not raw:
|
|
66
|
+
return OFF
|
|
67
|
+
if raw == SINGLE_USER:
|
|
68
|
+
return SINGLE_USER
|
|
69
|
+
return SHARED
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
MODE = _mode_from_env()
|
|
73
|
+
# Bound at import for MODE's reason. Only a value the bridge set counts.
|
|
74
|
+
CONFINEMENT = os.environ.get("VENASTINE_CONFINEMENT", "").strip()
|
|
75
|
+
|
|
76
|
+
# HD13. The sign-ins the BRIDGE completes for this session -- ModelScope's,
|
|
77
|
+
# on modelscope.ai and on modelscope.cn (batch 176), whose apps each need a
|
|
78
|
+
# client secret that only the bridge holds. The names are
|
|
79
|
+
# deploy/hosted/sign_in.py's SITES, which this layer does not import;
|
|
80
|
+
# test_hosted_mode.py holds the two together. Bound at import for MODE's
|
|
81
|
+
# reason, and honoured only in a hosted session: the bridge sets it when it
|
|
82
|
+
# can finish the sign-in, and a local install has no bridge to finish it,
|
|
83
|
+
# however this variable reads.
|
|
84
|
+
BRIDGE_SIGN_IN_NAMES = frozenset({"modelscope", "modelscope-cn"})
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _bridge_sign_ins_from_env() -> frozenset:
|
|
88
|
+
if MODE == OFF:
|
|
89
|
+
return frozenset()
|
|
90
|
+
raw = os.environ.get("VENASTINE_BRIDGE_SIGN_IN", "")
|
|
91
|
+
return frozenset(name.strip().lower() for name in raw.split(",")) \
|
|
92
|
+
& BRIDGE_SIGN_IN_NAMES
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
BRIDGE_SIGN_INS = _bridge_sign_ins_from_env()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def mode() -> str:
|
|
99
|
+
return MODE
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def refused_tools() -> frozenset:
|
|
103
|
+
"""What this deployment refuses whatever config.yaml says: nothing
|
|
104
|
+
unless it is shared; then the container tools always, and the math
|
|
105
|
+
tools unless their confinement was verified on this host (HD4, HD11)."""
|
|
106
|
+
if MODE != SHARED:
|
|
107
|
+
return frozenset()
|
|
108
|
+
if CONFINEMENT == CONFINEMENT_VERIFIED:
|
|
109
|
+
return SHARED_REFUSED_TOOLS
|
|
110
|
+
return SHARED_REFUSED_TOOLS | CONFINED_TOOLS
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def is_hosted() -> bool:
|
|
114
|
+
return MODE != OFF
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def is_shared() -> bool:
|
|
118
|
+
return MODE == SHARED
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def bridge_signs_in(name: str) -> bool:
|
|
122
|
+
"""Whether this session's bridge completes `name`'s sign-in (HD13)."""
|
|
123
|
+
return name in BRIDGE_SIGN_INS
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def make_undumpable() -> bool:
|
|
127
|
+
"""Mark this process non-dumpable, so other processes of the same user
|
|
128
|
+
cannot read its memory or environment (HD6). True when it took effect.
|
|
129
|
+
|
|
130
|
+
`prctl(PR_SET_DUMPABLE, 0)`: the kernel then hands `/proc/<pid>/mem`,
|
|
131
|
+
`/proc/<pid>/environ` and the rest to root and refuses a debugger
|
|
132
|
+
attach without CAP_SYS_PTRACE. Measured under WSL before it was relied
|
|
133
|
+
on: a sibling process read an ordinary process's environ, secret
|
|
134
|
+
included, and was refused the same read once the target had made this
|
|
135
|
+
call. It is per PROCESS and an exec resets it, which is why the session
|
|
136
|
+
makes it itself, first thing, rather than the bridge making it for the
|
|
137
|
+
child.
|
|
138
|
+
|
|
139
|
+
Linux only, and never raises: off Linux there is no shared container to
|
|
140
|
+
protect, and a hosted session that cannot harden itself still runs --
|
|
141
|
+
the bridge's own isolation is the first line, and this is the second.
|
|
142
|
+
"""
|
|
143
|
+
if not sys.platform.startswith("linux"):
|
|
144
|
+
return False
|
|
145
|
+
try:
|
|
146
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
147
|
+
return libc.prctl(4, 0, 0, 0, 0) == 0 # PR_SET_DUMPABLE == 4
|
|
148
|
+
except (OSError, AttributeError):
|
|
149
|
+
return False
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def die_with_parent() -> bool:
|
|
153
|
+
"""Ask the kernel for SIGTERM when the bridge that started this session
|
|
154
|
+
goes away (HD8). True when it took effect.
|
|
155
|
+
|
|
156
|
+
The bridge starts every session in a NEW process group, so that stopping
|
|
157
|
+
one reaches what it started; the cost is that a signal to the bridge
|
|
158
|
+
reaches no session. Measured 2026-10-20 under WSL: a SIGTERM to the
|
|
159
|
+
bridge left the open session running, orphaned, with its directory, and
|
|
160
|
+
nothing would ever have stopped it -- it holds a visitor's key in memory
|
|
161
|
+
and counts against the container's. `prctl(PR_SET_PDEATHSIG)` closes
|
|
162
|
+
that, in the session, because like PR_SET_DUMPABLE it does not survive
|
|
163
|
+
the exec that starts one.
|
|
164
|
+
|
|
165
|
+
The signal comes when the THREAD that forked this process exits; the
|
|
166
|
+
bridge spawns from its event loop's thread, which lives as long as the
|
|
167
|
+
server does. If the bridge died before this call, the signal is already
|
|
168
|
+
missed, so a changed parent pid ends the session here instead.
|
|
169
|
+
|
|
170
|
+
Linux only, and never raises, for make_undumpable's reasons.
|
|
171
|
+
"""
|
|
172
|
+
if not sys.platform.startswith("linux"):
|
|
173
|
+
return False
|
|
174
|
+
parent = os.getppid()
|
|
175
|
+
try:
|
|
176
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
177
|
+
ok = libc.prctl(1, int(signal.SIGTERM), 0, 0, 0) == 0 # PR_SET_PDEATHSIG == 1
|
|
178
|
+
except (OSError, AttributeError):
|
|
179
|
+
return False
|
|
180
|
+
if ok and os.getppid() != parent:
|
|
181
|
+
os.kill(os.getpid(), signal.SIGTERM)
|
|
182
|
+
return ok
|