Skip to content

Commit aa12fce

Browse files
committed
block: address CR feedback
1 parent 4b800a3 commit aa12fce

File tree

13 files changed

+318
-125
lines changed

13 files changed

+318
-125
lines changed

charts/vastblock/templates/node.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
{{- toYaml .Values.node.podAntiAffinity | nindent 10 }}
4040
nodeAffinity:
4141
{{- toYaml .Values.node.nodeAffinity | nindent 10 }}
42+
hostIPC: true
4243
containers:
4344
- name: csi-node-driver-registrar
4445
image: {{ printf "%s:%s" $csi_images.csiNodeDriverRegistrar.repository (toString $csi_images.csiNodeDriverRegistrar.tag) }}

charts/vastblock/templates/shared/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
6464
app.kubernetes.io/name: {{ include "vastcsi.name" . }}
6565
app.kubernetes.io/instance: {{ .Release.Name }}
6666
{{- end }}
67+
68+
69+
{{- define "vastcsi.dictToYaml" -}}
70+
{{- $input := index . 0 -}} {{/* The map to render */}}
71+
{{- $prefix := index . 1 | default "" -}} {{/* Optional prefix for keys */}}
72+
{{- if not (kindIs "map" $input) }}
73+
{{- $errorMsg := printf "Invalid format. Expected a dictionary but got:\n%s" (toYaml $input) }}
74+
{{- fail $errorMsg }}
75+
{{- else }}
76+
{{- range $k, $v := $input }}
77+
{{- if and $v (ne $v "") }}
78+
{{ printf "%s%s: %s" $prefix $k ($v | quote) }}
79+
{{- end }}
80+
{{- end }}
81+
{{- end }}
82+
{{- end }}

