Repository navigation
Ticket 0007a: Anchorer core API in cog-anchor - #317
Conversation
Add the anchoring API — Anchorer, AnchorRequest, AnchorError, and generate_key_file — inside cog-anchor. Anchorer::open becomes the sole LogWriter construction site in the deadbolt estate (CLAUDE.md law 3). Dev-grade key custody: a 64-lowercase-hex Ed25519 seed file, created create-new (refuses overwrite) and never auto-generated. smoke.rs is refactored to route through Anchorer so LogWriter::open has exactly one call site. Deps: serde/serde_json only (OS RNG via bcrypt/urandom FFI, no new cargo deps). Split A of parent ticket 0007; 0007b wires emission into cog-cli. Implemented by Codex (gpt-5.5) via delegation; reviewed by Claude — 7 tests green, clippy -D warnings clean, cargo tree -i magpie-log shows one dependent (cog-anchor). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa2964cbbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut file = OpenOptions::new() | ||
| .write(true) | ||
| .create_new(true) | ||
| .open(key_path) |
There was a problem hiding this comment.
Restrict generated seed file permissions
On Unix hosts with a permissive umask such as 022, this OpenOptions create path uses the platform default create mode, so the generated Ed25519 seed file can end up group/world-readable (for example 0644). Because that seed is sufficient to append anchors as deadbolt, the generator should create it with restrictive permissions such as 0600 on Unix instead of relying on the caller's umask.
Useful? React with 👍 / 👎.
Architect ruling on the 0007a review: replace the hand-rolled OS RNG FFI (BCryptGenRandom / /dev/urandom) with getrandom, the audited ecosystem answer for entropy. Weak-entropy bugs are silent and permanent (Debian-OpenSSL-shaped), and this is the crate's most security-critical op. - Add getrandom 0.4 (dedupes with the version already in the tree). - generate_key_file fills the seed via getrandom::fill; all cfg(windows)/ cfg(unix) FFI deleted. Public signature, refuse-to-overwrite, and hex output format unchanged. - Add #![forbid(unsafe_code)]: the identity-creation crate now carries a compile-time no-unsafe guarantee (compiles clean — the FFI was the only unsafe in the crate). - decode_seed_hex: trim_end() so \r\n is handled, not just \n. All five 0007a tests still green, unmodified. clippy -D warnings clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Revise pass applied (architect ruling) — re-recommend ACCEPTForce of the ruling: the "no new deps" constraint was meant to stop scope creep, not to force hand-rolling the crate's most security-critical operation. Hand-rolled entropy fails silent-and-permanent (Debian-OpenSSL-shaped); Four changes (commit
The Validation (my runs, in the PR worktree):
Behaviour is identical to the first pass — only the entropy source and the crate's unsafe-ness changed. Recommend merge. |
What
Ticket 0007a — the anchoring core inside
cog-anchor(split A of parent ticket 0007). Adds the real API the emitter will use:Anchorer/AnchorRequest/AnchorErrorandgenerate_key_file.Anchorer::openis now the soleLogWriterconstruction site in the deadbolt estate (CLAUDE.md law 3).create_new(refuses to overwrite), never auto-generated.serde+serde_jsononly. OS randomness viaBCryptGenRandom(Windows) //dev/urandom(Unix) FFI — no new cargo deps.tests/smoke.rsrefactored to route throughAnchorersoLogWriter::openhas exactly one call site.Nothing outside
cog-anchorimports it yet; emission intocog-cliis 0007b (parked until this merges — it imports this API).Review (independently verified, not from the worker's summary)
cargo test -p cog-anchoranchorer.rs+ 2smoke.rs)cargo clippy -p cog-anchor --all-targets -- -D warningscargo tree -i magpie-logLogWriter::opengrepAnchorer::openAnchorError::Log, len unchangedReviewer notes (non-blocking)
smoke.rsmodified — outside 0007a's enumerated file list but withincrates/cog-anchor/**and necessary: it was a secondLogWriter::opensite, so routing it throughAnchoreris what makes the "sole construction site" criterion true.unsafeFFI — chosen to honor "serde-only, no new deps." Small and correct-looking; flagging the platformunsafeas a design trade vs. an explicitgetrandomdep. Minor nit:decode_seed_hexstrips\nbut not\r\n(irrelevant to the newline-free file it generates).Provenance
Implemented by Codex (gpt-5.5) via the delegation wrapper; ticket authored and diff reviewed by Claude. Human is the merge authority.
🤖 Generated with Claude Code