@@ -46,7 +46,7 @@ const (
46
46
type Spec struct {
47
47
Name string
48
48
NICName string
49
- SSHKeyData string
49
+ SSHKeyData [] string
50
50
Size string
51
51
Zone string
52
52
Image infrav1.Image
@@ -99,7 +99,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
99
99
klog .V (2 ).Infof ("creating vm %s : %v" , vmSpec .Name , vmSpec )
100
100
101
101
sshKeyData := vmSpec .SSHKeyData
102
- if sshKeyData == "" {
102
+ if len ( sshKeyData ) == 0 {
103
103
privateKey , perr := rsa .GenerateKey (rand .Reader , 2048 )
104
104
if perr != nil {
105
105
return errors .Wrap (perr , "Failed to generate private key" )
@@ -109,7 +109,16 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
109
109
if perr != nil {
110
110
return errors .Wrap (perr , "Failed to generate public key" )
111
111
}
112
- sshKeyData = string (ssh .MarshalAuthorizedKey (publicRsaKey ))
112
+ sshKeyData = []string {string (ssh .MarshalAuthorizedKey (publicRsaKey ))}
113
+ }
114
+
115
+ sshPublicKeys := []compute.SSHPublicKey {}
116
+ sshKeyPath := fmt .Sprintf ("/home/%s/.ssh/authorized_keys" , azurestackhci .DefaultUserName )
117
+ for i := 0 ; i < len (sshKeyData ); i ++ {
118
+ sshPublicKeys = append (sshPublicKeys , compute.SSHPublicKey {
119
+ Path : & sshKeyPath ,
120
+ KeyData : & sshKeyData [i ],
121
+ })
113
122
}
114
123
115
124
randomPassword , err := GenerateRandomString (32 )
@@ -131,12 +140,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
131
140
OsType : compute .OperatingSystemTypes (vmSpec .OSDisk .OSType ),
132
141
LinuxConfiguration : & compute.LinuxConfiguration {
133
142
SSH : & compute.SSHConfiguration {
134
- PublicKeys : & []compute.SSHPublicKey {
135
- {
136
- Path : to .StringPtr (fmt .Sprintf ("/home/%s/.ssh/authorized_keys" , azurestackhci .DefaultUserName )),
137
- KeyData : to .StringPtr (sshKeyData ),
138
- },
139
- },
143
+ PublicKeys : & sshPublicKeys ,
140
144
},
141
145
DisablePasswordAuthentication : to .BoolPtr (false ),
142
146
},
@@ -164,12 +168,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
164
168
165
169
virtualMachine .OsProfile .WindowsConfiguration = & compute.WindowsConfiguration {
166
170
SSH : & compute.SSHConfiguration {
167
- PublicKeys : & []compute.SSHPublicKey {
168
- {
169
- Path : to .StringPtr (fmt .Sprintf ("/users/%s/.ssh/authorized_keys" , azurestackhci .DefaultUserName )),
170
- KeyData : to .StringPtr (sshKeyData ),
171
- },
172
- },
171
+ PublicKeys : & sshPublicKeys ,
173
172
},
174
173
}
175
174
}
0 commit comments