Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/OPERATOR_AUTHORIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Operator authorization boundary

The PhiShell and GhostWalk HTTP surfaces expose observation and proposal
interfaces. POSTs to authorization-console `decisions`, `bindings`, and `leases`
return **403 operator_channel_required**, before parsing or calling a service.
A loopback address, a browser origin, or a PhiVessel session does not identify
an operator. Other HTTP writes require the exact loopback Host, JSON content
type, and a matching Origin when present; cross-site fetches are rejected.
These checks reduce browser request forgery; they do not authenticate agents.

Install the Python package to obtain `phi-operator`, or run
`python -m phios.ghostwalk_operator` from the source checkout. Use the same
protected state root and policy environment as the host:

```sh
phi-operator --state-root ~/.phios --target <inference-sha256> inspect
phi-operator --state-root ~/.phios --target <inference-sha256> decide APPROVE
phi-operator --state-root ~/.phios --target <inference-sha256> decide HOLD
phi-operator --state-root ~/.phios --target <inference-sha256> decide DENY
phi-operator --state-root ~/.phios --target <inference-sha256> bind
phi-operator --state-root ~/.phios --target <inference-sha256> lease
```

Each mutation displays the current normalized evidence as escaped JSON and
requires typing the action and full snapshot digest. There is no `--yes` or
unattended option. Cancellation does not mutate authority. Changed evidence
requires a new review, and the existing services still check their exact
request, previous decision, mapping, policy, enforcement and epoch hashes.
Approval does not create a binding or lease. The command never executes an
effect or mounts an executor. Refresh PhiShell after terminal operations.

Without a valid trusted execution manifest, only inspection and decisions
are available. Binding and lease issuance currently require the supported
Windows desktop host. Linux previews must report this capability unavailable.
The CLI requires its manifest inside the protected state root, rejects
symlinked state, and on POSIX rejects state owned by another user or writable
by group/others. It does not silently repair existing permissions.

## Trust and remaining release gates

A TTY is an explicit interaction requirement, **not proof of human identity**.
A malicious process sharing the operator's OS account can create a pseudo-TTY,
import Python services, or edit that account's files. Run untrusted agents as
separate OS principals without access to operator state, terminal or desktop.
On Windows, protect the state with an owner-only ACL; this CLI does not attest
Windows ACLs. The Linux OS release remains held until principal separation,
broker authentication, concurrent writer safety and durable state recovery
have independent evidence. Do not describe this patch as universal human
authentication or whole-OS sandboxing.
37 changes: 37 additions & 0 deletions docs/os/IMPLEMENTATION_STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Linux OS implementation register

Controlling input: the operator-approved *PhiOS OS Release Audit and Plan*,
2026-09-30, SHA-256 `aba53c05f18ac2f874236a1b6566b74096eabff9422e9e0fee0b5da54b54a676`, audited source `dad7a7d7cd53874926ad366f19d3fc0fa6b99a49`.
This register tracks candidate implementation, not permission to publish or
proof that PhiOS is a completed OS. Preserve the repository AGENTS.md rules.

| Requirement | Candidate change | Evidence / remaining gate |
| --- | --- | --- |
| R1: HTTP callers cannot mint operator authority | Decision, binding and lease POSTs held; explicit terminal review | HTTP rejection, cancellation and stale-review tests; same-user isolation and Windows ACL evidence remain required |
| R2: Freeze a truthful Linux release contract | Pending | x86_64 UEFI, Arch, Wayfire, PhiShell, distinct OS version |
| R3: Install current Python and UI packages | Pending | Locked inputs, pacman inventory, installed smoke checks |
| R4: Real non-root graphical login and supervised services | Pending | Session start, stop, reboot and no elevated browser |
| R5: Produce and UEFI boot exact live ISO | Pending | Archiso build and QEMU evidence, graphical qualification |
| R6: Recover durable private state | Pending | Concurrent writes, crash recovery, backup/restore, migrations |
| R7: Explicit blank-disk installation | Pending | Disposable VM install, boot without ISO, persistence |
| R8: Whole-OS update and recovery | Pending | Signed artifacts, failed update recovery; app rollback is insufficient |
| R9: Qualify hardware and one Linux governed workflow | Pending | Named hardware matrix and observed effect verification |
| R10: Sign and publish the exact qualified artifact | Held | Proven preceding gates, hashes, SBOM, signatures, source/license notices and maintainer release decision |

## First builder handoff

The approval boundary is a bounded candidate repair. Core normalized
contracts, adapter selection, advisory rollout behavior and private PhiKernel
internals remain untouched. Existing terminal services perform each stage
separately; no capability payload or lease lifetime is selected by the CLI.

Focused security tests and Python lint/type checks are required before review.
The full existing suite must also run in GitHub CI: the local execution host
restricts AF_UNIX, network enumeration and bubblewrap preflight. Environment
failures must be preserved and reported separately, never silently skipped to
claim a pass. Reviewers should rerun the boundary tests and assess the stated
same-user trust limitation before merging. Later milestones must update this
register with actual artifact identities and evidence, rather than readiness
percentages or forecast dates.

