Skip to content

Commit 4c2708c

Browse files
authored
Merge pull request #71 from germag/Add-rsa-ssh-key
Inject RSA ssh key
2 parents 949638f + 8fe62b6 commit 4c2708c

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

cmd/run.go

Lines changed: 7 additions & 4 deletions
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"
@@ -19,7 +20,6 @@ type osVmConfig struct {
1920
CloudInitDir string
2021
KsFile string
2122
Background bool
22-
NoCredentials bool
2323
RemoveVm bool // Kill the running VM when it exits
2424
RemoveDiskImage bool // After exit of the VM, remove the disk image
2525
Quiet bool
@@ -47,7 +47,6 @@ func init() {
4747
runCmd.Flags().StringVar(&vmConfig.CloudInitDir, "cloudinit", "", "--cloudinit <cloud-init data directory>")
4848

4949
runCmd.Flags().StringVar(&diskImageConfigInstance.Filesystem, "filesystem", "", "Override the root filesystem (e.g. xfs, btrfs, ext4)")
50-
runCmd.Flags().BoolVar(&vmConfig.NoCredentials, "no-creds", false, "Do not inject default SSH key via credentials; also implies --background")
5150
runCmd.Flags().BoolVarP(&vmConfig.Background, "background", "B", false, "Do not spawn SSH, run in background")
5251
runCmd.Flags().BoolVar(&vmConfig.RemoveVm, "rm", false, "Remove the VM and it's disk when the SSH session exits. Cannot be used with --background")
5352
runCmd.Flags().BoolVar(&vmConfig.Quiet, "quiet", false, "Suppress output from bootc disk creation and VM boot console")
@@ -104,16 +103,20 @@ func doRun(flags *cobra.Command, args []string) error {
104103
}
105104
}()
106105

106+
sSHIdentityPath, err := credentials.Generatekeys(bootcVM.CacheDir())
107+
if err != nil {
108+
return fmt.Errorf("unable to generate ssh key: %w", err)
109+
}
110+
107111
cmd := args[1:]
108112
err = bootcVM.Run(vm.RunVMParameters{
109113
Cmd: cmd,
110114
CloudInitDir: vmConfig.CloudInitDir,
111-
NoCredentials: vmConfig.NoCredentials,
112115
CloudInitData: flags.Flags().Changed("cloudinit"),
113116
RemoveVm: vmConfig.RemoveVm,
114117
Background: vmConfig.Background,
115118
SSHPort: sshPort,
116-
SSHIdentity: machine.SSHIdentityPath,
119+
SSHIdentity: sSHIdentityPath,
117120
VMUser: vmConfig.User,
118121
})
119122

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type NewVMParameters struct {
5454
type RunVMParameters struct {
5555
VMUser string //user to use when connecting to the VM
5656
CloudInitDir string
57-
NoCredentials bool
5857
CloudInitData bool
5958
SSHIdentity string
6059
SSHPort int
@@ -71,6 +70,7 @@ type BootcVM interface {
7170
WaitForSSHToBeReady() error
7271
RunSSH([]string) error
7372
DeleteFromCache() error
73+
CacheDir() string
7474
Exists() (bool, error)
7575
GetConfig() (*BootcVMConfig, error)
7676
CloseConnection()
@@ -253,6 +253,10 @@ func (v *BootcVMCommon) DeleteFromCache() error {
253253
return os.RemoveAll(v.cacheDir)
254254
}
255255

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

pkg/vm/vm_darwin.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ func (b *BootcVMMac) Run(params RunVMParameters) (err error) {
8484
b.vmUsername = params.VMUser
8585
b.sshIdentity = params.SSHIdentity
8686

87-
if params.NoCredentials {
88-
b.sshIdentity = ""
89-
if !b.background {
90-
fmt.Print("No credentials provided for SSH, using --background by default")
91-
b.background = true
92-
}
93-
}
94-
9587
execPath, err := os.Executable()
9688
if err != nil {
9789
return fmt.Errorf("getting executable path: %w", err)

pkg/vm/vm_linux.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ func (v *BootcVMLinux) Run(params RunVMParameters) (err error) {
123123
v.vmUsername = params.VMUser
124124
v.sshIdentity = params.SSHIdentity
125125

126-
if params.NoCredentials {
127-
v.sshIdentity = ""
128-
if !v.background {
129-
fmt.Print("No credentials provided for SSH, using --background by default")
130-
v.background = true
131-
}
132-
}
133-
134126
if v.domain != nil {
135127
isRunning, err := v.IsRunning()
136128
if err != nil {

pkg/vm/vm_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func runTestVM(bootcVM vm.BootcVM) {
9696
err := bootcVM.Run(vm.RunVMParameters{
9797
VMUser: "root",
9898
CloudInitDir: "",
99-
NoCredentials: false,
10099
CloudInitData: false,
101100
SSHPort: 22,
102101
Cmd: []string{},

0 commit comments

Comments
 (0)