charts/vastblock/templates/storage-class.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
{{- $tenant_name := pluck "tenantName" $options $.Values.storageClassDefaults | first | quote -}}
2828
{{- $volume_group := pluck "volumeGroup" $options $.Values.storageClassDefaults | first | quote -}}
29-
{{- $volume_encryption := pluck "volumeEncryption" $options $.Values.storageClassDefaults | first | quote -}}
3029
{{- $mount_options := pluck "mountOptions" $options $.Values.storageClassDefaults | first -}}
3130
{{- $reclaim_policy := pluck "reclaimPolicy" $options $.Values.storageClassDefaults | first | quote -}}
3231
{{-
@@ -39,7 +38,7 @@
3938
{{- $storage_class_secret_namespace := pluck "secretNamespace" $options $.Values.storageClassDefaults | first | default $.Release.Namespace | quote -}}
4039
{{- $fstype := pluck "fsType" $options $.Values.storageClassDefaults | first -}}
4140
{{- $transport_type := pluck "transportType" $options $.Values.storageClassDefaults | first -}}
42-
41+
{{- $host_encryption := pluck "hostEncryption" $options $.Values.storageClassDefaults | first | default dict -}}
4342

4443
kind: StorageClass
4544
apiVersion: storage.k8s.io/v1
@@ -54,11 +53,14 @@ metadata:
5453
reclaimPolicy: {{ $reclaim_policy }}
5554
parameters:
5655
subsystem: {{ $subsystem }}
57-
{{- range $key, $value := dict "vip_pool_name" $vip_pool_name "vip_pool_fqdn" $vip_pool_fqdn "volume_group" $volume_group "volume_encryption" $volume_encryption "transport_type" $transport_type "fsType" $fstype "tenant_name" $tenant_name }}
56+
{{- range $key, $value := dict "vip_pool_name" $vip_pool_name "vip_pool_fqdn" $vip_pool_fqdn "volume_group" $volume_group "transport_type" $transport_type "fsType" $fstype "tenant_name" $tenant_name }}
5857
{{- if and $value (ne $value ( quote "" )) }}
5958
{{ $key }}: {{ if (kindIs "int" $value) }}{{ $value | quote }}{{ else }}{{ $value }}{{ end }}
6059
{{- end }}
6160
{{- end }}
61+
{{- if $host_encryption }}
62+
{{- include "vastcsi.dictToYaml" (list $host_encryption "host_encryption.") | indent 2 }}
63+
{{- end }}
6264
{{- if ne $storage_class_secret ( quote "" ) }}
6365
csi.storage.k8s.io/provisioner-secret-name: {{ $storage_class_secret }}
6466
csi.storage.k8s.io/provisioner-secret-namespace: {{ $storage_class_secret_namespace }}

charts/vastblock/values.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,19 @@ storageClassDefaults:
5959
# - "folder1/folder2/block-{namespace}-{id}
6060
volumeGroup: ""
6161
# Enables encryption using LUKS on the device on the client side.
62-
# If set to true, the CSI driver will expect a volume-specific secret to be provided
63-
# with the encryption passphrase.
64-
# This secret must be referenced in the StorageClass with the keys:
65-
# csi.storage.k8s.io/volume-secret-name: <secret-name>
66-
# csi.storage.k8s.io/volume-secret-namespace: <namespace>
62+
# If set to true, the CSI driver will expect a passphrase to be provided
63+
# with the vast-mgmt secret.
6764

68-
# Example Kubernetes Secret for volume encryption:
69-
# kubectl create secret generic volume-secret-namespace \
70-
# --from-literal=passphrase='my-secret-pass'
65+
# Example Kubernetes Secret for host encryption:
66+
# kubectl create secret generic vast-mgmt --from-literal=username='' --from-literal=password='' --from-literal=endpoint='' --from-literal=passphrase=''
7167

72-
# Ensure the StorageClass has the following parameters set when volume_encryption is true:
73-
# csi.storage.k8s.io/volume-secret-name: volume-secret
74-
# csi.storage.k8s.io/volume-secret-namespace: default
75-
volume_encryption: true
68+
# Ensure the StorageClass has the following parameters set when host Eencryption is true:
69+
# Optional host encryption parameters (will default if not specified):
70+
# cipher: "aes-xts-plain64" # Encryption cipher
71+
# key_size: "512" # Key size in bits (e.g., 256 or 512)
72+
# hash: "sha256" # Hashing algorithm
73+
# pbkdf_memory: "65536" # Memory cost for PBKDF in KB
74+
hostEncryption: {}
7675
# Name of VAST VIP pool to use. Must specify either vipPool or vipPoolFQDN.
7776
vipPool: ""
7877
# The FQDN of the VIP pool to use. Must specify either vipPool or vipPoolFQDN.

examples/block/sc-vol-encryption.yaml renamed to examples/block/sc-with-host-encryption.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ parameters:
1010
csi.storage.k8s.io/provisioner-secret-name: vast-mgmt
1111
csi.storage.k8s.io/provisioner-secret-namespace: default
1212
subsystem: myblock
13-
vip_pool_name: vip1
13+
vip_pool_name: vippool-1
1414
transport_type: TCP
15-
volume_encryption: "true"
16-
csi.storage.k8s.io/volume-secret-name: volume-secret
17-
csi.storage.k8s.io/volume-secret-namespace: default
15+
hostEncryption:
16+
luks_type: luks2
17+
cipher: aes-xts-plain64
18+
key_size: "512"
19+
hash_algo: sha256
20+
pbkdf_mem: "65536"
1821
provisioner: block.csi.vastdata.com

vast_csi/block_utils.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,6 @@ def is_native_multipath_enabled():
3030
except Exception:
3131
return False
3232

33-
def is_luks_device(device_path: str) -> bool:
34-
"""
35-
Check if the given device is a LUKS-encrypted volume.
36-
37-
Args:
38-
device_path (str): The path to the block device.
39-
40-
Returns:
41-
bool: True if the device is LUKS, False otherwise.
42-
"""
43-
try:
44-
run(["cryptsetup", "isLuks", device_path])
45-
return True
46-
except ProcessExecutionError:
47-
return False
48-
49-
def is_crypto_luks(device_path):
50-
"""
51-
Determines whether the given device is a LUKS-encrypted block device.
52-
53-
Args:
54-
device_path (str): The path to the block device (e.g., /dev/nvme0n1).
55-
56-
Returns:
57-
bool: True if the device is using LUKS encryption (FSTYPE is crypto_LUKS), False otherwise.
58-
"""
59-
try:
60-
result = subprocess.run(
61-
['lsblk', '-no', 'FSTYPE', device_path],
62-
check=True,
63-
stdout=subprocess.PIPE,
64-
stderr=subprocess.DEVNULL,
65-
text=True
66-
)
67-
return result.stdout.strip() == 'crypto_LUKS'
68-
except subprocess.CalledProcessError:
69-
return False
70-
7133
def list_nvme_sessions():
7234
"""
7335
Example output:

vast_csi/builders/block.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BlockProvisionBase(BaseVolumeBuilder):
3737
capacity_range: Optional[int] = None
3838
pvc_name: Optional[str] = None
3939
pvc_namespace: Optional[str] = None
40-
volume_encryption: Optional[str] = None
40+
host_encryption: Optional[dict] = None
4141
volume_content_source: Optional[types.VolumeContentSource] = None # Either volume or snapshot
4242

4343
@classmethod
@@ -57,7 +57,7 @@ def from_parameters(
5757
vip_pool_fqdn = parameters.get("vip_pool_fqdn")
5858
vip_pool_name = parameters.get("vip_pool_name")
5959
volume_group = parameters.get("volume_group", "")
60-
volume_encryption = parameters.get("volume_encryption", "False")
60+
host_encryption = cls._extract_host_encryption(parameters)
6161
transport_type = parameters.get("transport_type", "TCP").upper()
6262
metadata = cls._parse_metadata_from_params(parameters)
6363
cls._validate_mount_src(vip_pool_name, vip_pool_fqdn, conf.use_local_ip_for_mount)
@@ -73,9 +73,9 @@ def from_parameters(
7373
tenant_name=tenant_name,
7474
transport_type=transport_type,
7575
volume_group=volume_group,
76-
volume_encryption=volume_encryption,
7776
vip_pool_name=vip_pool_name,
7877
vip_pool_fqdn=vip_pool_fqdn,
78+
host_encryption=host_encryption,
7979
cluster_name=cluster_name,
8080
volume_content_source=volume_content_source,
8181
**metadata,
@@ -104,6 +104,16 @@ def build_volume_name(self) -> str:
104104
# make sure the volume group is a valid absolute path
105105
return os.path.join("/", volume_group, self.name).lstrip("/")
106106

107+
@staticmethod
108+
def _extract_host_encryption(parameters):
109+
prefix = "host_encryption."
110+
host_encryption = {
111+
key[len(prefix):]: str(value)
112+
for key, value in parameters.items()
113+
if key.startswith(prefix)
114+
}
115+
return host_encryption
116+
107117
@property
108118
def volume_context(self) -> dict:
109119
context = {
@@ -116,8 +126,9 @@ def volume_context(self) -> dict:
116126
context["vip_pool_name"] = self.vip_pool_name
117127
elif self.vip_pool_fqdn:
118128
context["vip_pool_fqdn"] = self.vip_pool_fqdn_with_prefix
119-
if self.volume_encryption:
120-
context["volume_encryption"] = self.volume_encryption
129+
if self.host_encryption:
130+
for key, value in self.host_encryption.items():
131+
context[f"host_encryption.{key}"] = value
121132
return context
122133

123134

@@ -282,7 +293,6 @@ class StaticBlockVolumeBuilder(BaseVolumeBuilder):
282293
cluster_name: Optional[str] = None
283294
vip_pool_name: Optional[str] = None
284295
vip_pool_fqdn: Optional[str] = None
285-
volume_encryption: Optional[str] None
286296
transport_type: Optional[str] = "TCP"
287297

288298
@classmethod
@@ -300,7 +310,6 @@ def from_parameters(
300310
vip_pool_fqdn = parameters.get("vip_pool_fqdn")
301311
vip_pool_name = parameters.get("vip_pool_name")
302312
transport_type = parameters.get("transport_type", "TCP").upper()
303-
volume_encryption = parameters.get("volume_encryption")
304313
cls._validate_mount_src(vip_pool_name, vip_pool_fqdn, conf.use_local_ip_for_mount)
305314
cluster_name = parameters.get("cluster_name")
306315
return cls(
@@ -314,7 +323,6 @@ def from_parameters(
314323
vip_pool_fqdn=vip_pool_fqdn,
315324
transport_type=transport_type,
316325
cluster_name=cluster_name,
317-
volume_encryption=volume_encryption,
318326
)
319327

320328
@property
@@ -329,8 +337,6 @@ def volume_context(self) -> dict:
329337
context["vip_pool_name"] = self.vip_pool_name
330338
elif self.vip_pool_fqdn:
331339
context["vip_pool_fqdn"] = self.vip_pool_fqdn_with_prefix
332-
if self.volume_encryption:
333-
context["volume_encryption"] = self.volume_encryption
334340
return context
335341

336342
def build_volume(self) -> types.Volume:

vast_csi/builders/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestVolumeBuilder(BaseVolumeBuilder):
2727
cluster_name: Optional[str] = None
2828
vip_pool_name: Optional[str] = None
2929
vip_pool_fqdn: Optional[str] = None
30-
volume_encryption: Optional[str] = None
30+
host_encryption: Optional[dict] = None
3131
qos_policy: Optional[str] = None
3232
capacity_range: Optional[int] = None # Optional desired volume capacity
3333
pvc_name: Optional[str] = None

vast_csi/filesystem_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ def need_resize(device: str, target_mount, fs_type: str):
338338
return device_size > fs_size + block_size
339339

340340

341-
def resize_device(device: str, target_mount: str, fs_type: str):
341+
def resize_device(device: str, target_mount: str, fs_type: str, passphrase=None):
342342
"""Perform resize of the filesystem."""
343343
if need_resize(device, target_mount, fs_type):
344+
if passphrase:
345+
luks_manager = LuksManager(logger, device_path=device)
346+
luks_manager.luks_resize_device(passphrase)
344347
if fs_type in ("ext3", "ext4"):
345348
ext_resize(device)
346349
elif fs_type == "xfs":

0 commit comments

Comments
 (0)