feat(ssh): Set custom name for ssh identity

This commit is contained in:
Brian Waldon
2014-03-05 14:30:38 -08:00
parent 743b2dd939
commit 95a00070c3
4 changed files with 13 additions and 5 deletions

View File

@@ -6,6 +6,8 @@ import (
"launchpad.net/goyaml"
)
const DefaultSSHKeyName = "coreos-cloudinit"
type CloudConfig struct {
SSH_Authorized_Keys []string
Coreos struct{Etcd struct{ Discovery_URL string }; Fleet struct{ Autostart bool } }
@@ -26,9 +28,9 @@ func (cc CloudConfig) String() string {
}
}
func ResolveCloudConfig(cfg CloudConfig) error {
func ResolveCloudConfig(cfg CloudConfig, sshKeyName string) error {
if len(cfg.SSH_Authorized_Keys) > 0 {
err := AuthorizeSSHKeys(cfg.SSH_Authorized_Keys)
err := AuthorizeSSHKeys(sshKeyName, cfg.SSH_Authorized_Keys)
if err == nil {
log.Printf("Authorized SSH keys for core user")
} else {

View File

@@ -10,7 +10,7 @@ import (
// Add the provide SSH public key to the core user's list of
// authorized keys
func AuthorizeSSHKeys(keys []string) error {
func AuthorizeSSHKeys(name string, keys []string) error {
for i, key := range keys {
keys[i] = strings.TrimSpace(key)
}
@@ -19,7 +19,7 @@ func AuthorizeSSHKeys(keys []string) error {
// also ends with a newline
joined := fmt.Sprintf("%s\n", strings.Join(keys, "\n"))
cmd := exec.Command("update-ssh-keys", "-u", "core", "-a", "coreos-cloudinit")
cmd := exec.Command("update-ssh-keys", "-u", "core", "-a", name)
stdin, err := cmd.StdinPipe()
if err != nil {
return err