diff --git a/examples/gcp.yml b/examples/gcp.yml index 5384e6700..cc889b629 100644 --- a/examples/gcp.yml +++ b/examples/gcp.yml @@ -27,7 +27,7 @@ onboot: net: host command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: metadata - image: "mobylinux/metadata:5c64c2305040009891b713df22bd4bae7894c3ec" + image: "mobylinux/metadata:c5567e65e9125f0a4c4b8cb9d56a86377be62652" binds: - /dev:/dev - /var:/var diff --git a/pkg/metadata/provider_gcp.go b/pkg/metadata/provider_gcp.go index 6aa3ae359..764c70a81 100644 --- a/pkg/metadata/provider_gcp.go +++ b/pkg/metadata/provider_gcp.go @@ -48,35 +48,10 @@ func (p *ProviderGCP) Extract() ([]byte, error) { return nil, fmt.Errorf("GCP: Failed to write hostname: %s", err) } - // SSH keys: - // TODO also retrieve the instance keys and respect block - // project keys see: - // https://cloud.google.com/compute/docs/instances/ssh-keys - // The keys have usernames attached, but as a simplification - // we are going to add them all to one root file - // TODO split them into individual user files and make the ssh - // container construct those users - sshKeys, err := gcpGet(project + "attributes/sshKeys") - if err == nil { - if err := os.Mkdir(path.Join(ConfigPath, SSH), 0755); err != nil { - log.Printf("Failed to create %s: %s", SSH, err) - goto ErrorSSH - } - rootKeys := "" - for _, line := range strings.Split(string(sshKeys), "\n") { - parts := strings.SplitN(line, ":", 2) - // ignoring username for now - if len(parts) == 2 { - rootKeys = rootKeys + parts[1] + "\n" - } - } - err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600) - if err != nil { - log.Printf("GCP: Failed to write ssh keys: %s", err) - } + if err := p.handleSSH(); err != nil { + log.Printf("GCP: Failed to get ssh data: %s", err) } -ErrorSSH: // Generic userdata userData, err := gcpGet(instance + "attributes/userdata") if err != nil { @@ -112,3 +87,36 @@ func gcpGet(url string) ([]byte, error) { } return body, nil } + +// SSH keys: +// TODO also retrieve the instance keys and respect block +// project keys see: +// https://cloud.google.com/compute/docs/instances/ssh-keys +// The keys have usernames attached, but as a simplification +// we are going to add them all to one root file +// TODO split them into individual user files and make the ssh +// container construct those users +func (p *ProviderGCP) handleSSH() error { + sshKeys, err := gcpGet(project + "attributes/sshKeys") + if err != nil { + return fmt.Errorf("Failed to get sshKeys: %s", err) + } + + if err := os.Mkdir(path.Join(ConfigPath, SSH), 0755); err != nil { + return fmt.Errorf("Failed to create %s: %s", SSH, err) + } + + rootKeys := "" + for _, line := range strings.Split(string(sshKeys), "\n") { + parts := strings.SplitN(line, ":", 2) + // ignoring username for now + if len(parts) == 2 { + rootKeys = rootKeys + parts[1] + "\n" + } + } + err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600) + if err != nil { + return fmt.Errorf("Failed to write ssh keys: %s", err) + } + return nil +} diff --git a/projects/demo/etcd/etcd.yml b/projects/demo/etcd/etcd.yml index 2cfa1938a..d9530d33c 100644 --- a/projects/demo/etcd/etcd.yml +++ b/projects/demo/etcd/etcd.yml @@ -43,7 +43,7 @@ onboot: net: host command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: metadata - image: "mobylinux/metadata:5c64c2305040009891b713df22bd4bae7894c3ec" + image: "mobylinux/metadata:c5567e65e9125f0a4c4b8cb9d56a86377be62652" binds: - /dev:/dev - /var:/var