Skip to content

Commit 8fe62b6

Browse files
committed
Generate RSA ssh key
For simplicity, we were using the ssh key from podman-machine, but it has the inconvenience that this key is ed25519 and does not work in FIPS mode. Let's generate and inject an RSA ssh key that it's FIPS approved. Signed-off-by: German Maglione <[email protected]>
1 parent cfc170a commit 8fe62b6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

cmd/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/containers/podman-bootc/pkg/bootc"
88
"github.com/containers/podman-bootc/pkg/config"
9+
"github.com/containers/podman-bootc/pkg/credentials"
910
"github.com/containers/podman-bootc/pkg/user"
1011
"github.com/containers/podman-bootc/pkg/utils"
1112
"github.com/containers/podman-bootc/pkg/vm"
@@ -102,6 +103,11 @@ func doRun(flags *cobra.Command, args []string) error {
102103
}
103104
}()
104105

106+
sSHIdentityPath, err := credentials.Generatekeys(bootcVM.CacheDir())
107+
if err != nil {
108+
return fmt.Errorf("unable to generate ssh key: %w", err)
109+
}
110+
105111
cmd := args[1:]
106112
err = bootcVM.Run(vm.RunVMParameters{
107113
Cmd: cmd,
@@ -110,7 +116,7 @@ func doRun(flags *cobra.Command, args []string) error {
110116
RemoveVm: vmConfig.RemoveVm,
111117
Background: vmConfig.Background,
112118
SSHPort: sshPort,
113-
SSHIdentity: machine.SSHIdentityPath,
119+
SSHIdentity: sSHIdentityPath,
114120
VMUser: vmConfig.User,
115121
})
116122

pkg/credentials/ssh.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
"github.com/containers/podman-bootc/pkg/config"
1111
)
1212

13-
// Generatekeys creates an ed25519 set of keys
13+
// Generatekeys creates an RSA set of keys
1414
func Generatekeys(outputDir string) (string, error) {
1515
sshIdentity := filepath.Join(outputDir, config.SshKeyFile)
1616
_ = os.Remove(sshIdentity)
1717
_ = os.Remove(sshIdentity + ".pub")
1818

19-
args := []string{"-N", "", "-t", "ed25519", "-f", sshIdentity}
19+
// we use RSA here so it works on FIPS mode
20+
args := []string{"-N", "", "-t", "rsa", "-f", sshIdentity}
2021
cmd := exec.Command("ssh-keygen", args...)
2122
stdErr, err := cmd.StderrPipe()
2223
if err != nil {

pkg/vm/vm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type BootcVM interface {
7070
WaitForSSHToBeReady() error
7171
RunSSH([]string) error
7272
DeleteFromCache() error
73+
CacheDir() string
7374
Exists() (bool, error)
7475
GetConfig() (*BootcVMConfig, error)
7576
CloseConnection()
@@ -252,6 +253,10 @@ func (v *BootcVMCommon) DeleteFromCache() error {
252253
return os.RemoveAll(v.cacheDir)
253254
}
254255

256+
func (v *BootcVMCommon) CacheDir() string {
257+
return v.cacheDir
258+
}
259+
255260
func (b *BootcVMCommon) oemString() (string, error) {
256261
systemdOemString, err := oemStringSystemdCredential(b.vmUsername, b.sshIdentity)
257262
if err != nil {

0 commit comments

Comments
 (0)