Skip to content

Commit 9685507

Browse files
committed
fix(codex): keep signed records owner-only
1 parent b637710 commit 9685507

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

plugins/agentrust-codex/PRIVACY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ tool outputs, or environment secrets.
2929

3030
The plugin writes baselines, latest snapshots, and its signing key below
3131
`$CODEX_HOME/agentrust`, which defaults to `~/.codex/agentrust`. It requests
32-
owner-only permissions for private state. Signed reports go to the output
33-
directory you choose.
32+
owner-only permissions for private state and signed report files. Signed
33+
reports go to the output directory you choose.
3434

3535
The plugin makes no network request during SessionStart, snapshot, verify, or
3636
approve. A signed-report request can run the included bootstrap, which installs

plugins/agentrust-codex/engine/capture.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import platform
1717
import re
1818
import socket
19-
import stat
2019
import sys
2120
import tempfile
2221
import time
@@ -739,7 +738,7 @@ def build_trace(current: Mapping[str, Any]) -> Dict[str, Any]:
739738
}
740739

741740

742-
def _atomic_write(path: Path, content: str, mode: int = 0o600) -> None:
741+
def _atomic_write(path: Path, content: str) -> None:
743742
path.parent.mkdir(parents=True, exist_ok=True)
744743
temporary: Optional[str] = None
745744
try:
@@ -755,7 +754,7 @@ def _atomic_write(path: Path, content: str, mode: int = 0o600) -> None:
755754
os.fsync(handle.fileno())
756755
temporary = handle.name
757756
try:
758-
os.chmod(temporary, mode)
757+
os.chmod(temporary, 0o600)
759758
except OSError:
760759
pass
761760
os.replace(temporary, path)
@@ -767,8 +766,8 @@ def _atomic_write(path: Path, content: str, mode: int = 0o600) -> None:
767766
pass
768767

769768

770-
def _save(path: Path, value: Mapping[str, Any], mode: int = 0o600) -> None:
771-
_atomic_write(path, json.dumps(value, indent=2, sort_keys=True) + "\n", mode)
769+
def _save(path: Path, value: Mapping[str, Any]) -> None:
770+
_atomic_write(path, json.dumps(value, indent=2, sort_keys=True) + "\n")
772771

773772

774773
def _load(path: Path) -> Tuple[Optional[Dict[str, Any]], str]:
@@ -813,7 +812,6 @@ def _load_or_create_manifest_keypair():
813812
"private_b64url": keypair.private_b64url(),
814813
"created_at": _now_iso(),
815814
},
816-
stat.S_IRUSR | stat.S_IWUSR,
817815
)
818816
return keypair
819817

@@ -845,15 +843,15 @@ def sign_all(
845843
trace = sign_record(build_trace(current), generate_key())
846844

847845
outdir.mkdir(parents=True, exist_ok=True)
848-
_save(outdir / "manifest.json", manifest, 0o644)
849-
_save(outdir / "trace.json", trace, 0o644)
846+
_save(outdir / "manifest.json", manifest)
847+
_save(outdir / "trace.json", trace)
850848
verification_key = {
851849
"algorithm": "Ed25519",
852850
"key_id": keypair.key_id,
853851
"public_key_b64url": keypair.public_b64url(),
854852
"note": "Load this key into agent-manifest trusted_keys to verify the manifest signature.",
855853
}
856-
_save(outdir / "verification_key.json", verification_key, 0o644)
854+
_save(outdir / "verification_key.json", verification_key)
857855
return manifest, trace
858856

859857

plugins/agentrust-codex/tests/test_capture.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ def test_signed_outputs_verify_and_pass_trace_level_zero(tmp_path, monkeypatch):
353353
)
354354
good = verify_manifest(manifest, context, RevocationStore())
355355
assert good.signature_verified is True
356+
if os.name == "posix":
357+
for name in ("manifest.json", "trace.json", "verification_key.json"):
358+
assert stat_mode(out / name) == 0o600
356359

357360
tampered = json.loads(json.dumps(manifest))
358361
tampered["artifacts"]["policy_bundle"]["hash"] = "sha256:" + "0" * 64

0 commit comments

Comments
 (0)