Skip to content

Commit

Permalink
Merge pull request containers#12709 from flouthoc/ign_add_certs
Browse files Browse the repository at this point in the history
ignition: add `certs` from current user into the machine while `init`
  • Loading branch information
openshift-merge-robot authored Jan 4, 2022
2 parents e6cbfae + f217449 commit 47cf00e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/machine/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"

"github.com/sirupsen/logrus"
)

/*
Expand Down Expand Up @@ -355,6 +358,56 @@ machine_enabled=true
},
})

// get certs for current user
userHome, err := os.UserHomeDir()
if err != nil {
logrus.Warnf("Unable to copy certs via ignition %s", err.Error())
return files
}

certFiles := getCerts(filepath.Join(userHome, ".config/containers/certs.d"))
files = append(files, certFiles...)

certFiles = getCerts(filepath.Join(userHome, ".config/docker/certs.d"))
files = append(files, certFiles...)

return files
}

func getCerts(certsDir string) []File {
var (
files []File
)

certs, err := ioutil.ReadDir(certsDir)
if err == nil {
for _, cert := range certs {
b, err := ioutil.ReadFile(filepath.Join(certsDir, cert.Name()))
if err != nil {
logrus.Warnf("Unable to read cert file %s", err.Error())
continue
}
files = append(files, File{
Node: Node{
Group: getNodeGrp("root"),
Path: filepath.Join("/etc/containers/certs.d/", cert.Name()),
User: getNodeUsr("root"),
},
FileEmbedded1: FileEmbedded1{
Append: nil,
Contents: Resource{
Source: encodeDataURLPtr(string(b)),
},
Mode: intToPtr(0644),
},
})
}
} else {
if !os.IsNotExist(err) {
logrus.Warnf("Unable to copy certs via ignition, error while reading certs from %s: %s", certsDir, err.Error())
}
}

return files
}

Expand Down

0 comments on commit 47cf00e

Please sign in to comment.