fix(security): harden sandbox SSH with mandatory HMAC secret, NetworkPolicy, and nonce replay detection#127
Merged
johntmyers merged 2 commits intomainfrom Mar 5, 2026
Conversation
…Policy, and nonce replay detection Closes #25 - Make NEMOCLAW_SSH_HANDSHAKE_SECRET mandatory: server and sandbox both refuse to start if the secret is empty/unset. Cluster deployments auto-generate it via openssl rand in the entrypoint script. - Add Kubernetes NetworkPolicy restricting sandbox port 2222 ingress to the gateway pod only, preventing lateral movement from other cluster workloads. - Add NSSH1 nonce replay detection with a TTL-bounded cache, rejecting replayed handshakes within the timestamp validity window. - Add unit tests for verify_preface (valid, replay, expired, bad HMAC, malformed) and env injection.
This was referenced Mar 5, 2026
drew
pushed a commit
that referenced
this pull request
Mar 16, 2026
…Policy, and nonce replay detection (#127) * fix(security): harden sandbox SSH with mandatory HMAC secret, NetworkPolicy, and nonce replay detection Closes #25 - Make NEMOCLAW_SSH_HANDSHAKE_SECRET mandatory: server and sandbox both refuse to start if the secret is empty/unset. Cluster deployments auto-generate it via openssl rand in the entrypoint script. - Add Kubernetes NetworkPolicy restricting sandbox port 2222 ingress to the gateway pod only, preventing lateral movement from other cluster workloads. - Add NSSH1 nonce replay detection with a TTL-bounded cache, rejecting replayed handshakes within the timestamp validity window. - Add unit tests for verify_preface (valid, replay, expired, bad HMAC, malformed) and env injection. * fix(deploy): pass sshHandshakeSecret in fast deploy helm upgrade --------- Co-authored-by: John Myers <johntmyers@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25
Summary
Hardens the SSH connection path between gateway and sandbox pods with three defense-in-depth improvements: mandatory HMAC handshake secret, Kubernetes NetworkPolicy restricting sandbox SSH ingress to the gateway, and nonce replay detection in the NSSH1 handshake. No UX changes — the secret is auto-generated for cluster deployments.
Changes Made
crates/navigator-sandbox/src/lib.rs: Fail startup ifNEMOCLAW_SSH_HANDSHAKE_SECRETis empty/unset when SSH is enabled (replaces silentunwrap_or_default())crates/navigator-sandbox/src/ssh.rs: AddNonceCachetype (Arc<Mutex<HashMap<String, Instant>>>), background reaper task, nonce replay rejection inverify_preface(), and 6 unit testscrates/navigator-server/src/lib.rs: Add startup validation rejecting emptyssh_handshake_secretcrates/navigator-server/src/sandbox/mod.rs: Always injectNEMOCLAW_SSH_HANDSHAKE_SECRETenv var (remove conditional guard), add env injection testdeploy/helm/navigator/templates/networkpolicy.yaml: New NetworkPolicy restricting sandbox pod port 2222 ingress to gateway pods only (gated bynetworkPolicy.enabled)deploy/helm/navigator/templates/statefulset.yaml: WireNEMOCLAW_SSH_HANDSHAKE_SECRETenv var into gateway poddeploy/helm/navigator/values.yaml: Addserver.sshHandshakeSecret(required) andnetworkPolicy.enabled: truedeploy/kube/manifests/navigator-helmchart.yaml: AddsshHandshakeSecretplaceholderdeploy/docker/cluster-entrypoint.sh: Auto-generate secret viaopenssl rand -hex 32at cluster deploy timearchitecture/sandbox-connect.md: Document mandatory secret, nonce replay detection, and NetworkPolicyDeviations from Plan
None — implemented as planned.
Tests Added
verify_prefacetests incrates/navigator-sandbox/src/ssh.rs(valid preface, replay rejection, expired timestamp, invalid HMAC, malformed input, distinct nonces); 1 env injection test incrates/navigator-server/src/sandbox/mod.rse2e/Documentation Updated
architecture/sandbox-connect.md: Added nonce replay detection section, mandatory handshake secret section, NetworkPolicy in security model, updated config referenceVerification