我正在使用OpenSSH证书作为主机池。 也就是说,在~/.ssh/known_hosts ,有一个条目看起来如此:
@cert-authority service.redacted.com ssh-rsa ...
…和service.redacted.com是一个循环的DNS条目,其中涉及的每个系统都有一个主机证书(请参阅man sshd_config的HostCertificate条目),签名为service.redacted.com有效。
当想要连接池中随机select的系统时,这种方法是完美的 – 但是如果有人想从池中连接到一个单一的特定系统,使用授予的authentication机构validation其主机密钥是合法的呢?
我试过的一件事就是:
service_name=service.redacted.com specific_host=1.2.3.4 ssh -v -oHostKeyAlias="$service_name" "$specific_host"
…结果如下:
debug1: Host 'service.redacted.com' is known and matches the RSA-CERT host certificate Certificate invalid: name is not a listed principal The authenticity of host 'service.redacted.com (1.2.3.4)' can't be established.
service.redacted.com肯定是证书上市的主体; 1.2.3.4不是。
就目前上游的OpenSSH-portable master( https://github.com/openssh/openssh-portable/commits/773dda25e828c4c9a52f7bdce6e1e5924157beab )而言,这是不可能的。
相关逻辑位于check_host_key()函数中 ,该函数只调用一次check_host_cert() ,最初传入ssh_login()的主机名仅通过将所有字符规范化为小写字母来修改。 在通过resolve_host()传递相同的主机名以获取用于实际连接的addrinfo *结构; resolve_host()尊重一些选项(select要使用的地址族),否则不提供覆盖机制。
也就是说,所需的更改是一个很短的(目前提交给上游邮件列表和待审核):
From 367fd8323d864daaf486047850f93c2167c66f37 Mon Sep 17 00:00:00 2001 From: Charles Duffy <[email protected]> Date: Tue, 17 Feb 2015 09:49:32 -0600 Subject: [PATCH] Allow HostKeyAlias to match a host certificate principal if HostName does not --- sshconnect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sshconnect.cb/sshconnect.c index df921be..666c3ff 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -902,7 +902,8 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port, debug("Found %s in %s:%lu", want_cert ? "CA key" : "key", host_found->file, host_found->line); if (want_cert && !check_host_cert(hostname, host_key)) - goto fail; + if (options.host_key_alias == NULL || !check_host_cert(options.host_key_alias, host_key)) + goto fail; if (options.check_host_ip && ip_status == HOST_NEW) { if (readonly || want_cert) logit("%s host key for IP address " -- 2.0.0