1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.curoverse.com/arvados.git/lib/cloud"
13 "golang.org/x/crypto/ssh"
17 errBadInstanceSecret = errors.New("bad instance secret")
19 // filename on instance, as given to shell (quoted accordingly)
20 instanceSecretFilename = "/var/run/arvados-instance-secret"
21 instanceSecretLength = 40 // hex digits
24 type tagVerifier struct {
28 func (tv tagVerifier) VerifyHostKey(pubKey ssh.PublicKey, client *ssh.Client) error {
29 expectSecret := tv.Instance.Tags()[tagKeyInstanceSecret]
30 if err := tv.Instance.VerifyHostKey(pubKey, client); err != cloud.ErrNotImplemented || expectSecret == "" {
31 // If the wrapped instance indicates it has a way to
32 // verify the key, return that decision.
35 session, err := client.NewSession()
40 var stdout, stderr bytes.Buffer
41 session.Stdin = bytes.NewBuffer(nil)
42 session.Stdout = &stdout
43 session.Stderr = &stderr
44 cmd := fmt.Sprintf("cat %s", instanceSecretFilename)
45 if u := tv.RemoteUser(); u != "root" {
48 err = session.Run(cmd)
52 if stdout.String() != expectSecret {
53 return errBadInstanceSecret