Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neonvm: ensure the TLS mount directory is available in the VM #1282

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions neonvm-runner/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,32 @@ func run(logger *zap.Logger) error {

// create iso9660 disk with runtime options (command, args, envs, mounts)
tg.Go("iso9660-runtime", func(logger *zap.Logger) error {
disks := vmSpec.Disks

// add the tls path.
// this is needed to just `mkdir` the mounting directory.
if vmSpec.TLS != nil {
disks = append(disks, vmv1.Disk{
Name: "tls-keys",
MountPath: vmSpec.TLS.MountPath,
Watch: lo.ToPtr(true),
ReadOnly: nil,
DiskSource: vmv1.DiskSource{
EmptyDisk: nil,
ConfigMap: nil,
Secret: nil,
Tmpfs: nil,
},
})
}

return createISO9660runtime(
runtimeDiskPath,
vmSpec.Guest.Command,
vmSpec.Guest.Args,
sysctl,
vmSpec.Guest.Env,
vmSpec.Disks,
disks,
enableSSH,
swapSize,
shmSize,
Expand Down Expand Up @@ -686,8 +705,9 @@ func monitorFiles(ctx context.Context, logger *zap.Logger, wg *sync.WaitGroup, v
}

if vmSpec.TLS != nil {
secrets["/vm/mounts/var/tls/..data"] = "/var/tls"
secretsOrd = append(secretsOrd, "/vm/mounts/var/tls/..data")
dataDir := fmt.Sprintf("/vm/mounts%s/..data", vmSpec.TLS.MountPath)
secrets[dataDir] = vmSpec.TLS.MountPath
secretsOrd = append(secretsOrd, dataDir)
}

if len(secretsOrd) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions neonvm/apis/neonvm/v1/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ type TLSProvisioning struct {

// This is the common name for the TLS certificate
ServerName string `json:"serverName,omitempty"`

// Which directory in the VM these certificates should be mounted to.
// Will be exposed as `tls.key` and `tls.crt`.
// +kubebuilder:default:=/var/tls
// +optional
MountPath string `json:"mountPath,omitempty"`
}

func (spec *VirtualMachineSpec) Resources() VirtualMachineResources {
Expand Down
6 changes: 6 additions & 0 deletions neonvm/config/crd/bases/vm.neon.tech_virtualmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3010,6 +3010,12 @@ spec:
description: This is required to set the duration that the certificate
should be valid for before expiring
type: string
mountPath:
default: /var/tls
description: |-
Which directory in the VM these certificates should be mounted to.
Will be exposed as `tls.key` and `tls.crt`.
type: string
renewBefore:
description: This is required to set the duration before certificate
expiration that the certificate is renewed
Expand Down
2 changes: 1 addition & 1 deletion pkg/neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ func podSpec(
// Add TLS secret
mnt := corev1.VolumeMount{
Name: "tls",
MountPath: fmt.Sprintf("/vm/mounts%s", "/var/tls"),
MountPath: fmt.Sprintf("/vm/mounts%s", vm.Spec.TLS.MountPath),
}
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, mnt)
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/vm-tls/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 70
commands:
- script: |
set -eux
pod="$(kubectl get neonvm -n "$NAMESPACE" example -o jsonpath='{.status.podName}')"
kubectl exec -n "$NAMESPACE" $pod -- scp guest-vm:/var/tls/tls.crt tls.crt
---
apiVersion: vm.neon.tech/v1
kind: VirtualMachine
Expand Down
Loading