pkg/build: chmod output ssh key

ssh is very picky about ssh key permissions.
Let's enforce the right persmissions without bothering user with this.
This commit is contained in:
Dmitry Vyukov 2020-05-29 08:30:49 +02:00
parent d19ed305ae
commit 7e7ceb21ba

View File

@ -7,6 +7,7 @@ package build
import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
@ -65,6 +66,11 @@ func Image(params *Params) (string, error) {
if err != nil {
return "", extractRootCause(err, params.TargetOS, params.KernelDir)
}
if key := filepath.Join(params.OutputDir, "key"); osutil.IsExist(key) {
if err := os.Chmod(key, 0600); err != nil {
return "", fmt.Errorf("failed to chmod 0600 %v: %v", key, err)
}
}
sign := ""
if signer, ok := builder.(signer); ok {
sign, err = signer.sign(params)