github.com/openshift/installer@v1.4.17/pkg/asset/machines/machineconfig/authorizedkeys.go (about) 1 package machineconfig 2 3 import ( 4 "fmt" 5 6 igntypes "github.com/coreos/ignition/v2/config/v3_2/types" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 9 mcfgv1 "github.com/openshift/api/machineconfiguration/v1" 10 "github.com/openshift/installer/pkg/asset/ignition" 11 ) 12 13 // ForAuthorizedKeys creates the MachineConfig to set the authorized key for `core` user. 14 func ForAuthorizedKeys(key string, role string) (*mcfgv1.MachineConfig, error) { 15 ignConfig := igntypes.Config{ 16 Ignition: igntypes.Ignition{ 17 Version: igntypes.MaxVersion.String(), 18 }, 19 Passwd: igntypes.Passwd{ 20 Users: []igntypes.PasswdUser{{ 21 Name: "core", SSHAuthorizedKeys: []igntypes.SSHAuthorizedKey{igntypes.SSHAuthorizedKey(key)}, 22 }}, 23 }, 24 } 25 26 rawExt, err := ignition.ConvertToRawExtension(ignConfig) 27 if err != nil { 28 return nil, err 29 } 30 31 return &mcfgv1.MachineConfig{ 32 TypeMeta: metav1.TypeMeta{ 33 APIVersion: mcfgv1.SchemeGroupVersion.String(), 34 Kind: "MachineConfig", 35 }, 36 ObjectMeta: metav1.ObjectMeta{ 37 Name: fmt.Sprintf("99-%s-ssh", role), 38 Labels: map[string]string{ 39 "machineconfiguration.openshift.io/role": role, 40 }, 41 }, 42 Spec: mcfgv1.MachineConfigSpec{ 43 Config: rawExt, 44 }, 45 }, nil 46 }