Skip to content

Commit

Permalink
fix: change ssh key mode, mount key by subpath. (#5203)
Browse files Browse the repository at this point in the history
* change ssh key mode, mount key by subpath.

* remove private key mount.
  • Loading branch information
lingdie authored Nov 12, 2024
1 parent a927563 commit c808ad6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (r *DevboxReconciler) generateDevboxPod(devbox *devboxv1alpha1.Devbox, runt
volumes = append(volumes, devbox.Spec.ExtraVolumes...)

volumeMounts := runtime.Spec.Config.VolumeMounts
volumeMounts = append(volumeMounts, helper.GenerateSSHVolumeMounts())
volumeMounts = append(volumeMounts, helper.GenerateSSHVolumeMounts()...)
volumeMounts = append(volumeMounts, devbox.Spec.ExtraVolumeMounts...)

containers := []corev1.Container{
Expand Down
25 changes: 15 additions & 10 deletions controllers/devbox/internal/controller/helper/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,20 @@ func GetLastSuccessCommitImageName(devbox *devboxv1alpha1.Devbox, runtime *devbo
return commit.Image
}

func GenerateSSHVolumeMounts() corev1.VolumeMount {
return corev1.VolumeMount{
Name: "devbox-ssh-keys",
MountPath: "/usr/start/.ssh",
ReadOnly: true,
func GenerateSSHVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: "devbox-ssh-keys",
MountPath: "/usr/start/.ssh/authorized_keys",
SubPath: "authorized_keys",
ReadOnly: true,
},
{
Name: "devbox-ssh-keys",
MountPath: "/usr/start/.ssh/id.pub",
SubPath: "id.pub",
ReadOnly: true,
},
}
}

Expand All @@ -364,10 +373,6 @@ func GenerateSSHVolume(devbox *devboxv1alpha1.Devbox) corev1.Volume {
Secret: &corev1.SecretVolumeSource{
SecretName: devbox.Name,
Items: []corev1.KeyToPath{
{
Key: "SEALOS_DEVBOX_PRIVATE_KEY",
Path: "id",
},
{
Key: "SEALOS_DEVBOX_PUBLIC_KEY",
Path: "id.pub",
Expand All @@ -377,7 +382,7 @@ func GenerateSSHVolume(devbox *devboxv1alpha1.Devbox) corev1.Volume {
Path: "authorized_keys",
},
},
DefaultMode: ptr.To(int32(0644)),
DefaultMode: ptr.To(int32(420)),
},
},
}
Expand Down

0 comments on commit c808ad6

Please sign in to comment.