Skip to content

fix: Split SSH gateway key into separate host and user keys#351

Open
minhtule wants to merge 4 commits into
masterfrom
feat/mt/ssh-separate-host-user-keys
Open

fix: Split SSH gateway key into separate host and user keys#351
minhtule wants to merge 4 commits into
masterfrom
feat/mt/ssh-separate-host-user-keys

Conversation

@minhtule

Copy link
Copy Markdown
Contributor

Related Tickets & Documents

Changes

  • Generate separate host and user keypairs instead of one shared gateway key

@minhtule minhtule changed the title fix: split SSH gateway key into separate host and user keys fix: Split SSH gateway key into separate host and user keys Jun 29, 2026
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.94%. Comparing base (ae1a656) to head (7d8c199).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/sshhandler/config.go 80.95% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
- Coverage   86.07%   85.94%   -0.14%     
==========================================
  Files          40       40              
  Lines        2830     2832       +2     
==========================================
- Hits         2436     2434       -2     
- Misses        269      272       +3     
- Partials      125      126       +1     
Flag Coverage Δ
integration 54.89% <72.72%> (+0.03%) ⬆️
unit 78.42% <81.81%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/sshhandler/keys.go 80.64% <100.00%> (ø)
internal/sshhandler/config.go 79.68% <80.95%> (-1.27%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Issue #350 by reducing key-compromise blast radius in the SSH gateway: it replaces the single shared gateway keypair with two distinct keypairs—one for host certificates (downstream) and one for user certificates (upstream).

Changes:

  • Split the gateway keypair into separate host and user signers/public keys in Config.
  • Generate independent host/user keypairs during config initialization.
  • Extend NewConfig unit test coverage to assert the two keys are distinct.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/sshhandler/config.go Replaces shared gateway key material with separate host/user keys and wires them into downstream/upstream certificate flows.
internal/sshhandler/config_test.go Adds assertions ensuring host and user keys are both generated and distinct.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/sshhandler/config.go Outdated
Comment thread internal/sshhandler/config.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comment on lines -81 to -84
gatewaySigner, gatewayPublicKey, err := keyConfig{
typ: keyType,
bits: sshCfg.Gateway.Key.Bits,
}.Generate(rand.Reader)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an existing bug that is also fixed with this change: the old code constructs keyConfig instance directly instead of using the constructor newKeyConfig. As such, key type in SSH format like ssh-ed25519 is treated as error.

Comment on lines -75 to -78
// Apply defaults for Gateway's key config
keyType := keyType(sshCfg.Gateway.Key.Type)
if keyType == "" {
keyType = defaultKeyType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this default to newKeyConfig constructor because it's more appropriate and also testable.

@minhtule minhtule requested a review from clement0010 June 29, 2026 17:23

@clement0010 clement0010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

@minhtule minhtule requested a review from sghiocel July 3, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants