feat(ssh): Set custom name for ssh identity
This commit is contained in:
parent
743b2dd939
commit
95a00070c3
@ -15,6 +15,9 @@ Only a subset of [cloud-config functionality][cloud-config] is implemented. A se
|
||||
|
||||
Provided public SSH keys will be authorized for the `core` user.
|
||||
|
||||
The keys will be named "coreos-cloudinit" by default.
|
||||
Override this with the `--ssh-key-name` flag when calling `coreos-cloudinit`.
|
||||
|
||||
### Custom cloud-config Parameters
|
||||
|
||||
#### coreos.etcd.discovery_url
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -28,6 +28,9 @@ func main() {
|
||||
var workspace string
|
||||
flag.StringVar(&workspace, "workspace", "/var/lib/coreos-cloudinit", "Base directory coreos-cloudinit should use to store data")
|
||||
|
||||
var sshKeyName string
|
||||
flag.StringVar(&sshKeyName, "ssh-key-name", cloudinit.DefaultSSHKeyName, "Add SSH keys to the system with the given name")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if printVersion == true {
|
||||
@ -70,7 +73,7 @@ func main() {
|
||||
|
||||
switch t := parsed.(type) {
|
||||
case cloudinit.CloudConfig:
|
||||
err = cloudinit.ResolveCloudConfig(t)
|
||||
err = cloudinit.ResolveCloudConfig(t, sshKeyName)
|
||||
case cloudinit.Script:
|
||||
var path string
|
||||
path, err = cloudinit.PersistScriptInWorkspace(t, workspace)
|
||||
|
Loading…
Reference in New Issue
Block a user