Validation: 73 focused Python tests passed; Ruff and mypy (301 source files) passed. PhiShell production build and 12 targeted HTTP boundary/proposal tests passed. Full PhiShell TypeScript suite passed; three existing Node integration tests fail on this host due to restricted network enumeration and absent systemd, as recorded in the audit. GitHub CI remains the required full-platform check.
209 changes: 209 additions & 0 deletions phios/ghostwalk_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
"""Explicit terminal review of the existing decision -> binding -> lease chain.

This process never installs or calls an executor. A terminal is an intentional
operator interface, not proof of a human or isolation from a malicious process
running as the same OS user. Such processes must use a separate OS principal.
"""

from __future__ import annotations

import argparse
import json
import os
import re
import stat
import sys
from datetime import UTC, datetime
from pathlib import Path
from typing import TextIO

from phios.macro_accepted_intent import GhostWalkAcceptedIntentRegistry
from phios.macro_action_lease_service import GhostWalkActionLeaseService, GhostWalkLeasePolicyRegistry
from phios.macro_authority_request import GhostWalkAuthorityRequestService
from phios.macro_authorization_console import (
GhostWalkAuthorizationConsoleError,
GhostWalkAuthorizationConsoleService,
GhostWalkAuthorizationConsoleSnapshot,
)
from phios.macro_authorization_decision import (
GhostWalkAuthorizationDecisionKind,
GhostWalkAuthorizationDecisionService,
)
from phios.macro_capability_binding import (
GhostWalkCapabilityBindingService,
GhostWalkCapabilityMappingRegistry,
)
from phios.macro_ghostwalk_control_server import DEFAULT_OPERATOR_AUTHOR_ID, default_state_root
from phios.macro_ghostwalk_operator_editor import GhostWalkOperatorEditor
from phios.macro_policy_admission import GhostWalkPolicyAdmissionService, GhostWalkPolicyProfile
from phios.phivessel_local_execution import (
ManifestAuthorityEpochProvider,
PhiVesselLocalExecutionManifest,
execution_manifest_path,
)
from phios.spine.ledger import RealityLedger


def _check_owned_path(path: Path) -> None:
"""Reject symlinks and shared-writable state before constructing services."""
info = path.lstat()
if stat.S_ISLNK(info.st_mode):
raise ValueError(f"operator state must not be a symlink: {path}")
if os.name == "posix":
if info.st_uid != os.getuid() or info.st_mode & 0o022:
raise ValueError(f"operator state must be owned by you and not shared-writable: {path}")


def build_operator_console(state_root: Path) -> GhostWalkAuthorizationConsoleService:
root = state_root.expanduser().absolute()
# Existing state is never silently repaired or permission-changed.
root.mkdir(parents=True, exist_ok=True, mode=0o700)
_check_owned_path(root)
for path in root.rglob("*"):
_check_owned_path(path)
ledger_dir = root / "ledger"
ledger_dir.mkdir(exist_ok=True, mode=0o700)
ledger = RealityLedger(ledger_dir / "receipts.jsonl")
editor = GhostWalkOperatorEditor(ledger=ledger, author_id=DEFAULT_OPERATOR_AUTHOR_ID)
intents = GhostWalkAcceptedIntentRegistry(ledger=ledger, accepted_by=DEFAULT_OPERATOR_AUTHOR_ID)
admission = GhostWalkPolicyAdmissionService(
ledger=ledger, accepted_intents=intents, operator_editor=editor,
profile=GhostWalkPolicyProfile.from_environment(os.environ),
)
requests = GhostWalkAuthorityRequestService(
ledger=ledger, policy_admission=admission, requester_id=DEFAULT_OPERATOR_AUTHOR_ID,
)
decisions = GhostWalkAuthorizationDecisionService(
ledger=ledger, authority_requests=requests, authorizer_id=DEFAULT_OPERATOR_AUTHOR_ID,
)
manifest_path = execution_manifest_path(state_root=root)
if not manifest_path.absolute().is_relative_to(root):
raise ValueError("operator execution manifest must be inside the protected state root")
if not manifest_path.exists():
return GhostWalkAuthorizationConsoleService(authorization_decisions=decisions)
_check_owned_path(manifest_path)
manifest = PhiVesselLocalExecutionManifest.read(manifest_path)
if not manifest.enabled:
return GhostWalkAuthorizationConsoleService(authorization_decisions=decisions)
# The installed desktop executor currently only supports Windows. Linux
# previews must not mint a lease for an unavailable effect implementation.
if sys.platform != "win32" or not manifest.desktop_executor_enabled:
raise ValueError("desktop binding and lease issuance require the supported Windows host")
bindings = GhostWalkCapabilityBindingService(
ledger=ledger, authorization_decisions=decisions,
registry=GhostWalkCapabilityMappingRegistry(manifest.mappings),
)
leases = GhostWalkActionLeaseService(
ledger=ledger, capability_bindings=bindings,
policies=GhostWalkLeasePolicyRegistry(manifest.lease_policies),
authority_epochs=ManifestAuthorityEpochProvider(
path=manifest_path, expected_static_config_sha256=manifest.static_config_sha256,
),
)
return GhostWalkAuthorizationConsoleService(
authorization_decisions=decisions, capability_bindings=bindings, action_leases=leases,
)


