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.
|
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
|
### Custom cloud-config Parameters
|
||||||
|
|
||||||
#### coreos.etcd.discovery_url
|
#### coreos.etcd.discovery_url
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"launchpad.net/goyaml"
|
"launchpad.net/goyaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DefaultSSHKeyName = "coreos-cloudinit"
|
||||||
|
|
||||||
type CloudConfig struct {
|
type CloudConfig struct {
|
||||||
SSH_Authorized_Keys []string
|
SSH_Authorized_Keys []string
|
||||||
Coreos struct{Etcd struct{ Discovery_URL string }; Fleet struct{ Autostart bool } }
|
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 {
|
if len(cfg.SSH_Authorized_Keys) > 0 {
|
||||||
err := AuthorizeSSHKeys(cfg.SSH_Authorized_Keys)
|
err := AuthorizeSSHKeys(sshKeyName, cfg.SSH_Authorized_Keys)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("Authorized SSH keys for core user")
|
log.Printf("Authorized SSH keys for core user")
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Add the provide SSH public key to the core user's list of
|
// Add the provide SSH public key to the core user's list of
|
||||||
// authorized keys
|
// authorized keys
|
||||||
func AuthorizeSSHKeys(keys []string) error {
|
func AuthorizeSSHKeys(name string, keys []string) error {
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
keys[i] = strings.TrimSpace(key)
|
keys[i] = strings.TrimSpace(key)
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ func AuthorizeSSHKeys(keys []string) error {
|
|||||||
// also ends with a newline
|
// also ends with a newline
|
||||||
joined := fmt.Sprintf("%s\n", strings.Join(keys, "\n"))
|
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()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -28,6 +28,9 @@ func main() {
|
|||||||
var workspace string
|
var workspace string
|
||||||
flag.StringVar(&workspace, "workspace", "/var/lib/coreos-cloudinit", "Base directory coreos-cloudinit should use to store data")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
if printVersion == true {
|
if printVersion == true {
|
||||||
@ -70,7 +73,7 @@ func main() {
|
|||||||
|
|
||||||
switch t := parsed.(type) {
|
switch t := parsed.(type) {
|
||||||
case cloudinit.CloudConfig:
|
case cloudinit.CloudConfig:
|
||||||
err = cloudinit.ResolveCloudConfig(t)
|
err = cloudinit.ResolveCloudConfig(t, sshKeyName)
|
||||||
case cloudinit.Script:
|
case cloudinit.Script:
|
||||||
var path string
|
var path string
|
||||||
path, err = cloudinit.PersistScriptInWorkspace(t, workspace)
|
path, err = cloudinit.PersistScriptInWorkspace(t, workspace)
|
||||||
|
Loading…
Reference in New Issue
Block a user