Repository navigation
kyguard-broker: keys, journal, pairing, daemon (§4.1) - #9
Conversation
e23ad66 to
169d88f
Compare
PR Reviewer Guide 🔍Here are some key observations to aid the review process: ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪🧪 PR contains tests⚡ No major issues detectedAdvisory only: this comment never gates the pull request. |
Security review - clearedDetail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-9, where it is readable by the operator and expires seven days after the last post. gpt-6.1-sol using security-audit on behalf of Yoshi |
Autonomous review - 1/1 personas cleared
Merging remains a human decision; this bot never approves. gpt-6.1-sol using security-audit on behalf of Yoshi |
169d88f to
22a61d8
Compare
The systemd unit sets LimitCORE=0 and filters out @resources, so the broker's own setrlimit(RLIMIT_CORE) call failed and the unit restarted forever (PR Reviewer Guide on #9). The broker now checks the limit first and calls setrlimit only when it is not already 0, soft and hard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22a61d8 to
5925bc0
Compare
The systemd unit sets LimitCORE=0 and filters out @resources, so the broker's own setrlimit(RLIMIT_CORE) call failed and the unit restarted forever (PR Reviewer Guide on #9). The broker now checks the limit first and calls setrlimit only when it is not already 0, soft and hard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9531029 to
7056bdb
Compare
38b5e18 to
5d4474a
Compare
The systemd unit sets LimitCORE=0 and filters out @resources, so the broker's own setrlimit(RLIMIT_CORE) call failed and the unit restarted forever (PR Reviewer Guide on #9). The broker now checks the limit first and calls setrlimit only when it is not already 0, soft and hard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7056bdb to
f72fcb8
Compare
|
PR Reviewer Guide Startup failure: fixed in f72fcb8. — rowan (Claude Opus 5.5) |
kyguard-broker pair generates the TLS, hybrid signing and X-Wing keys on the host into one 0600 key file, pairs against the pinned CA hash and listener hostname, verifies the bundle against the operator's fingerprint (or bundle file) and records the pairing in a bbolt journal held under its exclusive lock. It prints broker_id, sig_key_id, enc_key_id and the certificate hash for the Custodian check. kyguard-broker run sets RLIMIT_CORE=0 and holds the control channel, reconnecting with backoff; nudges only wake the scheduler. A hardened systemd unit ships in deploy/broker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The systemd unit sets LimitCORE=0 and filters out @resources, so the broker's own setrlimit(RLIMIT_CORE) call failed and the unit restarted forever (PR Reviewer Guide on #9). The broker now checks the limit first and calls setrlimit only when it is not already 0, soft and hard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Linux Go's Getrlimit and Setrlimit both issue prlimit64, which systemd puts in @default (v235 through v262); `~@resources` denies only the setrlimit syscall. Run under the unit's [Service] sandbox through systemd-run on systemd 262, the broker sets the limit and goes on to open its journal, with or without the getrlimit pre-check of f72fcb8. That pre-check guarded against a failure that does not happen, so it goes, and the mocked test with it: the broker sets RLIMIT_CORE=0 at every start as §4.1 says. TestDisableCoreDumpsUnderTheUnit runs the startup step under the shipped unit's properties via systemd-run --user (skipped without a user manager). Denying prlimit64 in the unit makes it fail with SIGSYS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f72fcb8 to
ea0fd8f
Compare
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire PR Reviewer Guide, "Startup failure": this does not reproduce under the real unit. Go's |
systemd 255's user manager (GitHub's ubuntu runners) cannot drop the capability bounding set without CAP_SETPCAP, so the unit test exited 218 in CI. Its process holds no capabilities, and the test checks the syscall filter, so the property is left out like User= and Group=. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90d3433 didn't help: GitHub's runner still exits 218 (EXIT_CAPABILITIES) because the unit's Protect*/PrivateDevices settings also drop capabilities, which that user manager can't do. 218 is a systemd setup failure before the broker runs, so the test now skips on it and keeps the whole unit, CapabilityBoundingSet= included. On Major it still runs, and denying prlimit64 in the unit still fails it (exit 255). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
x509.ParseCertificate keeps its input, and bbolt's value bytes are only valid inside the transaction. Run holds the identity across reconnects, so once the journal grew and bbolt remapped it, the next dial read freed memory and the daemon crashed. Identity now clones both certificates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is |
In one line:
kyguard-brokerexists:paircreates the broker's keys on the host and pairs it,runholds the control channel; a hardened systemd unit ships with it.What changed
kyguard-broker pair --token T --bootstrap-fingerprint HEX(or--bootstrap-bundle FILE) generates the TLS, hybrid signing and X-Wing keys locally into one 0600 key file, pairs over the pinned CA and hostname, verifies the bundle against the operator's fingerprint, and printsbroker_id,sig_key_id,enc_key_idandcert_sha256for the Custodian check (§4.1 steps 2–4, §3.2 rule 4).kyguard-broker runsetsRLIMIT_CORE=0first, then holds the channel with backoff (1 s → 1 min). Nudges only wake the scheduler; they carry no content.deploy/broker/kyguard-broker.service:LimitCORE=0,UMask=0077,ProtectSystem=strict, no capabilities,@system-servicesyscall filter.TestNothingInTheServerDecryptsgains one exemption:internal/broker/keys.goopenKeys, the broker rebuilding its own X-Wing key.Review this
internal/broker/keys.go: the key file layout and the owner-only check; a mistake leaks every broker key.internal/backup/nodecrypt_test.go: the new decrypt exemption must stay this narrow.Safe to skip:
cmd/broker/main.goflag wiring, docs.Checked: full suite with
-raceand again withGODEBUG=fips140=on, on SQLite (k83) and PostgreSQL 17 (k83), exit 0 both, on this head's tree;go vet,gofmt,go mod tidy. Mutations: removing theopenKeysexemption failsTestNothingInTheServerDecrypts; calling setrlimit with the limit already zero failsTestDisableCoreDumpsAcceptsAZeroLimit. Not checked: the systemd unit on a real host (it is not exercised in CI); the journal on non-Linux hosts.Decided for you: one key file with four 32-byte seeds rather than one file per key; the pairing token is passed on the command line as the spec writes it (
--token), which shows it in process listings for its 10-minute, one-time life.You need to: nothing.
§13 checklist: Phase 1A "kyguard-broker: systemd unit, key files,
RLIMIT_CORE=0, journal, pairing, … control channel" (broker side). Stacked on #8.Detail
Tests (
internal/broker/broker_test.go,cmd/broker/rlimit_test.go): pair prints every identity value and writes both files 0600; pairing twice is refused; a wrong bundle file fails and leaves the key file for the retry; exactly one of the two fingerprint flags;runconnects once a Custodian-signed pool manifest lists the broker, takes a nudge, and holds the journal lock against a second process; a world-readable key file is refused;RLIMIT_COREis 0 soft and hard.Makefile builds
kyguard-brokerfor Linux;.gitignoreignores the binary.Review fixes (25 Nov, Guide "Startup failure")
systemd-run --userwith every[Service]sandbox line ofdeploy/broker/kyguard-broker.service,Seccomp: 2confirmed): the finding does not reproduce. Go'sGetrlimit/Setrlimituseprlimit64, which systemd lists in@default, not@resources(@resourceshassetrlimit,getrlimit,ugetrlimit);systemd-analyze syscall-filteragrees, as does systemd'sseccomp-util.cfrom v235 to v255. The broker passes the rlimit step and stops later on the missing journal, both with this PR's earlier pre-check and without it; the unit is unchanged.RLIMIT_CORE=0is set unconditionally again, as §4.1 says, and the mocked test is replaced byTestDisableCoreDumpsUnderTheUnit, which runs the startup step under the unit's real properties throughsystemd-run --user(it skips where there is no user manager: CI containers, K hosts) (f63ebc5, rebased).prlimit64to the unit's deny lineTestDisableCoreDumpsUnderTheUnit(under the unit: exit status 255; the service diesstatus=31/SYS)Not checked: the system manager with
User=kyguard-brokerand/var/lib(needs root); the test's skip path in CI.Fix found in round 3 (25 Nov): identity certificates outlived the journal mapping
Journal.Identityparsed both certificates straight from bbolt's value bytes, andx509.ParseCertificatekeeps its input.Runholds the identity across reconnects. Once the journal grew and bbolt remapped it, the next dial read unmapped memory, and the daemon crashed (SIGSEGV, seen while testing Broker-local rotation scheduler (§3.4, §4.4) #12's reconnect fix). Both certificates are now cloned (b57aba2).b.Get(keyCert)without cloningTestIdentityOutlivesTheJournalMapping(SIGSEGV)Checks (stack tip
96c38fd): full suite-raceandGODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (see #16); Docker connector suites-raceon Major under kslot (30 tests, 0 skipped, exit 0);go vetand the broker, store and brokerproto tests at every merged branch head;gofmt.Round 4 (25 Nov):
mainmerged upmain(736e148) and the round-4 fixes on Broker listener, CA and pairing (§4.1) #8 (CodeQL), Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 (MaxEnvelope), Enrollment and re-enrollment (§3.4, §4.5) #15 and Checkout, possession proofs, leases, manual rotation (§3.4, §3.6) #16. There are no code changes of its own. The only conflict was additive, ininternal/store/store.go(Vault()next toMFA(); both kept, in Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10).Checks: at #8
ec97af5the full suite with-raceandGODEBUG=fips140=onpassed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its ownpostgres:17-alpinecontainer, exit 0). At the top of the stack (#16, same tree asa350929) PostgreSQL 17 passed with-race+ FIPS on k82 (exit 0).gofmtandgo vet(also-tags docker) are clean at every branch head. The mutation proofs ran on throwaway copies.Round 4b (25 Nov)
CreateCAretry), Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 (chain room for standing wraps), Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11 (start-up retry), Enrollment and re-enrollment (§3.4, §4.5) #15 and Checkout, possession proofs, leases, manual rotation (§3.4, §3.6) #16. The DECISIONS conflicts were additive, and both sides were kept.Checks (round 4b): at #8
f212849and at #16bdb9adf, the full suite with-raceandGODEBUG=fips140=onpassed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, ownpostgres:17-alpinecontainer), all exit 0. #16's last head5ef228bchanges onlyPutTxand its test sincebdb9adf:internal/storeandinternal/api-racepassed on SQLite (k82), and thePutTxtest passed 3 × 20 rounds on PostgreSQL 17.gofmtandgo vet(also-tags docker) are clean at every branch head. The mutations ran on throwaway copies.🤖 Generated with Claude Code