def _perform(
console: GhostWalkAuthorizationConsoleService,
snapshot: GhostWalkAuthorizationConsoleSnapshot,
action: str,
decision: str | None,
note: str | None,
) -> dict[str, object]:
target = snapshot.target_inference_receipt_sha256
if action == "decide":
auth = snapshot.authorization_readiness
if not auth.ready or auth.authority_request_sha256 is None or decision is None:
raise ValueError(f"decision held: {auth.reason.value}")
return console.record_decision(
target_inference_receipt_sha256=target,
expected_authority_request_sha256=auth.authority_request_sha256,
expected_previous_decision_sha256=auth.latest_decision_sha256,
decision=GhostWalkAuthorizationDecisionKind(decision), decision_note=note,
).to_dict()
if action == "bind":
binding = snapshot.binding_readiness
if (binding is None or not binding.ready or binding.authorization_decision_sha256 is None
or binding.selected_mapping_sha256 is None):
raise ValueError("binding held: current trusted mapping and approval required")
return console.create_binding(
target_inference_receipt_sha256=target,
expected_authorization_decision_sha256=binding.authorization_decision_sha256,
expected_mapping_sha256=binding.selected_mapping_sha256,
expected_mapping_set_sha256=binding.mapping_set_sha256,
bound_at=datetime.now(UTC).isoformat(),
).to_dict()
lease = snapshot.lease_readiness
if (lease is None or not lease.ready or lease.executable_binding_sha256 is None
or lease.policy_sha256 is None or lease.enforcement_profile_sha256 is None
or lease.authority_epoch_sha256 is None):
raise ValueError("lease held: current binding, policy, enforcement and authority required")
return console.issue_lease(
target_inference_receipt_sha256=target,
expected_executable_binding_sha256=lease.executable_binding_sha256,
expected_policy_sha256=lease.policy_sha256,
expected_policy_set_sha256=lease.policy_set_sha256,
expected_enforcement_profile_sha256=lease.enforcement_profile_sha256,
expected_authority_epoch_sha256=lease.authority_epoch_sha256,
).to_dict()


def review(
console: GhostWalkAuthorizationConsoleService, *, target: str, action: str,
decision: str | None = None, note: str | None = None,
input_stream: TextIO, output_stream: TextIO,
) -> int:
if action not in {"inspect", "decide", "bind", "lease"}:
raise ValueError("unsupported operator action")
if action != "inspect" and not (input_stream.isatty() and output_stream.isatty()):
raise ValueError("operator mutations require an interactive terminal; no unattended flag exists")
snapshot = console.snapshot(target_inference_receipt_sha256=target)
# JSON escaping prevents proposal text from injecting terminal control codes.
print(json.dumps(snapshot.to_dict(), indent=2, ensure_ascii=True), file=output_stream)
if action == "inspect":
return 0
confirmation = f"{decision if action == 'decide' else action.upper()} {snapshot.snapshot_sha256}"
print(f"Type exactly {confirmation} to confirm, or anything else to cancel:",
file=output_stream, flush=True)
if input_stream.readline().strip() != confirmation:
print("Cancelled; no decision, binding, or lease was created.", file=output_stream)
return 2
current = console.snapshot(target_inference_receipt_sha256=target)
if current.snapshot_sha256 != snapshot.snapshot_sha256:
raise ValueError("evidence changed during review; inspect and confirm again")
result = _perform(console, snapshot, action, decision, note)
print(json.dumps({"operator_action": action, "result": result,
"execution_authority": False, "effect_performed": False}, indent=2),
file=output_stream)
return 0


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--state-root", type=Path, default=default_state_root())
parser.add_argument("--target", required=True)
actions = parser.add_subparsers(dest="action", required=True)
actions.add_parser("inspect")
decide = actions.add_parser("decide")
decide.add_argument("decision", choices=("APPROVE", "HOLD", "DENY"))
decide.add_argument("--note")
actions.add_parser("bind")
actions.add_parser("lease")
args = parser.parse_args(argv)
try:
if re.fullmatch(r"[0-9a-f]{64}", args.target) is None:
raise ValueError("target must be a lowercase SHA-256 digest")
if args.action != "inspect" and not (sys.stdin.isatty() and sys.stdout.isatty()):
raise ValueError("operator mutations require an interactive terminal")
return review(build_operator_console(args.state_root), target=args.target, action=args.action,
decision=getattr(args, "decision", None), note=getattr(args, "note", None),
input_stream=sys.stdin, output_stream=sys.stdout)
except (ValueError, OSError, GhostWalkAuthorizationConsoleError) as exc:
print(f"Operator action held: {exc}", file=sys.stderr)
return 1


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading