Public: anyone can read this; the crew can change it.

The forge's SSH terminal is off after every boot: the host key comes up mode 660; the forge should tighten its own key to 0600 at start #16984

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

The forge now tightens its SSH host key to 0600 when it loads it, so a key that comes up 0660 no longer turns the terminal off. I ran test/file-modes.test.ts and test/spawn-app-links.test.ts: 30 pass. tsc --noEmit and gate.ts --fix came back clean.

Notes

opened this

The forge now tightens its SSH host key to 0600 when it loads it, so a key that comes up 0660 no longer turns the terminal off. I ran test/file-modes.test.ts and test/spawn-app-links.test.ts: 30 pass. tsc --noEmit and gate.ts --fix came back clean. I did not start the forge or check the terminal's port.

What changed (src/ssh/keys.ts)

  • loadOrCreateHostKey now runs tightenPrivateFiles(dir) before the mode check. It sets every non-.pub regular file in the SSH directory to 0600, but only when the forge's own uid owns it and its mode is wider than that.
  • A key the forge can't chmod, or one owned by someone else, is still refused with the same "must be 0600" message. The old comment said "never chmod it quietly", so this reverses a stated rule, and the issue says the owner decides. I limited the reversal to files the forge owns.

Test (test/file-modes.test.ts)

  • The old case expected a 0640 key to be refused. It now writes a host key and another private file at 0660 and asserts both are 0600 after load.
  • The old assertion was wrong under the new rule, so I changed it.

Left out

  • The ssh -p 2222 banner check in the front-door check (item 2) is not done. It needs a new probe, so it should be its own pull.
  • I did not check the production volume's mode. The fsGroup premise predates the move to a vxrail container.
  • src/kernel/secret.ts still refuses a loose secret.key. I left it alone because it is outside this issue.
  • There is no web page, action, route or tool change here, so the commit says "No door".

Try it

  • Run chmod 660 $FORGE_APP_DATA/ssh/host_ed25519, boot the forge, and the key is back to 0600 and SSH listens.

🤖 Generated with Claude Code

Closes #6671

commented

The forge now tightens its SSH host key to 0600 when it loads it, so a key that comes up 0660 no longer turns the terminal off. I ran test/file-modes.test.ts and test/spawn-app-links.test.ts: 30 pass. tsc --noEmit and gate.ts --fix came back clean. I did not start the forge or check the terminal's port.

What changed (src/ssh/keys.ts)

  • loadOrCreateHostKey now runs tightenPrivateFiles(dir) before the mode check. It sets every non-.pub regular file in the SSH directory to 0600, but only when the forge's own uid owns it and its mode is wider than that.
  • A key the forge can't chmod, or one owned by someone else, is still refused with the same "must be 0600" message. The old comment said "never chmod it quietly", so this reverses a stated rule, and the issue says the owner decides. I limited the reversal to files the forge owns.

Test (test/file-modes.test.ts)

  • The old case expected a 0640 key to be refused. It now writes a host key and another private file at 0660 and asserts both are 0600 after load.
  • The old assertion was wrong under the new rule, so I changed it.

Left out

  • The ssh -p 2222 banner check in the front-door check (item 2) is not done. It needs a new probe, so it should be its own pull.
  • I did not check the production volume's mode. The fsGroup premise predates the move to a vxrail container.
  • src/kernel/secret.ts still refuses a loose secret.key. I left it alone because it is outside this issue.
  • There is no web page, action, route or tool change here, so the commit says "No door".

Try it

  • Run chmod 660 $FORGE_APP_DATA/ssh/host_ed25519, boot the forge, and the key is back to 0600 and SSH listens.

🤖 Generated with Claude Code

commented

The forge now tightens only its own SSH host key (host_ed25519) to 0600 at start, when its own uid owns the file. I ran tsc --noEmit and test/file-modes.test.ts (6 pass), and bun scripts/gate.ts --fix changed nothing. I did not run the rest of the suite or scripts/design-lint.ts. A plain bun scripts/gate.ts printed only "the duplicate scan stopped after 8000 ms: it compared against part of the tree", so I can't say it passed in full.

  • Scope: I dropped the readdirSync loop and the other_key assertions. src/ssh/keys.ts now has tightenHostKey, which looks at the host key alone.
  • Fail-closed test: loadOrCreateHostKey(dir, ownerUid?) takes an optional uid, defaulting to process.getuid(). A new test in test/file-modes.test.ts passes a different uid with a 0640 key. It expects the refusal host_ed25519 is mode 640; it must be 0600 and checks the file is left at 0640.
  • Swallowed error: the empty catch {} is gone. A failed chmod is logged as ssh: cannot tighten <path> to 0600: <reason>, and the mode check then refuses with the mode.
  • Docs: docs/OPERATING.md now says the forge tightens its own host key at start. It also says a key the forge doesn't own, or can't chmod, is refused and the terminal stays off.

The commit has the Direction: line naming #6671 and the "No door" line, since no page, action, route or tool changed.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs