SSH keys fixes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adam Štrauch 2023-04-13 22:49:06 +02:00
parent bcc641307a
commit 036aa4fc28
Signed by: cx
GPG Key ID: 018304FFA8988F8D
3 changed files with 9 additions and 6 deletions

View File

@ -242,17 +242,17 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) {
return false, nil
}
_, err := driver.Exec(c.App.Name, []string{"mkdir", "-p", "/srv/.ssh"}, "", []string{}, false)
_, err := driver.Exec(c.App.Name, []string{"mkdir", "-p", "/srv/.ssh"}, "", []string{}, true)
if err != nil {
return false, err
}
_, err = driver.Exec(c.App.Name, []string{"ssh-keygen", "-f", "/srv/.ssh/id_rsa", "-P", ""}, "", []string{}, false)
_, err = driver.Exec(c.App.Name, []string{"ssh-keygen", "-f", "/srv/.ssh/id_rsa", "-P", ""}, "", []string{}, true)
if err != nil {
return false, err
}
_, err = driver.Exec(c.App.Name, []string{"chown", "app:app", "-R", "/srv/.ssh"}, "", []string{}, false)
_, err = driver.Exec(c.App.Name, []string{"chown", "app:app", "-R", "/srv/.ssh"}, "", []string{}, true)
if err != nil {
return false, err
}
@ -301,7 +301,7 @@ func (c *Container) GetHostKey() (string, error) {
}
// Append text to a file in the container
func (c *Container) AppendOfFile(filename string, text string, mode string) error {
func (c *Container) AppendFile(filename string, text string, mode string) error {
driver := c.getDriver()
_, err := driver.Exec(c.App.Name, []string{"tee", "-a", filename}, text, []string{}, false)

View File

@ -510,7 +510,7 @@ func (p *Processor) GenerateDeploySSHKeys() (string, string, error) {
}
if created {
err = container.AppendOfFile(sshPubKeysLocation, pubKey+"\n", "0600")
err = container.AppendFile(sshPubKeysLocation, pubKey+"\n", "0600")
if err != nil {
return "", "", err
}

View File

@ -419,7 +419,10 @@ func getDeploySSHKeysEventHandler(m *nats.Msg, message *RequestMessage) error {
// Assembling reply message
reply := ReplyMessage{
Payload: struct{ PrivateKey, PublicKey string }{
Payload: struct {
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key"`
}{
PrivateKey: privateKey,
PublicKey: pubKey,
},