1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/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 {
29 func (tv TagVerifier) InitCommand() cloud.InitCommand {
30 return cloud.InitCommand(fmt.Sprintf("umask 0177 && echo -n %q >%s", tv.Secret, instanceSecretFilename))
33 func (tv TagVerifier) VerifyHostKey(pubKey ssh.PublicKey, client *ssh.Client) error {
34 if err := tv.Instance.VerifyHostKey(pubKey, client); err != cloud.ErrNotImplemented || tv.Secret == "" {
35 // If the wrapped instance indicates it has a way to
36 // verify the key, return that decision.
39 session, err := client.NewSession()
44 var stdout, stderr bytes.Buffer
45 session.Stdin = bytes.NewBuffer(nil)
46 session.Stdout = &stdout
47 session.Stderr = &stderr
48 cmd := fmt.Sprintf("cat %s", instanceSecretFilename)
49 if u := tv.RemoteUser(); u != "root" {
52 err = session.Run(cmd)
56 if stdout.String() != tv.Secret {
57 return errBadInstanceSecret