Skip to content

Commit a06e908

Browse files
committed
neonvm: ensure the TLS mount directory is available in the VM
1 parent 1473aca commit a06e908

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

neonvm-runner/cmd/main.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,33 @@ func run(logger *zap.Logger) error {
225225

226226
// create iso9660 disk with runtime options (command, args, envs, mounts)
227227
tg.Go("iso9660-runtime", func(logger *zap.Logger) error {
228+
disks := vmSpec.Disks
229+
230+
// add the tls path.
231+
// this is needed to just `mkdir` the mounting directory.
232+
if vmSpec.TLS != nil {
233+
watch := true
234+
disks = append(disks, vmv1.Disk{
235+
Name: "tls-keys",
236+
MountPath: vmSpec.TLS.MountPath,
237+
Watch: &watch,
238+
ReadOnly: nil,
239+
DiskSource: vmv1.DiskSource{
240+
EmptyDisk: nil,
241+
ConfigMap: nil,
242+
Secret: nil,
243+
Tmpfs: nil,
244+
},
245+
})
246+
}
247+
228248
return createISO9660runtime(
229249
runtimeDiskPath,
230250
vmSpec.Guest.Command,
231251
vmSpec.Guest.Args,
232252
sysctl,
233253
vmSpec.Guest.Env,
234-
vmSpec.Disks,
254+
disks,
235255
enableSSH,
236256
swapSize,
237257
shmSize,
@@ -686,8 +706,9 @@ func monitorFiles(ctx context.Context, logger *zap.Logger, wg *sync.WaitGroup, v
686706
}
687707

688708
if vmSpec.TLS != nil {
689-
secrets["/vm/mounts/var/tls/..data"] = "/var/tls"
690-
secretsOrd = append(secretsOrd, "/vm/mounts/var/tls/..data")
709+
dataDir := fmt.Sprintf("/vm/mounts%s/..data", vmSpec.TLS.MountPath)
710+
secrets[dataDir] = vmSpec.TLS.MountPath
711+
secretsOrd = append(secretsOrd, dataDir)
691712
}
692713

693714
if len(secretsOrd) == 0 {

neonvm/apis/neonvm/v1/virtualmachine_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ type TLSProvisioning struct {
182182

183183
// This is the common name for the TLS certificate
184184
ServerName string `json:"serverName,omitempty"`
185+
186+
// Which directory in the VM these certificates should be mounted to.
187+
// Will be exposed as `tls.key` and `tls.crt`.
188+
// +kubebuilder:default:=/var/tls
189+
// +optional
190+
MountPath string `json:"mountPath,omitempty"`
185191
}
186192

187193
func (spec *VirtualMachineSpec) Resources() VirtualMachineResources {

neonvm/config/crd/bases/vm.neon.tech_virtualmachines.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,12 @@ spec:
30103010
description: This is required to set the duration that the certificate
30113011
should be valid for before expiring
30123012
type: string
3013+
mountPath:
3014+
default: /var/tls
3015+
description: |-
3016+
Which directory in the VM these certificates should be mounted to.
3017+
Will be exposed as `tls.key` and `tls.crt`.
3018+
type: string
30133019
renewBefore:
30143020
description: This is required to set the duration before certificate
30153021
expiration that the certificate is renewed

pkg/neonvm/controllers/vm_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ func podSpec(
16911691
// Add TLS secret
16921692
mnt := corev1.VolumeMount{
16931693
Name: "tls",
1694-
MountPath: fmt.Sprintf("/vm/mounts%s", "/var/tls"),
1694+
MountPath: fmt.Sprintf("/vm/mounts%s", vm.Spec.TLS.MountPath),
16951695
}
16961696
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, mnt)
16971697
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{

tests/e2e/vm-tls/00-assert.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
33
timeout: 70
4+
commands:
5+
- script: |
6+
set -eux
7+
pod="$(kubectl get neonvm -n "$NAMESPACE" example -o jsonpath='{.status.podName}')"
8+
kubectl exec -n "$NAMESPACE" $pod -- scp guest-vm:/var/tls/tls.crt tls.crt
49
---
510
apiVersion: vm.neon.tech/v1
611
kind: VirtualMachine

0 commit comments

Comments
 (0)