Hacker News 中文摘要

RSS订阅

SSH无Host标头 -- SSH has no Host header

文章摘要

文章指出SSH协议没有类似HTTP的Host头字段,导致在共享IP地址时无法区分不同虚拟机。exe.dev服务因成本考虑无法为每个VM分配独立IPv4地址,而IPv6又存在兼容性问题。虽然HTTP可通过Host头解决此问题,但SSH缺乏类似机制,给多虚拟机共享IP带来技术挑战。

文章总结

SSH协议缺乏Host头机制——exe.dev博客解决方案

背景挑战: exe.dev平台为每个虚拟机提供标准URL(如undefined-behavior.exe.xyz),用户可通过同一域名进行HTTPS和SSH访问。但由于IPv4地址成本限制,无法为每个VM分配独立IPv4地址,也不能完全采用IPv6(会影响部分网络访问),必须共享IPv4地址。

核心问题: HTTP协议通过Host头实现多站点共享IP,但SSH协议没有等效机制。当多个VM共享IP时,无法正确路由SSH连接。

解决方案: 1. 建立公共IPv4地址池 2. 为每个VM分配相对于用户唯一的IP地址(非全局唯一) 3. 通过DNS CNAME记录实现映射: undefined-behavior.exe.xyz → s003.exe.xyz → 16.145.102.7 4. 利用{用户公钥, IP地址}二元组唯一标识目标VM

技术实现难点: - 需开发跨系统通信机制 - 精确基于用户/团队分配IP地址 - 在云环境中处理NAT转换后的地址识别 - 构建定制化管理软件

该方案虽不适合通用场景,但确保了域名行为的统一性和可预测性,是exe.dev平台的特殊解决方案。

(注:原文中的图片链接、导航菜单等非核心内容已省略,保留了技术细节和解决方案的关键逻辑)

评论总结

以下是评论内容的总结:

1. 对SSH协议的批评与改进建议

  • 观点:SSH协议设计存在缺陷,特别是密钥管理和认证机制。
  • 论据
    • "SSH typically uses 'bare' keys and lacks a mechanism like the X.509 key usage extension"(评论2)
    • "many things about the protocol are poorly designed, including its essentially made-up-as-you-go-along wire formats"(评论2)

2. 替代方案:跳板机/代理服务器

  • 观点:使用跳板机或代理服务器是更简单和安全的解决方案。
  • 论据
    • "What they want is a reverse proxy for SSH, and doesn’t SSH already have that via jump/bastion hosts?"(评论6)
    • "jump servers, it’s a thing and a good security measure."(评论17)

3. IPv6的推广

  • 观点:IPv6是解决IPv4地址不足的根本方案。
  • 论据
    • "The solution is ipv6."(评论13)
    • "Give a user a option for use IPv6 only, and if the user need legacy IP add it as a additional cost"(评论7)

4. 技术实现的具体建议

  • 观点:通过用户名或证书路由、端口敲门等技术实现多VM共享IP。
  • 论据
    • "I was using username for host routing. And real user was determined by the principal in SSH certificate"(评论10)
    • "set up knockd, and then generate a random knock sequence for each individual user"(评论12)

5. 对用户体验的重视

  • 观点:开发者应重视用户体验,简化操作流程。
  • 论据
    • "It’s hard to think of a clearer example for the concept of Developer Experience."(评论14)
    • "We mostly take the git clone git@github.com/author/repo for granted"(评论14)

6. 其他技术方案

  • 观点:SRV记录、TLS SNI等技术可以作为替代方案。
  • 论据
    • "I would love it if more systems just understood SRV records"(评论8)
    • "The solution to this is TLS SNI redirecting."(评论9)

7. 对SSH必要性的质疑

  • 观点:SSH并非必要,可以通过控制面板管理VM。
  • 论据
    • "You don’t need SSH. Installing an SSH server to such a VM is a hold over from how UNIX servers worked."(评论11)
    • "I would reconsider if offering ssh is an actual requirement here"(评论11)

8. 对现有方案的批评

  • 观点:现有方案存在安全风险或用户体验问题。
  • 论据
    • "This is a clever trick, but I can’t help but wonder where it breaks."(评论4)
    • "it’s really ghetto. You have to handle username collisions"(评论20)